Friday, February 14, 2020

Data base Optimization


Database is the most important and powerful part of any application. If your database is not working properly and taking long time to compute the result, this means something is going wrong in database.

  1. ·         Use  index on table
  2. ·         Use  to Avoid Null value in fixed length field
  3. ·         Use  Appropriate Datatype
  4. ·         Use  Common Table Expressions (CTEs) instead of Temp table
  5. ·         Use  Appropriate Naming Convention
  6. ·         Use  UNION ALL instead of UNION
  7. ·         Use  Small data type for Index 
  8. Use  the stored procedure because stored procedures are fast and easy to maintain for 



     

Abstract Class

I  have implemented most of my projects abstract class as a base class and all derived classes must implement abstract definition. we can avoid duplicate code.
·         creating something that provides common functionality to unrelated classes, use an interface
·         Abstract classes allow to provide default functionality for the subclasses.
·         creating something for objects that are closely related in a hierarchy, use an abstract class
If the base class will be changing often and an interface was used instead of an abstract class, we are going to run into problems. Once an interface is changed, any class that implements that will be broken. Now if it’s just you working on the project, that’s no big deal. However, once your interface is published to the client, that interface needs to be locked down. At that point, you will be breaking the clients code.


abstract class TestClass {
 
    protected int myNumber;  
    public abstract int numbers
    {
        get;
        set;
    }
}
 
class absDerived : TestClass {
 
    public override int numbers
    {
        get
        {
            return myNumber;
        }
        set
        {
            myNumber = value;
        }
    }
}
 
class order{
 
    // Main Method
    public static void Main)
    {
        TestDerived d = new TestDerived();
        d.numbers = 7;
        Console.WriteLine(d.numbers);
    }
}

c# generics


generics to write a class or method that can work with any data type. When the compiler encounters a constructor for the class or a function call for the method, it generates code to handle the specific data type.
It helps you to maximize code reuse, type safety, and performance

·         Use generic types to maximize code reuse, type safety, and performance.
·         The most common use of generics is to create collection classes.

public class GenericList
{
    public void Add(T input) { }
}
class TestGenericList
{
    private class ExampleClass { }
    static void Main()
    {
        // Declare a list of type int.
        GenericList list1 = new GenericList();
        list1.Add(1);

        // Declare a list of type string.
        GenericList list2 = new GenericList();
        list2.Add("");

        // Declare a list of type ExampleClass.
        GenericList list3 = new GenericList();
        list3.Add(new ExampleClass());
    }
}

c# Memory Clean of Objects


finally statement is to ensure that the necessary cleanup of objects, usually objects that are holding external resources, occurs immediately, even if an exception is thrown. One example of such cleanup is calling Close on a FileStream immediately after use instead of waiting for the object to be garbage collected by the common language runtime, as follows

static void CodeobjectCleanup()
{
    System.IO.FileStream file = null;
    System.IO.FileInfo fileInfo = new System.IO.FileInfo("C:\\file.txt");

    file = fileInfo.OpenWrite();
    file.WriteByte(0xF);

    file.Close();
}

Monday, July 5, 2010

Sesquential Workflow

Sequential workflow




Workflow.cs
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
namespace WorkflowConsoleApplication7
{
public sealed partial class Workflow6: SequentialWorkflowActivity
{
public Workflow6()
{
InitializeComponent();
}
private void codeActivity1_ExecuteCode(object sender, EventArgs e)
{
Console.WriteLine("Start workflow");
}
private void codeActivity2_ExecuteCode(object sender, EventArgs e)
{
Console.WriteLine("step1");
}
private void codeActivity3_ExecuteCode(object sender, EventArgs e)
{
Console.WriteLine("step2");
}
private void codeActivity4_ExecuteCode(object sender, EventArgs e)
{
Console.WriteLine("End workflow");
Console.ReadLine();
}
}
}

Program.cs
using System;
using System.Collections.Generic;using System.Text;
using System.Threading;
using System.Workflow.Runtime;
using System.Workflow.Runtime.Hosting;
namespace WorkflowConsoleApplication7
{
class Program
{
static void Main(string[] args)
{
using(WorkflowRuntime workflowRuntime = new WorkflowRuntime())
{ AutoResetEvent waitHandle = new AutoResetEvent(false); workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) {waitHandle.Set();}; workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
{
Console.WriteLine(e.Exception.Message);
waitHandle.Set();
};
WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(WorkflowConsoleApplication7.Workflow7));
instance.Start();
waitHandle.WaitOne();
}
}
}
}

Workflow Delay

Delay in Workflow






workflow.cs

using System;

using System.ComponentModel;

using System.ComponentModel.Design;

using System.Collections;

using System.Drawing;

using System.Workflow.ComponentModel.Compiler;

using System.Workflow.ComponentModel.Serialization;

using System.Workflow.ComponentModel;

using System.Workflow.ComponentModel.Design;

using System.Workflow.Runtime;

using System.Workflow.Activities;

using System.Workflow.Activities.Rules;
namespace WorkflowConsoleApplication7

{

public sealed partial class Workflow5: SequentialWorkflowActivity

{

public Workflow5()

{

InitializeComponent();

}
private void codeActivity1_ExecuteCode(object sender, EventArgs e)

{

Console.WriteLine("Start workflow");

}
private void codeActivity2_ExecuteCode(object sender, EventArgs e)

{

Console.WriteLine("Left Side1");

}
private void codeActivity3_ExecuteCode(object sender, EventArgs e)

{ Console.WriteLine("Right side2");

}
private void codeActivity4_ExecuteCode(object sender, EventArgs e)

{

Console.WriteLine("Left side2");

}
private void delayActivity1_InitializeTimeoutDuration(object sender, EventArgs e)

{
}
private void codeActivity7_ExecuteCode(object sender, EventArgs e)

{

Console.WriteLine("Right side1");

}
private void codeActivity6_ExecuteCode(object sender, EventArgs e)

{

Console.WriteLine("Right side3");

}
private void codeActivity5_ExecuteCode(object sender, EventArgs e)

{

Console.WriteLine("End workflow");

Console.ReadLine();

}

}
}

program.cs

using System;

using System.Collections.Generic;

using System.Text;

using System.Threading;

using System.Workflow.Runtime;

using System.Workflow.Runtime.Hosting;
namespace WorkflowConsoleApplication7

{

class Program

{

static void Main(string[] args)

{

using(WorkflowRuntime workflowRuntime = new WorkflowRuntime())

{

AutoResetEvent waitHandle = new AutoResetEvent(false); workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) {waitHandle.Set();}; workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)

{

Console.WriteLine(e.Exception.Message);

waitHandle.Set();

};

WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(WorkflowConsoleApplication7.Workflow3));

instance.Start();

waitHandle.WaitOne();

}

}

}

}

Workflow While Loop

While Loop in Workflow






workflow.cs
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
namespace WorkflowConsoleApplication7
{
public sealed partial class Workflow3: SequentialWorkflowActivity
{
public Workflow3()
{
InitializeComponent();
}
private void codeActivity1_ExecuteCode(object sender, EventArgs e)
{ Console.WriteLine("Start");
}
private void codeActivity2_ExecuteCode(object sender, EventArgs e)
{ Console.WriteLine("Left side flow");
}
private void codeActivity3_ExecuteCode(object sender, EventArgs e)
{
Console.WriteLine("Right side flow");
}
private void codeActivity4_ExecuteCode(object sender, EventArgs e)
{
Console.WriteLine("End");
Console.ReadLine();
}
}
}
program.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Workflow.Runtime;
using System.Workflow.Runtime.Hosting;
namespace WorkflowConsoleApplication7
{
class Program
{
static void Main(string[] args)
{
using(WorkflowRuntime workflowRuntime = new WorkflowRuntime())
{
AutoResetEvent waitHandle = new AutoResetEvent(false); workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) {waitHandle.Set();}; workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
{
Console.WriteLine(e.Exception.Message);
waitHandle.Set();
};
WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(WorkflowConsoleApplication7.Workflow3));
instance.Start();
waitHandle.WaitOne();
}
}
}
}