ASP.NET Code Generator

Labels
AJAX(112) App Studio(7) Apple(1) Application Builder(245) Application Factory(207) ASP.NET(95) ASP.NET 3.5(45) ASP.NET Code Generator(72) ASP.NET Membership(28) Azure(18) Barcode(2) Barcodes(3) BLOB(18) Business Rules(1) Business Rules/Logic(140) BYOD(13) Caching(2) Calendar(5) Charts(29) Cloud(14) Cloud On Time(2) Cloud On Time for Windows 7(2) Code Generator(54) Collaboration(11) command line(1) Conflict Detection(1) Content Management System(12) COT Tools for Excel(26) CRUD(1) Custom Actions(1) Data Aquarium Framework(122) Data Sheet(9) Data Sources(22) Database Lookups(50) Deployment(22) Designer(177) Device(1) DotNetNuke(12) EASE(20) Email(6) Features(101) Firebird(1) Form Builder(14) Globalization and Localization(6) How To(1) Hypermedia(2) Inline Editing(1) Installation(5) JavaScript(20) Kiosk(1) Low Code(3) Mac(1) Many-To-Many(4) Maps(6) Master/Detail(36) Microservices(4) Mobile(63) Mode Builder(3) Model Builder(3) MySQL(10) Native Apps(5) News(18) OAuth(9) OAuth Scopes(1) OAuth2(13) Offline(20) Offline Apps(4) Offline Sync(5) Oracle(11) PKCE(2) Postgre SQL(1) PostgreSQL(2) PWA(2) QR codes(2) Rapid Application Development(5) Reading Pane(2) Release Notes(183) Reports(48) REST(29) RESTful(29) RESTful Workshop(15) RFID tags(1) SaaS(7) Security(81) SharePoint(12) SPA(6) SQL Anywhere(3) SQL Server(26) SSO(1) Stored Procedure(4) Teamwork(15) Tips and Tricks(87) Tools for Excel(2) Touch UI(93) Transactions(5) Tutorials(183) Universal Windows Platform(3) User Interface(338) Video Tutorial(37) Web 2.0(100) Web App Generator(101) Web Application Generator(607) Web Form Builder(40) Web.Config(9) Workflow(28)
Archive
Blog
ASP.NET Code Generator
Sunday, July 1, 2012PrintSubscribe
Drag and Drop, Cut/Copy/Paste, and More…

Code On Time release 6.0.0.29 includes enhancements to both code generation library and application design environment.

Generated web applications now support JavaScript Business Rules and Automatic Tracking of Selected Record. The Project Designer has been enhanced with drag & drop and cut/copy/paste  capabilities and offers “Navigate To” window that allows quickly locating project configuration elements.

The following features, enhancements, and bug fixes are included in this release:

  • Drag & drop and cut/copy/paste are support for pages, containers, data views, controls, user controls, controllers, and commands. Other project configuration elements will also be enhanced in the coming weeks.
     
  • The entire data controller can now be cloned.
     
  • Project Designer properties of menu configuration elements can be easily synchronized with Project Explorer.
     
  • Navigate To window allows quickly finding project configuration elements.
      
  • Code generator automatically combines all JavaScript files found in [Documents]\Code OnTime\Library\_Client\Scripts folder in a single _System.js file. The file is included in the generated web applications of all types.
     
  • Automatic Tracking of Selected Record is supported by the client library. Developers can take advantage of selected record synchronization.
     
  • New search option $autocompleteanywhere will cause the auto-complete to search anywhere in the field values. By default, the framework searches using "Begins With" operation, which generally performs better, but will not yield partial matches.
     
  • Data field property "Search Options" supports $disableautocomplete, $disablesamples, and $disablemultiplevalues options.
     
  • Modal form views now support dragging of the header.
     
  • View Details shows a modal view that will refresh the original source if changes are made.
     
  • "Hidden" fields will be displayed in summary if marked as "Show In Summary".
     
  • Master data sheet views automatically set focus on the first cell of the first row.
     
  • "Flat" actions will display the action description as a tooltip.
     
  • Implemented a fix for Import Processor to ensure that field values that are missing in import file are created to simulate as if the values were entered in the user interface form. Previous implementation has passed the non-blank values only. This makes it possible to implement UPSERT when importing data records.
     
  • Code On Time will now pre-process the designer logs before navigating to the data controller summary.
     
  • Localizer now takes into account the name of the module/webpart when caching the resource strings.
     
  • Project Explorer tab now feature "Home" button that shows List of Pages, List of Controllers, or List of User Controls.
     
  • The issue with the left border in AjaxControlToolkit tabs is fixed in all themes.
     
  • Sorting on fields with Format On Client = false will not cause a runtime exception.
     
  • Method Controller.UserInInRole is now creating an instance of ControllerUtility class to verify the user identity. This allows implementing custom role validation against SharePoint or DotNetNuke user groups.
     
  • ControllerDataSource will correctly perform Update/Insert/Delete operations when C#/VB business rules are associated with the data controller.
     
  • Component ControllerDataSource will use "=" filter operation if FilterParameter instance has its DBType property set to any value other than Object or String.
     
  • Aggregate fields are correctly formatted on the server when "Format On Client" property of a data field is set to "false".
     
  • It is possible to specify "about:blank" as the URL of top level pages without breaking the rendering of Advanced Menus.
     
  • Context Field Filters now support static filters in the both formats:
    FieldName = 12345 and FieldName='12345'
      
  • Decimal parameters are automatically initialized as Decimal(38,10) in SQL Business Rules and SQL action.
     
Monday, January 9, 2012PrintSubscribe
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.

image

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.

image

Here is the sub-tree of the Customers data controller with the  Report action selected.

image

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.

image

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.

image

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.

image

The custom method will execute and you will see the following prompt to download the file AROUT.jpg if you browsing with IE 9.

image

Click Open and the default image viewer will start.

image

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.

Thursday, January 5, 2012PrintSubscribe
Baseline + Log = Cache

Code On Time has released update 6.0.0.18.

This release introduces important changes to the code generator architecture that will speed up code generation.

Understanding Baseline and Cache

The previous version of the code generator created baseline application and controller collection files every time the project is generated. The temporary baseline was deleted right after the completion of the code generation. The logs of Designer changes to the application and controller collection are stored in Application.Log.xml and Controllers.Log.xml files. The transactions from the log files were applied to the corresponding baselines during each code generation session.

Things have changed with this release.

The baselines is now permanent.

You will notice four new files as soon as you change and/or generate a project.

The files are Application.Baseline.xml, Application.Cache.xml, Controllers.Baseline.xml, and Controllers.Cache.xml.

The "baseline" files are persistent copies of the baseline app and controllers.

"Cache" files are results of applying the designer transactions from the log to the "baseline".


Application.Baseline.xml + Application.Log.xml = Application.Cache.xml

Controllers.Baseline.xml + Controllers.Log.xml = Controllers.Cache.xml


You can copy the baseline from one project to another or change the baseline in XML editor if you need to move a part of your app to another existing/new project.

The new Refresh mechanism will delete *.Cache.xml files and will also offer developer a chance to indicate if any controllers in Controllers.Baseline.xml must be replaced with the fresh copy constructed by the code generator. Application baseline will be intact. Any new "host" pages for new data controllers will be added under "New Pages" node in the application. An example of using Refresh can be found at /blog/2011/12/ease-auditing.html.

The net effect is as follows:
1. If your project has a large number of designer changes then it may take a long time to process the log. The new release will process them once and will not do so again until a Project Refresh is requested. This will bring the time to process the log to zero.

2. If you change the project in Designer then the changes are written to the *.Log.xml and to the *.Cache.xml file at the same time.

3. Introduction of baselines will eliminate the issue of controllers acquiring unwanted fields that reflect changes to the database. The application navigation menu will also remain unchanged. Any new pages constructed by the code generator will show up in a predictable "New Pages" node.

Other Changes

The list of enhancements included in the release.

  • You can now develop your applications OFFLINE even if you are not connected to the internet.
     
  • New “Social” theme is now available.
    image
     
  • The project summary page has been enhanced to offer Design, Settings, Refresh, and Generate actions.
    image 
     
  • Implementation of Created By/On and Modified By/On will not interfere with the Import.
     
  • Import correctly displays the upload controls when executed under local web development server.
     
  • New “White Smoke” theme is now available.
    image
     
  • Action bar assigns "First" and "Last" CSS classes to the corresponding action  buttons in "flat" action groups.
     
  • Annotation Icon on the action bar has been restored.
     
  • Customized properties Description and Confirmation defined on standard actions are not overwritten by default values. For example, entering a confirmation on Delete action does not require a customized HeaderText of the action.
     
  • Action "Settings" displays a list of Project Wizard shortcuts. Shortcuts provide quick access to specific configuration settings group. Button Finish is displayed in all groups to allow convenient completion of configuration.
    image 
     
  • Standard control Welcome has a margin at the bottom and will not overlap with the data views and controls that belong to the same container.
     
  • Chart view with "Show View Selector" = False will not raise an exception at runtime.
     
  • Exit from Designer while the preview is generated will not result in exception if user activtes the designer and tries to preview once more.
     
  • Referential integrity verification mechanism has been integrated in Designer. The first check is removal of any references to a data field from other categories of a data view when a data field is moved or inserted in a different category.
    A data field can exists only in once category in a view.
     
  • Horizontal scrolling position is now retained in Project Explorer when an project element is changed in Designer.
     
  • All pages of Project Wizard now feature icons in headings of pages to match the menu of page shortcuts.
       
  • Project Wizard now supports Left Shift+Next shortcut to skip the rest of the steps remaining. Left Shift + Next will proceed to the summary of data controllers.
     
  • Sample images of themes are now integrated in the Project Wizard. 
     
  • Missing "partial" attribute on ControllerUtilities class is not available.

Continue to Northwind Sample