Friday, December 31, 2010

DB Design consideration

 Is easily to update – either in real time, or in monthly batches.
 Permits ad hoc drill down queries and reports
 Allows you to store an unlimited amount of data about any object
 Permits you to add fields without redoing the whole database.
 Makes it easy to modify the data and to retrieve information
 Makes it easy to develop and carry out personalized communications.
 Permits the inclusion of business rules in the database design.

http://www.crm2day.com/editorial/EpVkEkkylZNkorRHLx.php

Thursday, December 23, 2010

How To: Sending email over Power Shell

$EmailFrom = "your@email.com"
$EmailTo = "destination@email.com"
$Subject = "Your subject goes here"
$Body = "the body info which usually will a parameter with gathered info."
$SMTPServer = "smtp.email.com"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25)
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("user", "pwd");
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

links for virtualization architectures

A great overview of tools and links for virtualization architectures


http://www.chriswolf.com/?page_id=93

Wednesday, December 22, 2010

How To: Add Context Menu Registry

I found to today a small utility to scan and visualize my harddisc (http://www.steffengerlach.de/freeware/). in the installation folder i found the following code to add a program to the registry:

save the content in a *.reg file to execute it:

ADD:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\Scan_Content]
@="Scan Content"

[HKEY_CLASSES_ROOT\Directory\shell\Scan_Content\command]
@="C:\\Program Files\\Scanner\\Scanner.exe \"%1\""

[HKEY_CLASSES_ROOT\Drive\shell\Scan_Content]
@="Scan Content"

[HKEY_CLASSES_ROOT\Drive\shell\Scan_Content\command]
@="C:\\Program Files\\Scanner\\Scanner.exe \"%1\""


REMOVE:

Windows Registry Editor Version 5.00

[-HKEY_CLASSES_ROOT\Directory\shell\Scan_Content]

[-HKEY_CLASSES_ROOT\Directory\shell\Scan_Content\command]


[-HKEY_CLASSES_ROOT\Drive\shell\Scan_Content]

[-HKEY_CLASSES_ROOT\Drive\shell\Scan_Content\command]

Sunday, December 19, 2010

How To: Versioning Builds With TFS 2010

http://www.richard-banks.org/2010/07/how-to-versioning-builds-with-tfs-2010.html

by Richard Banks

how to Office Developers is called No-PIA

This sample shows how to use the C# 4.0 features called COM Interop, omitting ref, indexed properties and Named and Optional Parameters to create a C# application that communicates with Microsoft Office. C# developers have traditionally had to write relatively verbose code in order to access Microsoft Office applications such as Word or Excel. New C# 4.0 features make it much simpler to call Office APIs.

Consider this declaration for a Microsoft Office method used in this sample:

void PasteSpecial(ref object IconIndex = null, ref object Link = null,
ref object Placement = null, ref object DisplayAsIcon = null,
ref object DataType = null, ref object IconFileName = null,
ref object IconLabel = null);

As you can see, this method takes a fairly large number of parameters. In C#, developers have traditionally had to fill out each parameter, even though the developers of this call had intended to simplify its use by supporting optional parameters. In C# 4.0, the new support for named and optional parameters allows the developer to specify only the parameters of interest, and to take default values for the other parameters:

word.Selection.PasteSpecial(Link: true, DisplayAsIcon: true);

In the call to the PasteSpecial method the Link and DisplayAsIcon parameters are explicitly named, and set to the value true. All the other parameters default to values specified internally by the developers of the Office API, as shown in the above signature.

You can create your own calls that support named and optional paramters. Consider this example:

public void M(int x, int y = 5, int z = 7) { }

In this method, the parameters y and z are assigned default values. Calls to this method might look like this:

M(1, 2, 3); // ordinary call of M
M(1, 2); // omitting z – equivalent to M(1, 2, 7)
M(1); // omitting both y and z – equivalent to M(1, 5, 7)
M(1, z: 3); // passing z by name
M(x: 1, z: 3); // passing both x and z by name
M(z: 3, x: 1); // reversing the order of arguments

A new dynamic feature in C# 4.0 makes Office much easier for C# developers to use. Types used in Office are now presented to C# developers as if they were declared with the type dynamic. Here is the traditionally way to set a Cell property:

((Excel.Range)excel.Cells[1, 1]).Value2 = "ID";

In C# 4.0 developers can now write code that looks like this:

X1.Cells[1, 1].Value = "ID";

A feature called Index Properties allows us to simplify the call further, so that it looks like this:

xl.Cells[1, 1] = "ID";

A final feature of interest to Office Developers is called No-PIA. Primary Interop Assemblies are generated from COM interfaces and provide helpful type support at design time. At runtime, however, they increase the size of your program, and can cause versioning issues. The No-PIA feature allows you to continue to use PIAs at design but omit them at runtime. The C# compiler will bake the small part of the PIA that a program actually uses directly into its assembly. You will no longer need to include PIA's in the distribution of your programs.


// Copyright © Microsoft Corporation.  All Rights Reserved.
// This code released under the terms of the
// Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)
//

using System;
using System.Collections.Generic;

using Excel = Microsoft.Office.Interop.Excel;
using Word = Microsoft.Office.Interop.Word;

public class Account
{
public int ID { get; set; }
public double Balance { get; set; }
}

public class Program
{
static void Main(string[] args)
{
var checkAccounts = new List<Account> {
new Account {
ID = 345,
Balance = 541.27
},
new Account {
ID = 123,
Balance = -127.44
}
};

DisplayInExcel(checkAccounts, (account, cell) =>
{
// This multiline lambda will set
// custom processing rules.
cell.Value = account.ID;
cell.Offset[0, 1].Value = account.Balance;

if (account.Balance < 0)
{
cell.Interior.Color = 255;
cell.Offset[0, 1].Interior.Color = 255;
}
});

var word = new Word.Application();
word.Visible = true;
word.Documents.Add();
word.Selection.PasteSpecial(Link: true, DisplayAsIcon: true);
}

public static void DisplayInExcel(IEnumerable<Account> accounts,
Action<Account, Excel.Range> DisplayFunc)
{
var xl = new Excel.Application();

xl.Workbooks.Add();
xl.Visible = true;
xl.Cells[1, 1] = "ID";
xl.Cells[1, 2] = " Balance";
xl.Cells[2, 1].Select();
foreach (var ac in accounts)
{
DisplayFunc(ac, xl.ActiveCell);
xl.ActiveCell.Offset[1, 0].Select();
}

xl.Range["A1:B3"].Copy();
//xl.get_Range("A1:B3").Copy();

xl.Columns[1].AutoFit();
xl.Columns[2].AutoFit();
}
}

Thursday, December 16, 2010

ThreadSafeCache class in C#



using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Collections.ObjectModel;

namespace Caching
{
public class ThreadSafeCache<T1, T2>
{
static ReaderWriterLockSlim rwlock = new ReaderWriterLockSlim();
private const int DoNotTimeOut = 0;
private Dictionary<T1, T2> mCache = new Dictionary<T1, T2>();

public bool ContainsKey(T1 key)
{
bool result = false;
rwlock.EnterReadLock();
try
{
result = mCache.ContainsKey(key);
}
finally
{
rwlock.ExitReadLock();
}
return result;
}

public T2 this[T1 index]
{
get
{
T2 result;
rwlock.EnterReadLock();
try
{
result = mCache[index];
}
finally
{
rwlock.ExitReadLock();
}
return result;
}
set
{
rwlock.EnterWriteLock();
try
{
mCache[index] = value;
}
finally
{
rwlock.ExitWriteLock();
}
}
}

public void Add(T1 key, T2 value)
{
rwlock.EnterWriteLock();
try
{
mCache.Add(key, value);
}
finally
{
rwlock.ExitWriteLock();
}
}
public void AddOrIgnore(T1 key, T2 value)
{
rwlock.EnterWriteLock();
try
{
if (!mCache.ContainsKey(key))
mCache.Add(key, value);
}
finally
{
rwlock.ExitWriteLock();
}
}
public void AddOrReplace(T1 key, T2 value)
{
rwlock.EnterWriteLock();
try
{
if (!mCache.ContainsKey(key))
mCache.Add(key, value);
else
mCache[key] = value;
}
finally
{
rwlock.ExitWriteLock();
}
}
public bool Remove(T1 key)
{
bool result = false;
rwlock.EnterWriteLock();
try
{
result = mCache.Remove(key);
}
finally
{
rwlock.ExitWriteLock();
}
return result;
}

public void Clear()
{
rwlock.EnterWriteLock();
try
{
mCache.Clear();
}
finally
{
rwlock.ExitWriteLock();
}
}

public ReadOnlyCollection<T1> Keys
{
get
{
ReadOnlyCollection<T1> result;
rwlock.EnterReadLock();
try
{
result = new ReadOnlyCollection<T1>(new List<T1>(mCache.Keys));
}
finally
{
rwlock.ExitReadLock();
}
return result;
}
}
}
}

Monday, December 13, 2010

High Availability

Availability is traditionally measured according the percentage of time that the system is available to its end users.

Therefore, 100 percent availability means that the system is available all of the time and there is no downtime. However, achieving 100 percent availability is virtually impossible. Too many technical and human factors are involved for that to be a realistic possibility. Even so, by utilizing technology and creating a suitable operating environment, very high levels of availability are achievable. The highest practical measure of availability is typically expressed as “five nines” or 99.999 percent. The percentage of availability can be calculated using the following formula:

Percentage of availability = ((total elapsed time – sum of downtime)/total elapsed time)

The percentage of system availability equals the total elapsed time minus the sum of the system downtime. This result is then divided by the total elapsed time.

Let’s take a little deeper look at what this means in a practical sense. A year has a total of 8,760 hours (24 hours per day × 365 days per year = 8,760 hours). Therefore, an availability of 8,760 hours over a year would be 100 percent uptime as you can see in the following equation:

100 = ((8,760 – 0)/8,760) × 100

A much more common scenario is for a system to have a regular period of downtime every month. For many organizations this might be as little as eight hours of downtime in every month, or essentially two hours per week. This downtime might be the result of planned system maintenance such as system backup procedures. Two hours of downtime per week or eight hours per month results in 98.9 percent availability, as the following formula illustrates:

98.9 = ((8,760 – (8 × 12)/8,760)) × 100

Many organizations don’t achieve that level of availability. However, when expressed as a measure of nine, 98.9 percent isn’t even two nines, as the base level of availability is lower than 99 percent. While one nine may not seem like a high level of availability, for many organizations one day of downtime per month would be perfectly adequate.

However, many businesses are running critical lines of business and e-commerce applications where one nine of availability is not enough. These organizations require three nines or even five nines of availability. So how much actual downtime is associated with these levels of availability? Table 1-1 gives you an idea of the amount of downtime that is permitted with each increasing level of “nines.”
Number of Nines and Downtime





































Number of NinesPercentage AvailabilityDowntime per YearDowntime per MonthDowntime per Week
Two nines99.0%3.65 days7.30 hrs1.68 hrs
Three nines99.9%8.76 hrs43.8 mins10.1 mins
Four nines99.99%52.6 mins4.38 mins1.01 mins
Five nines99.999%5.26 mins26.28 secs6.06 secs


The above table shows how each increasing nine level of availability requires significant decreases in downtime. While reaching two nines of availability can be accomplished with a total of 1.68 hours per week of downtime, five nines of availability is only slightly more than five minutes of downtime per year.

Five minutes of downtime per year is an impressive and difficult number to achieve. Another important factor to remember is that the costs and operational disciplines increase substantially with each successive level of availability. Achieving these higher levels of availability cannot be accomplished using technology only. Creating a highly available environment requires a combination of several factors.

Shared Cache - .Net Caching made easy

All information about Shared Cache is available here: http://www.sharedcache.com/. Its free and easy to use, we provide all sources at codeplex.

Facebook Badge