<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
  <channel>
    <title>CodeKeep C# Feed</title>
    <description>The latest and greatest C# code snippets publicly available</description>
    <link>http://www.codekeep.net/feeds.aspx</link>
    <lastBuildDate>Sat, 26 May 2012 19:45:55 GMT</lastBuildDate>
    <docs>http://backend.userland.com/rss</docs>
    <generator>RSS.NET: http://www.rssdotnet.com/</generator>
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/CodeKeepCSharp" /><feedburner:info uri="codekeepcsharp" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
      <title>ConnectionScope</title>
      <description>Description: Create a disposable that will automatically close a connection when it goes out of scope&lt;br /&gt;&lt;br /&gt;Link: &lt;a href='http://www.codekeep.net/snippets/f4d9205b-e5af-4d7f-9f5f-0d9092154972.aspx'&gt;http://www.codekeep.net/snippets/f4d9205b-e5af-4d7f-9f5f-0d9092154972.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style='font-size: 9pt;'&gt;internal class ConnectionScope : IDisposable
{
    private readonly IDbConnection _connection;
    private readonly bool _needToClose;

    public ConnectionScope(IDbConnection connection)
    {
        if (connection == null)
            throw new ArgumentNullException(&amp;quot;The parameter 'connection' cannot be null!&amp;quot;, &amp;quot;connection&amp;quot;);

        _connection = connection;
        if (connection.State != ConnectionState.Open)
        {
            connection.Open();
            _needToClose = true;
        }
    }

    ~ConnectionScope()
    {
        Dispose(false);
    }

    public IDbConnection Connection { get { return _connection; } }

    public void Dispose()
    {
        Dispose(true);
    }

    public void Dispose(bool disposing)
    {
        try
        {
            if (_needToClose &amp;amp;&amp;amp; _connection.State == ConnectionState.Open)
                _connection.Close();
            if (disposing) GC.SuppressFinalize(this);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
        }
    }
}&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeKeepCSharp/~4/Xhe7lDbc1_0" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/CodeKeepCSharp/~3/Xhe7lDbc1_0/f4d9205b-e5af-4d7f-9f5f-0d9092154972.aspx</link>
      <pubDate>Sat, 26 May 2012 19:45:55 GMT</pubDate>
    <feedburner:origLink>http://www.codekeep.net/snippets/f4d9205b-e5af-4d7f-9f5f-0d9092154972.aspx</feedburner:origLink></item>
    <item>
      <title>Return a IDbConnection for a given ConnectonString name</title>
      <description>Description: Uses DbProviderFactories to weave it's magic&lt;br /&gt;&lt;br /&gt;Link: &lt;a href='http://www.codekeep.net/snippets/f4da295e-75d4-46ec-a329-036bdd474c66.aspx'&gt;http://www.codekeep.net/snippets/f4da295e-75d4-46ec-a329-036bdd474c66.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style='font-size: 9pt;'&gt;// reference System.Configuration.dll

private static IDbConnection GetConnection(string connectionStringName)
{
    var setting = ConfigurationManager.ConnectionStrings[connectionStringName];
    var factory = DbProviderFactories.GetFactory(setting.ProviderName);;
    var result = factory.CreateConnection();

    if (result == null)
        throw new DataException(string.Format(&amp;quot;The data-provider '{0}' cannot create a connection!&amp;quot;, setting.ProviderName));

    result.ConnectionString = setting.ConnectionString;
    return result;
}

&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeKeepCSharp/~4/1m8YhfZ20Ik" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/CodeKeepCSharp/~3/1m8YhfZ20Ik/f4da295e-75d4-46ec-a329-036bdd474c66.aspx</link>
      <pubDate>Sat, 26 May 2012 19:31:53 GMT</pubDate>
    <feedburner:origLink>http://www.codekeep.net/snippets/f4da295e-75d4-46ec-a329-036bdd474c66.aspx</feedburner:origLink></item>
    <item>
      <title>Using a WebClient</title>
      <description>Description: Simple demonstration on using a WebClient&lt;br /&gt;&lt;br /&gt;Link: &lt;a href='http://www.codekeep.net/snippets/bf4d5ff7-1c8a-42eb-88c0-501185dee953.aspx'&gt;http://www.codekeep.net/snippets/bf4d5ff7-1c8a-42eb-88c0-501185dee953.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style='font-size: 9pt;'&gt;private static string ReadWebPage(string url)
{
    string page = null;
    WebClient client = new WebClient();
    try
    {
        using (var stream = client.OpenRead(url))
        {
            if (stream != null)
                using (StreamReader sr = new StreamReader(stream))
                {
                    page = sr.ReadToEnd();
                }
        }
    }
    catch (WebException ex)
    {
        Console.WriteLine(ex);
        return null;
    }
    return page;
}&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeKeepCSharp/~4/UpFtMy0tBqo" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/CodeKeepCSharp/~3/UpFtMy0tBqo/bf4d5ff7-1c8a-42eb-88c0-501185dee953.aspx</link>
      <pubDate>Wed, 23 May 2012 10:41:46 GMT</pubDate>
    <feedburner:origLink>http://www.codekeep.net/snippets/bf4d5ff7-1c8a-42eb-88c0-501185dee953.aspx</feedburner:origLink></item>
    <item>
      <title>A simple routine to wait for an object to be assigned</title>
      <description>Description: useful for testing purposes&lt;br /&gt;&lt;br /&gt;Link: &lt;a href='http://www.codekeep.net/snippets/3ab3b6f6-8ac3-40f3-b93b-a8916337129c.aspx'&gt;http://www.codekeep.net/snippets/3ab3b6f6-8ac3-40f3-b93b-a8916337129c.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style='font-size: 9pt;'&gt;        private void WaitForAssignment(ref string obj, int millsecondTimeout = 2000)
        {
            DateTime start = DateTime.Now;
            while((DateTime.Now - start).TotalMilliseconds &amp;lt;= millsecondTimeout)
            {
                System.Threading.Thread.Sleep(1);
                if (obj != null) return;
            }
        }&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeKeepCSharp/~4/jLxVz9_QLkQ" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/CodeKeepCSharp/~3/jLxVz9_QLkQ/3ab3b6f6-8ac3-40f3-b93b-a8916337129c.aspx</link>
      <pubDate>Wed, 09 May 2012 16:03:38 GMT</pubDate>
    <feedburner:origLink>http://www.codekeep.net/snippets/3ab3b6f6-8ac3-40f3-b93b-a8916337129c.aspx</feedburner:origLink></item>
    <item>
      <title>Regex For Replacing Contents Between Tags</title>
      <description>Description: A regular expression used  for replacing content between HTML tags.&lt;br /&gt;&lt;br /&gt;Link: &lt;a href='http://www.codekeep.net/snippets/5df4d269-eaed-48d9-9cd1-b769d223d366.aspx'&gt;http://www.codekeep.net/snippets/5df4d269-eaed-48d9-9cd1-b769d223d366.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style='font-size: 9pt;'&gt;const string pattern = &amp;quot;(?&amp;lt;=&amp;lt;BEGIN_TAG_GOES_HERE&amp;gt;)(\n|\r|\r\n)(?&amp;lt;content&amp;gt;.+?)(\n|\r|\r\n)(?=&amp;lt;/END_TAG_GOES_HERE&amp;gt;)&amp;quot;;
var regex = new Regex(pattern);
var result = regex.Replace(fileContents, viewContent);&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeKeepCSharp/~4/2vFgMZuurCk" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/CodeKeepCSharp/~3/2vFgMZuurCk/5df4d269-eaed-48d9-9cd1-b769d223d366.aspx</link>
      <pubDate>Mon, 07 May 2012 17:31:20 GMT</pubDate>
    <feedburner:origLink>http://www.codekeep.net/snippets/5df4d269-eaed-48d9-9cd1-b769d223d366.aspx</feedburner:origLink></item>
    <item>
      <title>Object Detection</title>
      <description>Description: Applies colour filters to Bitmap Image before using that Bitmap object for object detection which return a rectangle. This rectangle can then be used to track an object or used in a finite state machine for a bang bang robotic controller.&lt;br /&gt;&lt;br /&gt;Link: &lt;a href='http://www.codekeep.net/snippets/36f3bec5-35f7-4c98-92f0-11df32ff038a.aspx'&gt;http://www.codekeep.net/snippets/36f3bec5-35f7-4c98-92f0-11df32ff038a.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style='font-size: 9pt;'&gt;using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Net;
using System.IO;
using System.Threading;
using System.Runtime.InteropServices;
//Requires the AForge Library
using AForge.Imaging.Filters;

//Change to your namespace
namespace detectObject
{
    public class Detection
    {

        /// &amp;lt;summary&amp;gt;
        /// Get camera image and converts it to a bitmap
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name=&amp;quot;camImg&amp;quot;&amp;gt;Image, saved image from a camera&amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt;Bitmap Image&amp;lt;/returns&amp;gt;
        public Bitmap getcamImg(Image newImg)
        {
            System.Drawing.Bitmap bImg = new System.Drawing.Bitmap(newImg);
            return bImg;
        }


        /// &amp;lt;summary&amp;gt;
        /// Filter the image froma HSV colour range
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name=&amp;quot;image&amp;quot;&amp;gt;Bitmap Image, any suitable image&amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt;Bitmap Image&amp;lt;/returns&amp;gt;
        public Bitmap addFilters(Bitmap image)
        {
			//Instantiate new HSL filter 
            AForge.Imaging.Filters.HSLFiltering hslFilter = new AForge.Imaging.Filters.HSLFiltering();
			
			//Define HSL colour range (default colour is orange)
            hslFilter.Hue = new AForge.IntRange(0, 50);
            hslFilter.Saturation = new AForge.DoubleRange(0.7, 1);
            hslFilter.Luminance = new AForge.DoubleRange(0.2, 0.7);

	    //Instantiate new RGB filter 
            /*AForge.Imaging.Filters.ColorFiltering rgbFilter = new AForge.Imaging.Filters.ColorFiltering();
			
	    //Define RGB colour range (default colour is orange)
            rgbFilter.Red = new AForge.IntRange(60, 180);
            rgbFilter.Green = new AForge.IntRange(10, 80);
            rgbFilter.Blue = new AForge.IntRange(5, 25);*/

	    //Apply the HSL filter to the input image
            hslFilter.ApplyInPlace(image);
			
	    //Create a 5 by 5 matrix using a short array
            int rows = 5;
            int cols = 5;
            short[,] Matrix = new short[rows, cols];

            for (int i = 0; i &amp;lt; rows; i++)
                for (int j = 0; j &amp;lt; cols; j++)
                    Matrix[i, j] = 1;
			
			//Instantiate new dilate filter with the 5 by 5 matrix
			AForge.Imaging.Filters.Dilatation dilate = new AForge.Imaging.Filters.Dilatation(Matrix);
			//Apply the filter
			dilate.ApplyInPlace(image);

            return image;
        }

        /// &amp;lt;summary&amp;gt;
        /// Apply rectangle to image
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name=&amp;quot;image&amp;quot;&amp;gt;Bitmap, any suitable image&amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt;Rectangle&amp;lt;/returns&amp;gt;
        public Rectangle DrawRectangle(Bitmap image)
        {
	    //Instantiate new blob counter
            AForge.Imaging.BlobCounter detectBlob = new AForge.Imaging.BlobCounter();

            //Get object by size
            detectBlob.ObjectsOrder = AForge.Imaging.ObjectsOrder.Size;
			
	    //Apply BlobCounter
            detectBlob.ProcessImage(image);

            //objects in an array.0
            Rectangle[] rects = detectBlob.GetObjectsRectangles();
			
	    //Create graphics from image
            Graphics g = Graphics.FromImage(image);

            try
            {
		//Draw rectangle around largest rectangle (default colour is red)
                g.DrawRectangle(new Pen(Color.Red), rects[0]);
				
		//Optional to save the result image to the startup directory
                //string startupPath = System.IO.Directory.GetCurrentDirectory();
                //image.Save(startupPath + @&amp;quot;\nameyourfile.jpg&amp;quot;);
				
		//Return the rantngla
                return rects[0];

            }
            catch (IndexOutOfRangeException e)
            {
		//If no blobs return empty rectangle
                Rectangle rrr = new Rectangle(0, 0, 0, 0);
                return rrr;
            }


        }
    }

}

&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeKeepCSharp/~4/BrmqlYAYiQ8" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/CodeKeepCSharp/~3/BrmqlYAYiQ8/36f3bec5-35f7-4c98-92f0-11df32ff038a.aspx</link>
      <pubDate>Mon, 30 Apr 2012 22:01:28 GMT</pubDate>
    <feedburner:origLink>http://www.codekeep.net/snippets/36f3bec5-35f7-4c98-92f0-11df32ff038a.aspx</feedburner:origLink></item>
    <item>
      <title>Test</title>
      <description>Description: test face&lt;br /&gt;&lt;br /&gt;Link: &lt;a href='http://www.codekeep.net/snippets/bbefe6ee-b4b2-4780-98db-6b13886130d2.aspx'&gt;http://www.codekeep.net/snippets/bbefe6ee-b4b2-4780-98db-6b13886130d2.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style='font-size: 9pt;'&gt;using DataContext 
{
	DBContext context=new DBContext();
}&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeKeepCSharp/~4/Yi7IF9zfdvI" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/CodeKeepCSharp/~3/Yi7IF9zfdvI/bbefe6ee-b4b2-4780-98db-6b13886130d2.aspx</link>
      <pubDate>Tue, 24 Apr 2012 10:09:10 GMT</pubDate>
    <feedburner:origLink>http://www.codekeep.net/snippets/bbefe6ee-b4b2-4780-98db-6b13886130d2.aspx</feedburner:origLink></item>
    <item>
      <title>Create a C-style union</title>
      <description>Description: This Visual C# code snippet uses the ExplicitLayout attribute to layout a struct explicitly and create a C-style union.&lt;br /&gt;&lt;br /&gt;Link: &lt;a href='http://www.codekeep.net/snippets/d8e84db3-b835-478b-9e45-d48c459f6307.aspx'&gt;http://www.codekeep.net/snippets/d8e84db3-b835-478b-9e45-d48c459f6307.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style='font-size: 9pt;'&gt;using System.Runtime.InteropServices;
...
[StructLayout(LayoutKind.Explicit)]
internal struct Union
{
   [FieldOffset (6)] internal byte byteData;
   [FieldOffset (0)] internal string stringText;
   [FieldOffset (4)] internal short unionShort;
   [FieldOffset (4)] internal byte lowByte;
   [FieldOffset (5)] internal byte highByte;
}
 
public class TestUnion
{
   public static void Main( )
   {
      Union union = new Union ();
      union.stringText = &amp;quot;Union&amp;quot;;
      union.byteData   = 0xFF;
      union.lowByte    = 0x01;
      union.highByte   = 0x01;
      Console.WriteLine (union.unionShort + &amp;quot; = &amp;quot; + 
         (union.highByte * 256 + union.lowByte).ToString());
   }			
}&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeKeepCSharp/~4/c0V9eTsHLlg" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/CodeKeepCSharp/~3/c0V9eTsHLlg/d8e84db3-b835-478b-9e45-d48c459f6307.aspx</link>
      <pubDate>Tue, 24 Apr 2012 08:54:26 GMT</pubDate>
    <feedburner:origLink>http://www.codekeep.net/snippets/d8e84db3-b835-478b-9e45-d48c459f6307.aspx</feedburner:origLink></item>
    <item>
      <title>C# Case Insensitive String Replace</title>
      <description>Description: Replace string A inside string B using string C, no attention is paid to the case.&lt;br /&gt;&lt;br /&gt;Link: &lt;a href='http://www.codekeep.net/snippets/89332015-9377-4390-8571-2d2f40df9b51.aspx'&gt;http://www.codekeep.net/snippets/89332015-9377-4390-8571-2d2f40df9b51.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style='font-size: 9pt;'&gt;        #region &amp;quot; Case-Insensitive String Replace &amp;quot;

        /// &amp;lt;summary&amp;gt;
        /// replace text in a string without consideration for the case of the input
        ///   string or the find string
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name=&amp;quot;input&amp;quot;&amp;gt;the string to search&amp;lt;/param&amp;gt;
        /// &amp;lt;param name=&amp;quot;oldText&amp;quot;&amp;gt;the text to find and replace&amp;lt;/param&amp;gt;
        /// &amp;lt;param name=&amp;quot;newText&amp;quot;&amp;gt;the text that replace the 'old' text&amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt;a new string with the replaced text&amp;lt;/returns&amp;gt;
        public static string ReplaceText(string input, string oldText, string newText)
        {
            if (string.IsNullOrEmpty(input))
                return input;
            if (string.IsNullOrEmpty(oldText))
                return input;

            // build the case insensitive regx to use
            var regxBuilder = new StringBuilder(&amp;quot;(&amp;quot;);
            for (var i = 0; i &amp;lt; oldText.Length; i++)
                regxBuilder.AppendFormat(&amp;quot;[{0}{1}]&amp;quot;, oldText.Substring(i, 1).ToLower(), oldText.Substring(i, 1).ToUpper());
            regxBuilder.Append(&amp;quot;)&amp;quot;);

            // perform the replacement
            var result = System.Text.RegularExpressions.Regex.Replace(input, regxBuilder.ToString(), newText);
            return result;
        }

        #endregion&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeKeepCSharp/~4/yITGrv-C9QA" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/CodeKeepCSharp/~3/yITGrv-C9QA/89332015-9377-4390-8571-2d2f40df9b51.aspx</link>
      <pubDate>Tue, 17 Apr 2012 20:13:21 GMT</pubDate>
    <feedburner:origLink>http://www.codekeep.net/snippets/89332015-9377-4390-8571-2d2f40df9b51.aspx</feedburner:origLink></item>
    <item>
      <title>Get Date From String with SQL Min check</title>
      <description>Description: Get Date From String with SQL Min check&lt;br /&gt;&lt;br /&gt;Link: &lt;a href='http://www.codekeep.net/snippets/2bed0d69-b15e-4204-a522-617d083f0a14.aspx'&gt;http://www.codekeep.net/snippets/2bed0d69-b15e-4204-a522-617d083f0a14.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style='font-size: 9pt;'&gt;        public static DateTime GetDateFromDateString(string date, out string resultMessage)
        {
            resultMessage = String.Empty;
            DateTime resultDate;
            // Do the Parsing first in order to fill-in the resultDate variable
            if (!DateTime.TryParse(date, out resultDate))
            {
                // Badly formatted dates or text in date fields will not parse
                resultMessage = &amp;quot;Improperly formatted Date.&amp;quot;;
            }
            else if (resultDate &amp;gt; new DateTime(DateTime.Parse(&amp;quot;12/31/9999 11:59:59 PM&amp;quot;).Ticks) || resultDate &amp;lt; new DateTime(DateTime.Parse(&amp;quot;1/1/1753 12:00:00 AM&amp;quot;).Ticks))
            {
                // MSSQL date Min and Max differ from DateTime Min and Max. Eventhough the object creates without error,
                // the SQL will raise Exception on date range
                resultMessage = &amp;quot;Date must be between 1/1/1753 and 12/31/9999&amp;quot;;
            }

            return resultDate;
        }&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeKeepCSharp/~4/mVStuxfHbJU" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/CodeKeepCSharp/~3/mVStuxfHbJU/2bed0d69-b15e-4204-a522-617d083f0a14.aspx</link>
      <pubDate>Wed, 04 Apr 2012 19:00:11 GMT</pubDate>
    <feedburner:origLink>http://www.codekeep.net/snippets/2bed0d69-b15e-4204-a522-617d083f0a14.aspx</feedburner:origLink></item>
    <item>
      <title>Load DataTable to Crystal Report</title>
      <description>Description: Load DataTable to Crystal Report&lt;br /&gt;&lt;br /&gt;Link: &lt;a href='http://www.codekeep.net/snippets/f1b43cc2-a18d-4671-88a4-e7508892601b.aspx'&gt;http://www.codekeep.net/snippets/f1b43cc2-a18d-4671-88a4-e7508892601b.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style='font-size: 9pt;'&gt;my_rpt objRpt;
            // Creating object of our report.
            objRpt = new my_rpt();

            String ConnStr = &amp;quot;SERVER=mydb;USER ID=user1;PWD=user1&amp;quot;;

            OracleConnection myConnection = new OracleConnection(ConnStr);

            String Query1 = &amp;quot;select a.PROJECT_ID,a.PROJECT_NAME,b.GROUP_NAME from 
            tbl_project a,tbl_project_group b where a.group_code= b.group_code&amp;quot;;

            OracleDataAdapter adapter = new OracleDataAdapter(Query1, ConnStr);

            DataSet Ds = new DataSet();

            // here my_dt is the name of the DataTable which we 
            // created in the designer view.
            adapter.Fill(Ds, &amp;quot;my_dt&amp;quot;);

            if (Ds.Tables[0].Rows.Count == 0)
            {
                MessageBox.Show(&amp;quot;No data Found&amp;quot;, &amp;quot;CrystalReportWithOracle&amp;quot;);
                return;
            }

            // Setting data source of our report object
            objRpt.SetDataSource(Ds);

            CrystalDecisions.CrystalReports.Engine.TextObject root;
            root = (CrystalDecisions.CrystalReports.Engine.TextObject)
                 objRpt.ReportDefinition.ReportObjects[&amp;quot;txt_header&amp;quot;];
            root.Text = &amp;quot;Sample Report By Using Data Table!!&amp;quot;;

            // Binding the crystalReportViewer with our report object. 
            crystalReportViewer1.ReportSource = objRpt;&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeKeepCSharp/~4/SEx6AOL1VsQ" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/CodeKeepCSharp/~3/SEx6AOL1VsQ/f1b43cc2-a18d-4671-88a4-e7508892601b.aspx</link>
      <pubDate>Fri, 30 Mar 2012 23:05:10 GMT</pubDate>
    <feedburner:origLink>http://www.codekeep.net/snippets/f1b43cc2-a18d-4671-88a4-e7508892601b.aspx</feedburner:origLink></item>
    <item>
      <title>Export Crystal Report to PDF</title>
      <description>Description: Export Crystal Report to PDF&lt;br /&gt;&lt;br /&gt;Link: &lt;a href='http://www.codekeep.net/snippets/6fd44e27-2581-4b02-8fa3-f6a28ed0f4d6.aspx'&gt;http://www.codekeep.net/snippets/6fd44e27-2581-4b02-8fa3-f6a28ed0f4d6.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style='font-size: 9pt;'&gt;try
            {
                ExportOptions CrExportOptions ;
                DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
                PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
                CrDiskFileDestinationOptions.DiskFileName = &amp;quot;c:\\csharp.net-informations.pdf&amp;quot;;
                CrExportOptions = cryRpt.ExportOptions;
                {
                    CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                    CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
                    CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
                    CrExportOptions.FormatOptions = CrFormatTypeOptions;
                }
                cryRpt.Export();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeKeepCSharp/~4/wW82xGp_T9M" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/CodeKeepCSharp/~3/wW82xGp_T9M/6fd44e27-2581-4b02-8fa3-f6a28ed0f4d6.aspx</link>
      <pubDate>Fri, 30 Mar 2012 23:04:20 GMT</pubDate>
    <feedburner:origLink>http://www.codekeep.net/snippets/6fd44e27-2581-4b02-8fa3-f6a28ed0f4d6.aspx</feedburner:origLink></item>
    <item>
      <title>Switch &amp; Enum</title>
      <description>Description: How use switch with enum&lt;br /&gt;&lt;br /&gt;Link: &lt;a href='http://www.codekeep.net/snippets/1578ab10-1a99-4036-8370-a5f41fd993b9.aspx'&gt;http://www.codekeep.net/snippets/1578ab10-1a99-4036-8370-a5f41fd993b9.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style='font-size: 9pt;'&gt;enum Action
{
  NoAction,
  Save,
  Load,
  Open
}
 
Hashtable keybinds = new HashTable();
 
keybinds.Add(Keys.S, Action.Save);
keybinds.Add(Keys.O, Action.Save);
// .. and so on
 
switch (keybinds[pressedKey])
{
  case Action.Save:
    // do stuff
    break;
  // and so on
}
 &lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeKeepCSharp/~4/Ibzd4RzP-h0" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/CodeKeepCSharp/~3/Ibzd4RzP-h0/1578ab10-1a99-4036-8370-a5f41fd993b9.aspx</link>
      <pubDate>Fri, 30 Mar 2012 15:02:01 GMT</pubDate>
    <feedburner:origLink>http://www.codekeep.net/snippets/1578ab10-1a99-4036-8370-a5f41fd993b9.aspx</feedburner:origLink></item>
    <item>
      <title>CreateSalt</title>
      <description>Description: Create a salt for password hash&lt;br /&gt;&lt;br /&gt;Link: &lt;a href='http://www.codekeep.net/snippets/41088e1b-1626-4a03-b3fa-1218b1140400.aspx'&gt;http://www.codekeep.net/snippets/41088e1b-1626-4a03-b3fa-1218b1140400.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style='font-size: 9pt;'&gt;private static string CreateSalt(int size)
{
  // Generate a cryptographic random number using the cryptographic
  // service provider
  RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
  byte[] buff = new byte[size];
  rng.GetBytes(buff);
  // Return a Base64 string representation of the random number
  return Convert.ToBase64String(buff);
}&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeKeepCSharp/~4/9vrYan94Aek" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/CodeKeepCSharp/~3/9vrYan94Aek/41088e1b-1626-4a03-b3fa-1218b1140400.aspx</link>
      <pubDate>Thu, 29 Mar 2012 19:09:39 GMT</pubDate>
    <feedburner:origLink>http://www.codekeep.net/snippets/41088e1b-1626-4a03-b3fa-1218b1140400.aspx</feedburner:origLink></item>
    <item>
      <title>HashString</title>
      <description>Description: Hash a string&lt;br /&gt;&lt;br /&gt;Link: &lt;a href='http://www.codekeep.net/snippets/03455414-e9ce-411e-9f0b-c8691d860f3d.aspx'&gt;http://www.codekeep.net/snippets/03455414-e9ce-411e-9f0b-c8691d860f3d.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style='font-size: 9pt;'&gt;public static string HashString(string inputString, string hashName)
{
    HashAlgorithm algorithm = HashAlgorithm.Create(hashName);
    if (algorithm == null)
    {
        throw new ArgumentException(&amp;quot;Unrecognized hash name&amp;quot;, &amp;quot;hashName&amp;quot;);
    }
    byte[] hash = algorithm.ComputeHash(Encoding.UTF8.GetBytes(inputString));
    return Convert.ToBase64String(hash);
}&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeKeepCSharp/~4/2-Q6cBLNkhQ" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/CodeKeepCSharp/~3/2-Q6cBLNkhQ/03455414-e9ce-411e-9f0b-c8691d860f3d.aspx</link>
      <pubDate>Thu, 29 Mar 2012 19:03:29 GMT</pubDate>
    <feedburner:origLink>http://www.codekeep.net/snippets/03455414-e9ce-411e-9f0b-c8691d860f3d.aspx</feedburner:origLink></item>
    <item>
      <title>Entities</title>
      <description>Description: Entities m?u&lt;br /&gt;&lt;br /&gt;Link: &lt;a href='http://www.codekeep.net/snippets/7f478f67-6483-4f34-8515-0a111d515442.aspx'&gt;http://www.codekeep.net/snippets/7f478f67-6483-4f34-8515-0a111d515442.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style='font-size: 9pt;'&gt;public class BankTransactionEntities : BaseTransactionEntities
    {
        #region Public Properties
        /// &amp;lt;summary&amp;gt;
        /// Gets or sets bank transaction item list
        /// &amp;lt;/summary&amp;gt;
        public BOSList&amp;lt;ACBankTransactionItemsInfo&amp;gt; BankTransactionItemList { get; set; }
        #endregion

        #region Constructor
        public BankTransactionEntities()
            :base()
        {
            BankTransactionItemList = new BOSList&amp;lt;ACBankTransactionItemsInfo&amp;gt;();
        }
        #endregion

        #region Init Main Object,Module Objects functions
        public override void InitMainObject()
        {
            MainObject = new ACBankTransactionsInfo();
            SearchObject = new ACBankTransactionsInfo();
        }

        public override void InitModuleObjects()
        {
            ModuleObjects.Add(TableName.ACBankTransactionItemsTableName, new ACBankTransactionItemsInfo());
        }

        public override void InitModuleObjectList()
        {
            BankTransactionItemList.InitBOSList(
                                                    this,
                                                    TableName.ACBankTransactionsTableName,
                                                    TableName.ACBankTransactionItemsTableName,
                                                    BOSList&amp;lt;ACBankTransactionsInfo&amp;gt;.cstRelationForeign);
            BankTransactionItemList.ItemTableForeignKey = &amp;quot;FK_ACBankTransactionID&amp;quot;;
        }

        public override void InitGridControlInBOSList()
        {
            BankTransactionItemList.InitBOSListGridControl();
        }

        public override void SetDefaultMainObject()
        {
            base.SetDefaultMainObject();
            ACBankTransactionsInfo objBankTransactionsInfo = (ACBankTransactionsInfo)MainObject;
            objBankTransactionsInfo.FK_GECurrencyID = BOSApp.CurrentCompanyInfo.FK_GESaleCurrencyID;
            objBankTransactionsInfo.ACBankTransactionExchangeRate = BOSApp.CurrentCompanyInfo.CSCompanySaleExchangeRate;
        }

        public override void SetDefaultModuleObjectsList()
        {
            try
            {
                BankTransactionItemList.SetDefaultListAndRefreshGridControl();
            }
            catch (Exception)
            {
                return;
            }
        }

        #endregion

        #region Invalidate Main Objects functions
       
        public override void InvalidateMainObject(int iObjectID)
        {
            base.InvalidateMainObject(iObjectID);

        }

        public override void InvalidateModuleObjects(int iObjectID)
        {
            BankTransactionItemList.Invalidate(iObjectID);
        }
        #endregion

        #region Save Module Objects and Main Object functions
        public override int SaveMainObject()
        {
            return base.SaveMainObject();
        }
        public override void SaveModuleObjects()
        {
            BankTransactionItemList.SaveItemObjects();
        }
        #endregion

        #region Accounting
        public override bool CreateAccountingData()
        {
            bool isComplete = AccountHelper.SaveAccountAndRelativeAccount(this, ACDocumentList);
            return isComplete;
        }
        #endregion
    }&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeKeepCSharp/~4/B9Vsu91JGM0" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/CodeKeepCSharp/~3/B9Vsu91JGM0/7f478f67-6483-4f34-8515-0a111d515442.aspx</link>
      <pubDate>Wed, 28 Mar 2012 03:05:44 GMT</pubDate>
    <feedburner:origLink>http://www.codekeep.net/snippets/7f478f67-6483-4f34-8515-0a111d515442.aspx</feedburner:origLink></item>
    <item>
      <title>Generating an Dictionary of XElement</title>
      <description>Description: a LINQPad script&lt;br /&gt;&lt;br /&gt;Link: &lt;a href='http://www.codekeep.net/snippets/dfe8fa85-9329-433f-a075-017b86b7fdd3.aspx'&gt;http://www.codekeep.net/snippets/dfe8fa85-9329-433f-a075-017b86b7fdd3.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style='font-size: 9pt;'&gt;var dictionaryDeclarationStatement = new CodeVariableDeclarationStatement (
    typeof(Dictionary&amp;lt;int, XElement&amp;gt;),
    &amp;quot;EXElementDictionary&amp;quot;,
    new CodeObjectCreateExpression ( typeof(Dictionary&amp;lt;int, XElement&amp;gt;) ) );
    
var provider = CodeDomProvider.CreateProvider(&amp;quot;CSharp&amp;quot;);
provider.GenerateCodeFromStatement(dictionaryDeclarationStatement, Console.Out, null);&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeKeepCSharp/~4/Yh7KHMMsesc" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/CodeKeepCSharp/~3/Yh7KHMMsesc/dfe8fa85-9329-433f-a075-017b86b7fdd3.aspx</link>
      <pubDate>Tue, 13 Mar 2012 00:55:37 GMT</pubDate>
    <feedburner:origLink>http://www.codekeep.net/snippets/dfe8fa85-9329-433f-a075-017b86b7fdd3.aspx</feedburner:origLink></item>
    <item>
      <title>Using a CodeIndexerExpression</title>
      <description>Description: a LINQPad script&lt;br /&gt;&lt;br /&gt;Link: &lt;a href='http://www.codekeep.net/snippets/61f3d462-51df-487d-b91b-0076dc94216b.aspx'&gt;http://www.codekeep.net/snippets/61f3d462-51df-487d-b91b-0076dc94216b.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style='font-size: 9pt;'&gt;var typeRef = new CodeTypeReference(typeof(List&amp;lt;XElement&amp;gt;));
var typeRefExpr = new CodeTypeReferenceExpression(typeRef);
var provider = CodeDomProvider.CreateProvider(&amp;quot;CSharp&amp;quot;);
provider.GenerateCodeFromExpression(typeRefExpr, Console.Out, null);

Console.WriteLine();

var indexerExpr = new CodeIndexerExpression(new CodeSnippetExpression(&amp;quot;EXElement&amp;quot;), new CodePrimitiveExpression(2));
provider.GenerateCodeFromExpression(indexerExpr, Console.Out, null );&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeKeepCSharp/~4/PxT2mS3Pbq8" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/CodeKeepCSharp/~3/PxT2mS3Pbq8/61f3d462-51df-487d-b91b-0076dc94216b.aspx</link>
      <pubDate>Tue, 13 Mar 2012 00:51:48 GMT</pubDate>
    <feedburner:origLink>http://www.codekeep.net/snippets/61f3d462-51df-487d-b91b-0076dc94216b.aspx</feedburner:origLink></item>
    <item>
      <title>XPath parsing with regular expressions 2</title>
      <description>Description: Parse an XPath expression using regular expressions XPathAtomRegex is a compiled Regex using the expression in the preceding comment&lt;br /&gt;&lt;br /&gt;Link: &lt;a href='http://www.codekeep.net/snippets/847a80c0-3ead-445e-b5aa-7d313adbfefc.aspx'&gt;http://www.codekeep.net/snippets/847a80c0-3ead-445e-b5aa-7d313adbfefc.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style='font-size: 9pt;'&gt;var path = &amp;quot;A/B[0]&amp;quot;;
//var re = new Regex(@&amp;quot;(?&amp;lt;elementName&amp;gt;\w+)(?&amp;lt;subscript&amp;gt;\[(?&amp;lt;position&amp;gt;\d+)\])?&amp;quot;, RegexOptions.Compiled);
var re = new XPathAtomRegex();

var matches = re.Matches(path);
var lastMatch = matches[matches.Count - 1];

path.Substring(0, lastMatch.Groups[&amp;quot;elementname&amp;quot;].Index).Dump(&amp;quot;elementName&amp;quot;);
lastMatch.Value.Dump(&amp;quot;lastMatch.Value&amp;quot;);
var g = lastMatch.Groups[&amp;quot;subscript&amp;quot;];
path.Substring(0, g.Index).Dump(&amp;quot;elementPath&amp;quot;);
lastMatch.Groups[&amp;quot;position&amp;quot;].Dump(&amp;quot;position group&amp;quot;);

lastMatch.Dump();&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeKeepCSharp/~4/OU5qhXHj8Pc" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/CodeKeepCSharp/~3/OU5qhXHj8Pc/847a80c0-3ead-445e-b5aa-7d313adbfefc.aspx</link>
      <pubDate>Tue, 13 Mar 2012 00:49:06 GMT</pubDate>
    <feedburner:origLink>http://www.codekeep.net/snippets/847a80c0-3ead-445e-b5aa-7d313adbfefc.aspx</feedburner:origLink></item>
    <item>
      <title>Convert Base64 String to File</title>
      <description>Description: A LINQPad snippet for converting a Base64 string to a file&lt;br /&gt;&lt;br /&gt;Link: &lt;a href='http://www.codekeep.net/snippets/49dfdfc5-39a6-4df9-b814-467969b0f7fe.aspx'&gt;http://www.codekeep.net/snippets/49dfdfc5-39a6-4df9-b814-467969b0f7fe.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style='font-size: 9pt;'&gt;void Main()
{
	ConvertFromBase64String();
}

void ConvertFromBase64String()
{
	string fileName = GetSaveFileName();
	if ( fileName == null )
	{
		MessageBox.Show(&amp;quot;No file name specified&amp;quot;);
	}
	else
	{
		ConvertFromBase64String(fileName);
	}
}

void ConvertFromBase64String(string saveFileName)
{
	ConvertFromBase64String(Clipboard.GetText(), saveFileName);
}

void ConvertFromBase64String(string input, string saveFileName)
{
	var contents = Convert.FromBase64String(input);
	
	using (var fs = new FileStream(saveFileName, FileMode.Create, FileAccess.Write))
	{
		fs.Write(contents, 0, contents.Length);
		fs.Flush();
	}
}

string GetFileName(FileDialog fd)
{
	bool? result = fd.ShowDialog();
	if ( result != null &amp;amp;&amp;amp; result.Value )
	{
		return fd.FileName;
	}
	return null;
}

string GetOpenFileName()
{
	var ofd = new OpenFileDialog { Title = &amp;quot;Select text file&amp;quot;, Filter = &amp;quot;All files (*.*)|*.*&amp;quot;,
		RestoreDirectory = true };
	return GetFileName(ofd);
}

string GetSaveFileName()
{
	var sfd = new SaveFileDialog { Title = &amp;quot;Save file as&amp;quot;, Filter = &amp;quot;All files (*.*)|*.*&amp;quot;,
		RestoreDirectory = true };
	return GetFileName(sfd);
}&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeKeepCSharp/~4/4XDAmhegltA" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/CodeKeepCSharp/~3/4XDAmhegltA/49dfdfc5-39a6-4df9-b814-467969b0f7fe.aspx</link>
      <pubDate>Sun, 11 Mar 2012 15:27:56 GMT</pubDate>
    <feedburner:origLink>http://www.codekeep.net/snippets/49dfdfc5-39a6-4df9-b814-467969b0f7fe.aspx</feedburner:origLink></item>
    <item>
      <title>3rd Party Assembly Signing</title>
      <description>Description: When referencing a 3rd party dll that is not signed you will not be able to sign your project.
Use the following instructions to sign the 3rd party assembly.&lt;br /&gt;&lt;br /&gt;Link: &lt;a href='http://www.codekeep.net/snippets/015cb5e2-1e18-45fc-bbf6-fd68f1e95b1c.aspx'&gt;http://www.codekeep.net/snippets/015cb5e2-1e18-45fc-bbf6-fd68f1e95b1c.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style='font-size: 9pt;'&gt;Signing an unsigned Assembly

1. Open VS Console

2. Change DIR to location of dll to sign

3. Disassemble
	ildasm /all /out=AssemblyName.il AssemblyName.dll

4. Reassemble using your snk
	ilasm /dll /key=SNKNAME.snk AssemblyName.il
	
Where AssemblyName is the name of your assembly.

DONE...!&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeKeepCSharp/~4/KTVGUby3EBU" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/CodeKeepCSharp/~3/KTVGUby3EBU/015cb5e2-1e18-45fc-bbf6-fd68f1e95b1c.aspx</link>
      <pubDate>Fri, 09 Mar 2012 09:02:07 GMT</pubDate>
    <feedburner:origLink>http://www.codekeep.net/snippets/015cb5e2-1e18-45fc-bbf6-fd68f1e95b1c.aspx</feedburner:origLink></item>
    <item>
      <title>Get ASPX page Name</title>
      <description>Description: Gets name of a web page file ending with .aspx&lt;br /&gt;&lt;br /&gt;Link: &lt;a href='http://www.codekeep.net/snippets/bc4b156c-e8a8-42e9-b049-eb62d06f093b.aspx'&gt;http://www.codekeep.net/snippets/bc4b156c-e8a8-42e9-b049-eb62d06f093b.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style='font-size: 9pt;'&gt;        /// &amp;lt;summary&amp;gt;
        /// Returns the ASPX page name
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name=&amp;quot;Pg&amp;quot;&amp;gt;The HTTP webpage object&amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt;name of the page as in &amp;quot;Orders.aspx&amp;quot;&amp;lt;/returns&amp;gt;
        /// &amp;lt;remarks&amp;gt;Used for IRIS_GUIComponets table where each page can have components enabled, disabled, and so on.. controlled by the Database&amp;lt;/remarks&amp;gt;
        public static string GetASPXPageName(Page pg)
        {
            string sPath = pg.Request.Url.AbsolutePath;
            string[] strarry = sPath.Split('/');
            int lengh = strarry.Length;
            string sRet = strarry[lengh - 1];
            return sRet;
        }&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeKeepCSharp/~4/VbE4_arz01w" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/CodeKeepCSharp/~3/VbE4_arz01w/bc4b156c-e8a8-42e9-b049-eb62d06f093b.aspx</link>
      <pubDate>Thu, 08 Mar 2012 20:14:27 GMT</pubDate>
    <feedburner:origLink>http://www.codekeep.net/snippets/bc4b156c-e8a8-42e9-b049-eb62d06f093b.aspx</feedburner:origLink></item>
    <item>
      <title>How to Save Code First Using Store Procedures in the Entity Framework</title>
      <description>Description: Shows how I managed to get the entity framework to save entities via a store procedure. As a side note also shows you how to stop an entity from being deleted by accident.&lt;br /&gt;&lt;br /&gt;Link: &lt;a href='http://www.codekeep.net/snippets/e409b993-5d9a-45cb-a06b-3927cfd9b713.aspx'&gt;http://www.codekeep.net/snippets/e409b993-5d9a-45cb-a06b-3927cfd9b713.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style='font-size: 9pt;'&gt;public class MyContext : DbContext
{
        public override int SaveChanges()
        {
            int result = 0;

            var entities = ChangeTracker.Entries&amp;lt;MyEntity&amp;gt;();
            result += SavEntity(entities );

            return result + base.SaveChanges();
        }

        private int SaveCards(IEnumerable&amp;lt;DbEntityEntry&amp;lt;MyEntity&amp;gt;&amp;gt; cards)
        {
            int result = 0;

            foreach (var entry in entities)
            {
                if (entry.State == EntityState.Added)
                {
                    var storeProc = new SaveEntityProcedure(Database.Connection.ConnectionString);
                    var exResult = storeProc.Execute(entry.Entity);
                    if (exResult == 0)
                        throw new Exception(String.Format(&amp;quot;The save command for MyEntity '{0}' failed!&amp;quot;, entry.Entity.Id));
                    result += 1;

                    entry.State = EntityState.Unchanged;

                    if (Tracing.TraceSwitch.TraceVerbose) Trace.TraceInformation(string.Format(&amp;quot;Added MyEntity Id {0}&amp;quot;, entry.Entity.Id));
                }
                else if (entry.State == EntityState.Modified)
                {
                    var storeProc = new UpdateCardStoreProcedure(Database.Connection.ConnectionString);
                    var exResult = storeProc.Execute(entry.Entity);
                    if (exResult == 0)
                        throw new CardDataException(String.Format(&amp;quot;The update command for MyEntity '{0}' failed!&amp;quot;, entry.Entity.Id));
                    result += exResult;
                    
                    // trick to ensure the entity framework doesn't 'undo' changes when State is set to unchanged.
                    entry.State = EntityState.Added;
                    entry.State = EntityState.Unchanged;

                    if (Tracing.TraceSwitch.TraceVerbose) Trace.TraceInformation(&amp;quot;Updated MyEntity Id {0}&amp;quot;, entry.Entity.Id);
                }
                else if (entry.State == EntityState.Deleted)
                {
                    throw new Exception(string.Format(&amp;quot;Cannot delete a MyEntity ({0})!&amp;quot;, entry.Entity.Id));
                }
            }

            return result;
        }
}
&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeKeepCSharp/~4/oFvpC9CaMN4" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/CodeKeepCSharp/~3/oFvpC9CaMN4/e409b993-5d9a-45cb-a06b-3927cfd9b713.aspx</link>
      <pubDate>Fri, 02 Mar 2012 09:07:05 GMT</pubDate>
    <feedburner:origLink>http://www.codekeep.net/snippets/e409b993-5d9a-45cb-a06b-3927cfd9b713.aspx</feedburner:origLink></item>
    <item>
      <title>Get the PropertyInfo via an Expression</title>
      <description>Description: Retrieves the PropertyInfo for a given lambda expression&lt;br /&gt;&lt;br /&gt;Link: &lt;a href='http://www.codekeep.net/snippets/f72550cf-3a81-4825-99a0-3b1f27ebf91f.aspx'&gt;http://www.codekeep.net/snippets/f72550cf-3a81-4825-99a0-3b1f27ebf91f.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style='font-size: 9pt;'&gt;
MemberExpression memberExpression = expression.Body as MemberExpression;
if (memberExpression == null)
{
    UnaryExpression ubody = (UnaryExpression)expression.Body;
    memberExpression = ubody.Operand as MemberExpression;
} 
if (memberExpression == null || (memberExpression.Member as PropertyInfo) == null)
{
    throw new ArgumentException(string.Format(&amp;quot;The Expression {0} is not a member expression for a property&amp;quot;, expression));
}&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeKeepCSharp/~4/BqSbyfITiU4" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/CodeKeepCSharp/~3/BqSbyfITiU4/f72550cf-3a81-4825-99a0-3b1f27ebf91f.aspx</link>
      <pubDate>Wed, 29 Feb 2012 09:21:54 GMT</pubDate>
    <feedburner:origLink>http://www.codekeep.net/snippets/f72550cf-3a81-4825-99a0-3b1f27ebf91f.aspx</feedburner:origLink></item>
    <item>
      <title>C# PLINQ File / Directory Delete Routine</title>
      <description>Description: Parallel delete routine using PLINQ.&lt;br /&gt;&lt;br /&gt;Link: &lt;a href='http://www.codekeep.net/snippets/a1338f86-8123-473e-b047-c464d25dfe78.aspx'&gt;http://www.codekeep.net/snippets/a1338f86-8123-473e-b047-c464d25dfe78.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style='font-size: 9pt;'&gt;        /// &amp;lt;summary&amp;gt;
        /// use PLINQ to delete files from the system (1 operation per cpu core)
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name=&amp;quot;directoryPath&amp;quot;&amp;gt;the top level path to delete&amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt;the number of deleted files on success (0+), or -1 for failure&amp;lt;/returns&amp;gt;
        public static int DeleteDirectory(string directoryPath)
        {
            try
            {
                var del = new List&amp;lt;string&amp;gt;(Directory.GetFiles(directoryPath, &amp;quot;*.*&amp;quot;, SearchOption.AllDirectories));
                Parallel.ForEach(del, d =&amp;gt; { File.SetAttributes(d, FileAttributes.Normal); File.Delete(d); });
                return del.Count;
            }
            catch (Exception)
            {
                return -1;
            }
        }&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeKeepCSharp/~4/xEcaYQu1jWo" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/CodeKeepCSharp/~3/xEcaYQu1jWo/a1338f86-8123-473e-b047-c464d25dfe78.aspx</link>
      <pubDate>Thu, 23 Feb 2012 08:12:08 GMT</pubDate>
    <feedburner:origLink>http://www.codekeep.net/snippets/a1338f86-8123-473e-b047-c464d25dfe78.aspx</feedburner:origLink></item>
  </channel>
</rss>

