Code On Time release 6.0.0.20 includes various improvements to the many new themes introduced in the previous release.
Sunday, January 22, 2012
SharePoint Factory
Microsoft SharePoint Foundation 2010 is the fast growing corporate intranet portal gaining momentum in the development community and businesses. Powerful collaborative platform attracts developers and business users finding creative ways to utilize easy-to-build custom lists integrated with user generated content.
Developers soon discover that the custom list capabilities are limited and Microsoft does not recommend creating lists exceeding a couple of thousand records. The natural solution is the traditional database. Fortunately the development of applications based on Microsoft SharePoint is very simple. Install SharePoint Foundation 2010, build your app using Visual Studio 2010 and deploy to the server instance from Visual Studio.
There is a downside as well. It is your responsibility to write the code interacting with the database and presenting the results to the end users.
Code On Time and SharePoint Factory will greatly simplify the production of powerful database web applications that can be deployed natively to Microsoft SharePoint portals. These web applications will have a perfect visual match to SharePoint user interface elements. Generated web applications will provide data filtering and searching capabilities exceeding the comparable features of custom SharePoint lists while handling database tables of any size.
Installing Development Tools
Start by installing a Microsoft Foundation 2010 on your Windows 2008 or Windows 7 machine. We have compiled a useful tutorial that guides through the SharePoint Foundation 2010 installation steps.
Download and install Visual Web Developer Express and SharePoint Tools.
Download Code On Time web application generator at http://codeontime.com/download.aspx and install it on the same computer.
For the purpose of this tutorial we will create a web application that uses Microsoft SQL Server as the database backend.
Building a SharePoint Factory Project
Start Code On Time and select SharePoint Factory in the list of available project types.
Enter the project name and select the programming language that must be used to generate the project source code.
Click Create and validate the connection to your SharePoint instance.
Proceed to the Database Connection page of the project wizard. Click the button next to the Connection String input field. Enter the server name. If you are connecting to SQL Express instance then enter “.\SQLExpress”. If you have an instance of SQL Server then enter “.” in the Server field. Configure the login identity.
We will create a blank database and populate this database with the sample Northwind dataset. You can connect to an existing database if you wish.
Enter “SharePointNorthwindDemo” in the Database field and click Create button, select “Northwind” in the Sample Tables drop down and click Install.
Click OK button and continue to Reporting page of the project wizard. Enable dynamic and static reports and proceed to the Features page.
Activate Package Properties section and enter the title and description values as shown in the picture.
Click Next a few times until your reach the page displaying a summary of application data controllers. Proceed to generate the web application.
A sample web site will launch in the default browser when the web application code generation is over.
The web application displayed in the web browser does look a lot like Microsoft SharePoint portal. In fact, this is a sample ASP.NET web site created as a part of your project to allow quick prototyping and design that does not involve the actual instance of the portal.
The right-hand side of the page presents an area similar to the actual SharePoint Web Part property editor. Select the logical application page constructed by the code generator to activate the Preview mode.
Click OK button and you will see the selected logical application page in action.
Use Code On Time designer to customize the web application as needed.
Deploying SharePoint Factory Web Applications
The constructed web application solution include a special project that implements a single SharePoint 2010 web part. Web parts are building block of SharePoint sites.
Here is how you can deploy the application to the SharePoint portal installed on your computer.
Select the project name on the start page of the web application generator and click Publish.
The code generator will package the application for deployment and in a few short moments you will see a Windows prompt asking to allow the command line processor to alter settings on your computer.
The prompt will be launched to execute a Windows PowerShell installation script that requires elevated permission to run. The script will deploy your application to the SharePoint instance on your computer.
You will also see a folder with binary files that can be passed to your network for deployment on the production server. Notice that Deploy.bat and Retract.bat batch files are configured to run specifically on your computer and the administrator will have to change them to work correctly in the production environment.
Both batch files require elevated permissions to run. You can retract or re-deploy your web application if you right-click the corresponding file and choose “Run As administrator” option.
Using Generated Web Application in SharePoint
If the deployment has been successful then you are ready to start using your web application.
Launch a web browser and navigate to your local SharePoint instance. The following page will be displayed.
Create a new page by selecting Site Actions | New Page option in the menu.
Enter “Products” as the page name field and click Create button.
The new page will be displayed in design mode.
Select Insert tab on the ribbon and click Web Part button.
Select Web Apps under categories. You should see the single web part named “Share Point Factory Demo” listed under the category.
Click Add button to insert the web part in the page.
You will see the instruction in the main area of the page suggesting to select the logical application page. This is the default message rendered by your application when the web part is inserted in the page layout.
Choose Edit Web Part option in the context menu of the web part on the page.
Select the logical page Categories | Products and click OK button.
Exit page design mode and try interacting with your web application.
The next screen shot shows a SharePoint Factory web application up and running in the actual SharePoint portal.
Conclusion
SharePoint Factory and Code On Time allow quick and easy creation of powerful database web applications designed to operate in Microsoft SharePoint portal instances.
Create a collection of application pages implemented as user controls; package them for deployment as Microsoft SharePoint 2010 Feature with a single Web Part. Integrate a line-of-business database application with a widely adopted corporate web content management system.
Saturday, January 21, 2012
SharePoint Factory is Out!
Code On Time release 6.0.0.19 includes new code generation project SharePoint Factory and miscellaneous product enhancements.
This release includes the following features and enhancements:
- SharePoint Factory web application project.
- Theme page of the project wizard now offers an index of all theme samples.
- New themes: Mission, Laminate, Grapello, Graham, Convention, Construct, Cay, Bittersweet, Berry, Municipal.
- DotNetNuke Factory will produced a Visual Studio 2010 project if Visual Studio 2010 is detected.
- New "strongNameKey" code generator instruction creating a random key pair with the help of Strong Name Utility is integrated in the code generator. If the SNU is not available then the standard key is copied from the library to the output. This feature is provided to support SharePoint Factory.
- EASE EventTracker class has been updated to ensure compatibility with Visual Basic.
- Alias Field Name property of data fields is left blank if the Discovery Depth is set to zero.
- Suppression of duplicate foreign keys is now performed by the code generator in all project types. Duplicate foreign keys were previously causing erroneous code generation.
- "Project Refresh" window now offers Select All/None buttons to allow quick selection of all items.
- Quick Find performs a case-insensitive search in projects using Oracle backend.
- Settings "Features | Grid | Enable standard action column in all grid views" will add an action column to all views of an application.
- Click on a "View Details" link next to a lookup field in a master view will not stop refreshing of child views when the selected master record has changed.
- Slow running detail views will automatically cancel data requests if the master has changed. The previous implementation may have resulted in the wrong detail data displayed if the selected master record has changed before all details were retrieved.
- It is now possible to process "Report..." actions in business rules.
- Designer log progressing progress in now displayed in the log box of the code generator. This will be noticeable with large change longs only when the project is refreshed.
- Batch Update in grid view will not raise an "Unauthorized command..." exception when user tries to save the changes.
- Connection String Name defined in the data controller properties is correctly used in the generated apps. Read about implementing multi-database projects at http://blog.codeontime.com/2012/01/multiple-databases.html.
- Check for updates is automatically initiated when an activation code is registered.
Tuesday, January 10, 2012
Multiple Databases
Multiple Database support has been added in Code On Time web applications. The feature will be available in the next release. If you want the capability now, submit a ticket and request the multiple database hotfix.
Learn how to set up a web application that accesses data from multiple databases at http://codeontime.com/Documents/UG-Multiple_DB.pdf.
Monday, January 9, 2012
Converting Designer Spreadsheet to Baseline
Code On Time’s Designer Spreadsheet has been a popular tool for editing Code On Time applications in a rapid fashion. Unfortunately, it uses a different method for saving changes and has been phased out of use. However, this feature will soon be replaced with a new and improved version – Code On Time Tools for Excel. Those of you who used Designer Spreadsheet on your projects will need to migrate a few files to make sure all your changes are migrated to the newest version of Code On Time Generator.
First, you will need to find the folder location of your project. This can be easily done by running Code On Time Generator, selecting the project name, and press Open. Alternatively, you can navigate to My Documents/Code OnTime/Projects, and find it there. The folder should look like this.
You will need to delete the following four files:
Application.Baseline.xml
Application.Cache.xml
Controllers.Baseline.xml
Controllers.Cache.xml
All the changes made to the application in the Designer Spreadsheet are recorded in the file Controllers.Master.xml. Make a copy of the file, and rename the copy to Controllers.Baseline.xml.
You will need to make one more change to ensure that categories are processed correctly. After the Designer Spreadsheet was released, an id parameter was added to all categories. This field will need to be added to all of the old categories in the baseline file. Otherwise, Code On Time Designer will not place any data fields in the categories, as shown below.
Open this file in your preferred editor (we used Visual Studio). Find the first category, and add an id parameter to this category.
You will have to perform this operation on the rest of the categories as well. Find and Replace (Ctrl + H) is highly suggested at this time. Each category in the same view must have a unique id. If you have added multiple categories to the same view, you must manually change the id.
Once all the categories have an id, it is safe to save this file and open the project in Code On Time Generator. You can see that the data fields are now correctly nested in the proper category.
We apologize for any inconveniences this move may have made, but we believe that you will find Code On Time Tools for Excel to be a vast improvement, and well worth the upgrade.
Sunday, January 8, 2012
Standard Action Column in Grid Views
Code On Time release 6.0.0.19 and higher supports a new configuration option that automatically creates an action column with the standard actions Edit and Delete in all grid views of a generated web application.
Create a new Northwind sample project. Make sure to change the Features settings of the project as shown below when you step through the pages of the Project Wizard.
Generate the web application and you will notice that all grid views now feature Edit and Delete actions in the very first column.
If you select Edit action then the selected record will open editForm1 in edit mode.
Action Delete will display a prompt to delete the record.
If you have an existing application and want to incorporate an action column then either “refresh” the data controller or define a custom action group with the scope of Action Column so that it will looks as the following snapshot of the data controller in the Project Explorer. This particular screenshot represents the automatically configured action group.
Remember that you can add any number of actions including the custom ones in any action group.
Only one action group with the scope of “Action Column” is supported by the client library of your application.
Handling “Report…” Actions
Code On Time web applications support out-of-the-box reporting capabilities that require zero programming.
Standard Report Actions
All data views offer four standard actions that yield a different output.
- Action “ReportAsPdf” will render the data presented to end users as a Adobe PDF document. The shorthand action “Report” will produce the same result. This type of report requires a compatible software installed on the client computer to view and print the report output. You can download free Adobe Acrobat Reader at at http://get.adobe.com/reader.
- Action “ReportAsImage” creates a TIFF image file, which requires a compatible software installed on the client. TIFF format supports multiple pages and is a perfect alternative to PDF. The quality of output in PDF and TIFF formats is equivalent.
- Action “ReportAsWord” renders a report as Microsoft Word document with a high-quality output. In some instances the output is less precise then the output produced by the action “ReportAsImage” and “ReportAsPdf”.
- Action “ReportAsExcel” produces a Microsoft Excel spreadsheet that offer a lesser quality output due to rendering restriction of the popular spreadsheet software.
If a user requests a “Report...” action then a report is rendered on the server with the help of Microsoft Report Viewer. The output is streamed to the client browser. Typically a prompt is displayed before a compatible installed software viewer will be activated. Users also have an option to save the output locally. If a viewer is not installed on the client computer then the prompt to save the file is the only option.
Code On Time web applications execute various server calls off-band to provide smooth Web 2.0 user experience. Modern web browsers make sure to prevent all sorts of popups initiated by the scripts embedded in the web pages. The client library makes use of correct techniques to process reports on the server without causing automatic activation of popup blockers.
Custom Report Action Handlers
Code On Time web applications created with version 6.0.0.19 or higher allow developers to perform custom processing of reporting actions in business rules. There are several reasons that may require an execution of custom code that must precede or override the standard report rendering logic:
- The data must be “prepared” before a report is rendered.
- The report request must be logged.
- An external report rendering engine is available. The custom code will redirect the report request to such an engine.
- A special report preview page needs to be displayed.
- A custom report building code must execute. The custom code replaces the standard report rendering logic.
Create a business rule for your data controller and implement methods to handle the corresponding “Report...” actions when you need to override the standard report processing.
Example
Generate a Northwind sample using Code On Time web application generator.
Select the project name on the start page of the code generator and click Design.
Select Controllers tab in the Project Explorer and enter CustomerBusinessRules in the Handler property of the Customers data controllers. Click OK to save the changes.
Expand Actions node of the Customers data controller in Project Explorer, right-click Actions and create a new action group with the Scope of Action Column.
Add a new action in the newly created action group, set its Command Name to Report, and Command Argument to _blank.
Here is the sub-tree of the Customers data controller with the Report action selected.
Click Exit on the Designer tool bar and generate your application.
Select the project name on the start page of the web application generator and choose Develop. Visual Studio or Visual Web Developer will start.
Locate the file ~/App_Code/Rules/CustomerBusinessRules.cs(vb) and enter the following code.
C#:
using System; using System.Data; using System.Collections.Generic; using System.Linq; using MyCompany.Data; using System.IO; namespace MyCompany.Rules { public partial class CustomersBusinessRules : MyCompany.Data.BusinessRules { [ControllerAction("Customers", "Report", "_blank")] public void RedirectToCustomReport(string customerId, string companyName) { // Redirect user to another URL Result.NavigateUrl = String.Format( "~/Pages/Customers.aspx?CustomerID={0}&_controller=Customers" + "&_commandName=Select&_commandArgument=editForm1", customerId); } [ControllerAction("Customers", "ReportAsImage", "")] public void GenerateCustomReport(string customerId, string companyName) { PreventDefault(); // return the same image in response to all "Report..." commands Context.Response.Clear(); Context.Response.ContentType = "image/jpeg"; Context.Response.AddHeader("Content-Disposition", String.Format("attachment;filename={0}.jpg", customerId)); byte[] reportData = File.ReadAllBytes(@"C:\Users\Public\Pictures\Sample Pictures\Koala.jpg"); Context.Response.AddHeader("Content-Length", reportData.Length.ToString()); Context.Response.OutputStream.Write(reportData, 0, reportData.Length); } } }
Visual Basic:
Imports MyCompany.Data Imports System Imports System.Collections.Generic Imports System.Data Imports System.Linq Imports System.IO Namespace MyCompany.Rules Partial Public Class Customers Inherits MyCompany.Data.BusinessRules <ControllerAction("Customers", "Report", "_blank")> _ Sub RedirectToCustomReport(ByVal customerId As String, ByVal companyName As String) ' Redirect user to another URL Result.NavigateUrl = String.Format( _ "~/Pages/Customers.aspx?CustomerID={0}&_controller=Customers" + _ "&_commandName=Select&_commandArgument=editForm1", customerId) End Sub <ControllerAction("Customers", "ReportAsImage", "")> _ Sub GenerateCustomReport(ByVal customerId As String, ByVal companyName As String) PreventDefault() 'return the same image in response to all "Report..." commands Context.Response.Clear() Context.Response.ContentType = "image/jpeg" Context.Response.AddHeader("Content-Disposition", _ String.Format("attachment;filename={0}.jpg", customerId)) Dim reportData As Byte() = _ File.ReadAllBytes("C:\Users\Public\Pictures\Sample Pictures\Koala.jpg") Context.Response.AddHeader("Content-Length", reportData.Length.ToString()) Context.Response.OutputStream.Write(reportData, 0, reportData.Length) End Sub End Class End Namespace
The first method RedirectToCustomReport will use the ID of the selected customer to compose a URL relative to the application. The URL will open in a new browser window and will force the application to select a customer with the specified ID.
The new window will open if your have entered the command argument as “_blank” when defining the action in Project Designer. If action command argument has been left blank then the new URL will replace the page in the web browser. Users will have an option to return to the previous page using the browser’s Back button.
The screen shot of the Customers page prior to execution of our Report action is shown next.
If you click on the Report button then a new browser window will open. You can see the address bar reflecting the ID of the selected customer.
Our web application is using its own capabilities to present the data with the help of data controller URL parameters. You can redirect the report action to a generic web request handler or to a web-enabled report server such as Crystal Reports or Microsoft SQL Server Reporting Services.
The second method GenerateCustomReport takes control over the report rendering completely.
First, the method cancels out the default reporting logic at the very beginning by calling PreventDefault.
Next it reads the file C:\Users\Public\Pictures\Sample Pictures\Koala.jpg and streams it out. In a real-world application you can produce any sort of output using a custom code.
The method uses the customer ID to assign the file name to the output.
If you are reproducing this sample on a Windows 7 computer then there is not need to change the code . Otherwise change the path to the image file accordingly.
Run your web app, navigate to Customers page and select a customer.
Choose Report | Multipage Image on the action bar above the list of customers.
The custom method will execute and you will see the following prompt to download the file AROUT.jpg if you browsing with IE 9.
Click Open and the default image viewer will start.
If you select any other customer and choose the same action bar option then exactly the same image will be downloaded but the file name will reflect the actual primary key of the selected customer.
In a real-world applications you will likely stream other formats of output such as PDF or custom Microsoft Office documents using 3rd party reporting software.
