tag:blogger.com,1999:blog-22562814638213750172024-03-05T01:57:17.086-08:00C#, .Net, ASP.Net, jQuery and other stuff.General blog regarding C#, .Net etc. and other programming stuff.Mantorokhttp://www.blogger.com/profile/11519758107315204411noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-2256281463821375017.post-26376843601003046792010-05-28T01:21:00.000-07:002010-05-28T01:51:42.788-07:00AddThis validation issueThe <a href="http://www.addthis.com/">AddThis</a> button is a great addition to any website, however if your site needs to conform to W3C standards you may need to tweak the default HTML snippet that is provided, the issue is the use of the # in one of the JavaScript references:<br /><br /><pre class="brush:jscript"><br /><script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=blahblah"><br /></script><br /></pre><br /><br />Simply change the <span style="font-weight:bold;">#</span> to a <span style="font-weight:bold;">?</span> and you should be validating fine:<br /><br /><pre class="brush:jscript"><br /><script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js?username=blahblah"></script><br /></pre>Mantorokhttp://www.blogger.com/profile/11519758107315204411noreply@blogger.com0tag:blogger.com,1999:blog-2256281463821375017.post-25527722780262257602010-05-17T08:46:00.000-07:002010-05-18T05:54:33.302-07:00Linq equivalent of for-eachIf you've ever wondered about using Linq for a more elegant implementation of a for each loop then this may be useful, use the <span style="font-weight:bold;">Select<></span> method to perform actions against a set of items, as long as you return a value of any sort then you can perform any action during the selection.<br /><br />In the example below I need to remove all folders that were written to over an hour ago, it also returns info on the folders processed and whether they were successfully removed:<br /><br /><pre class="brush:csharp"><br />if (string.IsNullOrEmpty(RootWorkingFolder) || !Directory.Exists(RootWorkingFolder)) return;<br /><br />Directory.GetDirectories(RootWorkingFolder)<br /> .Where(f => Directory.GetLastWriteTime(f) < DateTime.Now.AddHours(-1))<br /> .Select(delegate(string f)<br /> {<br /> try<br /> {<br /> Directory.Delete(f, true);<br /> return new {Folder = f, Removed = true};<br /> }<br /> catch (IOException)<br /> {<br /> return new {Folder = f, Removed = false};<br /> }<br /> }).ToList();<br /></pre><br /><br />The <span style="font-weight:bold;">ToList</span> method is to ensure that the query is executed immediately.<br /><br />Pretty useful to know :-)Mantorokhttp://www.blogger.com/profile/11519758107315204411noreply@blogger.com0tag:blogger.com,1999:blog-2256281463821375017.post-41631955307288732532010-05-05T01:37:00.000-07:002010-05-05T01:39:59.194-07:00Visual Studio 2010 running slowFor anyone suffering with the performance of Visual Studio 2010, particularly intellisense, Microsoft has published a support article on the matter, apparently an update to Windows Automation API 3.0 can be applied that will improve matters.<br /><br />The article is here: <a href="http://support.microsoft.com/kb/981741/">http://support.microsoft.com/kb/981741/</a>.Mantorokhttp://www.blogger.com/profile/11519758107315204411noreply@blogger.com0tag:blogger.com,1999:blog-2256281463821375017.post-35185608016409636542010-04-29T07:18:00.000-07:002010-04-29T08:13:35.817-07:00Assigning click event using jQuery in FireFox not workingI've just stumbled upon a strange problem which highlighted some badly formatted Javascript on my part, I had around 30 anchors on my page which needed to have Click event handlers assigned in order for me to override the href invocation, the reason for this was to prevent my Click from propagating through the underlying DIV element that the anchor was sitting in, so here was my original code:<br /><br /><pre class="brush:jscript"><br />$(document).ready(function() {<br /> $(".addthis_button_facebook, .addthis_button_twitter").click(function() {<br /> return click_addthis(event, this.href)<br /> });<br />});<br /></pre><br /><br />Which actually worked fine in every browser except FireFox, this was stumping me for ages until I decided to post a question at the wonderful <a href="http://stackoverflow.com/questions/2737006/jquery-click-event-assignment-not-working-in-firefox">Stack Overflow</a> (what a god-send that place is!), which resulted in someone immediately spotting the missing argument in my function event.<br /><br />The code should've been:<br /><br /><pre class="brush:jscript"><br />$(document).ready(function() {<br /> $(".addthis_button_facebook, .addthis_button_twitter").click(function(e) {<br /> return click_addthis(e, this.href)<br /> });<br />});<br /></pre><br /><br />If you haven't noticed it, it is the argument in the function that is required, this can then be passed onto the function being called.<br /><br />I hope this helps someone who may have a similar issue/oversight, although it's probably just me and my limited JS experience!<br /><br />So thanks again to the helpful chaps at stack overflow!Mantorokhttp://www.blogger.com/profile/11519758107315204411noreply@blogger.com0tag:blogger.com,1999:blog-2256281463821375017.post-84924900084069685292009-08-20T03:38:00.000-07:002010-04-29T09:23:32.562-07:00Configuration files in GAC assembliesWe had an interesting problem recently where-by we were rolling out integration libraries and installing them into the GAC on our windows servers.<br /><br />The issue was that the only way to have the dlls respect configuration files was to copy the configuraiton file into the physical GAC path of the assembly, which can prove a bit tricky.<br /><br />In the end we opted to use a slightly bespoke solution of packaging the configuration file in with the DLL and write a procedure for extracting that, this way we could ensure a single DLL file and have multiple configuration files for each environment.<br /><br />To achieve this:<br /><br />1. You need to create your App.config file and set the <span style="font-weight: bold;">Build Action</span> to <span style="font-weight: bold;">Embedded Resource</span>, this ensures that the config file is embedded into the resulting DLL.<br /><br />2. Here's a snippet of the code to read the configuration and create a usable Congiruation instance (we ended up wrapping this up into a class, see link at the bottom of the article):<br /><br /><pre class="brush:csharp"><br />/// <summary><br />/// Ensures configuration exists.<br />/// </summary><br />public Configuration GetConfiguration()<br />{<br /> var filename = EnsureConfigFile();<br /> var map = new ExeConfigurationFileMap<br /> {<br /> ExeConfigFilename = filename<br /> };<br /><br /> if (File.Exists(filename))<br /> {<br /> return ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);<br /> }<br /><br /> return null;<br />}<br />/// <summary><br />/// Ensures that the configuration file is available to be read.<br />/// </summary><br />/// <returns>The configuration filename.</returns><br />private string EnsureConfigFile()<br />{<br /> var standardConfigFile = string.Empty;<br /> if (StandardConfigFileExists(out standardConfigFile))<br /> {<br /> return standardConfigFile;<br /> }<br /><br /> var assembly = ConfigurationFileAssembly ?? Assembly.GetCallingAssembly();<br /> var configFileName = string.Concat(assembly.GetName().Name, ".config");<br /> var filename = Path.Combine(Path.GetTempPath(), assembly.GetName().FullName);<br /><br /> if (!Directory.Exists(filename))<br /> Directory.CreateDirectory(filename);<br /><br /> filename = Path.Combine(filename, configFileName);<br /><br /> var info = new FileInfo(filename);<br /> if (!info.Exists || info.LastWriteTime.Date <= DateTime.Now.AddDays(1) || (Debugger.IsAttached)) <br /> { <br /> // Be aware that this assembly.GetManifestResourceStream is case sensitive so you need an "App.config" file. <br /> var resource = string.Format("{0}.App.config", assembly.GetName().Name);<br /> var stream = assembly.GetManifestResourceStream(resource); <br /> if (stream != null) <br /> {<br /> var reader = new StreamReader(stream);<br /> File.WriteAllText(filename, reader.ReadToEnd());<br /> }<br /> else <br /> {<br /> throw new Exception("Unable to access App.config as an embedded resource.");<br /> }<br /> }<br /> return filename; <br />} <br /></pre><br /><br />Now that you have an App.config file that is an embedded resource you can replace it when you do your builds with your environment-specific config file before you build your project:<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYFOk0NBqdM_nltOm7XARxEJ-Do0oryLDYWzg27cPWtODZ-ol0lDqJZhVmI0AgtNMqfBkKhcE5xqGy39nw_oX9tUw9Wf-0LPev5qQR8z4kxGkpUiB8HdSfHmgplM0E_HO1aZEv0I5xlFgr/s1600/multiple_configs.png"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 159px; height: 64px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYFOk0NBqdM_nltOm7XARxEJ-Do0oryLDYWzg27cPWtODZ-ol0lDqJZhVmI0AgtNMqfBkKhcE5xqGy39nw_oX9tUw9Wf-0LPev5qQR8z4kxGkpUiB8HdSfHmgplM0E_HO1aZEv0I5xlFgr/s320/multiple_configs.png" alt="" id="BLOGGER_PHOTO_ID_5465590401639321906" border="0" /></a><br /><br />Now, there is one handicap with this and that's that you can't update the configuration file once it has been built and compiled, but this isn't such a bad thing as it enforces you to follow a correct build/release process when deploying the assemblies.<br /><br /><a href="http://rs426.rapidshare.com/files/381617160/ServiceConfiguration.cs">ServiceConfiguration.cs</a>Mantorokhttp://www.blogger.com/profile/11519758107315204411noreply@blogger.com0