Wednesday, September 19, 2012

Use C# to get JSON data from the web and map it to .NET class

using Json.net , available through Nuget package
Use C# to get JSON data from the web and map it to .NET class => made easy! - CodeProject

http://james.newtonking.com/projects/json/help/index.html?topic=html/SerializingJSON.htm

using native datacontractjsonserializer
http://msdn.microsoft.com/en-us/library/hh674188.aspx


using native .NET JavascriptSerializer

Example code for deserializing the following JSON :

string
res =
@" {
""exhibitions"": [
{
""id"": ""1056"",
""name"": ""Alfa Romeo Sustaining Beauty"",
""admission_fee"": false,
""opened_on"": ""2001-12-01"",
""closed_on"": ""2001-05-31"",
""closed"": false,
""website"": null
},

{
""id"": ""1082"",
""name"": ""Agriculture"",
""admission_fee"": false,
""opened_on"": null,
""closed_on"": null,
""closed"": false,
""website"": http://www.sciencemuseum.org.uk/visitmuseum/galleries/agriculture.aspx
} ] }";

// the class property names must match those JSON names
   
public class Exhibition
{
public int id {get; set;}
public string name { get; set; }
public bool admission_fee { get; set; }
public string opened_on { get; set; }
public string closed_on { get; set; }
public bool closed { get; set; }
public string website { get; set; }
}


public class Response {
public Exhibition[] exhibitions;
}


System.Web.Script.Serialization.JavaScriptSerializer json = new System.Web.Script.Serialization.JavaScriptSerializer();

Response  list = json.Deserialize(res);


Example code for serializing objects to JSON string

System.Web.Script.Serialization.JavaScriptSerializer json = new System.Web.Script.Serialization.JavaScriptSerializer();
var e1 = new Exhibition { name = "Test1", closed = true };
var e2 = new Exhibition { name = "Test2", id = 456 };
var r = new Response();
r.exhibitions = new Exhibition[2] { e1, e2 };
string s = json.Serialize(r);
 

   

 



 
 

Tuesday, September 18, 2012

A Cloud Storage Programming Interface

The SharpBox API has a bug with Box.Net storage provider see
A Cloud Storage Programming Interface - Store everything - sharpbox - View Issue #16934: BoxDotNet GetRoot(); always returning NULL.

--- sample console application showing how to list , upload and download dropbox and box.net files.
static void Main(string[] args)

{


CloudStorage dropBoxStorage = new CloudStorage();
CloudStorage boxNetStorage = new CloudStorage();

 
//credentials access
 
GenericNetworkCredentials cred = new GenericNetworkCredentials();

cred.UserName =
somebody@somemail.com;

cred.Password =
"somePassword";

 
//access token
ICloudStorageAccessToken accessToken = null;

using (FileStream fs = File.Open("dropbox", FileMode.Open, FileAccess.Read, FileShare.None))

{

accessToken = dropBoxStorage.DeserializeSecurityToken(fs);

}




var dropBoxConfig = CloudStorage.GetCloudConfigurationEasy(nSupportedCloudConfigurations.DropBox);
var boxNetConfig = CloudStorage.GetCloudConfigurationEasy(nSupportedCloudConfigurations.BoxNet);



var boxNetstorageToken = boxNetStorage.Open(boxNetConfig, cred);
 
var dropBoxstorageToken = dropBoxStorage.Open(dropBoxConfig, accessToken);
 
var boxNetRoot = boxNetStorage.GetRoot();

var dropBoxRoot = dropBoxStorage.GetRoot();


foreach (var fof in boxNetRoot)

{

Boolean bIsDir = fof is ICloudDirectoryEntry;
 
Console.WriteLine("{0}:{1}", bIsDir ? "DIR" : "FIL", fof.Name);

}


foreach (var fof in dropBoxRoot)
{


Boolean bIsDir = fof is ICloudDirectoryEntry;


Console.WriteLine("{0}:{1}", bIsDir ? "DIR" : "FIL", fof.Name);

}

string tmpFile = Environment.ExpandEnvironmentVariables("%temp%");
 
//Console.WriteLine("Downloading..");


//dropBoxStorage.DownloadFile(dropBoxRoot, "big_file",tmpFile, UploadDownloadProgress);


Console.WriteLine("Uploading..");

boxNetStorage.UploadFile(tmpFile+
"\\big_file", boxNetRoot, UploadDownloadProgress);


Console.WriteLine("Completed");

boxNetStorage.Close();

dropBoxStorage.Close();



}


static void UploadDownloadProgress(Object sender, FileDataTransferEventArgs e)

{


Console.Write("x");

e.Cancel =
false;

}

}

Thursday, July 26, 2012

Windows Network Name and Firewall Profiles

Firewall Profiles are preset inbound and outbound rules on Windows firewall. There are by default 3 profiles: Private Domain and Public.

The Windows Network Location awareness detectes a network by looking quering the presence of default gateway, SSIDs to assign a name to the network. This network name is then associated with firewall profile to protect the connection. If there is no gateway detected on a network interface the network name will be Unidentified Network and you cannot change the firewall profile, it will always be Public.

Internet access detection is by querying a fixed URL
The local security policy Network List Manager Policies can be use to control the changing of network names etc.

Updated : 9/5
On Windows 8, public or private depends on whether file sharing is turn on/off. On->public, off->private

See:
http://technet.microsoft.com/en-us/library/cc753545.aspx
http://www.frostbyte.com.au/Blog/tabid/64/EntryId/9/Windows-7-incorrectly-reports-No-Internet-Access.aspx

Wednesday, July 25, 2012

VMware Host network DHCP service

On host network, the built-in VMware DHCP service, vmnetdhcp.exe is set to run automatically. To disable, use Windows service or comment out the scope in  C:\Users\All Users\VMware\vmnetdhcp.conf

VMware Player boot menu

bios.bootDelay = "5000"
to the VMX file - this will delay the boot by 5 seconds

press ESC to go into boot menu

Monday, July 23, 2012

Creating a default profile in Windows 7

    1. Create a new standard local user account (name it STDPROFILE), add this account to the local Administrators group on the PC.
    2. Reboot, then log onto the PC using the local user account from Step 2.
    3. Set up profile settings as desired; desktop icons, IE home page, etc…
    4. Reboot when finished, log back onto PC with the local “Administrator” account
    5. Double-click “Computer”, then Click Organize, Folder and Search Options. On the View tab, make sure “Show Hidden files, folders and drives” is selected; also uncheck “Hide protected Operating System Files”. Click OK.
    6. Under C:\Users, rename the hidden “Default” user folder (NOT “Default User”)
    • Make a copy of the profile (STDPROFILE) customized in Step 2, rename the folder “Default”.
    • Right-click the folder – under Properties, then Security tab - Add “Everyone” permissions with Full Control (include all folders and subfolders).
    1. Run regedit.exe
    2. Click on HKEY-LOCAL-MACHINE. Under File, select “Load Hive”
    3. Browse to the “C:\Users\Default” folder, click on ntuser.dat (make sure hidden and system files are displayed). Name the key TEMPLATE_ACCOUNT.
    • Right-click on the TEMPLATE_ACCOUNT key, select Export, save the .reg file to the desktop. Open the .reg file with Notepad, and under “Edit – Replace…”, put the user name STDPROFILE in the “Find what:” field, to be replaced with the string %USERNAME% - choose “Replace All” then save the .reg file. Double-click it to re-import the changes.
    1. Re-open regedit.exe (or switch over to it if it’s still open)
    2. Under TEMPLATE_ACCOUNT - Control Panel - Desktop, change “Wallpaper” path to the wallpaper of your choice (a local OR network path will work here). Check other settings and modify any other keys.
    3. If RealPlayer is installed to the image – click on TEMPLATE_ACCOUNT – SOFTWARE – RealNetworks. Delete the entire RealNetworks Key. This key will re-created for each user as they open Realplayer. If the RealNetworks Key is left in, RealPlayer will crash for each user with the message “EXITING APPLICATION”.
    4. When done, click on TEMPLATE_ACCOUNT. Then click File, select “Unload Hive”. This will save the changes you made.