<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>TITLE!</title>
	<atom:link href="http://www.hatefulbastard.com/index.php" rel="self" type="application/rss+xml" />
	<link>http://www.hatefulbastard.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Fri, 18 Mar 2011 13:40:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Assembly runtime forwarding not working without explanation</title>
		<link>http://www.hatefulbastard.com/index.php/archives/43</link>
		<comments>http://www.hatefulbastard.com/index.php/archives/43#comments</comments>
		<pubDate>Fri, 18 Mar 2011 13:40:30 +0000</pubDate>
		<dc:creator>Alec Horn</dc:creator>
				<category><![CDATA[.NET/C#]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Visual Studio .NET]]></category>

		<guid isPermaLink="false">http://www.hatefulbastard.com/?p=43</guid>
		<description><![CDATA[/** * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann * (http://qbnz.com/highlighter/ and http://geshi.org/) */ .xml {font-family:monospace;color: #006; border: 1px solid #d0d0d0; background-color: #f0f0f0;} .xml a:link {color: #000060;} .xml a:hover {background-color: #f0f000;} .xml .imp {font-weight: bold; color: red;} .xml .es0 {color: #000099; font-weight: bold;} .xml .br0 {color: #66cc66;} .xml .sy0 {color: [...]]]></description>
			<content:encoded><![CDATA[<style type="text/css">
/**
 * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
 * (http://qbnz.com/highlighter/ and http://geshi.org/)
 */
.xml  {font-family:monospace;color: #006; border: 1px solid #d0d0d0; background-color: #f0f0f0;}
.xml a:link {color: #000060;}
.xml a:hover {background-color: #f0f000;}
.xml .imp {font-weight: bold; color: red;}
.xml .es0 {color: #000099; font-weight: bold;}
.xml .br0 {color: #66cc66;}
.xml .sy0 {color: #66cc66;}
.xml .st0 {color: #ff0000;}
.xml .nu0 {color: #cc66cc;}
.xml .sc-1 {color: #808080; font-style: italic;}
.xml .sc0 {color: #00bbdd;}
.xml .sc1 {color: #ddbb00;}
.xml .sc2 {color: #339933;}
.xml .sc3 {color: #009900;}
.xml .re0 {color: #000066;}
.xml .re1 {color: #000000; font-weight: bold;}
.xml .re2 {color: #000000; font-weight: bold;}
.xml span.xtra { display:block; }
</style>
<p>After hours and hours of searching between a coworker and I as to why an assembly version forwarding in this dll hell we&#8217;ve caused ourself wasn&#8217;t working in one project and it was in another, we explored every possibility we could think of:</p>
<ol>
<li>Manually searching assemblies for manual loads</li>
<li>Searching the CLR for the location of runtime forwarding programatically (and failed)</li>
<li>Copying and pasting the exact same text from seperate configuration files known to be working in hopes of success</li>
<li>Sacrificing a kitten</li>
</ol>
<p>All to no avail. After searching, and searching more I finaally ran across this awesome <a href="http://social.msdn.microsoft.com/forums/en-US/netfxbcl/thread/956fd8ce-2ab1-43aa-b13a-7b60655fd939/">Microsoft Social post</a> where someone mentioned that the configuration element having an xmlns would cause runtime to be ignored. Surely, this couldn&#8217;t be the case, but a quick test proved it to in fact be a solution.</p>
<p>So, to summarize:</p>
<p>Bad:<br />
<code></p>
<div class="xml"><span class="sc3"><span class="re1">&lt;configuration</span> <span class="re0">xmlns</span>=<span class="st0">&quot;http://schemas.microsoft.com/.NetConfiguration/v2.0&quot;</span><span class="re2">&gt;</span></span></div>
<p></code></p>
<p>Good:<br />
<code></p>
<div class="xml"><span class="sc3"><span class="re1">&lt;configuration<span class="re2">&gt;</span></span></span></div>
<p></code></p>
<p>New one to me&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hatefulbastard.com/index.php/archives/43/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nHibernate and Remoting/Shallow Serialization</title>
		<link>http://www.hatefulbastard.com/index.php/archives/34</link>
		<comments>http://www.hatefulbastard.com/index.php/archives/34#comments</comments>
		<pubDate>Wed, 28 Oct 2009 13:04:35 +0000</pubDate>
		<dc:creator>Alec Horn</dc:creator>
				<category><![CDATA[.NET/C#]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[nHibernate]]></category>

		<guid isPermaLink="false">http://www.hatefulbastard.com/?p=34</guid>
		<description><![CDATA[So, recently had an issue with Weborb and nHibernate serializing our entire object model due to deep serialization. After much research and my lack of deep knowledge of nHibernate I came across http://trentacular.com/tag/nhibernate/. Shamelessly stolen, of course this solved my problems immediately allowing me to specify n levels of serialization to be kept down the [...]]]></description>
			<content:encoded><![CDATA[<p>So, recently had an issue with Weborb and nHibernate serializing our entire object model due to deep serialization. After much research and my lack of deep knowledge of nHibernate I came across http://trentacular.com/tag/nhibernate/. Shamelessly stolen, of course this solved my problems immediately allowing me to specify n levels of serialization to be kept down the line. I made a few alterations to allow for collections to be serialized:</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: Consolas, "Courier New", Courier, Monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}</p>
<p>.csharpcode pre { margin: 0em; }</p>
<p>.csharpcode .rem { color: #008000; }</p>
<p>.csharpcode .kwrd { color: #0000ff; }</p>
<p>.csharpcode .str { color: #006080; }</p>
<p>.csharpcode .op { color: #0000c0; }</p>
<p>.csharpcode .preproc { color: #cc6633; }</p>
<p>.csharpcode .asp { background-color: #ffff00; }</p>
<p>.csharpcode .html { color: #800000; }</p>
<p>.csharpcode .attr { color: #ff0000; }</p>
<p>.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}</p>
<p>.csharpcode .lnum { color: #606060; }
</style>
<pre class="csharpcode">
                <span class="kwrd">if</span> (nhType.IsCollectionType)
                {
                    <span class="kwrd">object</span> propertyValue = propertyInfo.GetValue(unproxiedObject, <span class="kwrd">null</span>);
                    <span class="kwrd">if</span> (propertyValue == <span class="kwrd">null</span>)
                        <span class="kwrd">continue</span>;
                    <span class="kwrd">if</span> (propertyValue <span class="kwrd">is</span> PersistentBag)
                    {
                        PersistentBag holder = (PersistentBag)propertyValue;
                        <span class="kwrd">for</span> (<span class="kwrd">int</span> j = 0; j &lt; holder.Count; j++)
                        {
                            holder[j] = holder[j].UnproxyObjectTree(sessionFactory, maxDepth - 1);
                        }

                        propertyInfo.SetValue(
                            unproxiedObject,
                            holder,
                            <span class="kwrd">null</span>);
                    }
                    <span class="kwrd">else</span> <span class="kwrd">if</span> (propertyValue <span class="kwrd">is</span> ISet)
                    {
                        ISet holder = (ISet)propertyValue;
                        ArrayList tempcoll = <span class="kwrd">new</span> ArrayList();
                        <span class="kwrd">foreach</span> (<span class="kwrd">object</span> o <span class="kwrd">in</span> (IEnumerable)propertyValue)
                        {
                            tempcoll.Add(o);
                        }
                        <span class="kwrd">for</span> (<span class="kwrd">int</span> j = 0; j &lt; tempcoll.Count; j++)
                        {
                            tempcoll[j] = tempcoll[j].UnproxyObjectTree(sessionFactory, maxDepth - 1);
                        }
                        holder.Clear();
                        holder.AddAll(tempcoll);
                        propertyInfo.SetValue(
                            unproxiedObject,
                            holder,
                            <span class="kwrd">null</span>);
                    }
                    <span class="kwrd">continue</span>;
                }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.hatefulbastard.com/index.php/archives/34/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Anonymous methods and Delegates</title>
		<link>http://www.hatefulbastard.com/index.php/archives/30</link>
		<comments>http://www.hatefulbastard.com/index.php/archives/30#comments</comments>
		<pubDate>Mon, 21 Sep 2009 17:37:32 +0000</pubDate>
		<dc:creator>Alec Horn</dc:creator>
				<category><![CDATA[.NET/C#]]></category>
		<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://www.hatefulbastard.com/?p=30</guid>
		<description><![CDATA[So, I&#8217;m currently working on a Windows forms application built by a coworker and adding some threading to it to provide a more enhanced interface. Of course we come into the issue of thread locking, and of course Invoke must be used. We&#8217;re in .NET 3.5, might as well get some of the benefits of [...]]]></description>
			<content:encoded><![CDATA[<p>So, I&#8217;m currently working on a Windows forms application built by a coworker and adding some threading to it to provide a more enhanced interface. </p>
<p>Of course we come into the issue of thread locking, and of course Invoke must be used. We&#8217;re in .NET 3.5, might as well get some of the benefits of the latest framework, right? Well, turned out to be a bit more confusing than I first thought. </p>
<p>Ex:</p>
<pre class="csharpcode">
      <span class="kwrd">delegate</span> <span class="kwrd">bool</span> GetBoolDelegate();
      <span class="kwrd">int</span> GetBoolValue()
      {
         <span class="kwrd">if</span> (!InvokeRequired)
            <span class="kwrd">return</span> (<span class="kwrd">bool</span>)vart.SelectedIndex;
         <span class="kwrd">else</span>
            <span class="kwrd">return</span> (<span class="kwrd">bool</span>)Invoke(<span class="kwrd">new</span> GetBoolDelegate(GetBoolValue), <span class="kwrd">null</span>);
      }
</pre>
<p>The pre 2.0 way of doing things, move along and try:</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode">
            <span class="kwrd">bool</span> regchecked = (<span class="kwrd">bool</span>)<span class="kwrd">this</span>.Invoke(
                  <span class="kwrd">delegate</span>()
                  {
                     <span class="kwrd">return</span> chkRegression.Checked;
                  }
               );</pre>
<p>Which gives the following error:</p>
<p>Cannot convert anonymous method to type &#8216;System.Delegate&#8217; because it is not a delegate type	</p>
<p>There are several ways around this, the easiest is:</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode">
      <span class="kwrd">public</span> <span class="kwrd">delegate</span> <span class="kwrd">bool</span> MethodBoolInvoke();
            <span class="kwrd">bool</span> regchecked = (<span class="kwrd">bool</span>)<span class="kwrd">this</span>.Invoke(
                  (MethodBoolInvoke)<span class="kwrd">delegate</span>()
                  {
                     <span class="kwrd">return</span> chkRegression.Checked;
                  }
               );</pre>
<p>And, the final simple example of invoking for general items:</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode">
<span class="kwrd">this</span>.Invoke( (MethodInvoker)<span class="kwrd">delegate</span>() {<span class="kwrd">this</span>.Cursor = Cursors.WaitCursor; });</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.hatefulbastard.com/index.php/archives/30/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Changing the Visual Studio &#8216;Developer Type&#8217;</title>
		<link>http://www.hatefulbastard.com/index.php/archives/28</link>
		<comments>http://www.hatefulbastard.com/index.php/archives/28#comments</comments>
		<pubDate>Fri, 19 Jun 2009 15:10:44 +0000</pubDate>
		<dc:creator>Alec Horn</dc:creator>
				<category><![CDATA[Visual Studio .NET]]></category>

		<guid isPermaLink="false">http://www.hatefulbastard.com/?p=28</guid>
		<description><![CDATA[So, every once and a while I accidently hit the wrong setup type when opening a brand new copy of VS after my 483rd format, and F5 is no longer debug, F6 no longer rebuild, and I realize that I *should* have hit &#8220;Visual C# Developer&#8221;. Alas, MSDN has a solution: http://msdn.microsoft.com/en-us/library/f1z20s6z.aspx Just keep in [...]]]></description>
			<content:encoded><![CDATA[<p>So, every once and a while I accidently hit the wrong setup type when opening a brand new copy of VS after my 483rd format, and F5 is no longer debug, F6 no longer rebuild, and I realize that I *should* have hit &#8220;Visual C# Developer&#8221;.</p>
<p>Alas, MSDN has a solution:</p>
<p>http://msdn.microsoft.com/en-us/library/f1z20s6z.aspx</p>
<p>Just keep in mind it will overwrite some other format settings if you have them set. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.hatefulbastard.com/index.php/archives/28/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How not to lock your database server for large deletes.</title>
		<link>http://www.hatefulbastard.com/index.php/archives/27</link>
		<comments>http://www.hatefulbastard.com/index.php/archives/27#comments</comments>
		<pubDate>Thu, 14 May 2009 17:17:01 +0000</pubDate>
		<dc:creator>Alec Horn</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.hatefulbastard.com/index.php/archives/27</guid>
		<description><![CDATA[So one of my coworkers recently brought down a website accidently since someone broke the session cleaning job. So, he of course runs the procedure to delete all of the old data, and kaboom it places a lock on the table while it deletes a few hundred thousand rows. Cute except that without that table [...]]]></description>
			<content:encoded><![CDATA[<p>So one of my coworkers recently brought down a website accidently since someone broke the session cleaning job. So, he of course runs the procedure to delete all of the old data, and kaboom it places a lock on the table while it deletes a few hundred thousand rows. </p>
<p>Cute except that without that table being able to be accessed no requests would technically go through. The workaround? Simply do small units of work at a time:</p>
<pre class="csharpcode"><span class="kwrd">WHILE</span> 1=1
<span class="kwrd">BEGIN</span>
      <span class="kwrd">DELETE</span>  <span class="kwrd">TOP</span> (1000)
      <span class="kwrd">FROM</span>    [db].[dbo].[table]
      <span class="kwrd">WHERE</span>  Expires &lt; @now;

      <span class="kwrd">IF</span> <span class="preproc">@@rowcount</span> = 0 <span class="kwrd">BREAK</span>;
<span class="kwrd">END</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.hatefulbastard.com/index.php/archives/27/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to convert an office 2007 document to 2003.</title>
		<link>http://www.hatefulbastard.com/index.php/archives/20</link>
		<comments>http://www.hatefulbastard.com/index.php/archives/20#comments</comments>
		<pubDate>Mon, 30 Mar 2009 16:46:27 +0000</pubDate>
		<dc:creator>Alec Horn</dc:creator>
				<category><![CDATA[.NET/C#]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Interop]]></category>
		<category><![CDATA[Office 2003]]></category>
		<category><![CDATA[Office 2007]]></category>

		<guid isPermaLink="false">http://www.hatefulbastard.com/?p=20</guid>
		<description><![CDATA[So, backwards converting seemed to be impossible, and is give or take but if you can interact with the desktop here&#8217;s a way to do it that&#8217;s beyond ugly, cludgy, and I wish someone had a better solution&#8230; Oh, this is to interact with OFFICE12\Moc.exe, best of luck! .csharpcode, .csharpcode pre { font-size: small; color: [...]]]></description>
			<content:encoded><![CDATA[<p>So, backwards converting seemed to be impossible, and is give or take but if you can interact with the desktop here&#8217;s a way to do it that&#8217;s beyond ugly, cludgy, and I wish someone had a better solution&#8230; Oh, this is to interact with OFFICE12\Moc.exe, best of luck!</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: Consolas, "Courier New", Courier, Monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}</p>
<p>.csharpcode pre { margin: 0em; }</p>
<p>.csharpcode .rem { color: #008000; }</p>
<p>.csharpcode .kwrd { color: #0000ff; }</p>
<p>.csharpcode .str { color: #006080; }</p>
<p>.csharpcode .op { color: #0000c0; }</p>
<p>.csharpcode .preproc { color: #cc6633; }</p>
<p>.csharpcode .asp { background-color: #ffff00; }</p>
<p>.csharpcode .html { color: #800000; }</p>
<p>.csharpcode .attr { color: #ff0000; }</p>
<p>.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}</p>
<p>.csharpcode .lnum { color: #606060; }
</style>
<pre class="csharpcode">
<span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.Collections.Generic;
<span class="kwrd">using</span> System.Linq;
<span class="kwrd">using</span> System.Text;
<span class="kwrd">using</span> System.Diagnostics;
<span class="kwrd">using</span> System.Runtime.InteropServices;
<span class="kwrd">using</span> System.Windows.Forms;
<span class="kwrd">using</span> System.Threading;
<span class="kwrd">using</span> System.IO;

<span class="kwrd">namespace</span> t
{
   <span class="kwrd">class</span> Program
   {

      <span class="kwrd">static</span> <span class="kwrd">void</span> Main(<span class="kwrd">string</span>[] args)
      {

         Program.ProcessChecker.Proc();
         Console.ReadLine();
      }

      <span class="kwrd">static</span> <span class="kwrd">class</span> ProcessChecker
      {

         <span class="kwrd">internal</span> <span class="kwrd">static</span> <span class="kwrd">class</span> NativeMethods
         {
            [DllImport(<span class="str">"user32.dll"</span>)]
            <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">extern</span> <span class="kwrd">bool</span> ShowWindowAsync(IntPtr hWnd, <span class="kwrd">int</span> nCmdShow);

            [DllImport(<span class="str">"user32.dll"</span>)]
            <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">extern</span> <span class="kwrd">bool</span> SetForegroundWindow(IntPtr hWnd);

            [DllImport(<span class="str">"user32.dll"</span>)]
            <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">extern</span> <span class="kwrd">bool</span> EnumWindows(EnumWindowsProcDel lpEnumFunc,
                Int32 lParam);

            [DllImport(<span class="str">"user32.dll"</span>)]
            <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">extern</span> <span class="kwrd">uint</span> GetWindowThreadProcessId(IntPtr hWnd,
                <span class="kwrd">ref</span> Int32 lpdwProcessId);

            [DllImport(<span class="str">"user32.dll"</span>)]
            <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">extern</span> <span class="kwrd">int</span> GetWindowText(IntPtr hWnd, StringBuilder lpString,
                Int32 nMaxCount);

            [DllImport(<span class="str">"user32.dll"</span>)]
            <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">extern</span> <span class="kwrd">bool</span> SetWindowText(IntPtr hWnd, <span class="kwrd">string</span> lpString);

            [DllImport(<span class="str">"user32.dll"</span>)]
            <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">extern</span> <span class="kwrd">int</span> GetFocus();

            [DllImport(<span class="str">"user32.dll"</span>)]
            <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">extern</span> <span class="kwrd">bool</span> AttachThreadInput(<span class="kwrd">uint</span> idAttach, <span class="kwrd">uint</span> idAttachTo, <span class="kwrd">bool</span> fAttach);

            [DllImport(<span class="str">"kernel32.dll"</span>)]
            <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">extern</span> <span class="kwrd">uint</span> GetCurrentThreadId();

            [DllImport(<span class="str">"user32.dll"</span>)]
            <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">extern</span> <span class="kwrd">uint</span> GetWindowThreadProcessId(<span class="kwrd">int</span> hWnd, <span class="kwrd">int</span> ProcessId);

            [DllImport(<span class="str">"user32.dll"</span>)]
            <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">extern</span> <span class="kwrd">int</span> GetForegroundWindow();

            [DllImport(<span class="str">"user32.dll"</span>, CharSet = CharSet.Auto, SetLastError = <span class="kwrd">false</span>)]
            <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">extern</span> <span class="kwrd">int</span> SendMessage(<span class="kwrd">int</span> hWnd, <span class="kwrd">int</span> Msg, <span class="kwrd">int</span> wParam, StringBuilder lParam);

            [DllImport(<span class="str">"user32.dll"</span>, CharSet = CharSet.Auto)]
            <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">extern</span> <span class="kwrd">int</span> GetClassName(IntPtr hWnd, StringBuilder lpClassName, <span class="kwrd">int</span> nMaxCount);

            [DllImport(<span class="str">"user32.dll"</span>, SetLastError = <span class="kwrd">true</span>)]
            <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">extern</span> IntPtr GetWindow(IntPtr hWnd, <span class="kwrd">uint</span> uCmd);

            <span class="kwrd">public</span> <span class="kwrd">enum</span> GetWindow_Cmd : <span class="kwrd">uint</span>
            {
               GW_HWNDFIRST = 0,
               GW_HWNDLAST = 1,
               GW_HWNDNEXT = 2,
               GW_HWNDPREV = 3,
               GW_OWNER = 4,
               GW_CHILD = 5,
               GW_ENABLEDPOPUP = 6
            }

            <span class="kwrd">public</span> <span class="kwrd">const</span> <span class="kwrd">int</span> SW_SHOWNORMAL = 1;
         }
         <span class="kwrd">const</span> <span class="kwrd">int</span> WM_SETTEXT = 12;
         <span class="kwrd">const</span> <span class="kwrd">int</span> WM_GETTEXT = 13;
         <span class="kwrd">public</span> <span class="kwrd">delegate</span> <span class="kwrd">bool</span> EnumWindowsProcDel(IntPtr hWnd, Int32 lParam);

         <span class="kwrd">static</span> <span class="kwrd">private</span> <span class="kwrd">bool</span> EnumWindowsProc(IntPtr hWnd, Int32 lParam)
         {
            <span class="kwrd">int</span> processId = 0;
            <span class="kwrd">uint</span> remoteThreadId = NativeMethods.GetWindowThreadProcessId(hWnd, <span class="kwrd">ref</span> processId);
            StringBuilder WindowText = <span class="kwrd">new</span> StringBuilder(5000);

            NativeMethods.GetWindowText(hWnd, WindowText, 5000);
            StringBuilder v_szbTest2 = <span class="kwrd">new</span> StringBuilder(99);
            NativeMethods.GetClassName(hWnd, v_szbTest2, 99);
            <span class="kwrd">if</span> (WindowText.ToString().Equals(<span class="str">"Save As"</span>) &amp;&amp; processId.Equals(lParam))
            {
               <span class="kwrd">uint</span> currentThreadId = NativeMethods.GetCurrentThreadId();
               NativeMethods.AttachThreadInput(remoteThreadId, currentThreadId, <span class="kwrd">true</span>);

               IntPtr i = IntPtr.Zero;
               i = NativeMethods.GetWindow(hWnd, (<span class="kwrd">uint</span>)NativeMethods.GetWindow_Cmd.GW_CHILD);
               <span class="kwrd">for</span> (; i.ToInt32() &gt; 0; )
               {

                  i = NativeMethods.GetWindow(i, (<span class="kwrd">uint</span>)NativeMethods.GetWindow_Cmd.GW_HWNDNEXT);
                  StringBuilder v_szbTest3 = <span class="kwrd">new</span> StringBuilder(99);
                  NativeMethods.GetClassName(i, v_szbTest3, 99);

                  StringBuilder builder = <span class="kwrd">new</span> StringBuilder(500);
                  builder.Append(<span class="str">"c:\\Hey look a text.xls"</span>);
                  <span class="kwrd">if</span> (v_szbTest3.ToString().Equals(<span class="str">"ComboBoxEx32"</span>))
                  {
                     NativeMethods.SendMessage(i.ToInt32(), WM_SETTEXT, builder.Capacity, builder);
                  }
                  StringBuilder v_szbText = <span class="kwrd">new</span> StringBuilder(256);
                  NativeMethods.GetWindowText(i, v_szbText, 256);
                  <span class="kwrd">if</span> (v_szbTest3.ToString().Equals(<span class="str">"Button"</span>) &amp;&amp; v_szbText.ToString().Equals(<span class="str">"&amp;Save"</span>))
                  {
                     <span class="rem">//Save!</span>
                     var BM_CLICK = 0xf5;
                     NativeMethods.SendMessage(i.ToInt32(), BM_CLICK, 0, builder);
                     NativeMethods.AttachThreadInput(remoteThreadId, currentThreadId, <span class="kwrd">false</span>);
                     <span class="rem">//Lets wait till we can access the file.</span>

                     <span class="kwrd">while</span> (<span class="kwrd">true</span>)
                     {
                        <span class="kwrd">try</span>
                        {
                           FileStream fso = File.Open(builder.ToString() + <span class="str">".xls"</span>, FileMode.Open, FileAccess.Write);
                           fso.Close();
                           <span class="rem">//kill our proc</span>
                           Process moc = Process.GetProcessById(lParam);
                           moc.Kill();
                           <span class="kwrd">return</span> <span class="kwrd">true</span>;
                        }
                        <span class="kwrd">catch</span> (IOException x)
                        {
                           Console.WriteLine(x);
                           Thread.Sleep(10);
                        }
                     }

                  }

               }

            }
            <span class="kwrd">return</span> <span class="kwrd">true</span>;
         }

         <span class="kwrd">static</span> <span class="kwrd">public</span> <span class="kwrd">bool</span> Proc()
         {

            Process[] v_oProcs = Process.GetProcesses();
            <span class="kwrd">foreach</span> (Process proc <span class="kwrd">in</span> v_oProcs)
            {
               <span class="kwrd">if</span> (proc.ProcessName.Equals(<span class="str">"Moc"</span>))
               {
                  NativeMethods.EnumWindows(<span class="kwrd">new</span> EnumWindowsProcDel(EnumWindowsProc),
                      proc.Id);
                  <span class="kwrd">return</span> <span class="kwrd">false</span>;
               }
            }
            <span class="kwrd">return</span> <span class="kwrd">true</span>;
         }
      }

      <span class="preproc">#region</span> EnumWindows
      <span class="rem">/// </span>
      <span class="rem">/// EnumWindows wrapper for .NET</span>
      <span class="rem">/// </span>
      <span class="kwrd">public</span> <span class="kwrd">class</span> EnumWindows
      {
         <span class="preproc">#region</span> Delegates
         <span class="kwrd">private</span> <span class="kwrd">delegate</span> <span class="kwrd">int</span> EnumWindowsProc(IntPtr hwnd, <span class="kwrd">int</span> lParam);
         <span class="preproc">#endregion</span>

         <span class="preproc">#region</span> UnManagedMethods
         <span class="kwrd">private</span> <span class="kwrd">class</span> UnManagedMethods
         {
            [DllImport(<span class="str">"user32"</span>)]
            <span class="kwrd">public</span> <span class="kwrd">extern</span> <span class="kwrd">static</span> <span class="kwrd">int</span> EnumWindows(
                EnumWindowsProc lpEnumFunc,
                <span class="kwrd">int</span> lParam);
            [DllImport(<span class="str">"user32"</span>)]
            <span class="kwrd">public</span> <span class="kwrd">extern</span> <span class="kwrd">static</span> <span class="kwrd">int</span> EnumChildWindows(
                IntPtr hWndParent,
                EnumWindowsProc lpEnumFunc,
                <span class="kwrd">int</span> lParam);
         }
         <span class="preproc">#endregion</span>

         <span class="preproc">#region</span> Member Variables
         <span class="kwrd">private</span> List&lt;IntPtr&gt; items = <span class="kwrd">null</span>;
         <span class="preproc">#endregion</span>

         <span class="rem">/// </span>
         <span class="rem">/// Returns the collection of windows returned by</span>
         <span class="rem">/// GetWindows</span>
         <span class="rem">/// </span>
         <span class="kwrd">public</span> List&lt;IntPtr&gt; Items
         {
            get
            {
               <span class="kwrd">return</span> <span class="kwrd">this</span>.items;
            }
         }

         <span class="rem">/// </span>
         <span class="rem">/// Gets all top level windows on the system.</span>
         <span class="rem">/// </span>
         <span class="kwrd">public</span> <span class="kwrd">void</span> GetWindows()
         {
            <span class="kwrd">this</span>.items = <span class="kwrd">new</span> List&lt;IntPtr&gt;();
            UnManagedMethods.EnumWindows(
                <span class="kwrd">new</span> EnumWindowsProc(<span class="kwrd">this</span>.WindowEnum),
                0);
         }

         <span class="rem">/// </span>
         <span class="rem">/// Gets all child windows of the specified window</span>
         <span class="rem">/// </span>
         <span class="rem">/// Window Handle to get children for</span>
         <span class="kwrd">public</span> <span class="kwrd">void</span> GetWindows(
             IntPtr hWndParent)
         {
            <span class="kwrd">this</span>.items = <span class="kwrd">new</span> List&lt;IntPtr&gt;();
            UnManagedMethods.EnumChildWindows(
                hWndParent,
                <span class="kwrd">new</span> EnumWindowsProc(<span class="kwrd">this</span>.WindowEnum),
                0);
         }

         <span class="preproc">#region</span> EnumWindows callback
         <span class="rem">/// </span>
         <span class="rem">/// The enum Windows callback.</span>
         <span class="rem">/// </span>
         <span class="rem">/// Window Handle</span>
         <span class="rem">/// Application defined value</span>
         <span class="rem">/// 1 to continue enumeration, 0 to stop</span>
         <span class="kwrd">private</span> <span class="kwrd">int</span> WindowEnum(
             IntPtr hWnd,
             <span class="kwrd">int</span> lParam)
         {
            <span class="kwrd">if</span> (<span class="kwrd">this</span>.OnWindowEnum(hWnd))
            {
               <span class="kwrd">return</span> 1;
            }
            <span class="kwrd">else</span>
            {
               <span class="kwrd">return</span> 0;
            }
         }
         <span class="preproc">#endregion</span>

         <span class="rem">/// </span>
         <span class="rem">/// Called whenever a new window is about to be added</span>
         <span class="rem">/// by the Window enumeration called from GetWindows.</span>
         <span class="rem">/// If overriding this function, return true to continue</span>
         <span class="rem">/// enumeration or false to stop.  If you do not call</span>
         <span class="rem">/// the base implementation the Items collection will</span>
         <span class="rem">/// be empty.</span>
         <span class="rem">/// </span>
         <span class="rem">/// Window handle to add</span>
         <span class="rem">/// True to continue enumeration, False to stop</span>
         <span class="kwrd">protected</span> <span class="kwrd">virtual</span> <span class="kwrd">bool</span> OnWindowEnum(
             IntPtr hWnd)
         {
            items.Add(hWnd);
            <span class="kwrd">return</span> <span class="kwrd">true</span>;
         }

         <span class="preproc">#region</span> Constructor, Dispose
         <span class="kwrd">public</span> EnumWindows()
         {
            <span class="rem">// nothing to do</span>
         }
         <span class="preproc">#endregion</span>
      }
      <span class="preproc">#endregion</span> EnumWindows

   }

}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.hatefulbastard.com/index.php/archives/20/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Entity SQL, Joins and the EntityDataSource with Child Relations</title>
		<link>http://www.hatefulbastard.com/index.php/archives/9</link>
		<comments>http://www.hatefulbastard.com/index.php/archives/9#comments</comments>
		<pubDate>Fri, 19 Dec 2008 13:35:39 +0000</pubDate>
		<dc:creator>Alec Horn</dc:creator>
				<category><![CDATA[.NET/C#]]></category>
		<category><![CDATA[ADO.NET]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[ado.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[entity]]></category>
		<category><![CDATA[EntityDataSource]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.hatefulbastard.com/?p=9</guid>
		<description><![CDATA[So, yesterday I actually started working with the Entity framework with a tad more complex queries than the basic select of a single Entity. The first issue I ran into is the flattening of a single Entity 1* Entity relationship. By default the Entity framework and the EntityDataSource actually keeps something similar to an DataTable-&#62;ChildDataTable [...]]]></description>
			<content:encoded><![CDATA[<p>So, yesterday I actually started working with the Entity framework with a tad more complex queries than the basic select of a single Entity. The first issue I ran into is the flattening of a single Entity 1* Entity relationship. By default the Entity framework and the EntityDataSource actually keeps something similar to an DataTable-&gt;ChildDataTable relationship with a prebuilt relationship. Unfortunately the ability to flatten this data is not inherently built in, and join syntax needs to be used:</p>
<pre class="csharpcode"><span class="kwrd">SELECT E.ID, E.Field, r.Field2 from EntitySet AS E INNER JOIN Entity2Set AS r ON r.Entity = E</span></pre>
<p>Which creates our flattened list of Entities for us based on the defined relationship.</p>
<p>Secondly: EntityDataSource and 1-1 relationships/child objects/picklists. This is much easier to do via the Entity framework and is simply defined via the &#8220;Include&#8221; parameter.</p>
<p>Ex:</p>
<pre class="csharpcode">
   <span class="kwrd">&lt;</span><span class="html">asp:EntityDataSource</span> <span class="attr">ID</span><span class="kwrd">="x_EntityDataSource"</span> <span class="attr">runat</span><span class="kwrd">="server"</span>
      <span class="attr">ConnectionString</span><span class="kwrd">="name=DataEntities"</span>
      <span class="attr">DefaultContainerName</span><span class="kwrd">="DataEntities"</span> <span class="attr">Where</span><span class="kwrd">="it.ID = @EntityID"</span>
      <span class="attr">EntitySetName</span><span class="kwrd">="EntitySet"</span> <span class="attr">EnableUpdate</span><span class="kwrd">="True"</span> <span class="attr">Include</span><span class="kwrd">="SubEntity"</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">WhereParameters</span><span class="kwrd">&gt;</span>
         <span class="kwrd">&lt;</span><span class="html">asp:QueryStringParameter</span> <span class="attr">Name</span><span class="kwrd">="EntityId"</span> <span class="attr">QueryStringField</span><span class="kwrd">="ID"</span> <span class="attr">Type</span><span class="kwrd">="Int32"</span> <span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;/</span><span class="html">WhereParameters</span><span class="kwrd">&gt;</span>
   <span class="kwrd">&lt;/</span><span class="html">asp:EntityDataSource</span><span class="kwrd">&gt;</span></pre>
<p>Which provides us with the Entity, and a secondary child Entity which is an FK relationship to a single value.<br />
And, lastly some great posts from the Microsoft team:<br />
<a href="http://blogs.msdn.com/diego/archive/2008/05/13/entitydatasource-to-wrap-or-not-to-wrap.aspx">http://blogs.msdn.com/diego/archive/2008/05/13/entitydatasource-to-wrap-or-not-to-wrap.aspx</a><a href="http://blogs.msdn.com/diego/archive/2008/05/24/entitydatasource-s-flattening-of-complex-type-properties.aspx"><br />
http://blogs.msdn.com/diego/archive/2008/05/24/entitydatasource-s-flattening-of-complex-type-properties.aspx</a><a href="http://blogs.msdn.com/zlatkom/archive/2007/07/10/entity-sql.aspx"></p>
<p>http://blogs.msdn.com/zlatkom/archive/2007/07/10/entity-sql.aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hatefulbastard.com/index.php/archives/9/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Iterating through an embedded resources file.</title>
		<link>http://www.hatefulbastard.com/index.php/archives/3</link>
		<comments>http://www.hatefulbastard.com/index.php/archives/3#comments</comments>
		<pubDate>Tue, 16 Dec 2008 17:44:37 +0000</pubDate>
		<dc:creator>Alec Horn</dc:creator>
				<category><![CDATA[.NET/C#]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[resources]]></category>
		<category><![CDATA[resx]]></category>

		<guid isPermaLink="false">http://www.hatefulbastard.com/?p=3</guid>
		<description><![CDATA[So, I decided to try a new format for handling picklists (database mappings) and decided to leave a full code based Enum model with resources files to map to proper names. From there the SQL can be generated during our build process to populate the database. Now, the issue came in when you need to [...]]]></description>
			<content:encoded><![CDATA[<p>So, I decided to try a new format for handling picklists (database mappings) and decided to leave a full code based Enum model with resources files to map to proper names. From there the SQL can be generated during our build process to populate the database. Now, the issue came in when you need to go from a sane (display) value back to the ID or Enum value. In order to get a ResourceReader on an embedded resource, the following works&#8230;</p>
<pre class="csharpcode">         ResourceReader v_oReader = <span class="kwrd">new</span> ResourceReader(<span class="kwrd">typeof</span>(T).Assembly.GetManifestResourceStream(<span class="kwrd">typeof</span>(T).FullName + <span class="str">"DataSource.resources"</span>));
         <span class="kwrd">try</span>
         {
            <span class="kwrd">foreach</span> (DictionaryEntry entry <span class="kwrd">in</span> v_oReader)
            {
               <span class="kwrd">if</span> (entry.Value.ToString().Equals(p_szDisplayValue))
               {
                  <span class="kwrd">return</span> (T)(Enum.Parse(<span class="kwrd">typeof</span>(T), entry.Key.ToString()));
               }
            }
            <span class="kwrd">throw</span> <span class="kwrd">new</span> ApplicationException(String.Format(<span class="str">"Unable to match value for '{0}'."</span>, p_szDisplayValue ));
         }
         <span class="kwrd">finally</span>
         {
            v_oReader.Close();
            v_oReader = <span class="kwrd">null</span>;
         }</pre>
<p>Where T is the Enum, and this code assumes that the embedded resx file is stored at Namespace.EnumDataSource.resources</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hatefulbastard.com/index.php/archives/3/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

