Nimble Coder

Adventures in Nimble Coding
posts - 76, comments - 39, trackbacks - 0

C#

C-Sharp
Using a delegate and Custom Appender with log4net to display live log text

Recently I needed to display the text that was sent to log4net in a TextBox in a Form. It turns out this is very easy to do using a custom appender and the AppenderSkeleton. The custom appender uses a delegate to allow the host program to define a callback function to handle the log text as necessary. 1. Create a new custom appender class I named my appender DelegateAppender because it needed to use a delegate to pass the text to the Form. using log4net.Core; namespace log4net.Appender { public delegate void LogTextAppend(string text); public class...

posted @ Friday, January 30, 2009 12:42 PM | Feedback (4) | Filed Under [ C# ]

Spinning Wait Symbol in Silverlight, Part4

SpinningCursor4.zip (57 KB): Source (VS2008/Silverlight 2.0) Series History Part 4: Adding an animation (static XAML) to the slices (in Silverlight/C#) Part 3: Adding curvature to the slices (in Silverlight/C#) Part 2: Dynamically building slices (in Silverlight/C#) Part 1: Treo-like wait symbol in static XAML   Introduction The goal of these posts is to build a spinning cursor similar to the Mac OS X wait cursor through programmatic means in Silverlight. The cursor is still very rough and will undergo improvements progrressively. One of the reasons to build the cursor programmatically is to have...

posted @ Thursday, November 06, 2008 2:03 AM | Feedback (2) | Filed Under [ C# SilverLight ]

Spinning Wait Symbol in Silverlight, Part3

SpinningCursor3.zip (34 KB): Source (VS2008/Silverlight 2.0) Series History Part 3: Adding curvature to the slices (in Silverlight/C#) Part 2: Dynamically building slices (in Silverlight/C#) Part 1: Treo-like wait symbol in static XAML In this post, I add curvature to the slices and refactor the code to support upcoming features. The goal of these posts is to build a spinning cursor similar to the Mac OS X wait cursor through programmatic means in Silverlight. One of the reasons to build the cursor programmatically is to create it will different number of slices or rotation or other...

posted @ Wednesday, October 29, 2008 11:16 AM | Feedback (3) | Filed Under [ C# SilverLight ]

Spinning Wait Symbol in Silverlight, Part 2

After my previous spinning wait symbol, I decided to see how difficult it would be to create a Silverlight version of the Mac OSX wait cursor that I referenced in the previous post. The Mac OSX cursor is commonly referred to as the "Spinning Pizza of Death" or the "Marble of Doom" and in fact there is a Marble of Doom web site dedicated to the amount of time spent waiting while watching the spinning cursor. The Marble of Doom web site has a very nice and large version of the cursor using Flash although it doesn't have any vector...

posted @ Monday, October 20, 2008 3:08 PM | Feedback (0) | Filed Under [ C# Programming SilverLight ]

Spinning Wait Symbol in Silverlight

Download: RotatingHourGlass VS2008 Source/Silverlight beta 2 (503 KB) My wife has a Treo with Windows Mobile and I when I was using it I noticed it had a cool rotating wait symbol, so I wondered how difficult it would be to build the symbol in Silverlight. The symbol is similar to the old BeOS wait cursor and has as well as the Mac OS X wait cursor which I've always thought looks nice. At one point in time I created a Windows cursor that duplicated the look of the BeOS cursor but I don't use it anymore. If I...

posted @ Wednesday, October 08, 2008 8:03 AM | Feedback (0) | Filed Under [ C# SilverLight ]

Bouncing Balls in Silverlight Part 1

BounceTest1 (104 KB): Source (VS2008) Recently I wanted to make a very simple sample in Silverlight that used a little code to animate bouncing balls. The overall effect is fairly simple, but getting the sample down to the basics took a little time. As part of my research, I looked at several old bouncing ball demos using JavaScript and it was an eye-opening reminder of the dark ages of browsers and JavaScript. For the sample, I wanted to keep everything very simple. I started with a circle (ellipse with the...

posted @ Sunday, September 14, 2008 11:28 PM | Feedback (0) | Filed Under [ C# SilverLight ]

On Sample Simplicity

I was working through a Communications sample of connecting SilverLight to POX, then Web Services, and finally WCF and I came across the following instructions: (Part 1: POX) The Generic handler will process an incoming request using the code declared in the ProcessRequest function. This function should create some new instances of CityData and add them to the myCities list. Here are some examples of cities with longitude and latitude { (London, 51.5, 0), (Stratford-upon-Avon, 52.3, -1.71), (Edinburgh, 55.95, -3.16) }. See if you can write the code to do this. (And later in the lab...) In this example...

posted @ Friday, June 13, 2008 4:08 PM | Feedback (0) | Filed Under [ C# Programming SilverLight LINQ ]

Automatically setting the Specified property in WSDL Generated files

The wsdl.exe tool with Visual Studio can be used to manually generate a code file to use with a project. If you use the nillable or minOccurs attributes in the XSD though, the wsdl.exe tool generates a boolean 'Specified' field that must be set to true in order to transmit the data through the web service. For example: WSDL File (myfile.wsdl)<xs:element name="duedate" type="xs:dateTime" nillable="1" minOccurs="0" maxOccurs="1" /> Generated CS File (wsdl.exe myfile.wsdl)// ... private System.Nullable<System.DateTime> duedateField; private bool duedateFieldSpecified; // ... /// <remarks/> [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)] public System.Nullable<System.DateTime> duedate { get { return this.duedateField; } ...

posted @ Tuesday, April 01, 2008 3:51 PM | Feedback (0) | Filed Under [ C# Tools Programming ]

Best Practice for Verbatim String Text Block

I was browsing various blogs today and I came across a good example for using a verbatim string instead of a StringBuilder object. The code I came across looked like this (I mean absolutely no disrespect to the author, so I won't include the original link):private void ClientScript() { StringBuilder sb_Script = new StringBuilder(); sb_Script.Append("<script language=\"javascript\">"); sb_Script.Append("\r"); sb_Script.Append("\r"); sb_Script.Append("function cb_verify(sender) {"); sb_Script.Append("\r"); sb_Script.Append("var val = document.getElementById(document.getElementById" +"(sender.id).controltovalidate);"); sb_Script.Append("\r"); sb_Script.Append("var col = val.getElementsByTagName(\"*\");"); sb_Script.Append("\r"); sb_Script.Append("if ( col != null ) {"); ...

posted @ Friday, November 23, 2007 12:05 AM | Feedback (0) | Filed Under [ C# JavaScript ]

Efficient String Blocks

One of the things that bothers me a lot is using a lot of string concatenation when you can just use the verbatim string literal (@"") to define a large block of text. For example, I saw some code on a blog the other day that looked something like this:string strValue = "<div id='test'>"; strValue += "<input type='text' id='name' value='" + strName + "/>"; strValue += "<input type='submit' />"; strValue += "</div>"; // Many more lines before it finally // finished building the string There are many things wrong with the code sample above including not using StringBuilder. I have seen the same type of code...

posted @ Friday, November 09, 2007 3:18 PM | Feedback (0) | Filed Under [ C# ]

Programming Crutch, Litmus Test, or Silver Bullet?

Lately I've been reading more about Ruby on Rails -- actually it has been rather entertaining, colorful, testy, and somewhat enlightening. One important aspect of programming is the ability to analyze, understand, and adapt. I have been using more Python lately in work as well as JavaScript and it has been enjoyable although I still like and prefer C#. Sometimes I wonder how many programmers get fixated on specific language features that in turn becomes a "must have" or requirement for any language he or she uses. That isn't to say the feature is not important but rather usually the...

posted @ Tuesday, October 23, 2007 3:58 PM | Feedback (0) | Filed Under [ C# Python Ruby ]

Using Generics to Instantiate Similar Test Forms

I had to build a application to exercise and test several web services. I created a form for each web service and used text boxes, combo boxes, and date pickers to fill in properties for the class used in the web service parameters. Eventually I had several test forms and started with the common method of starting multiple forms: private void buttonTestUI01_Click(object sender, EventArgs e) { TestUI01Form f = new TestUI01Form(); ...

posted @ Monday, July 23, 2007 3:01 PM | Feedback (0) | Filed Under [ C# ]

Disabling Fields on Submit

A while back I needed to disable fields on a web page during submit and I found a utility written by Nancy Michell for MSDN Magazine. The utility covered the basic cases, but I found that I needed to use it for AJAX style calls as well as standard submits. So I modified the code to include an enable function as well. Finally I added exception handling around the disable and enable code to avoid pesky Javascript errors. The only thing I might change is to capture an array of the controls that were successfully disabled and then process only...

posted @ Tuesday, May 01, 2007 10:31 PM | Feedback (2) | Filed Under [ C# ASP.NET ]

Exceptions and the Event Log

I was just reading an article on Builder.com about exception handling and it reminded me of some of my pet peeves regarding exception handling. Don't assume you have permissions to write to the Event Log! - Many people add code to log exceptions to the Event Log however they do not add any exception handling in case it fails. This is especially true for ASP.NET as many corporate networks are severely restricting permissions. It is possible for the System.Diagnostics.EventLog.WriteEntry() to throw exceptions! The exception for permissions issue is System.Security.SecurityException. Best practice is to use a wrapper function...

posted @ Monday, February 26, 2007 3:00 PM | Feedback (2) | Filed Under [ C# ASP.NET ]

Time Zone Adjustment in Datasets

I decided to publish a short article about time zone adjustment. While it uses a Microsoft KB article as the basis for the algorithm, the interesting portion of the code actually has to do with setting the client time zone and cookies. See the article here.

posted @ Sunday, February 04, 2007 12:41 AM | Feedback (0) | Filed Under [ C# ASP.NET ]

Full C# Archive

Powered by: