<?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>Jason Rowe</title>
	<atom:link href="http://jasonrowe.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://jasonrowe.com</link>
	<description></description>
	<lastBuildDate>Tue, 03 Aug 2010 23:10:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>WP7 Boot Camp with Jeff Brand</title>
		<link>http://jasonrowe.com/2010/08/03/wp7-boot-camp-with-jeff-brand/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=wp7-boot-camp-with-jeff-brand</link>
		<comments>http://jasonrowe.com/2010/08/03/wp7-boot-camp-with-jeff-brand/#comments</comments>
		<pubDate>Tue, 03 Aug 2010 18:38:38 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[WP7]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[wp7]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/2010/08/03/wp7-boot-camp-with-jeff-brand/</guid>
		<description><![CDATA[&#160; Today I went to the WP7 boot camp in Minneapolis. Not many people have actually seen a Windows Phone 7 yet. I was hoping to see the real thing but it wasn’t available. Although, the dev tools are ready &#8230; <a href="http://jasonrowe.com/2010/08/03/wp7-boot-camp-with-jeff-brand/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>Today I went to the WP7 boot camp in Minneapolis. Not many people have actually seen a Windows Phone 7 yet. I was hoping to see the real thing but it wasn’t available. Although, the dev tools are ready and very robust.</p>
<p>Getting started is easy using the <a href="http://developer.windowsphone.com/">developer tools</a> and <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=CA23285F-BAB8-47FA-B364-11553E076A9A&amp;displaylang=en">developer training kit</a>. After downloading and playing around I really hope WP7 is a success. The development experience is slick if you are willing to embrace XAML or XNA. </p>
<p>A note about the install. If you have a full version of Visual Studio it will integrate with that. Otherwise it will install Visual Studio express. A few people in the group were confused when they opened express and the tools were not available as they already had VS2010 installed. (Note, it might be safer to use VS Express for now with this beta if you can. The presenter was having issues adding service references with VS Pro but it works in express.)</p>
</p>
<div style="width: 250px" class="wp-caption alignright"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="wp7" border="0" alt="wp7" src="http://jasonrowe.com/wp-content/uploads/2010/08/wp7_thumb.png" width="135" height="244"/> </div>
<p>Since the first part of the conversation was about marketing information I ported over a Silverlight 3 test application which uses data binding and notifications to draw lines onto a canvas. All I had to do was copy the code verbatim and it ran on the phone. It took me 5 minutes. The ease of portability was impressive. Although, Silverlight is at a 60 &#8211; 65% <a href="http://riastats.com/">adoption rate</a> so portability is relative depending on market conditions.
</p>
<p>Below are a list of notes that caught my attention during the talk. This is all based on a beta product so some of this may change. For the latest information download the WP7 Training Kit and visit the wp7 developer site.</p>
<p>Basics</p>
<ul>
<li>$100 fee to upload apps to market place. You get paid after you make the first $100 but Microsoft will take a cut for each sale.  </li>
<li>Has ability to upload app in trial mode  </li>
<li>Silverlight capabilities is basically Silverlight 3 plus additional features. </li>
</ul>
<p>Known Issues with Emulator:</p>
<ul>
<li>Sometimes Emulator will not change from portrait to landscape if keyboard is enabled to be used. Hit PageDown to disable it  </li>
<li>When using VS Pro some users have not been able to add service references correctly. They didn’t generate the full proxy. </li>
</ul>
<p>Tips and Tricks:</p>
<ul>
<li>Use PageUp and PageDown keys to enable keyboard in emulator.  </li>
<li>Emulator can be kept running and will store all opened apps.  </li>
<li>Blend can be used to test light and dark template available to phone users. </li>
</ul>
<p>Tooling </p>
<ul>
<li>Code from Silverlight 3 should work on the phone with maybe only small tweaks for things like navigation and UI sizes.  </li>
<li>List Application (list and details page paradigm)  </li>
<li>Binding works just like in Silverlight  </li>
<li>DataContext works like Silverlight  </li>
<li>Input scopes “TelephoneAreaCode” and “EmailSMTPAdress”&nbsp; allow you to change keyboard layout.<strong> </strong><strong>Developer Note</strong>: You can use Verbose XAML syntax for intellisense. You can’t create your own input scopes right now. Demo in SDK uses reflection to explore input scopes.  </li>
<li>Accelerometer – can be used with emulator if laptop that has one built one in. Otherwise you can use <a href="http://msdn.microsoft.com/en-us/library/ff637521%28v=VS.92%29.aspx">accelerometer emulator using RX</a>.  </li>
<li>Audio – leverage raw data override BufferReady event at regular intervals save and manipulate audio. About a 10ms delay. All available in SDK.  </li>
<li>Video elements – Media support is on the hardware – video decoding is down on the hardware. Only one media element on the page at the time. No video media brush. DRM  </li>
<li>XNA API can be used to bring in sounds and background sounds.  </li>
<li>JavaScript can talk to Silverlight in control – Silverlight to script wb.InvokeScript&nbsp; &#8211; script to Silverlight wb_ScriptNotify. Window.external.Notify(string) </li>
</ul>
<p>3rd Party Tools and Links</p>
<ul>
<li><a href="http://mvvmlight.codeplex.com/">MVVM light for wp7</a>. Design Pattern.  </li>
<li>&nbsp;<strong></strong><strong>Developer Note</strong>: <a href="http://www.silverlighthack.com/post/2010/03/21/Using-the-Silverlight-Bing-Maps-control-on-the-Windows-Phone-7.aspx">Bing Maps Control</a> not yet available but being developed. </li>
</ul>
<p>Design</p>
<ul>
<li>All elements can be animated  </li>
<li>Elements can be projected onto 3d plane  </li>
<li>Templating – taking a control and laying a XAML rendering over the code base. Microsoft encourages using the metro theme but they did show a puzzle application that used templating to change buttons and panels.  </li>
<li>Styling can be set in the Application XAML resources or page resources.  </li>
<li>Two screen resolutions will be available.  </li>
<li>User can change the Theme  </li>
<li>Blend can be used to test dark and light themes available to users. Would only need to be done if you go off and build your own template. But if you use the metro theme you get the changes for free. For example, your applications buttons and backgrounds would be updated.  </li>
<li>App bar should be used to create consistent navigation and controls. <a href="http://msdn.microsoft.com/en-us/library/ff431786%28v=VS.92%29.aspx">How to: Add an Application Bar to Your Application</a> on MSDN.  </li>
<li>App bar Icon set can be <a href="http://www.microsoft.com/downloads/en/confirmation.aspx?familyId=369b20f7-9d30-4cff-8a1b-f80901b2da93&amp;displayLang=en">downloaded here.</a> </li>
</ul>
<p>Application Components</p>
<ul>
<li>Host (TaskHost)  </li>
<li>XAP file  </li>
<li>Pages (Silverlight)  </li>
<li>Content (Silverlight)  </li>
<li>Games (XNA) </li>
</ul>
<p>Application Structure</p>
<ul>
<li>Apps are built like web sites  </li>
<li>Functionality is split into pages  </li>
<li>Forward navigation via links  </li>
<li>Backward navigation via Back (should use hardware button).  </li>
<li>Users can navigate across different applications  </li>
<li>Previous app (pages) are in the back stack. No multi tasking for third party apps. The back stack means your app is shut down. </li>
</ul>
<p>Hardware buttons</p>
<ul>
<li>Back (only one you can inject into when it fires right now)  </li>
<li>Start  </li>
<li>Search  </li>
<li>Volume  </li>
<li>Camera </li>
</ul>
<p>Feels like web design.</p>
<ul>
<li>Application state can be passed between pages by querystring and frame context.  </li>
<li>hyperlinks can be used to navigate to other pages.  </li>
<li>UriMapping which is similar to MVC URL routing. </li>
</ul>
<p>Push Notification Service via the cloud (Microsoft Notification service)</p>
<ul>
<li><strong>Developer Note: When the emulator starts it takes 30 seconds to instantiate</strong> notification service.  </li>
<li>Phones subscribe to a service on your server for events via a Uri.  </li>
<li>All communication pushed to phone is via Microsoft.  </li>
<li>Events are sent from a server to Microsoft push service. </li>
</ul>
<p>Location Service:</p>
<ul>
<li><strong></strong><strong>Developer Note</strong>: No Emulator Support – <a href="http://msdn.microsoft.com/en-us/library/ff637517%28v=VS.92%29.aspx">MSDN RX emulator can be created</a>.  </li>
<li>Cell Tower, Satellite GPS, or WIFI can be used  </li>
<li><strong></strong><strong>Developer Note</strong>: Use cell tower to save battery but less accurate </li>
</ul>
<p>Types of Notifications on the Phone</p>
<ul>
<li>Tile Notifications –&nbsp; Tile on homepage which has an image, number, and simple text.  </li>
<li>Toast – pop-up will link back to app.  </li>
<li>If the app is running raw data can be accessed and displayed. </li>
</ul>
<p>Handling Life Time Events: Obscure VS Deactivated</p>
<p>Hidden By Shell UI: Obscured</p>
<ul>
<li>On Obscure you need to handle it gracefully then when un obscure you need to start. </li>
</ul>
<p>Moved to background: Deactivated</p>
<ul>
<li>Deactivate event fires  </li>
<li>Your app becomes suspended (you have a limited time to handle but not specified yet)  </li>
<li>State will be destroyed eventually if user doesn’t go back. Assume your app is killed.  </li>
<li>If user goes back to application Activate event will be fired  </li>
<li>You can load state via isolated storage and resume where you left off </li>
</ul>
<p>Interesting Questions asked during the presentation:</p>
<ul>
<li><strong>Question</strong>: Are ODBC drivers available or ported? <strong>Answer</strong>: Someone suggested using isolated storage for this instead.  </li>
<li><strong>Question</strong>: Does page Navigation come with default animation? <strong>Answer</strong>: It doesn’t come with a default animation. But you can add them in by intercepting the navigation event.  </li>
<li><strong>Question</strong>: How is back stack clean up done and can it be prioritized? <strong>Answer</strong>: Presenter guessed that it might be resource based but not sure yet.  </li>
<li><strong>Question</strong>: Can you control the Antenna for GPS? Can you turn it off or on and receive notifications when it is ready? <strong>Answer</strong>: Start and Stop service might be used for this but not sure. It looks like the API only tries to use it if available. Look at Location example in SDK. </li>
</ul>
<p>Links</p>
<ul>
<li><a title="http://www.silverlight.net/" href="http://www.silverlight.net/">http://www.silverlight.net/</a>  </li>
<li><a title="http://developer.windowsphone.com/" href="http://developer.windowsphone.com/">http://developer.windowsphone.com/</a>  </li>
<li><a title="http://slickthought.net/" href="http://slickthought.net/">http://slickthought.net/</a> Jeff Brand&#8217;s Site  </li>
<li><a href="http://blogs.msdn.com/b/microsoft_press/archive/2010/08/02/free-ebook-petzold-s-programming-windows-phone-7-special-excerpt-2.aspx">Programming Windows 7 Phone</a>&nbsp;</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2010/08/03/wp7-boot-camp-with-jeff-brand/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Top 5 Features of Code First Entity Framework CTP4</title>
		<link>http://jasonrowe.com/2010/07/18/top-5-features-of-code-first-entity-framework-ctp4/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=top-5-features-of-code-first-entity-framework-ctp4</link>
		<comments>http://jasonrowe.com/2010/07/18/top-5-features-of-code-first-entity-framework-ctp4/#comments</comments>
		<pubDate>Sun, 18 Jul 2010 16:19:26 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[EF]]></category>
		<category><![CDATA[ORM]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/2010/07/18/top-5-features-of-code-first-entity-framework-ctp4/</guid>
		<description><![CDATA[&#160; The latest release of Entity Framework CTP4 has some nice but unexpected changes. They introduced DbContext and DbSet to simplify model caching, database provisioning, schema creation and connection management. Here are my top 5 favorite features of the release. &#8230; <a href="http://jasonrowe.com/2010/07/18/top-5-features-of-code-first-entity-framework-ctp4/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<p>The latest release of Entity Framework CTP4 has some nice but unexpected changes. They introduced DbContext and DbSet to simplify model caching, database provisioning, schema creation and connection management. Here are my top 5 favorite features of the release.</p>
<ol>
<li><strong><em>Less code and fewer Concepts.</em></strong> The coolest part is the use of convention over configuration. See the <a href="http://blogs.msdn.com/b/adonet/archive/2010/07/14/ctp4piwalkthrough.aspx">Productivity Improvements</a> walk through and <a href="http://blogs.msdn.com/b/efdesign/archive/2010/06/01/conventions-for-code-first.aspx">Conventions for code first</a>. I like the extra touch that DbContext&#160; will create the database for you if you want. No code to write. Just use the default CreateDatabaseOnlyIfNotExists. </li>
<li><em><strong>Simplified Database Experience.</strong></em> With the introduction of DbContext and DbSet. EF now takes care of database provisioning, schema creation and connection management. Nice! My favorite part is the Interface IDbConnectionFactory to allow creation of your own conventions. </li>
<li><strong>Backwards Compatible.</strong> Yes, this is a feature when it comes to CTP’s and Betas. Some projects might just throw stuff away or completely change things on you. EF allows you to still use ObjectContext or <a href="http://blogs.msdn.com/b/efdesign/archive/2010/03/30/data-annotations-in-the-entity-framework-and-code-first.aspx">Data Annotations</a> for advanced scenarios where common conventions don’t work for you. </li>
<li><strong>Simplified Configuration Experience.</strong> As I mentioned you can use annotations for this but you also have another cool option. DbContext includes a virtual method that can be overridden to do configuration right in the class. This means no need for separate configuration classes now. I definitely like having it all in one place. Much cleaner and easy to read. </li>
<li><strong>Testability </strong>IDbSet&lt;TEntity&gt; allows you to define an interface that can be implemented by your derived context. This allows the context to be replaced with an in-memory test double for testing. </li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2010/07/18/top-5-features-of-code-first-entity-framework-ctp4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>EF CTP3 Code First and Castle Windsor</title>
		<link>http://jasonrowe.com/2010/07/12/ef-ctp3-code-first-and-castle-windsor/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=ef-ctp3-code-first-and-castle-windsor</link>
		<comments>http://jasonrowe.com/2010/07/12/ef-ctp3-code-first-and-castle-windsor/#comments</comments>
		<pubDate>Tue, 13 Jul 2010 04:31:28 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[Code First]]></category>
		<category><![CDATA[EF]]></category>
		<category><![CDATA[Windsor]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=1280</guid>
		<description><![CDATA[Awhile back I wrote a simple Holiday service to try out Entity Framework &#34;Code First&#34; (the new name for Code Only). I&#8217;ve upgraded the bits and tried out some of the new features of CTP3 using this walkthrough as a &#8230; <a href="http://jasonrowe.com/2010/07/12/ef-ctp3-code-first-and-castle-windsor/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Awhile back I wrote a simple Holiday service to try out Entity Framework &quot;Code First&quot; (the new name for Code Only). I&#8217;ve upgraded the bits and tried out some of the new features of CTP3 <a href="http://blogs.msdn.com/b/adonet/archive/2009/06/22/feature-ctp-walkthrough-code-only-for-the-entity-framework.aspx">using this walkthrough as a guide</a>. You can download my sample app from <a href="http://github.com/JasonRowe/EF-CTP3-HolidayService/zipball/master">git hub</a>.</p>
<p>In addition, I added Inversion of Control (IOC) using Castle Windsor and implemented a repository pattern. </p>
<p>My database generation script and test data now look like this.</p>
<pre class="brush: c#; ">

databasefactory.Create();
var repository = new HolidayRepository(databasefactory);

//... build up test data for xmas and newyear

repository.Add(xmas);
repository.Add(newYear);

//commit changes
var unitOfWork = new UnitOfWork(databasefactory);
unitOfWork.Commit();
</pre>
<p>The other interesting part of this sample project is using WCF and EF together and WCF dependency injection using Castle Windsor.</p>
<p>First I setup my interfaces and configuration files for EF and WCF.</p>
<pre class="brush: c#; ">

[DataContract]
public class Holiday : IEntity
{
    public long Id { get; set; }

    [DataMember]
    public string HolidayName { get; set; }

    [DataMember]
    public DateTime HolidayDate { get; set; }

    [DataMember]
    public ICollection&lt;holidayevent&gt; HolidayEvents {get; set;}
}
</pre>
<pre class="brush: c#; ">

[DataContract]
public class HolidayEvent : IEntity
{
    public long Id { get; set; }

    [DataMember]
    public string EventName { get; set; }

    [DataMember]
    public Holiday Holiday { get; set; }

    [DataMember]
    public long HolidayId { get; set; }
}
</pre>
<pre class="brush: c#; ">

public HolidayConfiguration()
{
    Property(h =&gt; h.Id).IsIdentity();
    Property(h =&gt; h.HolidayName).HasMaxLength(1000).IsRequired();

    Relationship(e =&gt; e.HolidayEvents).FromProperty(h =&gt; h.Holiday);
}
</pre>
<pre class="brush: c#; ">

public HolidayEventConfiguration()
{
    Property(e =&gt; e.Id).IsIdentity();
    Property(e =&gt; e.EventName).HasMaxLength(1000).IsRequired();

    //HolidayId is a FK property and Holiday is a navigation property backed by this FK
    Relationship(e =&gt; e.Holiday).FromProperty(h =&gt; h.HolidayEvents).HasConstraint((e, h) =&gt; e.HolidayId == h.Id);
}
</pre>
<p>In my .svc file I use a custom factory to do dependency injection</p>
<pre class="brush: c#; ">

Factory=&quot;Castle.Facilities.WcfIntegration.WindsorServiceHostFactory, Castle.Facilities.WcfIntegration&quot;
</pre>
<p>On startup, I add my HolidayService as a component and add the DatabaseFactory as a parameter. The DatabaseFactory is used to setup my EF Object Context.</p>
<pre class="brush: c#; ">

container.Register(Component.For&lt;iholidayservice&gt;().ImplementedBy&lt;holidayservices&gt;().DependsOn
    (Property.ForKey(&quot;databaseFactory&quot;).Eq(databaseFactory)));
</pre>
<p>A great resource for seeing many of the new features in EF CTP3 is the <a href="http://shrinkr.codeplex.com/">shrinker project</a>. This is where I found many great examples of property facets and relationships using Entity Framework.</p>
<p></holidayservices></iholidayservice></holidayevent></p>
]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2010/07/12/ef-ctp3-code-first-and-castle-windsor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Poor Mans Reverse Search with Lucene.net</title>
		<link>http://jasonrowe.com/2010/07/02/poor-mans-reverse-search-with-lucene-net/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=poor-mans-reverse-search-with-lucene-net</link>
		<comments>http://jasonrowe.com/2010/07/02/poor-mans-reverse-search-with-lucene-net/#comments</comments>
		<pubDate>Sat, 03 Jul 2010 04:54:21 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Lucene]]></category>
		<category><![CDATA[lucene]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=1268</guid>
		<description><![CDATA[As I mentioned in my last post I&#8217;ve been reading and learning about Lucene via Lucene in Action 2nd edition. Chapter 9.4, Fast memory-based indices, talks about MemoryIndex and InstantiatedIndex. MemoryIndex, contributed by Wolfgang Hoschek, is a fast RAM-only index &#8230; <a href="http://jasonrowe.com/2010/07/02/poor-mans-reverse-search-with-lucene-net/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>As I mentioned in my last <a href="http://jasonrowe.com/2010/06/23/lucene-in-action-net-samples/">post</a> I&#8217;ve been reading and learning about Lucene via Lucene in Action 2nd edition. Chapter 9.4, Fast memory-based indices, talks about MemoryIndex and InstantiatedIndex. </p>
<p>MemoryIndex, contributed by Wolfgang Hoschek, is a fast RAM-only index designed to test whether a single document matches a query. InstantiatedIndex, contributed by Karl Wettin, is similar, except it’s able to index and search multiple documents. Unfortunately, neither of these are yet ported to .Net. I thought about trying to port these but figured I would see if I could build a simple reverse search using the slower built in RamDirectory in Lucene and Lucene.net. </p>
<p>So what I want to create is a reverse search or on-the-fly matchmaking for documents. A simpler way to say that is I take a list of queries and check if they match a data object each time a data object is created. For simplicity sake I&#8217;m only working with the already ported Lucene code. </p>
<p>One cool features in Lucene version 2.9 was the addition of Near Real Time (NRT) searching. This seemed like a good fit for my scenario of trying to create a faster reverse search. It provides a way to search for documents that have not been committed yet. This helps take some of the overhead off when I need to add the one document to the index before running all the queries to test for matches. The explanation from the book says NRT enables you to rapidly search changes made to the index with an open IndexWriter, without having to first close or commit changes to that writer. </p>
<p>The NRT features allows me to do something like this: </p>
<p><em>It seems to be a big memory hog though so I made it disposable.</em></p>
<pre class="brush: c#; ">

 public class QueryProcessor : IDisposable
    {
        private readonly RAMDirectory _directory;
        private readonly IndexWriter _writer;

        public MetaQueryProcessor()
        {
            _directory = new RAMDirectory();
            _writer = new IndexWriter(_directory, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_CURRENT), IndexWriter.MaxFieldLength.UNLIMITED);
            _writer.SetMergeFactor(2);
        }

        public void Optimize()
        {
            _writer.Optimize();
        }

        public List&lt;string&gt; Search(List&lt;metaqueryrequest&gt; requests, Document doc)
        {
            _writer.AddDocument(doc);

            var results = new List&lt;string&gt;();

            foreach (var request in requests)
            {
                var reader = _writer.GetReader();//Near-real-time search not commited

                var indexSearcher = new IndexSearcher(reader);

                var primitiveQuery = request.LuceneQuery.Rewrite(reader);

                var hits = indexSearcher.Search(primitiveQuery, 1);

                if (hits.totalHits &gt; 0)
                {
                    results.Add(request.QueryName);
                }
            }

            _writer.DeleteAll();

            return results;
        }

        #region IDisposable Members

        public void Dispose()
        {
            _directory.Close();
        }

        #endregion
    }
</pre>
<p><a href="http://jasonrowe.com/wp-content/uploads/2010/07/reverse_search.png"><img src="http://jasonrowe.com/wp-content/uploads/2010/07/reverse_search.png" alt="" title="reverse_search" class="alignnone size-full wp-image-1274" /></a></p>
<p>If you know of a faster way to accomplish this please let me know. For more background information on this topic see these resources. </p>
<ul>
<li><a href="http://lucene.apache.org/java/2_2_0/api/org/apache/lucene/index/memory/MemoryIndex.html">MemoryIndex contrib project Lucene</a> </li>
<li><a href=" http://lucene.apache.org/java/2_4_0/api/contrib-instantiated/org/apache/lucene/store/instantiated/InstantiatedIndex.html">InstantiatedIndex contrib project Lucene</a> </li>
</ul>
<p></string></metaqueryrequest></string></p>
]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2010/07/02/poor-mans-reverse-search-with-lucene-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lucene in Action .Net Samples</title>
		<link>http://jasonrowe.com/2010/06/23/lucene-in-action-net-samples/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=lucene-in-action-net-samples</link>
		<comments>http://jasonrowe.com/2010/06/23/lucene-in-action-net-samples/#comments</comments>
		<pubDate>Thu, 24 Jun 2010 03:22:39 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Lucene.Net]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=1185</guid>
		<description><![CDATA[&#160; I started reading Lucene in Action by Otis Gospodnetic´ and Erik Hatcher.&#160; Lucene is a high performance, scalable Information Retrieval (IR) library. The library is in Java but I’m using the book to understand the Lucene .Net port. Why &#8230; <a href="http://jasonrowe.com/2010/06/23/lucene-in-action-net-samples/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<p>I started reading <a href="http://www.manning.com/hatcher3/">Lucene in Action</a> by Otis Gospodnetic´ and Erik Hatcher.&#160; Lucene is a high performance, scalable Information Retrieval (IR) library. The library is in Java but I’m using the book to understand the <a href="http://lucene.apache.org/lucene.net/">Lucene .Net</a> port.</p>
<p>Why buy a Java book to learn a .net Library? I couldn’t find a book specifically for the .Net version. Also, I wanted a 1000 foot level view of search technologies and because this is my first time working with IR. I was pleased to find the .net version is akin to the Java version presented in the book.</p>
<p>In some ways, learning from a different language has been beneficial. I invested more time converting the presented samples to C#.  I’ve also read <a href="http://www.amazon.com/Mathematics-Physics-Programmers-Game-Development/dp/1584503300">Mathematics and Physics for Programmers</a> which was completely written in a pseudo language. Again, lots of fun to convert the presented samples to a language I was more comfortable with.</p>
<p>It was also nice to find that the open source project <a href="http://code.google.com/p/subtext/source/browse/trunk/src/Subtext.Framework/Services/SearchEngine/SearchEngineService.cs">Subtext</a> is using Lucene .Net. They’ve worked out some locking issue recently and seem to be getting things setup in a nice way. Also, my co workers Kevin and Tim put together a nice library for Lucene .Net called <a href="http://code.google.com/p/activelucenenet/">ActiveLucene.Net &#8211; Attributed Lucene.Net</a>. The largest project seems to be <a href="http://linqtolucene.codeplex.com/">Linq to Lucene</a> but I haven&#8217;t looked at it yet. It was helpful to see how others are integrating Lucene into the Microsoft Web Platform.</p>
<p>
Anyway, here are the indexer and searcher in my C# interpretation. These are the first snippets presented in the book. These are a great way to get a jump start into understanding the basics.
</p>
<p><strong>Indexer</strong></p>
<pre class="brush: c#; ">

readonly static SimpleFSLockFactory _LockFactory = new SimpleFSLockFactory();

static void Main(string[] args)
{

    var dataPath = ConfigurationManager.AppSettings[&quot;DataDirectory&quot;];

    var indexPath = ConfigurationManager.AppSettings[&quot;IndexDirectory&quot;];

    if (!System.IO.Directory.Exists(dataPath))
    {
        throw new IOException(dataPath + &quot; directory does not exist&quot;);
    }

    DirectoryInfo indexInfo = new DirectoryInfo(indexPath);

    DirectoryInfo dataInfo = new DirectoryInfo(dataPath);

    Lucene.Net.Store.Directory indexDir = Lucene.Net.Store.FSDirectory.Open(indexInfo, _LockFactory);

    var start = DateTime.Now.TimeOfDay;
    var numIndexed = Index(indexDir, dataInfo);
    var end = DateTime.Now.TimeOfDay;

    var delta = end.TotalMilliseconds - start.TotalMilliseconds;

    Console.WriteLine(&quot;Indexing &quot; + numIndexed + &quot; files took &quot; + delta.ToString() + &quot; milliseconds&quot;);
}

public static int Index(Lucene.Net.Store.Directory indexDir, DirectoryInfo dataInfo)
{
    var writer = new IndexWriter(indexDir, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29), IndexWriter.MaxFieldLength.UNLIMITED);
    writer.SetMergePolicy(new LogDocMergePolicy(writer));
    writer.SetMergeFactor(5);

    try
    {
        var paths = dataInfo.EnumerateFiles(&quot;*.txt&quot;);

        foreach (var path in paths)
        {
            IndexFile(writer, path);
        }
    }
    catch (Exception ex)
    {
        writer.Close();
        throw ex;
    }

    var numIndexed = writer.MaxDoc();
    writer.Optimize();
    writer.Close();

    return numIndexed;
}

private static void IndexFile(IndexWriter writer, FileInfo file)
{
    if (!file.Exists)
    {
        return;
    }

    Console.WriteLine(&quot;Indexing &quot; + file.Name);

    Document doc = new Document();

    var path = file.FullName;

    System.IO.TextReader readFile = new StreamReader(path);

    doc.Add(new Field(&quot;contents&quot;, readFile));

    doc.Add(new Field(&quot;filename&quot;, file.Name,
        Field.Store.YES,
        Field.Index.ANALYZED,
        Field.TermVector.YES));

    writer.AddDocument(doc);
}
</pre>
<p><strong>Searcher</strong></p>
<pre class="brush: c#; ">

public static SimpleFSLockFactory _LockFactory = new SimpleFSLockFactory();

static void Main(string[] args)
{
    if (args.Length &lt; 2)
    {
        Console.WriteLine(&quot;Searcher takes two parameters&quot;);
        Console.WriteLine(&quot;Usage: ConsoleSearcher &lt;index dir&gt; &lt;query&gt;&quot;);
    }

    var indexInfo = new DirectoryInfo(args[0]);
    var query = args[1];

    if (!System.IO.Directory.Exists(args[0]))
    {
        throw new IOException(args[0] + &quot; directory does not exist&quot;);
    }

    SearchOption(indexInfo, query);
}

private static void SearchOption(DirectoryInfo indexInfo, string query)
{
    Lucene.Net.Store.Directory indexDir = Lucene.Net.Store.FSDirectory.Open(indexInfo, _LockFactory);

    IndexSearcher indexSearcher = new IndexSearcher(indexDir, true);

    QueryParser parser = BuildQueryParser();
    var luceneQuery = parser.Parse(query);

    var start = DateTime.Now.TimeOfDay;

    var hits = indexSearcher.Search(luceneQuery);
    var end = DateTime.Now.TimeOfDay;

    var delta = end.TotalMilliseconds - start.TotalMilliseconds;

    Console.WriteLine(&quot;Found &quot; + hits.Length() + &quot; document (s) (in &quot; + delta.ToString() + &quot; milliseconds) that matched query &#039;&quot; + query + &quot;&#039;:&quot;);

    for (int i = 0; i &lt; hits.Length(); i++)
    {
        Document doc = hits.Doc(i);

        Console.WriteLine(doc.Get(&quot;filename&quot;));
    }
}

private static QueryParser BuildQueryParser()
{
    var parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, &quot;contents&quot;, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29));
    parser.SetDefaultOperator(QueryParser.Operator.AND);
    return parser;
}
</pre>
<p></query></query></p>
]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2010/06/23/lucene-in-action-net-samples/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Odata Osht! and some examples</title>
		<link>http://jasonrowe.com/2010/06/19/odata-osht-and-some-examples/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=odata-osht-and-some-examples</link>
		<comments>http://jasonrowe.com/2010/06/19/odata-osht-and-some-examples/#comments</comments>
		<pubDate>Sat, 19 Jun 2010 08:14:31 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[data services]]></category>
		<category><![CDATA[odata]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/2010/06/19/odata-osht-and-some-examples/</guid>
		<description><![CDATA[  My head is spinning from looking at Odata tonight. I keep going back and forth on if this is the coolest thing in the world or just a way to browse data via the URI. Either way it&#8217;s fun. &#8230; <a href="http://jasonrowe.com/2010/06/19/odata-osht-and-some-examples/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>
 </p>
<p>My head is spinning from looking at <a href="http://www.odata.org/">Odata</a> tonight.  I keep going back and forth on if this is the coolest thing in the world or just a way to browse data via the URI. Either way it&#8217;s fun.  Below are my notes and examples showing some limitations and features of Odata.
</p>
<p> The first area I had some misunderstandings was when working with collections. Take a look at this question on StackOverflow &#8220;<a href="http://stackoverflow.com/questions/2679471/use-linq-to-query-nested-odata-collection">use linq to query nested odata collection</a>&#8220;.  This pretty much sums up the issue I was stuck on for awhile.  How do relationships work and how can I query collections. This <a href="http://www.chriswoodruff.com/index.php/2010/03/22/odata-does-not-support-select-many-queries/">blog post</a> helped me start to understand how keys and collections work.
</p>
<p>Then, I find this <a href="http://blogs.msdn.com/b/pablo/archive/2010/01/26/implementing-only-certain-aspects-of-odata.aspx">post</a> and <a href="http://odataprimer.com/">this collection of resources</a>. Now, I&#8217;m back to being sold on oData. The ease of filtering data is amazing. <a href="http://msdn.microsoft.com/en-us/library/cc668793.aspx">Filters also support functions</a> if needed. Thanks to this <a href="https://blogs.msdn.com/b/alexj/archive/2009/11/18/tip-44-how-to-navigate-an-odata-compliant-service.aspx">tip</a> for pointing that out.
</p>
</p>
<p>
 </p>
<p>Here is a set of <a href="http://developer.netflix.com/docs/OData_Catalog">examples</a> for the Odata Netflix feed.  I&#8217;ve listed the URI with the corresponding C# expression below.
</p>
<p>
 </p>
<p><a href="http://odata.netflix.com/Catalog/Titles?$filter=Name%20eq%20%27The%20Name%20of%20The%20Rose%27'">http://odata.netflix.com/Catalog/Titles?$filter=Name eq &#8216;The Name of The Rose&#8217;</a>
	</p>
<p>
 </p>
<pre class="brush: c#; ">

(from t in Titles
where t.Name == &quot;The Name of The Rose&quot;
select t)
</pre>
<p><a href="http://odata.netflix.com/Catalog/Titles?$filter=AverageRating%20lt%202%20and%20Instant/Available%20eq%20true">http://odata.netflix.com/Catalog/Titles?$filter=AverageRating lt 2 and Instant/Available eq true</a>
	</p>
<p>
 </p>
<pre class="brush: c#; ">

(from t in Titles
where t.AverageRating &lt; 2 &amp;&amp; t.Instant.Available == true
select t)
</pre>
</p>
<p>
 </p>
<p><a href="http://odata.netflix.com/Catalog/Titles?$filter=ReleaseYear%20le%201989%20and%20ReleaseYear%20ge%201980%20and%20AverageRating%20gt%204&amp;$expand=Awards">http://odata.netflix.com/Catalog/Titles?$filter=ReleaseYear le 1989 and ReleaseYear ge 1980 and AverageRating gt 4&amp;$expand=Awards</a>
	</p>
<p>
 </p>
<pre class="brush: c#; ">

(from t in Titles.Expand(&quot;Awards&quot;)
where t.ReleaseYear &lt; 1989 &amp;&amp; t.ReleaseYear &gt; 1980 &amp;&amp; t.AverageRating &gt; 4
select t)
</pre>
<p>
 </p>
<p><a href="http://odata.netflix.com/Catalog/Titles?$filter=Instant/Available%20eq%20true%20and%20%28Rating%20eq%20%27G%27%20or%20Rating%20eq%20%27PG-13%27%29">http://odata.netflix.com/Catalog/Titles?$filter=Type eq &#8216;Movie&#8217; and Instant/Available eq true and (Rating eq &#8216;G&#8217; or Rating eq &#8216;PG-13&#8242;)</a>
	</p>
<p>
 </p>
<pre class="brush: c#; ">

(from t in Titles
where t.Type == &quot;Movie&quot; &amp;&amp; t.Instant.Available == true &amp;&amp; (t.Rating == &quot;G&quot; || t.Rating == &quot;PG-13&quot;)
select t)
</pre>
<p>
 </p>
<p><a href="http://odata.netflix.com/Catalog/Titles?$filter=Instant/Available%20eq%20true%20and%20%28Rating%20ne%20%27R%27%20and%20Rating%20ne%20%27NC-17%27%20and%20Rating%20ne%20%27UR%27%20and%20Rating%20ne%20%27NR%27%29">http://odata.netflix.com/Catalog/Titles?$filter=Type eq &#8216;Movie&#8217; and Instant/Available eq true and (Rating ne &#8216;R&#8217; and Rating ne &#8216;NC-17&#8242; and Rating ne &#8216;UR&#8217; and Rating ne &#8216;NR&#8217;)</a>
	</p>
<p>
 </p>
<pre class="brush: c#; ">

(from t in Titles
where t.Type == &quot;Movie&quot; &amp;&amp; t.Instant.Available == true &amp;&amp; (t.Rating != &quot;R&quot; &amp;&amp; t.Rating != &quot;NC-17&quot; &amp;&amp; t.Rating != &quot;UR&quot; &amp;&amp; t.Rating != &quot;NR&quot;)
select t)
</pre>
<p>
 </p>
<p><a href="http://odata.netflix.com/Catalog/People?$filter=Name%20eq%20%27James%20Cameron%27&#038;$expand=Awards,TitlesDirected">http://odata.netflix.com/Catalog/People?$filter=Name eq &#8216;James Cameron&#8217;&#038;$expand=Awards,TitlesDirected</a>
	</p>
<p>
 </p>
<pre class="brush: c#; ">

(from p in People.Expand(&quot;Awards&quot;).Expand(&quot;TitlesDirected&quot;)
where p.Name == &quot;James Cameron&quot;
select p)
</pre>
<p>
 </p>
<p><a href="http://odata.netflix.com/Catalog/Languages%28%27Japanese%27%29/Titles?$filter=Type%20eq%20%27Movie%27">http://odata.netflix.com/Catalog/Languages(&#8216;Japanese&#8217;)/Titles?$filter=Type eq &#8216;Movie&#8217;&#8221;</a>
	</p>
<p>
 </p>
<pre class="brush: c#; ">

(from l in Languages
from t in l.Titles
where l.Name == &quot;Japanese&quot; &amp;&amp; t.Type == &quot;Movie&quot;
select t)
</pre>
<p>
 </p>
<p><a href="http://odata.netflix.com/Catalog/Languages%28%27French%27%29/Titles?$filter=Type%20eq%20%27Movie%27%20and%20Rating%20eq%20%27UR%27">http://odata.netflix.com/Catalog/Languages(&#8216;French&#8217;)/Titles?$filter=Type eq &#8216;Movie&#8217; and Rating eq &#8216;UR&#8217;</a>
	</p>
<p>
 </p>
<pre class="brush: c#; ">

(from l in Languages
from t in l.Titles
where l.Name == &quot;French&quot; &amp;&amp; t.Type == &quot;Movie&quot; &amp;&amp; t.Rating == &quot;UR&quot;
select t)
</pre>
<p>
 </p>
<p><a href="http://netflix.cloudapp.net/Catalog/Genres%28%27Horror%27%29/Titles/$count?$filter=Type%20eq%20%27Movie%27">http://odata.netflix.com/Catalog/Genres(&#8216;Horror&#8217;)/Titles/$count?$filter=Type eq &#8216;Movie&#8217;</a>
	</p>
<p>
 </p>
<pre class="brush: c#; ">

(from g in Genres
from t in g.Titles
where g.Name == &quot;Horror&quot; &amp;&amp; t.Type == &quot;Movie&quot;
select t).Count();
</pre>
<p><a href="http://odata.netflix.com/Catalog/Genres%28%27Horror%27%29/Titles?$filter=ReleaseYear%20le%201979%20and%20ReleaseYear%20ge%201970">http://odata.netflix.com/Catalog/Genres(&#8216;Horror&#8217;)/Titles?$filter=ReleaseYear le 1979 and ReleaseYear ge 1970</a>
	</p>
<p>
 </p>
<pre class="brush: c#; ">

(from g in Genres
from t in g.Titles
where g.Name == &quot;Horror&quot; &amp;&amp; t.ReleaseYear &lt; 1979 &amp;&amp; t.ReleaseYear &gt; 1970
select t)
</pre>
<p>
<a href="http://odata.netflix.com/Catalog/Titles('BVIuO')">http://odata.netflix.com/Catalog/Titles(&#8216;BVIuO&#8217;))</a>
	</p>
<p>
 </p>
<pre class="brush: c#; ">

(from t in Titles
where t.Id == &quot;BVIuO&quot;
select t)
</pre>
<p><a href="http://odata.netflix.com/Catalog/Genres%28%27Romantic%20Comedies%27%29/Titles?$filter=Type%20eq%20%27Movie%27%20and%20round%28AverageRating%29%20ge%205&#038;$orderby=year%28Instant/AvailableFrom%29">http://odata.netflix.com/Catalog/Genres(&#8216;Romantic Comedies&#8217;)/Titles?$filter=Type%20eq%20&#8242;Movie&#8217; and round(AverageRating) ge 5&amp;$orderby=year(Instant/AvailableFrom)</a>
	</p>
<p>
 </p>
<pre class="brush: c#; ">

(from g in Genres
from t in g.Titles
where g.Name == &quot;Romantic Comedies&quot; &amp;&amp; t.Type == &quot;Movie&quot; &amp;&amp; Math.Round(t.AverageRating.Value) &gt; 5
orderby t.Instant.AvailableFrom
select t)
</pre>
]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2010/06/19/odata-osht-and-some-examples/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Microsoft WebCamp Chicago – I won a purse!</title>
		<link>http://jasonrowe.com/2010/06/13/microsoft-webcamp-chicago-%e2%80%93-i-won-a-purse/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=microsoft-webcamp-chicago-%25e2%2580%2593-i-won-a-purse</link>
		<comments>http://jasonrowe.com/2010/06/13/microsoft-webcamp-chicago-%e2%80%93-i-won-a-purse/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 02:32:56 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[.Net]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=1048</guid>
		<description><![CDATA[  This weekend I drove to Chicago for Microsoft Web Camps not knowing what to expect. I definitely didn&#8217;t think I would win a purse and a cool t-shirt. So how did this happen?   Web Camps is a two &#8230; <a href="http://jasonrowe.com/2010/06/13/microsoft-webcamp-chicago-%e2%80%93-i-won-a-purse/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>
 </p>
<p><span style="font-family:Arial; font-size:12pt">This weekend I drove to Chicago for <a href="http://www.webcamps.ms/">Microsoft Web Camps</a> not knowing what to expect.  I definitely didn&#8217;t think I would win a purse and a cool t-shirt.  So how did this happen?<br />
</span></p>
<p>
<img alt="" src="http://jasonrowe.com/uploaded_images/061410_0232_MicrosoftWe1.jpg"  width="213" height="430" />
	</p>
<p>
 </p>
<p><span style="font-family:Arial; font-size:12pt">Web Camps is a two day event. The first day is all learning and was presented by James Senior and Jon Galloway who did an excellent job.<br />
</span></p>
<p><span style="font-family:Arial; font-size:12pt"><br />
<img alt="" src="http://jasonrowe.com/uploaded_images/061410_0232_MicrosoftWe2.jpg" class="alignnone" width="356" height="268" /><br />
		</span></p>
<p><span style="font-family:Arial; font-size:12pt">The second day was a build day.  You get into groups and build an application.  Then at the end of the day all the teams got to demo.  Thanks to my team members Mark Greenway and Tim McManemy, we got first place!<br />
</span></p>
<p><span style="font-family:Arial; font-size:12pt">Our application was called Fact or Crap. Basically you could submit a statement and others could vote if it is true or false. We used MVC2, <a href="http://github.com/jquery/jquery-tmpl">JQuery templating</a>, and Entity Framework.<br />
</span></p>
<p><span style="font-family:Arial; font-size:12pt"><br />
		</span></p>
<p>
<img alt="" src="http://jasonrowe.com/uploaded_images/061410_0232_MicrosoftWe3.png" class="alignnone" width="499" height="85" /><br />
 </p>
<p><span style="font-family:Arial; font-size:12pt">Hopefully Microsoft will do this again next year. This was probably the most fun I have had programming in awhile. Everyone learned a ton and made some new friends.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2010/06/13/microsoft-webcamp-chicago-%e2%80%93-i-won-a-purse/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Silverlight Binding</title>
		<link>http://jasonrowe.com/2010/05/14/silverlight-binding-3/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=silverlight-binding-3</link>
		<comments>http://jasonrowe.com/2010/05/14/silverlight-binding-3/#comments</comments>
		<pubDate>Sat, 15 May 2010 01:42:13 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[.Net]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=1040</guid>
		<description><![CDATA[  Binding is a fundamental part of Silverlight and allows developers to create a relationship between a UI property and a CLR object. Unfortunately, it can be a little confusing at first. Is it worth the trouble getting use to &#8230; <a href="http://jasonrowe.com/2010/05/14/silverlight-binding-3/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>
 </p>
<p><span style="font-size:12pt">Binding is a fundamental part of Silverlight and allows developers to create a relationship between a UI property and a CLR object.  Unfortunately, it can be a little confusing at first. Is it worth the trouble getting use to the syntax?<br />
</span></p>
<p>
 </p>
<p style="text-align: center"><span style="font-size:28pt">&lt;object property=&#8221;{Binding}&#8221; &#8230;/&gt;<br />
</span></p>
<p>
 </p>
<p><span style="font-size:12pt">It&#8217;s entirely possible to update the Silverlight presentation layer without using binding.  Although with the use of binding you can make your code more reusable and easier to extend.  Especially if you have multiple web requests that update the view.  I&#8217;m not saying binding is a silver bullet.  It can be very frustrating to track down issues and getting the syntax correct. But used in the right situations it can be very useful.<br />
</span></p>
<p>
 </p>
<p><span style="font-size:12pt">I&#8217;m not a Silverlight expert and I won&#8217;t be able to cover every detail of binding.  I&#8217;ll start by covering some basic syntax. Then give an example using notification properties and dependencies properties.  Then I will finish with a list of links and resources to find more information about MVVM and Silverlight 4.<br />
</span></p>
<p>
 </p>
<p>
 </p>
<p><span style="font-size:16pt; text-decoration:underline"><strong>Basic Binding Syntax<br />
</strong></span></p>
<p>
 </p>
<h2><span style="font-size:12pt">Let&#8217;s look at an example using an object named Cat and we will bind to the Speak property.<br />
</span></h2>
<pre class="brush: c#; ">

namespace BindingPatterns.ViewModel
{
    public class Cat
    {
        public string Speak { get; set; }
    }
}
</pre>
</p>
<p>
 </p>
<p>From now on I won&#8217;t include this much XAML detail but I wanted to be clear on the first example.  Notice the name space of where the Cat class is located is added.</p>
<pre class="brush: xml; ">

&lt;usercontrol x:Class=&quot;BindingPatterns.MainPage&quot;
    xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
    xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
    xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
    xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
    xmlns:data=&quot;clr-namespace:BindingPatterns.ViewModel&quot;
    mc:Ignorable=&quot;d&quot;
    d:DesignHeight=&quot;300&quot; d:DesignWidth=&quot;400&quot;&gt;

    &lt;/usercontrol&gt;&lt;usercontrol .Resources&gt;
        &lt;data :Cat x:Key=&quot;ViewModel&quot; Speak=&quot;meow&quot; /&gt;
    &lt;/usercontrol&gt;

    &lt;grid x:Name=&quot;LayoutRoot&quot;&gt;
        &lt;textblock x:Name=&quot;CatSound&quot; Text=&quot;{Binding Path=Speak, Source={StaticResource ViewModel}}&quot;&gt;&lt;/textblock&gt;
    &lt;/grid&gt;
</pre>
<p> </p>
<p><span style="font-size:12pt">I know this isn&#8217;t very useful but it&#8217;s only to demonstrate the binding.  What happens first in this example is the Cat class is instantiate as a static Resource. Then we set the Speak property to &#8220;meow&#8221;.  Finally we bind the TextBlock to the Speak property of that class.  We have to include the Source attribute to tell where the CLR binding is located.<br />
</span></p>
<p>
 </p>
<p><span style="font-size:12pt">Another way we could do this is using the data context.  Once &#8220;ViewModel&#8221; (which is the Cat class) is added to the DataContext we can reference directly in the TextBlock via the public property &#8220;Speak&#8221;.</span></p>
<pre class="brush: xml; ">

&lt;grid x:Name=&quot;LayoutRoot&quot; DataContext=&quot;{Binding Source={StaticResource ViewModel}}&quot;&gt;
    &lt;textblock x:Name=&quot;CatSound&quot; Text=&quot;{Binding Path=Speak}&quot;&gt;&lt;/textblock&gt;
&lt;/grid&gt;
</pre>
<p>
 </p>
<p><span style="font-size:12pt">To simplify more you can leave off the Path and just use the following.<br />
</span></p>
<pre class="brush: xml; ">

&lt;textblock x:Name=&quot;CatSound&quot; Text=&quot;{Binding Speak}&quot;&gt;&lt;/textblock&gt;
</pre>
<p>
 </p>
<p><span style="font-size:12pt">Notice the TextBlock no longer needs a Source extension because it looks in the DataContext by default.  A reason to use the DataContext is child controls can also access this. When you add a binding to that control first it will check the current UserControl and if it can&#8217;t be found it will check the parents DataContext.  For example, let&#8217;s move the TextBlock into a separate user control called CatControl.  Then we could get the same result as above using this.<br />
</span></p>
<pre class="brush: xml; ">

&lt;grid x:Name=&quot;LayoutRoot&quot; DataContext=&quot;{Binding Source={StaticResource ViewModel}}&quot;&gt;
        &lt;control :CatControl&gt;&lt;/control&gt;
&lt;/grid&gt;
</pre>
<p>
 </p>
<p><span style="font-size:12pt">Instead of using the Static Resource you can set the DataContext in C# as long as the control is initialized by doing the following.<br />
</span></p>
<pre class="brush: c#; ">

public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            DataContext = new Cat { Speak = &quot;meow in C#&quot; };
        }
    }
</pre>
<p> </p>
<p><span style="font-size:12pt">The binding syntax also supports drilling into properties of properties using dot notation.<br />
</span></p>
<pre class="brush: xml; ">

&lt;textblock x:Name=&quot;CatActivity&quot; Text=&quot;{Binding CatActivity.Scratch}&quot;&gt;&lt;/textblock&gt;
</pre>
<p><img src="http://jasonrowe.com/uploaded_images/051510_0248_Silverlight1.png" alt=""/><span style="font-size:12pt"><br />
		</span></p>
<pre class="brush: c#; ">

var activity = new CatActivity(){Scratch=&quot;scratchy&quot;};
DataContext = new Cat { Speak = &quot;meow in C#&quot;, CatActivity = activity };
</pre>
<p>
 </p>
<p><span style="font-size:16pt; text-decoration:underline"><strong>Binding with Notification and Dependency Properties<br />
</strong></span></p>
<p>
 </p>
<p><span style="font-size:12pt">An example where binding, notifications, and dependency properties show their power is when you need to make multiple Async web requests which have dependencies.<br />
</span></p>
<p><img src="http://jasonrowe.com/uploaded_images/051510_0248_Silverlight2.png" alt=""/><span style="font-size:12pt"><br />
		</span></p>
<p>
 </p>
<p><span style="font-size:12pt">To use notifications you need to inherit from <strong>INotifyPropertyChanged</strong>.  Then you can setup properties that will notify a binding when they change. For example, to update the quote we could have a notification property setup that would get updated by the request callback.<br />
</span></p>
<pre class="brush: c#; ">

        private Quote _quote;
        public Quote Quote
        {
            get { return _quote; }
            set
            {
                _quote = value;
                NotifyPropertyChanged(&quot;Quote&quot;);
            }
        }
        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }
</pre>
<pre class="brush: xml; ">

&lt;textblock x:Name=&quot;Price&quot; Text=&quot;{Binding Quote.Price}&quot;/&gt;
&lt;textblock x:Name=&quot;Price&quot; Text=&quot;{Binding Quote.PercentChange }&quot;/&gt;
</pre>
<p> </p>
<p><span style="font-size:12pt">For the Chart State we can setup a dependency property that will change the chart user control as needed. In this case we do some drawing and background changes.<br />
</span></p>
<pre class="brush: c#; ">

public static readonly DependencyProperty ChartStateProperty = DependencyProperty.Register(
            &quot;ChartState&quot;,
            typeof(StateIndicator),
            typeof(LineChartControl),
            new PropertyMetadata(StateIndicator.NoChange, OnChartStateChanged));

        private static void OnChartStateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var lineChart = (LineChartControl)d;
            lineChart.CreateStateBackground((StateIndicator)e.NewValue);
            lineChart.ChangeLineColor((StateIndicator)e.NewValue);
        }
</pre>
<p>
 </p>
<p><span style="font-size:12pt">For a simpler example of notification binding we can go back to the cat example. Let&#8217;s setup the notification.<br />
</span></p>
<pre class="brush: c#; ">

  public class Cat : INotifyPropertyChanged
    {
        public string Speak { get; set; }

        private CatActivity _catActivity;
        public CatActivity CatActivity
        {
            get { return _catActivity; }
            set
            {
                _catActivity = value;
                NotifyPropertyChanged(&quot;CatActivity&quot;);
            }
        }

        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }

         public event PropertyChangedEventHandler PropertyChanged;

     }
</pre>
<p>
 </p>
<p><span style="font-size:12pt">Then let&#8217;s make a button and a few fields to bind to the CatActivity property.  Don&#8217;t take this as good coding practice. This is just a simplistic example to show how the notifications can be triggered.<br />
</span></p>
<pre class="brush: c#; ">

        public Cat MyCat { get; set; }
        public MainPage()
        {
            InitializeComponent();

            var activity = new CatActivity(){Scratch=&quot;scratchy&quot;, Run=&quot;scramble&quot;};
            MyCat = new Cat { Speak = &quot;meow in C#&quot;, CatActivity = activity };
            DataContext = MyCat;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var newActivity = new CatActivity() { Scratch = &quot;scratchy again&quot;, Run = &quot;scramble again too&quot; };
            MyCat.CatActivity = newActivity;
        }
</pre>
<p>
 </p>
<p>When you click the button the following bindings will show &#8220;scratch again&#8221; and &#8220;scramble again too&#8221;.</p>
<pre class="brush: xml; ">

&lt;stackpanel&gt;
    &lt;button Click=&quot;Button_Click&quot;&gt;&lt;/button&gt;
    &lt;textblock x:Name=&quot;CatSound&quot; Text=&quot;{Binding Speak}&quot;&gt;&lt;/textblock&gt;

    &lt;textblock x:Name=&quot;CatActivityScratch&quot; Text=&quot;{Binding CatActivity.Scratch}&quot;&gt;&lt;/textblock&gt;

    &lt;textblock x:Name=&quot;CatActivityRun&quot; Text=&quot;{Binding CatActivity.Run}&quot;&gt;&lt;/textblock&gt;
&lt;/stackpanel&gt;
</pre>
<p>
 </p>
<p>
 </p>
<p><span style="font-size:16pt; text-decoration:underline"><strong>SL4 and MVVM Links<br />
</strong></span></p>
<p>
 </p>
<ul>
<li>An early approach to MVVM on MSDN (<a href="http://msdn.microsoft.com/en-us/magazine/dd458800.aspx">http://msdn.microsoft.com/en-us/magazine/dd458800.aspx</a>)
</li>
<li>Prism MVVM SL and WPF <a href="http://compositewpf.codeplex.com/">http://compositewpf.codeplex.com/</a>
		</li>
<li>SL4 Command Binding MVVM <a href="http://www.silverlight.net/community/samples/silverlight-samples/command-binding-in-silverlight-4-35238/">http://www.silverlight.net/community/samples/silverlight-samples/command-binding-in-silverlight-4-35238/</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2010/05/14/silverlight-binding-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silverlight  Drag and Drop with RX</title>
		<link>http://jasonrowe.com/2010/04/02/silverlight-drag-and-drop-with-rx/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=silverlight-drag-and-drop-with-rx</link>
		<comments>http://jasonrowe.com/2010/04/02/silverlight-drag-and-drop-with-rx/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 06:08:49 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[rx]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=1131</guid>
		<description><![CDATA[I highly recommend watching this video for the recently released RX extensions. It shows a walk through of implementing drag and drop in WPF. I took the same code and converted it to Silverlight for a fun exercise. The major &#8230; <a href="http://jasonrowe.com/2010/04/02/silverlight-drag-and-drop-with-rx/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I highly recommend watching this <a href="http://channel9.msdn.com/posts/J.Van.Gogh/Writing-your-first-Rx-Application/">video </a> for the recently released RX extensions. It shows a walk through of implementing drag and drop in WPF. I took the same code and converted it to Silverlight for a fun exercise.</p>
<p>The major differences are the Mouse event names are different and you need to use a dispatcher to avoid cross thread issues. Check the Rx forums for more recent and efficient ways to do this for use in production code.</p>
<p>You will also need to add the System.CoreEx, System.Observable, and System.Reactive .Net references.</p>
<p>[raw]</p>
<pre class="brush: c#; ">

// Observe MouseMove Events &lt;!--

var mouseMove = from evt in Observable.FromEvent&lt;mouseeventargs&gt;(this, &quot;MouseMove&quot;)
select evt.EventArgs.GetPosition(this);

// Observe Mouse LeftButtonUp Event --&gt; // &lt;!--

var mouseUp = from evt in Observable.FromEvent&lt;mousebuttoneventargs&gt;(this, &quot;MouseLeftButtonUp&quot;)
select evt.EventArgs.GetPosition(this);

// Observe MouseLeftButtonDown Event --&gt; &lt;!--

var mouseDown = from evt in Observable.FromEvent&lt;mousebuttoneventargs&gt;(this, &quot;MouseLeftButtonDown&quot;)
select evt.EventArgs.GetPosition(this);

// Calculate Movement and Display --&gt;

var q = from start in mouseDown
        from delta in mouseMove.StartWith(start).TakeUntil(mouseUp)
            .Let(mm =&gt; mm.Zip(mm.Skip(1), (prev, cur) =&gt;
                new { X = cur.X - prev.X, Y = cur.Y - prev.Y }))
        select delta;

q.Subscribe(value =&gt; textblock.Dispatcher.BeginInvoke(() =&gt;
{
  Canvas.SetLeft(image,Canvas.GetLeft(image) + value.X);
  Canvas.SetTop(image,Canvas.GetTop(image) + value.Y);
}));
</pre>
<p>[/raw]</p>
<p>For a better explanation of this code check out <a href="http://streaming.ndc2010.no/tcs/?id=2C3F6822-1694-48A6-9C49-8B3E3D4C6CE5">John Skeets RX video at NDC 2010</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2010/04/02/silverlight-drag-and-drop-with-rx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sending Email and Bounce Handling Rules</title>
		<link>http://jasonrowe.com/2010/03/26/sending-email-and-bounce-handling-rules/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=sending-email-and-bounce-handling-rules</link>
		<comments>http://jasonrowe.com/2010/03/26/sending-email-and-bounce-handling-rules/#comments</comments>
		<pubDate>Sat, 27 Mar 2010 04:11:08 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Commentary]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=1067</guid>
		<description><![CDATA[While listening to Stack Overflow Podcast 83 I was happy to hear I was not the only one that found sending email complicated. The act of sending mail is also incredibly complicated because spammers have abused the infrastructure for a &#8230; <a href="http://jasonrowe.com/2010/03/26/sending-email-and-bounce-handling-rules/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>While listening to <a href="http://blog.stackoverflow.com/2010/02/podcast-83/">Stack Overflow Podcast 83</a> I was happy to hear I was not the only one that found sending email complicated. </p>
<blockquote><p>The act of sending mail is also incredibly complicated because spammers have abused the infrastructure for a decade. There are a few immune responses that are still effective, such as <a href="http://en.wikipedia.org/wiki/DomainKeys_Identified_Mail">DKIM </a>and Reverse <a href="http://www.menandmice.com/knowledgehub/dnsqa/56/">PTR </a>records. <a href="SenderID">SenderID  </a>is another method, also based on DNS records, but it’s less well regarded. If you’re going to send email and you want it to arrive, you need to implement all this stuff!.</p>
</blockquote>
<p>I agree with this completely and would like to add some additional information about bounce handling. So after you get your <a href="http://en.wikipedia.org/wiki/Feedback_Loop_%28email%29">Feedback loop setup</a> with all the major ISPs, don&#8217;t blow it and ruin your reputation! Get some good bounce handling rules put in place.</p>
<div class="wp-caption alignright" style="width: 160px"><img alt="The at sign, required character of the e-mail address." src="http://upload.wikimedia.org/wikipedia/commons/thumb/9/98/%40%40%40.svg/150px-%40%40%40.svg.png" title="The at sign, required character of the e-mail address." width="150" height="150" />
<p class="wp-caption-text">The at sign, required character of the e-mail address.</p>
</div>
<p><strong>Bounce Handling Rules</strong><br /> <br />
Your server will be put on a IP blacklist if you don&#8217;t handle bounces correctly. After you send a bunch of email the job is not done. The methodology I use for bounce handling was adopted from <a href="http://www.isipp.com">ISIPP&#8217;s</a> white paper <a href="http://www.isipp.com/documents/bouncehandling-paper.pdf">Bounce Handling Process, Email Delivery Rejection, and Receiving System Policies</a>. I&#8217;ve been very happy with the results. Below is a brief summary, without getting into too much detail.</p>
<p><strong>Hard bounce Handling Policy:</strong></p>
<ul>
<li>Description: If a hard bounce, spam complaint, unsubscribe feedback, or user initiated block is received I consider the email address dead and remove it immediately from all mailing lists.
</li>
<li>
Frequency: I check for these types to be immediately removed every 15 minutes.
</li>
<li>
Example: A hard bounce is permanent, &#8220;user unknown&#8221; being one good example.
</li>
</ul>
<p><strong>Soft Bounce Handling Policy:</strong></p>
<ul>
<li>Description: Email address will be considered dead if the following criteria are met.
</li>
<li>
At least three delivery rejections have occurred in the last 30 days,
</li>
<li>
and user has had no successful deliveries in the last 15 days.
</li>
<li>
In addition, the time between the most recent delivery rejection and the initial delivery rejection is greater than 15 days.
</li>
<li>
Frequency: It&#8217;s acceptable to handle these types of bounces once per day
</li>
<li>
Example: Most commonly, a soft bounce is a temporary condition, such as &#8220;mailbox full.
</li>
</ul>
<p>Other areas you need to understand before sending emails include <a href="http://en.wikipedia.org/wiki/CAN-SPAM#Unsubscribe_compliance">unsubscribe compliance</a>, <a href="http://mailformat.dan.info/body/linelength.html">Mime Type Specifications</a>, and <a href="http://en.wikipedia.org/wiki/E-mail">email headers</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2010/03/26/sending-email-and-bounce-handling-rules/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
