Archive for the Category code

 
 

.Net localization (Hebrew version)

.NET supports Unicode and you can use variables and literals in your own language.Is it useful? I don’t know ,but looks amazing.

using System;
 
namespace Devintelligence.Localization
{
    /// <summary>
    /// Localization in Hebrew
    /// </summary>
    class Class1
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            for( int ?????    = 0;?????<10;?????++ )
            {
                Console.Write("{0}", ????? );
            }
            Console.ReadLine();
        }
    }
}

[Via Abhinaba's blog]

How to find out if the left shift or right shift key has been pressed down …

Add this declaration.

[DllImport("user32")]
public static extern short GetKeyState (Keys VirtKey);

On your KeyDown event, you can check which shift key has been pressed down in this way:

bool LShiftPressed = ((GetKeyState(Keys.LShiftKey) & 256)==256);
bool RShiftPressed = ((GetKeyState(Keys.RShiftKey) & 256)==256);

How to delete file on reboot.

This code snippet forces windows to delete the file on reboot.

[System.Runtime.InteropServices.DllImport("kernel32.dll")]
private static extern bool MoveFileEx(string lpExistingFileName, string lpNewFileName, int dwFlags);
const int MOVEFILE_DELAY_UNTIL_REBOOT = 0x00000004;
 
static void MarkFileToDeleteOnReboot(string fileName)
{
    MoveFileEx(fileName, null, MOVEFILE_DELAY_UNTIL_REBOOT);
} 
 
 

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");
        }
 
    }
}


Page 3 of 512345