Salient Solutions

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

April 2010 Entries

Visual Studio 2010 JavaScript Intellisense (VSJSI) Bug WorkAround

UPDATE: be sure to see official response at the end of this post.     As Joel D'Souza and I were discussing VS10 JavaScript Intellisense it became clear that, while it is overall an improvement from 2008, there is one silly bug. MS Connect Bug: https://connect.microsoft.com/VisualStudio/feedback/details/553372/vs10-javascript-intellisense-class-member-decorator-display-depends-on-microsoftajax-js In exploring javascript intellisense in VS10, it came to my notice that enums, interfaces and namespaces and classes all are decorated properly by adding the proper tag properties, but the class member decorators, e.g. events and properties etc, fail to display unless MicrosoftAjax.js was referenced. The line in MicrosoftAjax.js that 'triggered' the proper display of class member decorators is: Object.__class = true; Surely...

posted @ Thursday, April 22, 2010 11:30 AM | Feedback (0) |

JavaScript 'extend' implementation: copy members from one object to another

  function extend(target, deep, source /*, source, ... */) { /// <summary>Copies the properties of one or more objects to target.</summary> /// <param name="target" type="Object">The object upon which to copy the properties of source object(s)</param> /// <param name="deep" type="Boolean">If true, deep copy using recursion.</param> /// <param name="source" type="Object">Multiple source objects are supported.</param> var source; for (var argIndex = 2, argCount = arguments.length; argIndex < argCount; argIndex++) if ((source = arguments[argIndex]) != null) { ...

posted @ Thursday, April 22, 2010 11:16 AM | Feedback (0) |

C# truncate DateTime

Here is an extension method that will let you truncate a DateTime to any resolution... Usage: DateTime myDateSansMilliseconds = myDate.Truncate(TimeSpan.TicksPerSecond); DateTime myDateSansSeconds = myDate.Truncate(TimeSpan.TicksPerMinute) Class: public static class DateTimeUtils { /// <summary> /// <para>Truncates a DateTime to a specified resolution.</para> /// <para>A convenient source for resolution is TimeSpan.TicksPerXXXX constants.</para> /// </summary> /// <param name="date">The DateTime object to truncate</param> /// <param name="resolution">e.g. to round to nearest second, TimeSpan.TicksPerSecond</param> /// <returns>Truncated DateTime</returns> public static DateTime Truncate(this DateTime date, long resolution) { ...

posted @ Tuesday, April 20, 2010 9:44 PM | Feedback (1) | Filed Under [ CodeProject-Tip ]

The proper use and disposal of WCF channels. (or CommunicationObjectFaultedException ?!*#*$)

  In this post I explore the subtle but disastrous consequences of expecting a using block to clean up your WCF channels. NOTE: the examples show use of a generated proxy but the issue and solution applies to all ICommunicationObject including generated proxies (ClientBase<T>) as well as ChannelFactory and ChannelFactory<T>.  Many sleepless nights have been spent wondering why, regardless of any exception handling, the following code throws a CommunicationObjectFaultedException when .HelloWorld() throws. Typical 'using' disposal pattern using (WCFServiceClient c = new WCFServiceClient()) { try { c.HelloWorld(); } catch...

posted @ Monday, April 19, 2010 2:23 PM | Feedback (1) |

A better Visual Studio 2008 Development Server test fixture

  download the VS2008 solution here Introduction In a previous post I presented a class that enables the programmatic control of Visual Studio 2008 development server, WebDev.WebServer.exe. This use case for this functionality as presented here is in the interest of testing web applications and endpoints. Refactored While the previous implementation is capable in the context of interactive test runners, there were a few resource management issues affecting the usability in more autonomous scenarios such as continuous integration. Amongst these were the use of static port assignment and the lack of a means to shut down an instance, specifically the ability to start and stop an instance...

posted @ Saturday, April 17, 2010 4:46 AM | Feedback (1) |

Test Http endpoints with WebDev.WebServer, NUnit and Salient.Web.HttpLib

Retain your sanity! Quickly and easily write test suites for your Ajax/REST/Form/Upload/other http endpoints. download source code for HttpLib and this walkthrough here: Salient.Web.HttpLib.b1.zip Overview In this post I will introduce you to a small library, Salient.Web.HttpLib, that is designed primarily to support the testing of Http endpoints. Special attention is paid to the concerns of testing MS Ajax/WCF/WebServices endpoints and the primary focus of the tests will be centered on Ajax-enabled WCF service, static .aspx PageMethods and Xml WebServices that have been decorated with [ScriptService] or [ScriptMethod] attributes all demonstrate the same behavior and will hereafter referred to collectively as 'JSON endpoints'. Other...

posted @ Thursday, April 15, 2010 12:06 PM | Feedback (1) |

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) |

C# File Upload with form fields, cookies and headers

In it's most basic form, uploading a file or other data to an http form handler using managed code is quite simple using the System.Net.WebClient class. Listing 1: SimpleWebClientUpload public void SimpleWebClientUpload() { string filePath = Path.GetFullPath("TestFiles/TextFile1.txt"); var client = new WebClient(); client.UploadFile("http://localhost/myhandler.ashx", filePath); }   It is a common case that some cookies need to be maintained between requests or perhaps a header needs to be added to the request.  This is possible using the WebClient class but the technique is not immediately obvious. The trick is to create a class that inherits WebClient ...

posted @ Monday, April 12, 2010 11:52 AM | Feedback (1) |

A general purpose Visual Studio 2008 Development Server (WebDev.WebServer.exe) test fixture

   UPDATE: This post is valid as reference information, but an improved version of the code presented can be found here.     While I generally use CassiniDev for smoke testing, sometimes a quick and simple way to run some tests against a site using the built in server comes in handy. Spinning up an instance of WebDev.WebServer.exe is fairly simple. The executable can be found at C:\Program Files\Common Files\Microsoft Shared\DevServer\9.0\WebDev.WebServer.exe (Program Files (x86) for x64 Windows). If you invoke the .exe with no arguments you will see the usage document listed below. Listing 1: WebDev.WebServer Usage --------------------------- ASP.NET Development Server --------------------------- ASP.NET Development Server Usage: WebDev.WebServer /port:<port number> /path:<physical path> [/vpath:<virtual path>] port number: [Optional] An...

posted @ Sunday, April 11, 2010 4:15 PM | Feedback (0) |

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 ]

Visual Studio 2008 Post SP1 Hotfixes of interest (to me)

Just a short list of Post SP1 hotfixes that I always forget about when paving a machine.   KB958502 - JScript Editor support for “-vsdoc.js” IntelliSense doc. files (same hotfix for both x86 and x64)  KB957912 - Update for Visual Studio 2008 SP1 Debugging and Breakpoints  (same hotfix for both x86 and x64. additional x64 reqs)  

posted @ Saturday, April 10, 2010 1:32 PM | Feedback (0) |

RELEASE: SODDI v.10 - Quickly and easily import the StackOverflow Data Dump into MSSQL/SQLite/MySql

StackOverflow Data Dump Import v.10 ClickOnce Installer: http://skysanders.net/tools/se/soddi/publish.htm (c) 2010 Sky Sanders licensed under MIT/GPL - see license.txt msi :http://skysanders.net/files/soddi.10.msi info:http://skysanders.net/tools/se bin :http://skysanders.net/files/soddi.10.zip src :http://bitbucket.org/bitpusher/soddi/ SODDI is a .Net 3.5 sp1 executable written in C# that quickly and cleanly imports StackOverflow Data Dump XML files into MS Sql Server 2000/05/08, MySql Server 5.1 and SQLite3. (MySql and SQLite drivers are included) SODDI can be run as a command line utility or, when invoked with no arguments or GUI argument, will present a Windows Form interface. Quick Start: The quickest route to your own copy of the...

posted @ Friday, April 02, 2010 11:49 AM | Feedback (1) |

Powered by: