Archive for the Category dotnet

 
 

Read Rss into DataSet

The simple trick shows how to read rss feed into DataSet .

using System;
using System.Data;
using System.Net;
 
namespace DevIntelligence.Examples
{
    class RssReader
    {
        [STAThread]
        static void Main(string[] args)
        {
            HttpWebRequest feed = 
            HttpWebRequest.Create("http://msdn.microsoft.com/rss.xml") 
            as HttpWebRequest;
            
            DataSet data = new DataSet();
            data.ReadXml( feed.GetResponse().GetResponseStream()) ;
        }
    }
}

.Net Sample for Amazon Web Services (AWS) Request Authentication

The following code sample demonstrates how to calculate a request signature to sign authenticated requests to AWS.

 

using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
 
 
namespace Devintelligence.Aws
{
    /// <summary>
    /// Generation authentication signatures for AWS Platform requests.
    /// </summary>
    public class AwsUtils
    {
        /// <summary>
        /// Computes RFC 2104-compliant HMAC signature.
        /// </summary>
        /// <param name="data">The data to be signed.</param>
        /// <param name="key">The signing key.</param>
        /// <returns>The Base64-encoded RFC 2104-compliant HMAC signature.</returns>
        public static string calculateRFC2104HMAC(string data, string key)
        {
            byte[] bData = Encoding.UTF8.GetBytes(data);
            byte[] bKey = Encoding.UTF8.GetBytes(key);
 
 
            HMACSHA1 hmac = new HMACSHA1(bKey);
            using(CryptoStream cryptoStream =
                      new CryptoStream(Stream.Null, hmac, CryptoStreamMode.Write) )
            {
                cryptoStream.Write(bData, 0, bData.Length);
            }
            return Convert.ToBase64String(hmac.Hash);
        }
 
 
 
 
 
        /// <summary>
        /// Gets the time stamp.
        /// </summary>
        /// <param name="dateTime">Date time.</param>
        /// <returns></returns>
        public static string GetTimeStamp(DateTime dateTime)
        {
            return dateTime.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
        }
 
    }
}

Use BackgroundWorker with any class

BackgroundWorker works only with the classes that implements interface ISynchronizeInvoke – in order to use BackgroundWorker with any class necessary to make the following changes in the code.

The code after the changes ( BackgroundWorker.cs ):

private void InvokeDelegate(Delegate del, params object[] args)
{
    ISynchronizeInvoke synchronizer = del.Target as ISynchronizeInvoke;
    try
    {
        if(synchronizer != null) //A Windows Forms object
        {
            if (synchronizer.InvokeRequired == false)
            {
                del.DynamicInvoke(args);
                return;
            }
            synchronizer.Invoke(del, args);
        }
        else //Not a Windows Forms object
        {
            del.DynamicInvoke(args);
        }
    }
    catch (Exception e)
    {
        Trace.WriteLine(e.Message);
    }
}

 

 

Thanks to Roy Osherove for help in the solution of this problem

Encrypt your .NET application’s and DLLs

CodeVeil will add native code to the assembly to decrypt the assembly just before the .NET runtime needs access to the data. The decoder includes anti-debugging, anti-tracing, modification tracking, and various other
advanced techniques to avoid unauthorized access and modification of your assemblies. And, veiled assemblies can be used just like any other assembly. No third party dll is required with your distribution.

Downloada Free Trial Now

[Via help.net]

System.Drawing.Color serialization

The Person class includes a HairColor property that stores a Color object. Because a Color cannot be automatically serialized/deserialized using the .NET System.Xml.Serialization.XmlSerializer class, the Color object is saved to the XML file as an HTML string, and converted back into a Color when the XML file is loaded.

sing System;
using System.Drawing;
using System.Xml.Serialization;
 
 
//To support binary serialization you need to 
// add the "[Serializable]" attribute
[Serializable]
public class Person
{
    private Color _HairColor = Color.Empty;
        
    // Initializes a new instance of the Person class.
    // (required for serialization)
    public Person()
    {
            
    }
        
        
    // Set serialization to ignore this property
        // because the 'HairColorHtml' property
        // is used instead to serialize
        // the 'HairColor' Color as an HTML string.
    [XmlIgnoreAttribute()]
    public Color HairColor
    {
        get
        {
            return _HairColor;
        }
        set
        {
            _HairColor = value;
        }
    }
        
        
    // Serializes the 'HairColor' Color to XML.
    [XmlElement("HairColor")]
    public string HairColorHtml
    {
        get 
        { 
            return
                ColorTranslator.ToHtml(_HairColor);
        }
        set 
        { 
            _HairColor = ColorTranslator.FromHtml( value );
        }
    }
        
}


Page 6 of 14« First...45678...Last »