Skip to main content

Posts

Showing posts from 2014

Advance enum generation for lookup table through T4

Sometime back I had written simple T4 to generate enum for look up tables http://vikutech.blogspot.in/2014/01/enumeration-generation-for-lookup-table.html . Later on I had posted same on Nu-Get https://www.nuget.org/packages/t4.lookup . This time I am going to extend it to support multiple enums, enum Id, configuration through class and different settings for enum description, columns. Here is the entire code for generating code <#@ template debug="true" hostSpecific="true" #> <#@ output extension=".cs" #> <#@ Assembly Name="System.Data" #> <#@ import namespace="System" #> <#@ import namespace="System.Collections.Generic" #> <#@ include file="EF.Utility.CS.ttinclude"#> <#@ import namespace="System.Data.SqlClient" #> <# // TODO: Look for alternatives to remove connection string var connectString = "data source=.;initial...

Strong typed MVC routing on TypeScript/JavaScript

Very often we mess up with routing by giving path which does not exist due to various reason like spelling mistake, name confusions etc. for forming correct URLs . This happens on both server side codes and client side code. There are few strong typed routing provider library present for server side but none is present on the client side. We will look into creating a classes and function to set up our routing paths which will help us to give correct URL based on MVC routing. The idea is to create T4 template file which will be generating client side codes based on MVC routing. I have tried to keep it simple in this version which reads up MVC controllers and public function. The end result looks like this, which is TypeScript code. Makes it pretty simple to use these classes directly without worrying about correct URLs. module Routing { export declare var DomainName: string; export function GetDomainName(): string { return (DomainName != undefined && ...

Basic OOPS concept with TypeScript

Some time back I had written article on Introduction of TypeScript . We already know that OOPS concept can be used on JavaScript, but with TypeScript we can achieve in much simpler way. In this particular article we will check interaction of object in different way to handle HTML interaction situations in cleaner way with the help of objects and functions. We will check out by creating TS interface and passing it to some other function which will change some of the object properties and same can be communicated back to the source. I am trying to keep things simple only by using simple approach interface ICar { Model: string Speed: number; SpeedChange: (speed:number) => void; } Let's consume the above to other class which can be initialized be calling constructor. It is having simple method which is defining the SpeedChange body. class Main { constructor(private option: ICar) { option.SpeedChange = (speed) => { console.lo...

Auto fluent mapping generation for OpenAccess/Telerik DataAccess through T4

There is two way to map code first with DB related entities. The first is data annotation which is like setting attributes and the other one is fluent mapping. Fluent mapping is very powerful and flexible approach to map entities. The only downside of fluent mapping is incompatibility with client side validation where as MVC has inbuilt functionality to validate on client side with data annotation. We will look into basic fluent mapping generation along with data annotation if present. Default data annotation is not compatible with Telerik DataAccess/OpenAccess. This article does not gives information about how fluent mapping works or how to generate it but auto generation of fluent mapping by any give model. Pre-requisites for fluent generation I have took help of two different libraries to generate fluent mapping for OpenAccess. -  MultiOutput.ttinclude  ( https://github.com/subsonic/SubSonic-3.0-Templates/blob/master/ActiveRecord/MultiOutput.ttinclude ) : This is to ...

Dependency Injection through XML configuration and XML transformation through SlowCheetah

Dependency Injection (DI) is a design pattern to change definition by substituting object without changing code for the application. The most popular DI type is to construct classes based on certain interface and pass actual object on constructor level. What are we trying to do? We will be looking into a way to achieve dependency injection through XML configuration based on  build selection . The implemented classes derived through interface will get switched based on build selection. Where to use it? I really hate making dependencies with something specific which can be changed later on. In my case, Azure environment. I believe Azure is more like a platform where we can host the application rather then integrating the application with Azure. What if client decided to switch to other hosting environment, in that case we got to change every piece of code wherever Azure SDKs are referred. The above one is merely an example. We can use this approach on many other item as wel...

Storing and restoring Kendo Grid state from Database

There is no any built in way to store entire grid state into database and restore back again with all filters, groups, aggregates, page and page size. At first, I was trying to restore only filters by looking through DataSourceRequest. DataSourceRequest is kind of communication medium between client and server for the operation we do on grid. All the request comes via DataSourceRequest. In previous approach, I was trying to store IFileDescriptor interface which come with class FileDescriptor by looping through filters and serializing into string for saving into database but this IFileDescriptor can also contain CompositeFilterDescriptor which can be nested in nested object which are very tricky to handle. So, I had decompiled entire Kendo.MVC library and found out that all Kendo MVC controls are derived from “JsonObject”. It is there own implementation with ”Serialize” abstract function and “ToJson” function. In controls they are overriding “Serialize” method which depicts t...

Extending WhenAny,WhenAll like feature to get the task as soon as it completes

While working with list of task, we only get two built in options to retrieve task info for completion. First is WhenAny and other WhenAll. WhenAny can be used when any of the given tasks gets completed first where as WhenAll notifies when all of the task gets completed. There is no option to know each task as soon as it gets completed. I was going through  Pro Asynchronous Programming with .NET  book which shows better option to deal with notification of task completion efficiently. To return the task on completion,  TaskCompletionSource  will be used . Through TaskCompletionSource,  Task  could be created and with provided inbuilt methods outcome can be handled. This can be also helpful to wrap up legacy codes as well to built up task. Let's directly look in to core code to return task based on completion. /// <summary> /// Order by completion for Task. /// </summary> /// <typeparam name="...

Displaying progress status in asynchronous programming

UX is most important in any application and responsive application is an add-on to make UI free by running long running task in background. Sometimes we need to show more useful information about long running task to keep user informed about progress. In this article, we will be looking into showing up progress status for long running process with Task Parallel Library (TPL). In this particular example, we will be creating a Console application to re-size any amount of jpg files under directory with new image dimension but our main focus would be on showing progress status. Prior to .Net 4.5 Framework version, there was no inbuilt mechanism to show status of task. If it was needed, then we need to create event handler on class that is processing the long running task with custom defined event argument for progress status class and then subscription need to be done on consuming class for getting progress information. This was better and tidy approach for getting progress status...

TypeScript introduction

In newer web application development we are more and more diving into client side scripts. Slowly AJAX calls are completely or at least mostly replacing regular post backs for rich user experience. Somewhere we are dealing HTMLs returns or just interacting with model but with time we are ending up writing lot of JavaScript on pages or dedicated JavaScript files. After starting project, in short of span of time we are ending up with lot of scripts. Writing those script itself is problematic process as we do not get any type safety and on execution only we can know we have missed typed or added some variable in place of some other type. Mostly through comments only we are understanding the code association with pages unless we put JavaScript in respective pages or with naming JS according to respective page names. I know we can use some OOPS concept or JS framework like Backbone, Knockout etc. to manage things through MVC or MVVM approach. Those are really good way to handle JavaScr...

Strongly typed configuration through database

We usually save most of application setting under app.config or web.config with key and value pair under appSetting element. The big problem with those are whenever you need value, typecasting need to be done and also need to be called through key. The other problem I find is with hierarchy of settings like download related setting present should under download element for easy accessing. To solve strongly typed configuration and hierarchy, ConfigurationManager ( http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager(v=vs.110).aspx ) class comes for rescue. You might have seen under web.config where we have sectionGroup and related configuration under elements. To implement it, lot of codes need to written to achieve simplification. To reduce numbers of codes for implementing XML configuration a very good and free tool is available called "Configuration Section Designer" available on http://csd.codeplex.com/ . There we do not have to wri...