February 3, 2016

Difference between NameValueCollection and Dictionary in C#

The NameValueCollection can have duplicate keys while the Dictionary cannot.
Dictionary will be much faster because duplicate keys not allowed here while NameValueCollection allows duplicate keys.

//Add values into NameValueCollection object
NameValueCollection objNvc = new NameValueCollection()
{
  {
"key1", "value1"},
  {
"key2", "value2"}
};


// Access values from NameValueCollection object

foreach (string key in objNvc.AllKeys)
{
   
string value = objNvc[key];
}

//Add values into Dictionary object

Dictionary<string, string> objDictionary = new Dictionary<string, string>()
{
  {
"key1", "value1"},
  {
"key2", "value2"}
 };


// Retrieve values from Dictionary object

foreach (KeyValuePair<string, string> kvp in objDictionary)
{
   
string key = kvp.Key;
   
string val = kvp.Value;
}

February 2, 2016

Design Pattern Code Sample

If you want to find code sample for design patterns, please visit below url to find resource on this.

https://csharpdesignpatterns.codeplex.com/

February 1, 2016

How can we install mongoDB shell


If you want to install mongoDB shell on your system, please follow below url to get plenty of details on mongoDB shell installation.

https://docs.mongodb.org/v3.0/tutorial/getting-started-with-the-mongo-shell/

 

January 25, 2016

Disable text selection using CSS

 .disabletextsel
{
  
-webkit-touch-callout: none;
  
-webkit-user-select: none;
  
-khtml-user-select: none;
  
-moz-user-select: none;
  
-ms-user-select: none;
  
user-select: none;
}

January 24, 2016

Execute DOS commands from C#

string Commands = @"cmd.exe /c cd c:\mongodb\bin";

Process cmd = new Process();
cmd.StartInfo.FileName =
"cmd.exe";
cmd.StartInfo.WindowStyle =
ProcessWindowStyle.Hidden;
cmd.StartInfo.Arguments = Commands;
cmd.Start();
cmd.WaitForExit();

 

January 23, 2016

Export Sitecore mongoDB collection to CSV using C#

string PageInfoCollectionCommand = "mongo analytics -eval \"db.createCollection(" + "\\" + '\u0022' + "TMP_DT" + "\\" + '\u0022' + ", {autoIndexId: false } );var result = db.Interactions.aggregate([{$match: {SaveDateTime: { $gt: ISODate(" + "\\" + '\u0022' + "2016-01-01T00:00:00.000Z" + "\\" + '\u0022' + ") }}},{ $project : {_id: 1 ,ContactId: 1 ,Pages: 1}},{ $unwind :" + "\\" + '\u0022' + "$Pages" + "\\" + '\u0022' + " }]);db." + "TMP_DT" + ".insert(result.toArray());";


string PageInfoExportCSVCommand = "mongoexport --db analytics --collection " + "TMP_DT" + " --type=csv --out " + "DLY_DATA" + "/INTERACTION-PAGE-INFO-DATA-" + "DLY_DATA" + ".csv" + " --fields fields name comma seperated ";

string PageInfoExportTempCollectionDeleteCommand = "mongo analytics -eval \"db." + "TMP_DT" + ".drop();" + '\u0022';

string Commands = @"cmd.exe /c cd c:\mongodb\bin & " + PageInfoCollectionCommand + '\u0022' + " & " + PageInfoExportCSVCommand + " & " + PageInfoExportTempCollectionDeleteCommand + " & mongoexport --db analytics --collection Interactions --type=csv --out " + "DLY_DATA" + "/INTERACTION-DATA-" + "DLY_DATA" + ".csv" + " --fields fields name comma seperated " + "--query " + '\u0022' + "{ " + '\u0027' + "SaveDateTime" + '\u0027' + ":{" + '\u0027' + "$gt" + '\u0027' + ":{ " + '\u0027' + "$date" + '\u0027' + ":" + '\u0027' + "2016-01-01T00:00:00.000Z" + '\u0027' + " }}}" + '\u0022' + "" + " --sort " + '\u0022' + "{SaveDateTime: 1}" + '\u0022';


Process cmd = new Process();

cmd.StartInfo.FileName =
"cmd.exe";
cmd.StartInfo.WindowStyle =
ProcessWindowStyle.Hidden;
cmd.StartInfo.Arguments = Commands;
cmd.Start();
cmd.WaitForExit();