RSS

Category Archives: C# Development

Hover Intent for Silverlight

Updated: Now on GitHub: https://github.com/cairey/Hover-Intent-Silverlight

You have probably already used the Hover intent plugin for JQuery. Maybe you want to do the same thing for Silverlight? Well using the reactive extensions you can quite easily. Of course we are using MVVM so we can capture the elements mouse enter event and bind a command to it on the view model.

You can then bind in the XAML like so:
Button x:Name="Eyecon" commands:MouseEnterIntent.Command="{Binding Open}" commands:MouseEnterIntent.DueTime="50"

The MouseEnterIntent class creates the attached behavior using dependency properties. The MouseEnterIntentCommandBehavior class bind the events to the command.

Advertisements
 
Leave a comment

Posted by on September 21, 2010 in C# Development, Silverlight, Websites

 

Tags: , , , , , , , ,

JQuery plugin – showAge

Updated: See the plugin page.

I thought I would experiment, write and share a JQuery plugin. I have written simple plugins for applications, but this is a first time for a public release plugin.Ā The plugin is designed to manipulate dates. For any date on the page, you can transform the date to show its real age. To overcome a few huddles, I will explain.

JavaScript DateTime is not a reliable source, for getting the current date. JavaScript runs on the clients machine, in turn it relies on the client system clock to be 100% correct. While this shouldn’t generally be an issue, it’s not reliable. So, to get the real date I am calling a .NET web service and returning JSON using JQuery’s built-in mechanism for handling this.

To return JSON from an ASMX service, JQuery can be setup like so:

I have simplified JQuery’s mechanism in the plugin, and by no means you don’t have to use this. However for my case, I wrapped it inside a function for ease. This is how it should be setup to request JSON from an ASMX web service. The web service will see in the request headers JSON is requested, and therefore return JSON. So how do we do this?

You can provide your own mechanism for getting the current date, but this shows how it works.

The function call to getJson() calls the web service, which returns an anonymous object. Notice that month is returning month – 1. Why is this? Well JavaScript date begins in January at Month 0, in .NET January begins at Month 1. So, we do a bit of correction there. The web service knows that an XML Request (Ajax Request) is being sent but also with the content type JSON. The web service is clever enough to know how to handle this async JSON request and will return a JSON object. The callback function returns a data object with our date. Do notice however that data.d is used. “.d” to access our returns object, as designed by Microsoft.

The plugin has the following options.

TodaysDate (optional): – this is a JavaScript Date object, to be set to the current date. (Default value sets the current date using JavaScript).
InsertMode (optional): – this controls how the age is inserted. (Default value is set to ‘append’).
CustomCompare (optional): – this takes a function to compare dates and return the number of years between them. (Default uses its own compare).

InsertMode consists of the following options.

‘replace’ – replace the date with the real age.
‘append’ – append the date with real age.
‘prepend’ – prepend the date with the real age.

In its simplist form:

Will display:

Although the example is a VS project, the JQuery plugin is not .NET specific.

Download – v1.1
 
Leave a comment

Posted by on January 12, 2010 in C# Development, HTML / CSS, JavaScript

 

Tags: , , , , , , , , , , , , , ,

Entity framework, session per request

I am releasing a HTTP Module, that will open and close the entity session, because this works for each HTTP request a new context instance is created for each user per request.

Download

 
3 Comments

Posted by on October 14, 2009 in C# Development, Software Development

 

Tags: , , , ,

UML and Visual Studio

Much to my disappointment and after about 6 hours of trying to get it to work, Visual Studio 2008 does not support UML (Unified Modelling Language). Visual Studio 2008 allows you to create a class diagram that will self generate all the classes in the project (of course you would have done all your class diagrams first, ahem), but this is not UML! Microsoft Visio has UML support, but it cannot generate it from classes or a visual studio project, unless you have the “uber apparently works edition”. Great, so there you are with this huge project and you need to document it, but VS2008 does not know what the hell UML is.

The good news is that there will be full UML support in Visual Studio 2010! Yippee! However for me that will be too late šŸ˜¦

 
Leave a comment

Posted by on August 12, 2009 in C# Development, Software Development

 

Tags: , , , ,

Additions to combine control

Ok, I’ve slightly changed some of the behaviour of the script combining control. In addition it now combines, compresses, minifies and caches CSS files! The CSS can also be used to target certain browsers and versions. It can be used like this:

<cc:CSSCombine ID="CSSCombiner" runat="server" CSSHandler="~/Handlers/CSSCombine.ashx">
<CSSReferences>
<cc:CSSReference TargetBrowser="All" Path="~/Styles/admin.css" /> <%--Will target all versions of all browsers--%>
<cc:CSSReference Path="~/Styles/webTV.css" /> <%-- Will target all versions of all browsers --%>
<cc:CSSReference TargetBrowser="IE" TargetVersion="8" Path="~/Styles/admin_old.css" /> <%-- Will target version 8 of IE --%>
<cc:CSSReference TargetBrowser="FF" TargetVersion="2" Path="~/Styles/screen.css" /> <%-- Will target versions 2 of FireFox --%>
<cc:CSSReference TargetBrowser="Chrome" Path="~/Styles/main.css" /> <%-- Will target all versions of Chrome --%>
<cc:CSSReference TargetBrowser="Safari" Path="~/Styles/sifr.css" /> <%-- Will target all versions of Safari --%>
</CSSReferences>
</cc:CSSCombine>

<cc:CSSCombine ID="CSSCombiner" runat="server" CSSHandler="~/Handlers/CSSCombine.ashx">

<CSSReferences>

<cc:CSSReference TargetBrowser="All" Path="~/Styles/admin.css" /> <%--Will target all versions of all browsers--%>

<cc:CSSReference Path="~/Styles/webTV.css" /> <%-- Will target all versions of all browsers --%>

<cc:CSSReference TargetBrowser="IE" TargetVersion="8" Path="~/Styles/admin_old.css" /> <%-- Will target version 8 of IE --%>

<cc:CSSReference TargetBrowser="FF" TargetVersion="2" Path="~/Styles/screen.css" /> <%-- Will target versions 2 of FireFox --%>

<cc:CSSReference TargetBrowser="Chrome" Path="~/Styles/main.css" /> <%-- Will target all versions of Chrome --%>

<cc:CSSReference TargetBrowser="Safari" Path="~/Styles/sifr.css" /> <%-- Will target all versions of Safari --%>

</CSSReferences>

</cc:CSSCombine>

Download itĀ download

 
Leave a comment

Posted by on June 5, 2009 in C# Development, HTML / CSS, JavaScript

 

Tags: , , , , , ,

Script Combining Control

Combining JavaScript files. Why is this important? If you have for example 10 JavaScript files included on your website, that means the browser will make a separate request for each one of these files. Latency can be seen as an issue here. We aren’t maximising throughput.

This analogy can be compared to for example, a set of Traffic Lights. You may have seen it sometimes when traffic lights are not functioning correctly, or sometimes you’re in a queue and you’re saying “for god sake, the lights don’t stay green long enough.” So it may stay green for about 5 seconds, which is just enough time for you to pull down the hand brake, accelerate and go. In that time you may get about 5 cars though for example. Now lets say the lights go green for 10 seconds. Now you may expect to get 10 cars through, but you may get 15 through. The time to negotiateĀ the hand brake, accelerating and stopping is less frequent, so we are maximizing throughput. Read on:Ā http://sumo.sourceforge.net/docs/dkrajzew_TRAF9_AgentbasedTLS.pdf

This is the same for negotiating each request in our case. I have seen a lot of different ways of people achieving script combining. Most commonly and a good way is to use a Handler, that returns the combined result. I have a handler that works in a similar way, but it can be implemented in a more friendly manor using a Custom Server Control.

The control has other configurable properties, such as caching, minifying and compressing. They are all switched on by default. The code below will look familiar to the ASP.NET AJAX Script Manager, script combining, but the control I wrote gives you more control over caching, minifying and compressing (using GZip).

It can be implimented like so.

<cc:ScriptCombine ScriptHandler="~/ScriptCombine.ashx" ID="ScriptCombiner" runat="server">
<Scripts>
<cc:ScriptPath Path="~/Scripts/jquery-1.3.2.min.js" />
<cc:ScriptPath Path="~/Scripts/ui.core.js" />
<cc:ScriptPath Path="~/Scripts/ui.accordion.js" />
<cc:ScriptPath Path="~/Scripts/ui.datepicker.js" />
<cc:ScriptPath Path="~/Scripts/ui.progressbar.js" />
<cc:ScriptPath Path="~/Scripts/ui.draggable.js" />
<cc:ScriptPath Path="~/Scripts/ui.sortable.js" />
<cc:ScriptPath Path="~/Scripts/ui.slider.js" />
<cc:ScriptPath Path="~/Scripts/ui.resizable.js" />
<cc:ScriptPath Path="~/Scripts/ui.draggable.js" />
<cc:ScriptPath Path="~/Scripts/ui.selectable.js" />
<cc:ScriptPath Path="~/Scripts/ui.droppable.js" />
</Scripts>
</cc:ScriptCombine>

<cc:ScriptCombine ScriptHandler="~/ScriptCombine.ashx" ID="ScriptCombiner" runat="server">

<Scripts>

<cc:ScriptPath Path="~/Scripts/jquery-1.3.2.min.js" />

<cc:ScriptPath Path="~/Scripts/ui.core.js" />

<cc:ScriptPath Path="~/Scripts/ui.accordion.js" />

</Scripts>

</cc:ScriptCombine>

You can download an example project with the source code: Download

You can script combine in your project by taking the ScriptCombine.ashx and the CustomControls.dll and reference accordingly like the example.

 
Leave a comment

Posted by on May 27, 2009 in C# Development, JavaScript

 

Tags: , , , , , ,