Salient Solutions

wrasslin ones and nones for fun and profit - Sky Sanders' Blog
posts - 96, comments - 70, trackbacks - 0

C-Sharp

There are 7 entries for the tag C-Sharp
Deserializing MS Ajax ClientScript JSON in managed code revisited. e.g. {"d":{"__type":

Overview In a previous post, I proposed a means of deserializing JSON returned from calls to ClientScript endpoints such as XML WebServices decorated with [ScriptService] or [ScriptMethod] attributes, Ajax-enabled WCF Services and WCF services created with WebScriptServiceHostFactory. The use case that prompted this requirement is testing endpoints called by client-side JavaScript. Calling WebScript enpoints in managed code using HttpWebRequest is easy, the trick is to specify content-type 'application/json'. And this is where the problems start. Problem Domain When a WebScript endpoint responds to a request with content-type 'application/json' it understandably assumes that it is being called from JavaScript and, as of 3.5sp1, wraps the actual...

posted @ Tuesday, April 13, 2010 4:44 AM | Feedback (1) |

Using WMI to fetch the command line that started all instances of a process

/// <summary> /// Using WMI to fetch the command line that started all instances of a process /// </summary> /// <param name="processName">Image name, e.g. WebDev.WebServer.exe</param> /// <returns></returns> /// adapted from http://stackoverflow.com/questions/504208/how-to-read-command-line-arguments-of-another-process-in-c/504378%23504378 /// original code by http://stackoverflow.com/users/61396/xcud private static IEnumerable<string> GetCommandLines(string processName) { List<string> results = new List<string>(); string wmiQuery = string.Format("select CommandLine from Win32_Process where Name='{0}'", processName); using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(wmiQuery)) { using (ManagementObjectCollection retObjectCollection = searcher.Get()) { foreach...

posted @ Sunday, April 11, 2010 2:12 PM | Feedback (0) | Filed Under [ CodeProject-Tip ]

Preventing caching of content in ASP.Net Pages and other HttpHandlers

  Sometimes I forget to squash caching on my JSON handlers and end up with odd runtime behavior, especially when using IE. You can ensure that each request actually pulls data instead of hitting the cache by adding this to the top of a handler (.ashx) or in the page_load of a .aspx. Drop 'context.' for use in page_load.   context.Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1)); context.Response.Cache.SetCacheability(HttpCacheability.NoCache); context.Response.Cache.SetNoStore();   This is what the head of my JSON handlers typically look like: public void ProcessRequest(HttpContext context) { context.Response.ClearContent(); ...

posted @ Tuesday, March 23, 2010 2:59 AM | Feedback (0) | Filed Under [ CodeProject-Tip ]

Generic NullSafe IDataRecord Field Getter

// usage var name = GetValueOrDefault<string>(reader, "Name"); var name = reader.GetValueOrDefault<string>("Name"); var name = reader.GetValueOrDefault<string>(0); // extension public static T GetValueOrDefault<T>(this IDataRecord row, string fieldName) { int ordinal = row.GetOrdinal(fieldName); return row.GetValueOrDefault<T>(ordinal); } public static T GetValueOrDefault<T>(this IDataRecord row, int ordinal) { return (T)(row.IsDBNull(ordinal) ? default(T) : row.GetValue(ordinal)); } Technorati tags: C-Sharp, ADO.Net, CodeProject-Tip

posted @ Tuesday, March 02, 2010 12:15 PM | Feedback (0) | Filed Under [ CodeProject-Tip ]

Adding/Removing UAC Shield to button

#region UAC private const int BcmFirst = 0x1600; //Normal button private const int BcmSetshield = (BcmFirst + 0x000C); //Elevated button [DllImport("user32")] private static extern UInt32 SendMessage(IntPtr hWnd, UInt32 msg, UInt32 wParam, UInt32 lParam); private static void AddShieldToButton(Button b) { b.FlatStyle = FlatStyle.System; SendMessage(b.Handle, BcmSetshield, 0, 0xFFFFFFFF); } private static void RemoveShieldFromButton(Button b) { b.FlatStyle = FlatStyle.System; SendMessage(b.Handle, BcmSetshield, 0, 0x0); } private static bool IsAdmin() { ...

posted @ Thursday, January 07, 2010 3:43 AM | Feedback (0) | Filed Under [ CodeProject-Tip ]

Short: Inline multithreading with lambdas

Not going to write a novel. just a snippet. Mayhaps will explain when I am sure I know what I am talking about. private static void InlineThreadingWithLambda() { int local = 0; var thread = new Thread(() => { ...

posted @ Wednesday, December 16, 2009 3:03 AM | Feedback (0) | Filed Under [ CodeProject-Tip ]

Read StandardOutput and StandardOutput in one method via inline multi-threading with anonymous delegates

Conventional strategies for reading both StandardOut and StandardError involve helper methods and state objects similar to Listing 1 Listing 1: How it has been done: public static void RunProcessConventional(string command, string args) { var proc = new Process { StartInfo = ...

posted @ Wednesday, December 16, 2009 2:42 AM | Feedback (1) |

Powered by: