31 August 2012

Window Services in C#.Net


Introduction:
         Recently, I was hunting about Windows Service. So I wrote this article. I just explained windows Service and usage in the .Net Application.
Windows Service:
Windows Service applications are long-running applications that are ideal for use in server environments. Services can be automatically started when the computer is booted. Windows Services are controlled through the Service Control Manager where they can be stopped, paused, and started as needed.
Create Windows Service:
Add Assemblies for Windows Service:
1)  System.Configuration.Install
2)  System.ServiceProcess.
System.Configuration.Install:
Provides classes that allow you to write custom installers for your own components.
System.ServiceProcess:
Allow you to implement, install, and control Windows service applications.
System.ServiceProcess.ServiceBase:
Provides a base class for a service that will exist as part of a service application. ServiceBase must be derived from when creating a new service class.
Every Service should override OnStart() and OnStop() and also Pause, Shutdown and Continue.
Step by Step Processing:
· Create New Application.
· Select Windows Service in the Template Window.
· Go to Program.cs file.
· Declare namespace Using System.ServiceProcess.ServiceBase.

How to add some information about our Service?
class Program :ServiceBase
{
  static voidMain(string[] args)
  {
  }

  public Program()
  {
    this.ServiceName= "ERP";  //Here, User puts name of Service.
  }
  protected overridevoid OnStart(string[] args)
  {
    base.OnStart(args);
    //TODO: place your start code here
  }

  protected overridevoid OnStop()
  {
    base.OnStop();

    //TODO: clean up any variables and stop any threads
  }
}
Now, we implement Service for your Application. We create an Installer for your Application.

How to create installer for your Application?
   Create another Class for installer that is called “MyApplicationInstaller”.
 Assign a Class to Public Modifier like this.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace
MyApplicationInstaller
{
  public class
MyApplicationInstaller
  {
  }
}
Add Two Class library for installer Class.
· System.Configuration.Install
· System.ComponentModel
System.Configuration.Install:
Provides classes that allow you to write custom installers for your own components.
System.ComponentModel:
Provides classes that are used to implement the run-time and design-time behavior of components and controls.

Now, we need to configure how we want to our Service installed.
[RunInstaller(true)]
public class MyApplicationInstaller:Installer
{
  public MyApplicationInstaller ()
  {
    var proInstaller = newServiceProcessInstaller();
    var serInstaller = newServiceInstaller();
   proInstaller.Account = ServiceAccount.LocalSystem;
   proInstaller.DisplayName = "ERP";
   serInstaller.StartType = ServiceStartMode.Manual;                        serInstaller.ServiceName = "ERP";
    this.Installers.Add(proInstaller);
    this.Installers.Add(serInstaller);
  }
}

Four Members of ServiceAccountin Windows Service:
1)  LocalService
2)  NetworkService
3)  LocalSystem
4)  User
LocalService:
An account that acts as a non-privileged user on the local computer.
NetworkService:
An account that provides extensive local privileges and any remote Services.
LocalSystem:
An account, used by the service control manager that has extensive privileges on the local computer and acts as the computer on the network.
User:
    An account defined by a specific user on the network.       

Three Members of ServiceStartMode:
1)  Manual
2)  Automatic
3)  Disabled

Manual:
Indicates that the service is started only manually, by a user
Automatic:
Indicates that the service is to be started (or was started) by the operating system, at system start-up
Disabled:
Indicates that the service is disabled, so that it cannot be started by a user or application.
Conclusion:
      I hope, this Article will get some ideas about Windows Services. Thanks for reading this article. Thanks to Google and MSDN.

29 August 2012

List of WPF Controls based on .Net Framework version

Here, I give  a control name and .Net framework in WPF.

Control Name.Net Framework
· AccessText 3.0 ,3.5,4.0,4.5
· Border Control 3.0 ,3.5,4.0,4.5
· Button Control 3.0 ,3.5,4.0,4.5
· BulletDecorator Control 3.0 ,3.5,4.0,4.5
· Canvas Control 3.0 ,3.5,4.0,4.5
· Calendar Control 4.0,4.5
· CheckBox Control 3.0 ,3.5,4.0,4.5
· ComboBox Control 3.0 ,3.5,4.0,4.5
· ContextMenu Control 3.0 ,3.5,4.0,4.5
· Datagrid Control 4.0,4.5
· DatePicker Control 4.0,4.5
· DockPanel Control 3.0 ,3.5,4.0,4.5
· DocumentViewer Control3.0 ,3.5,4.0,4.5
· Expander Control 3.0 ,3.5,4.0,4.5
· FlowDocumentPageviewer Control3.0 ,3.5,4.0,4.5
· FlowDocumentReader Control3.0 ,3.5,4.0,4.5
· FlowDocumentScrollviewer Control3.0 ,3.5,4.0,4.5
· Frame3.0 ,3.5,4.0,4.5
· Grid Control 3.0 ,3.5,4.0,4.5
· GridView Control3.0 ,3.5,4.0,4.5
· GridSplitter Control3.0 ,3.5,4.0,4.5
· GroupBox Control3.0 ,3.5,4.0,4.5
· Hyperlink3.0 ,3.5,4.0,4.5
· Image Control3.0 ,3.5,4.0,4.5
· InkCanvas Control3.0 ,3.5,4.0,4.5
· InkPresenter Control3.0 ,3.5,4.0,4.5
· Label3.0 ,3.5,4.0,4.5
· ListView Control 3.0 ,3.5,4.0,4.5
· ListBox Control3.0 ,3.5,4.0,4.5
· Menu 3.0 ,3.5,4.0,4.5
· MediaElement3.0 ,3.5,4.0,4.5
· NavigationWindow3.0 ,3.5,4.0,4.5
· OpenFiledialog Control3.0 ,3.5,4.0,4.5
· PasswordBox Control3.0 ,3.5,4.0,4.5
· Panel Control3.0 ,3.5,4.0,4.5
· Page3.0 ,3.5,4.0,4.5
· PrintDialog Control3.0 ,3.5,4.0,4.5
· Popup3.0 ,3.5,4.0,4.5
· ProgressBar3.0 ,3.5,4.0,4.5
· RadioButton3.0 ,3.5,4.0,4.5
· Repeated Control 3.0 ,3.5,4.0,4.5
· ResizeGrip Control3.0 ,3.5,4.0,4.5
· RichTextBox Control3.0 ,3.5,4.0,4.5
· SaveFileDialog Control3.0 ,3.5,4.0,4.5
· Separator Control3.0 ,3.5,4.0,4.5
· ScrollBar Control 3.0 ,3.5,4.0,4.5
· ScrollViewer Control 3.0 ,3.5,4.0,4.5
· Slider3.0 ,3.5,4.0,4.5
· SoundPlayerAction3.0 ,3.5,4.0,4.5
· StackPanel Control3.0 ,3.5,4.0,4.5
· StrickNoteControl3.0 ,3.5,4.0,4.5
· StatusBar3.0 ,3.5,4.0,4.5
· TabControl3.0 ,3.5,4.0,4.5
· TextBlock3.0 ,3.5,4.0,4.5
· TextBox Control3.0 ,3.5,4.0,4.5
· Thumb Control 3.0 ,3.5,4.0,4.5
· ToolTip3.0 ,3.5,4.0,4.5
· ToolBar3.0 ,3.5,4.0,4.5
· TreeviewControl3.0 ,3.5,4.0,4.5
· Viewbox Control3.0 ,3.5,4.0,4.5
· VirtualizingStackPanel Control3.0 ,3.5,4.0,4.5
· Window Control 3.0 ,3.5,4.0,4.5
· WrapPanel Control3.0 ,3.5,4.0,4.5

27 August 2012

WPF Day-5

Introduction:
    Last Four days, we talked about WPF Introduction, AccessText Control, Board and Canvas, Calendar, CheckBox, ComboBox and ContextMenu Control. Today we will discuss about Datagrid, DatePicker, DockPanel, and DocumentViewer Control.

·  Datagrid Control:
               Represents a control that displays data in a customizable grid.
                  It starts from .Net Framework 4.0.
Please refer this: http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid%28v=vs.100%29.aspx
·  DatePicker Control:
               Represents a control that allows the user to select a date.
               It starts from .Net Framework 4.0.
Please refer this: http://msdn.microsoft.com/en-us/library/system.windows.controls.datepicker.aspx
·  DockPanel Control :
     Defines an area where you can arrange child elements either horizontally or vertically, relative to each other.
Create ContextMenu in XAML:
<DockPanel Background="AliceBlue">
            <TextBox Name="textBox1" TextWrapping="Wrap" Margin="10, 10, 5, 5" Grid.Row="7" Height="36" Width="202">The quick brown fox jumps over the lazy dog.
                <TextBox.ContextMenu>
                    <ContextMenu>
                        <MenuItem Header="_USA" />
                        <Separator />
                        <MenuItem Header="_INDIA"  />
                        <Separator />
                        <MenuItem Header="CHINA"/>
                        <Separator />
                        <MenuItem Header="SOUTH AFRICA" />
                    </ContextMenu>
                </TextBox.ContextMenu>
            </TextBox>
        </DockPanel>

Create ContextMenu in Coding:
    CheckBoxchkYes;
     CheckBoxchkNo;
     DockPaneldockPanel;
private voiddockPanelControl()
        {
            dockPanel = new DockPanel();
            dockPanel.Background = Brushes.LightSlateGray;
            dockPanel.Margin = new Thickness(10, 15, 5, 10);
            dockPanel.Height = 100;
            dockPanel.Width= 200;
            dockControl(dockPanel);
            this.Content = dockPanel;
        }
        privatevoid dockControl(DockPaneldpnl)
        {
            chkYes = newCheckBox();
            chkYes.ClickMode = ClickMode.Press;
            chkYes.Content = "Yes";
            chkYes.IsChecked = true;
            chkYes.Margin = new Thickness(10, 10, 25, 20);

            chkNo = newCheckBox();
            chkNo.ClickMode = ClickMode.Press;
            chkNo.Content = "No";
            chkNo.Margin = new Thickness(10, 10, 25, 20);
            dpnl.Children.Add(chkYes);
            dpnl.Children.Add(chkNo);
        }
private voidWindow_Loaded(object sender, RoutedEventArgs e)
        {
            dockPanelControl();
        }
·  DocumentViewer Control:
           Document viewing control that can host paginated FixedDocumentcontent such as an XpsDocument. Simple says that user can view all documents like (PDF, text. Image files)
FixedDocument:
   It is a fixed format document with read Access for user.
    Provides a Packagethat holds the content of an XPS document.
Package:
           Container that can store multiple data objects.
Create ContextMenu in XAML:
<DocumentViewer Margin="20,12,12,26" Name="documentViewer1"Background="Azure" />
Create ContextMenu in Coding:
        DocumentViewerdocViewer;
             privatevoid documentViewerControl()
              {
                   docViewer = new DocumentViewer();
                   docViewer.Background = Brushes.LightSlateGray;
                    this.Content = docViewer;
        }
            privatevoid Window_Loaded(objectsender, RoutedEventArgs e)
             {
                 documentViewerControl();
             }
Conclusion:
  I hope, you to get some ideas about Datagrid, DatePicker, DockPanel, and DocumentViewer Control in WPF. Thanks for reading this article. We will talk about other controls in next Chapters.