Sunday, February 12, 2012



Licensing a product with the help of Licenser


Introduction:


This article explains the importance of why licensing a product/application is important. Also explains how we can re-use open source License Manager Tools in our application.

Consider a scenario where in you have developed a small application for a customer. At first you may not be thinking about licensing part. You may have developed as a prototype or a proof of concept and deliver it to the customer. She/he may be happily using all the features that you have provided in your application. The customer may also install and use your application in more than one system.




Eventually as the product/ application features get enhanced, one has to think about how we can license a feature so that we can restrict the clients from being using that. Or you can think about selling your product based upon some features. This is where product or application licensing by features comes into picture and it is very much important for a product/ application developer or an organization.



We shall see how to license our applications with the help of one Open Source codeplex tool named Licenser which is located at http://licenser.codeplex.com/



The Licenser package has the following things:

1. Licenser / Production – A license production tool

2. Licenser / API – An API for checking a license
3. Licenser / Identification – A tool that is used one-time by the end-user to display the computer id.
  
The first thing which is required for licensing is the client computer id. Ask your client to run LicenserIdentification.exe and send the computer id.


Creating a License File:

Once you receive the customer Id you are ready to go with generating a license for your client. Run LicenserProduction.exe , Click on File -> New


Fill in the customer details and save it.
Right click on the customer and click on New License


You need to fill in the following details and click on OK button to save the information
1.     Product name: Name of the product for which you want to license.
2.     License Type:
a.  Node Locked License: You are licensing based upon the computer Id.
b.  Demo license: Used for demo purpose and not in production.
3.     Password: The password with which you want to license you client. You can choose any password and send it across to your client. The client will make use of this while using the product. The LicenserAPI will validate based upon the License file, password and Feature name.
4.     Computer Ids: Computer Id of the client for which you want to generate a license.

Adding product features for licensing

In the Feature grid, key in the Feature Name. You have an option to make it either time dependent or not. If ‘IsTimeDependent’ is checked then you will have to provide the Expiration date.
Click on ‘Generate’ button to generate the License file. A Save dialog will be opened with a default file name. Just select the location where you wish to save the license file.



Test License

Now we will see how we can test the license by product feature from the LicenserProduction tool.

Under Customer -> Right click and select Test License. Below is the screen which pops up.


Testing the license file requires the following.

1.  Selecting the License file.
2.  Key in the password that you have chosen while generating the license for your customer.
3.  Enter the Feature name for which you want to test.

Click on ‘Test’ button to verify whether the LicenserAPI validates with the information which you have provided.

So now you got the license file, it has the list of features with which you can validate for a client to see if we can allow him to use a feature or not.                                                 

You will have to use this information in your application to validate the client and provide access to use only those features which are meant for him.


Behind the scene of a Licenser Tool:


The produced license file is digitally signed and it’s also specific for the licensed computer.
·  
   In order to enhance security, the application has to pass to the licenser a PASSCODE during run-time.
·  
   There are no restrictions for the number of features being licensed for the product.
·  
  The feature information, as well as the licensed computer identification together with the PASSCODE is encrypted into a digital signature that is written in the license file. So any tampering done to the license file say by modifying the information within it will invalidate the license.

Thursday, February 9, 2012


Convert PowerPoint to HTML

Introduction:

A tool developed to convert PowerPoint to HTML. It was completely developed using .NET Framework 4.0 Winform Technology.

Consider a scenario, where you are preparing some presentation for a client. Assume the client may not be having a PowerPoint installed in his/her machine, he/she may wish to view the same PowerPoint presentation through static HTML pages.

This tool evolved from the above requirement. It takes PowerPoint as input and converts the same to static HTML pages.

Note: Surprisingly the MS PowerPoint did not provide an option to Save As HTML.

Features of this tool:

1.     Convert PowerPoint to HTML static pages.
2.     Save HTML folder path settings: Once the settings are saved by the user; the HTML folder settings will be read and displayed on the html folder path textbox for the subsequent use of the application.
3.     Minimize on System tray option: You can simply minimize the application if you are not currently using it. On minimize, the convertor will be on the system tray. You can notice a folder icon for this tool in system tray.


Snapshots:
1.     Main screen


2.     Select a PowerPoint by clicking on the Open PowerPoint File button. Then type the HTML folder path.





3.     Click on the ‘Convert to HTML’ button to convert the Powerpoint presentation to HTML static pages.


4.     Folder settings

5.     About Us

Sunday, January 29, 2012


Remote System Monitoring and Controlling via Web based Mobile or Desktop Application

Introduction:

The idea of remote system monitoring and controlling application is to do some of the actions like ex: Shutdown, Reboot, Hibernate of the users systems remotely. The user can also make use of this application to query additional details of the systems.
Consider a scenario where you have a set of systems (Computers) and you want to control them from your mobile or any other desktop anywhere from the world. So this started as initial requirement of how we can implement the same to control numerous systems remotely.
Consider another scenario of how you can retrieve the information of a particular system remotely from your handheld devices or through desktops. By retrieving information, one may be interested in knowing the following

1.       Machine Name
2.       CPU information
3.       Username
4.       Domain Name
5.       OS Version

Software Requirements Specification

1.       Aim: The aim of this project is to provide a facility for the end user to remotely control their systems through desktop or mobile based web application.
2.       Purpose: The purpose of this project is to implement a proof or concept of the same. And to show how easily it can be done with .NET technology
3.       Scope: The scope of this project is very limited to controlling the system with few actions like Shutdown, Reboot, Hibernate, Logoff, Force close all applications etc. The user registration is done only at the client application and the it should be always running in-order to control the system remotely.

4.       User Characteristics:  The Following things are taken into consideration with this software development
a.       Users can have multiple systems for controlling. There is absolutely no limit in the number of systems being controlled by the users.
b.      The user can either control her/his systems through mobile or desktop based web application.
c.       Each user can control his/her system only and don’t have access to control others systems.
d.      Right now there is only one type of user of this system i.e. the System Administrators who will be using this system to control or fetch additional information of the system on their own interest.



Software and Hardware Requirement

Software Requirements:
·       Operating system: Microsoft Windows XP / Win 7 / Vista
·       .NET framework 4.0
·       SQL Server 2008

Hardware Requirements:
·       Processor Pentium 4
·       RAM- 256Mb
·       HDD-10GB


Technologies Used
·       Visual Studio.NET
    • The Client Application is developed with .NET C# Winform technology
    • The Server side web application is developed with ASP.NET MVC3 technology.

·       Internet based / Cloud based Microsoft SQL Server 2008
    • This software is designed with Software as a Service model with a common single cloud database which stores all the users and their system information.

How does the software functions?
Client Application:

When you run the client application for the first time, you will have to register yourself with the username and password. The same has to be provided as log on information which will authenticate the user in client and server applications.

Once authenticated, the user has to click on the Start button for continuous monitoring of the system behind the scene. The system registers by itself by putting an entry in database (this happens only for the first usage of the client app) so that the user can control that particular machine.  When the user closes the client application, the entry in the database for that system will be deactivated.  For subsequent usable of the client application, the system will be activated for monitoring and controlling.

Server Application:

It is a web based application, on requesting the user will be authenticated. The use has to provide the same username and password he/she has provided at the time of user registration in client app.
On successful authentication, the list of active systems will be displayed in a screen. The user can select one and perform the actions like Shutdown, Reboot etc.




Database Entity Relationship Design Diagram




Snapshots of Client App




Snapshots of Server Application
 





Thursday, January 19, 2012


Dependency Injection

Dependency injection basically allows us to create loosely coupled, reusable, and testable objects in your software designs by removing dependencies.

We will take a look into the Object dependencies before digging in more.
Consider a scenario of fetching an employee details and show display in UI. Let us say create a Business logic layer class named EmployeeBAL and a data access layer class named EmployeeDAO


public class EmployeeDao
{
     //Some code
}


public class EmployeeBAL
{
      var employeeDAO = new EmployeeDao();
      //Some code
}

From the above code you will notice one thing that we are creating EmployeeDAO instance inside the Business logic layer class. So here comes the dependency


What is wrong if we have a dependency?


Think about whether your code is unit testable. We cannot fully unit test the EmployeeBAL as it has a dependency on Employee DAO. So we can say as long as the composition of the DAO exists within the BAL we cannot unit test the EmployeeBAL.


You will also notice one more thing here; with this type of implementation you will see a high coupling of BAL and DAL.

How to make it loose coupling?


The basic idea behind Dependency Injection is that you should isolate the implementation of an object from the construction of objects on which it depends

Coming to the example, we should be isolating the implementation of EmployeeBAL object and the construction of the dependent EmployeeDAO object.

We will see how we can make loosely coupled objects in detail
      
           Constructor based dependency injection
    
      We will have to modify the EmployeeBAL to accept an EmployeeDAO instance within its constructor.


public class EmployeeDao
{
     //Some code
}



public class EmployeeBAL
{
     EmployeeDao employeeDAO;

     public EmployeeBAL(EmployeeDAO employeeDao){
             this.employeeDAO  = employeeDao;
     }
     //Some code
}

     Property based dependency injection

      
      With property based injection we will have a public getter and setter Property of type EmployeeDao so that the dependency can be externally set.


public class EmployeeBAL
{
             Public EmployeeDao EmployeeDataAccess{ get; set; }
}
  
var employeeBAL = new EmployeeBAL();
EmployeeBAL.EmployeeDataAccess = new EmployeeDao();

Wait!!!


The above ones are just some techniques of injecting the dependency. We are still yet to discuss one more interesting thing Unit Testing.

Are you agreeing that we have removed the DAO creation from the Business Logic EmployeeBAL? Yes it is good but it still depends on the actual instance of EmployeeDao.  


Consider the below mentioned implementation of the same sample senarios

interface IDataAccess
{
     //Some code
}
   
class EmployeeDao : IDataAccess
{
     //Some code
}
   
public class EmployeeBAL
{
    private IDataAccess dataAccess;
    public BusinessFacade(IDataAccess dao)
    {
        dataAccess = dao;
    }
}
 
You can notice we are doing a constructor dependency injection but most important thing here 
is we are using Interface type than creating a strongly typed object. 

The advantage that we are getting here is we can have an In-memory data access object of
IDataAccess interface type and we can  easily inject the dependency to the EmployeeBAL. 
By this way we need not inject the concrete instance of the data access object.


Are you happy that we can unit test the BAL without the data access dependency? 

Advantages of Dependency Injection
The primary advantages of dependency injection are:
  • Loose coupling
  • Centralized configuration
  • Easily testable

Monday, January 16, 2012

3 Tier Architecture in .NET C#



3-Tier architecture generally contains User Interface (UI) or Presentation Layer, Business Access/Logic Layer (BAL) and Data Access Layer (DAL). 

Presentation Layer (UI) 

Presentation layer is responsible for displaying the views. Contains windows forms or ASP.NET pages, where data is presented to the user or input is taken from the user. We will consider a sample Windows form application which will show the Authors information and details in the UI.

Business Access Layer (BAL) or Business Logic Layer 

BAL contains business logic, validations or calculations related with the data

Business Entities

Business entities are reusable entities developed as per the application. We are making use of these entities in BAL and DAL. The data access layer fetches the data and converts the data say to a List of business entity. Ex: When we are retrieving a list of Authors details, the DAL will fetch all the authors and returns List<AuthorsBE> list of author’s business entities.

Data Access Layer (DAL) 

DAL contains methods that helps business layer to connect the data and perform required action, might be returning data or manipulating data (insert, update, delete etc). For this demo pubs sample application, the BAL makes a call to data access to get all the list of authors i.e GetAllAuthors(), to get all the list of author titles GetAuthorTitleDetails(string authorID)

Advantages of N-Tier Application

1.    Decoupling the logic: By loose coupling the logics of Presentation, Business and Data access suppose if there is a change in the UI layer, you will only have to worry about the modifications in the Presentation layer. Right now it is using SQL Server database , if in future you are changing your mind in is using other databases , we will only have to modify the logic within the Data access layer and nothing else is required.
2.    With layered architecture you can do the software development in Parallel. That means you can code each layers independently
3.    Easy to Test: The testability of the software increases by decoupling the logics into multiple layers. You can independently Unit Test the logics of different layers
4.    Re usability of components




How to run the sample
1)   Download pubs database sample from http://www.microsoft.com/download/en/details.aspx?id=23654 link
2)   Open SQL Management studio and execute the stored procedures with in the DataAccessLayer - > Scripts folder in Pubs database.
3)   Open PubsSamplePresentation.sln Solution from VS 2010 or VS2011
4)   Go to PubsSamplePresentation and open App.config
5)   Change the connection string (PubsConnectionString) value appropriately
6)   Run the Windows Form application (PubsSamplePresentation)


Class Diagram of Logger Library


Delegates

A delegate in C# is similar to a function pointer in C or C++. Using a delegate allows the programmer to encapsulate a reference to a method inside a delegate object. The delegate object can then be passed to code which can call the referenced method, without having to know at compile time which method will be invoked.
The signature of a single cast delegate is shown below:
delegate result-type identifier ([parameters]);
where:
  • result-type: The result type, which matches the return type of the function.
  • identifier: The delegate name.
  • parameters: The Parameters that the function takes.
Delegates allow a clearer separation of specification and implementation. A delegate specifies the signature of a method, and authors can write methods that are compatible with the delegate specification.

Multicast Delegate

With multicast delegate, it is just like a normal delegate but it can point to multiple functions so on invocation of such delegate it will invoke all the methods and functions associated with the same one after another sequentially.

Events

Events are wrapper around the delegate. It sits on top of the delegate and provides only the necessary encapsulation so that the destination objects can subscribe to the Event and not have full control on the delegate object.
Events are declared using delegates. The delegate object encapsulates a method so that it can be called anonymously. An event is a way for a class to allow clients to give it delegates to methods that should be called when the event occurs. When the event occurs, the delegate(s) given to it by its clients are invoked.
We will consider an example implementation of Logger application, which can be used to log messages in Console, File or Database etc.
We will declare a delegate named LogWriteDelegate which accepts one parameter named message.

public delegate void LogWriteDelegate(string message);

Next we will declare an Event of type LogWriteDelegate

public event LogWriteDelegate LogWriteEvent;

In our sample Logger the FileLogger and ConsoleLogger will subscribe or register to the above mentioned event so that when the Write method of logger is called the respective logic within the Write method of FileLogger and ConsolLogger will also gets invoked.

using (var logger = new Logger("testing", EntryType.Debug))
{
      logger.LogWriteEvent += new Logger.LogWriteDelegate(consoleLogger.Write);
      logger.LogWriteEvent += new Logger.LogWriteDelegate(fileLogger.Write);
      logger.Write();
}

You can notice here a multicast delegate; the LogWriteEvent is being registered with Console and File log write methods.
While firing an Event within the Logger object, it is always a good practice to check whether the event is registered or not.

public void Write()
{
       if (LogWriteEvent != null)
            LogWriteEvent(ToString());
}

Here the LogWriteEvent holds the address of the methods console.Write and fileLogger.Write. When firing an event it will sequentially call the respective methods which are pre-registered to this Event.
Note: The Logger application is designed in the way that in future you can have multiple implementations of Loggers. Right now we have Console and File Logger; if you are interested in implementing a Database logger we can create a new Class named DatabaseLogger which will implement ILogger interface. Provide necessary Write method logic so that it will log messages to database.

Ones you have done with the DatabaseLogger implementation, you just have to create an instance and register the event as we have done for Console and File Loggers.