tag:blogger.com,1999:blog-23659706920912255092024-02-20T18:33:50.549-08:00hashfooDavid Faivrehttp://www.blogger.com/profile/09936208490636664645noreply@blogger.comBlogger15125tag:blogger.com,1999:blog-2365970692091225509.post-66783007534675016742012-04-23T16:42:00.001-07:002012-04-23T16:45:04.865-07:00Fluent NHibernate: Cannot create an instance of AutoMapping X because Type.ContainsGenericParameters is trueThis happens probably because you forgot to tell Fluent NHibernate which classes to map explicitly (i.e. its trying to map a class that isn’t one of your entity models).<br />
I usually filter my Fluent NHibernate models overriding the DefaultAutomappingConfiguration:<br />
<pre class="brush: csharp;">public class AutoMappingConfig : DefaultAutomappingConfiguration
{
public override bool ShouldMap(Type type)
{
return typeof(EntityBase).IsAssignableFrom(type);
}
}</pre>
<br />
And tell Fluent NHibernate about it:<br />
<pre class="brush: csharp;">Fluently.Configure()
.Database(databaseConfig)
.Mappings(
m =>
m.AutoMappings.Add(
AutoMap.AssemblyOf<User>(new AutoMappingConfig()));</pre>David Faivrehttp://www.blogger.com/profile/09936208490636664645noreply@blogger.com0tag:blogger.com,1999:blog-2365970692091225509.post-7748045455255798332012-02-22T07:32:00.001-08:002012-02-22T07:32:47.860-08:00XAML Control to Control Binding<p>I have a control that I want to enable/disable based on a checkbox. I ended up using a binding with ElementName and Path:</p><pre class="brush: xml;"><CheckBox <br /> x:Name="Enabler" /><br /><br /><ComboBox <br /> IsEnabled="{Binding ElementName=Enabler,Path=IsChecked}" /><br /></pre> David Faivrehttp://www.blogger.com/profile/09936208490636664645noreply@blogger.com0tag:blogger.com,1999:blog-2365970692091225509.post-2704042671874711722012-02-21T16:28:00.001-08:002012-02-21T16:35:17.811-08:00Add a ToolTip in CodeToday I had to create many controls in code (not XAML). I wanted to add tooltips as I created them:<br />
<pre class="brush: c-sharp;">void AddManyControls()
{
var control = new Control();
ToolTip toolTip = new ToolTip
{
Content = "ToolTip Content"
}
ToolTipService.SetToolTip(control, toolTip);
}
</pre>David Faivrehttp://www.blogger.com/profile/09936208490636664645noreply@blogger.com0tag:blogger.com,1999:blog-2365970692091225509.post-29473537265272327502012-02-20T12:11:00.001-08:002012-02-20T12:11:01.553-08:00ASP.NET Restarting On Every Request<p>It turns out I was writing some temporary files to a subfolder in the “bin” (or application) directory. The server saw that there were changes, and (correctly) decided a restart was required.</p> <p>Here are some other options on why the server (both WebDev and IIS/IISExpress) may be restarting/recycling too much: <a href="http://blogs.msdn.com/b/johan/archive/2007/05/16/common-reasons-why-your-application-pool-may-unexpectedly-recycle.aspx">http://blogs.msdn.com/b/johan/archive/2007/05/16/common-reasons-why-your-application-pool-may-unexpectedly-recycle.aspx</a></p> David Faivrehttp://www.blogger.com/profile/09936208490636664645noreply@blogger.com0tag:blogger.com,1999:blog-2365970692091225509.post-13727795349767904802012-02-19T06:50:00.000-08:002012-02-20T12:04:53.880-08:00Reload fstab Without a RebootFound this nice post: http://chrisschuld.com/2007/08/reload-fstab-etcfstab/<br />
<br />
After you edit the <span style="font-family: 'Courier New', Courier, monospace;">/etc/fstab</span>, use <span style="font-family: 'Courier New', Courier, monospace;">mount -a</span>.David Faivrehttp://www.blogger.com/profile/09936208490636664645noreply@blogger.com1tag:blogger.com,1999:blog-2365970692091225509.post-63706508338404360572012-02-19T06:48:00.000-08:002012-02-19T07:10:17.682-08:00Add a VirtualBox Disk to LinuxI've started to play around with linux in VirtualBox. I'm going to start posting things I find useful, since I'm a Windows man by trade. This is the first:<br />
<br />
I was adding a new VirtualBox disk for my data (so I can keep the OS/programs seperate from my personal stuff). Here's how I did it.<br />
<ol>
<li>Create the disk in the VirtualBox GUI.</li>
<li>Format the disk in Linux: </li>
<ol>
<li>Find the disk (probably <span style="font-family: "Courier New",Courier,monospace;">/dev/sdb</span> or some such path): <span style="font-family: "Courier New",Courier,monospace;">fdisk -l</span></li>
<li><span style="font-family: inherit;">Format</span> the disk: <span style="font-family: "Courier New",Courier,monospace;">fdisk /dev/sdb</span></li>
</ol>
<li>Edit the fstab to mount the disk where you want it:</li>
<ul>
<li><span style="font-family: inherit;">/dev/sdb /home/david ext2 defaults 0 0</span></li>
</ul>
<ul>
<li><i>Note that I mounted to my home directory, so I need to move my existing home dir (which has all the crappy Windows type folders) and then create it again so that the mount can find the folder</i>. </li>
</ul>
<li>Remount: mount -a</li>
<li>EDIT 2012-02-19: Copy all of the .* files from the old user dir to the new one. </li>
<li>Done! (I think, I'm new at this)</li>
</ol>David Faivrehttp://www.blogger.com/profile/09936208490636664645noreply@blogger.com1tag:blogger.com,1999:blog-2365970692091225509.post-36245131718676381872011-10-19T13:21:00.001-07:002011-10-19T13:39:25.581-07:00Ensure Correct Ring Orientation for SqlGeography<p>SqlGeography is very picky about the order of points when reading Well Known Text (WKT): if your WKT points aren’t just so, the de-serialization will throw something like this:</p> <blockquote> <p><em>A .NET Framework error occurred during execution of user-defined routine or aggregate "geography":<br>Microsoft.SqlServer.Types.GLArgumentException: 24205: The specified input does not represent a valid geography instance because it exceeds a single hemisphere. Each geography instance must fit inside a single hemisphere. A common reason for this error is that a polygon has the wrong ring orientation.</em></p></blockquote> <p>Luckily, there are smarter people in the world than me. Here’s a post on how to <a href="http://blogs.msdn.com/b/edkatibah/archive/2008/08/19/working-with-invalid-data-and-the-sql-server-2008-geography-data-type-part-1b.aspx" target="_blank">use T-SQL to ensure correct ring orientation</a>. Here’s how I do it using Microsoft.SqlServer.Types in C#:</p><pre class="brush: csharp;">// a helper SqlGeometry, which isn't picky about ring orientation<br />var geometryHelper = <br /> SqlGeometry.STGeomFromText(wkt.ToSqlChars(), srid).MakeValid();<br /><br />// STUnion will automagically correct any bad ring orientation<br />var validGeom = <br /> geometryHelper.STUnion(geometryHelper.STStartPoint());<br /><br />// use the validGeom with correct ring orientation to <br />// create a SqlGeography.<br />var validGeography =<br /> SqlGeography.STGeomFromText(validGeom.STAsText(), srid);<br /></pre> David Faivrehttp://www.blogger.com/profile/09936208490636664645noreply@blogger.com2tag:blogger.com,1999:blog-2365970692091225509.post-70471358026618689222011-10-18T09:16:00.001-07:002011-10-18T09:17:38.591-07:00Switch/Flag Parameters in PowerShell<p>I wanted to create a function with a ‘-force’ option. First, I tried to add a [boolean] parameter, but that doesn’t work because it needs a value with the argument; I want it to be invoked with just the presence of the switch/flag. Here’s how I finally did it:</p><pre class="brush: ps; gutter: false;">function Update-Something {<br /> param(<br /> [switch] $force)<br /><br /> if ($force) { <br /> #do something here<br /> }<br />}<br /><br /><br /># use like:<br />$> Update-Something -force<br /></pre> David Faivrehttp://www.blogger.com/profile/09936208490636664645noreply@blogger.com4tag:blogger.com,1999:blog-2365970692091225509.post-53533708858109493012011-10-14T11:10:00.001-07:002011-10-14T11:10:07.353-07:00DotSpatial Accepted Pull Request!<p><em>Tooting my own horn</em>: the <a href="http://dotspatial.codeplex.com/" target="_blank">DotSpatial project</a> accepted <a href="http://dotspatial.codeplex.com/SourceControl/network/Forks/dfaivre/dfaivrehashfoo/contribution/1565" target="_blank">a pull request of mine</a> for nuspec and build helper files -- woot!</p> David Faivrehttp://www.blogger.com/profile/09936208490636664645noreply@blogger.com0tag:blogger.com,1999:blog-2365970692091225509.post-65408595093991708142011-10-13T11:01:00.001-07:002011-10-13T11:01:56.906-07:00Rounding In PowerShell<p>Another simple one (<a href="http://www.johndcook.com/blog/2008/05/19/rounding-and-integer-division-in-powershell/" target="_blank">from John D. Cook</a>):</p><pre class="brush: ps; gutter: false;">$> [int] 1.1<br />1<br /><br />$> [int] 1.5<br />2<br /><br />$> [int] 1.8<br />2<br /></pre>David Faivrehttp://www.blogger.com/profile/09936208490636664645noreply@blogger.com0tag:blogger.com,1999:blog-2365970692091225509.post-19208166331763604652011-10-13T10:46:00.000-07:002011-10-13T10:48:42.913-07:00PowerShell: Parse Date from StringIncredibly simple (checkout this <a href="http://www.johndcook.com/PowerShellCookbook.html">PowerShell Cookbook</a>):<br />
<pre class="brush: ps; gutter: false;">$> (get-date 2000/01/01)
Saturday, January 01, 2000 12:00:00 AM</pre>David Faivrehttp://www.blogger.com/profile/09936208490636664645noreply@blogger.com0tag:blogger.com,1999:blog-2365970692091225509.post-87806608631434443252011-10-06T15:04:00.000-07:002011-10-06T15:08:58.401-07:00NuGet Without Committing PackagesI like NuGet. I’m using it to distribute the <a href="http://nuget.org/List/Packages/HashFoo.Rest.Common" target="_blank">#foo REST</a> project. I had this idea that it would be nice NOT to check in package binaries to source control. As usual, I’m <a href="http://docs.nuget.org/docs/workflows/using-nuget-without-committing-packages" target="_blank">not the first one with that idea</a>. God bless all the people that are smarter than me:<br />
<pre class="brush: ps; gutter: false;">PM> Enable-PackageRestore
Attempting to resolve dependency 'NuGet.CommandLine (≥ 1.4)'.
Successfully installed 'NuGet.CommandLine 1.4.20615.182'.
Successfully installed 'NuGet.Build 0.16'.
Copying nuget.exe and msbuild scripts to D:\Code\StarterApps\Mvc3Application\.nuget
Successfully uninstalled 'NuGet.Build 0.16'.
Successfully uninstalled 'NuGet.CommandLine 1.4.20615.182'.
Don't forget to commit the .nuget folder
Updated 'Mvc3Application' to use 'NuGet.targets'
Enabled package restore for Mvc3Application</pre>
David Faivrehttp://www.blogger.com/profile/09936208490636664645noreply@blogger.com0tag:blogger.com,1999:blog-2365970692091225509.post-47472618938334025132011-10-05T15:16:00.001-07:002011-10-05T15:17:11.699-07:00CodePlex and Windows Live Writer<p>I’m working on a simple POCO message based service layer to sit on top of ASP.NET MVC. The project (not yet published) is/will be hosted at CodePlex. As part of this blog, I discovered <a href="http://explore.live.com/windows-live-writer" target="_blank">Windows Live Writer</a> and have been happy with it. I am even more happy that it <a href="http://blogs.msdn.com/b/codeplex/archive/2010/08/19/windows-live-writer-support-and-source-code-branch-selector.aspx" target="_blank">works with CodePlex wiki pages</a>. And I’m giddy that you can use the <a href="http://insertcode.codeplex.com/releases/view/840" target="_blank">Insert Code</a> plugin to add code snippets without leaving Live Writer (don’t be freaked out that the last release was in 2006…).</p> <p>As an aside, I use the more robust <a href="http://alexgorbatchev.com/SyntaxHighlighter/" target="_blank">SyntaxHighlighter</a> with the <a href="http://precode.codeplex.com/" target="_blank">PreCode</a> Live Writer plugin for this blog. I use version 2.x so that the toolbar buttons still show. There are <a href="http://alexgorbatchev.com/SyntaxHighlighter/hosting.html" target="_blank">publicly hosted source files</a> for SyntaxHighlighter, if you’re interested. I basically then followed the install instructions, substituting the 2.x hosted file URLs where needed.</p> David Faivrehttp://www.blogger.com/profile/09936208490636664645noreply@blogger.com0tag:blogger.com,1999:blog-2365970692091225509.post-76476807995300950502011-10-04T14:08:00.000-07:002011-10-04T14:08:35.478-07:00PowerShell Format-List (fl)Staying with the late to the party theme on my PowerShell adventure, today I discovered <a href="http://technet.microsoft.com/en-us/library/dd347700.aspx" target="_blank">Format-List</a> (fl alias). You can pipe results into it and get more detailed output.<br><br>Without Format-List:<pre class="brush: ps;">PS> [Array]<br><br>IsPublic IsSerial Name BaseType<br>-------- -------- ---- --------<br>True True Array System.Object</pre>With Format-List:<pre class="brush: ps;">PS> [Array] | fl<br><br>Module : CommonLanguageRuntimeLibrary<br>Assembly : mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b7<br> 7a5c561934e089<br>TypeHandle : System.RuntimeTypeHandle<br>DeclaringMethod : <br>BaseType : System.Object<br>UnderlyingSystemType : System.Array<br>FullName : System.Array<br>AssemblyQualifiedName : System.Array, mscorlib, Version=4.0.0.0, Culture=neutral, Pub<br> licKeyToken=b77a5c561934e089<br>Namespace : System<br>GUID : 200fb91c-815d-39e0-9e07-0e1bdb2ed47b<br>IsEnum : False<br>GenericParameterAttributes : <br>IsSecurityCritical : False<br>IsSecuritySafeCritical : False<br>IsSecurityTransparent : True</pre> David Faivrehttp://www.blogger.com/profile/09936208490636664645noreply@blogger.com0tag:blogger.com,1999:blog-2365970692091225509.post-84588651675389963152011-10-03T18:56:00.001-07:002011-10-04T08:21:34.662-07:00PowerShell RegExTrying to learn PowerShell by using it to create a NuGet build scripts. In order to parse some code files, I needed to filter a list of strings using a regular expression and capture a match group from the first string matched:<br />
<pre class="brush: ps;">$line =
$assembly_info |
where {$_ -match 'AssemblyDescription\("(?<1>[^"]*)"\)'} |
select -first 1
$matches[1]</pre>
Looks almost like a functional language. Better late to the party than never…David Faivrehttp://www.blogger.com/profile/09936208490636664645noreply@blogger.com0