Friday, 27 February 2015

How to add a trusted publisher for your software


The advantage of the trusted application deployment is that you can run the application/software with  a high level of trust.
It will resolve the "Unknown publisher" error that you are encountering during the deployment of your application/software.




Publisher certificates are like a unique public-private key pair.

The organization that is granting the certificate is known as Certificate Authority(CA) or certificate issuer.
The organization to which the CA is granting the certificate is known as the publisher.


There are various companies which are providing/issuing certificates to the organizations. These companies will verify the identity of  organizations to which they are issuing the certificates.

Verisign and thawte are some of the well known examples of the companies who are providing the services of issuing certificates to legitimate the publisher.

You can visit the Verisign site by using the below link :

Wednesday, 25 February 2015

Adding Installers in your project using InoSetup


What is Innosetup Installer ?
It is used to create a installer for your project. For e.g: You are delivering a project to a client, but a client cannot register the service of its own or can execute the sql queries. To resolve this issue, we can make the installers which will register the services automatically and can run batch files which will execute sql queries automatically.

[Inosetup installer]
Inosetup

Steps to work with Inosetup installer in c#:-

1.Install the Inosetup
2.Add the .iss file in your solution projects
For e.g:- If you are having three projects[Client,Service,Shell] in your solution project then you need to add three installer[.iss] files per project
3. In your client project add the "Common.iss" installer which contains the common functionalities of the installers like the installer pop-up windows.
4.In your service project you will have installer file which will help you to register the .xml config file.
Your service installer[.iss] file will basically have a procedure which will execute the [.xml] config file.
E.g:-
procedure AfterInstallBatch();
begin
if     ExecBatch('Registering Warranty Title Tools Server Package...',  ExpandConstant('{app}\sps.exe'),         ExpandConstant('register /server:{code:GetSPServerInfo|Address} /user:{code:GetSPServerInfo|Username},{code:GetSPServerInfo|Password} ProjectServiceRegistration.xml'))

5.In your shell[U.I part of the project]project, you will add the projectname.Shell.Install.iss which will basically copies the ProjectName.client.dll and ProjectName.Shell.dll of your project from the bin folder to the softwares service directory which you want to integrate with your project.

Download .iss installer files [replace projectname with your project names]

Add the Installer\common.iss in your client project :-
common.iss

Add the Installer\projectname.service.install.iss in your client project :-
Service Installer
Add the Installer\projectname.shell.installer.iss in your shell project
Shell installer

Tuesday, 24 February 2015

CODING STANDARDS AND NAMING CONVENTIONS

 Explicitly declare the scope of the event delegate e.g:- private

 Private class level variable names should have preceding _(underscore) on them

 Private class member variable names should start with lower case character

 Delegate Method Names should start with Upper case character

 Remove _(underscore) from property names, make the property names indicate what they are for

 public property should not start with a _ and lower case char

 use  " this." before accessing any class level variable

 Declare scope, and move the variable declaration with others

 If we are not utilizing catch then don't use try block let the exception propagate to the calling code

 Properly Format the message shown in message box, with title,icon, button & a properly formatted message string

 Private properties should be names like a normal property

 If Properties are not used outside the class why not declare them as variables instead.


Monday, 23 February 2015

How to get Enum Description

For e.g:- If you a enum as follows:-

public enum EnumName
{
   [Description("Description1 of value1")]
   value1,
   [Description("Description2 of value2")]
   value2,
   [Description("Description3 of value3")]
   value3
}

//To fetch the description e.g["Description1 of value1"] from value1 of enum :-

using System;
using System.Reflection; // for FieldInfo 

using System.ComponentModel; // for DescriptionAttribute

static void Main(string[] args)
 {
            string desc1 = ToDescription(EnumName.value1);
            Console.WriteLine("the description is [value1]:" + desc1);
 EnumName val1=GetValueFromDescription<EnumName >(desc1);

           Console.WriteLine("the description is :" + val1);
}

//It will fetch description from enum value
 public static string ToDescription(object value)
  {
      FieldInfo field =value.GetType().GetField(value.ToString());
      DescriptionAttribute[] attributes =(DescriptionAttribute[])field
      .GetCustomAttributes(typeof(DescriptionAttribute), false);
       if (attributes.Length > 0)
        {
                return attributes[0].Description;
        }
            return value.ToString();
  }
//it will fetch value from description:-

 public static EnumName GetValueFromDescription<EnumName>(string description)
{
            var type = typeof(EnumName);
            if (!type.IsEnum) throw new InvalidOperationException();
            foreach (var field in type.GetFields())
            {
                var attribute = Attribute.GetCustomAttribute(field,
                    typeof(DescriptionAttribute)) as DescriptionAttribute;
                if (attribute != null)
                {
                    if (attribute.Description == description)
                        return (EnumName)field.GetValue(null);
                }
                else
                {
                    if (field.Name == description)
                    return (EnumName)field.GetValue(null);
                }
            }
            throw new ArgumentException("Not found.", "description");
            // or return default(call);

}



Creating and Importing VM

HOW TO ADD AUTOMATIC VERSION UPDATER IN C#?

Adding version updater for Assembly files in projects:-
=====================================================

 STEP 1:
----------
1. Add a new folder[e.g- utils] in your project solution and add a updateversions.exe file
2. Add the same file in the physical location as well.
3. You need to provide the path of all assemblies for which you want to change the versions.
4. Add versions.txt file in a new folder[e.g:-Solution item] in your project solution
5. Add same file in physical location as well.

STEP 2 :
----------
1. Next you need to add the locaion of your updateversions.exe in the Properties\"BUILD EVENTS"
 of your client project.
2.In the "Pre-build event command line" of build events, write the following code:-
if $(ConfigurationName) == Release (
"$(SolutionDir)"utils\updateversions.exe "$(SolutionDir)")
3. Now run the project in "Release" mode and your updater will update the assembly version
as you desired

UPDATEVERSION.EXE
versions.txt
 

Monday, 9 February 2015

HOW TO SET LOGIN IN SQL DATABASE


To set the Login in Ms-Sql Server :-
1.Open the SQl serer using your Administrator profile.
 
2.Go to Security>logins
3.Right click on login and select "New Login"
4.Click "search" button and a pop-window will open as follows:-



5.Now click the "Advanced" button and the following window will pop-up :-



6.Click the "Find Now" button.
7.In search results arera, list of profile names will be loaded. Select your profile from which you want to access the sql server and click the "ok" button.
8.Under "server roles" and "user mappings" check the checkboxes to grant the rights to your selected profile.