<?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>My Other Pants &#187; wpf</title>
	<atom:link href="http://myotherpants.com/tag/wpf/feed/" rel="self" type="application/rss+xml" />
	<link>http://myotherpants.com</link>
	<description>I left it in my other pants</description>
	<lastBuildDate>Sun, 28 Feb 2010 21:27:58 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Crouching Donny, Iron Cucumber &#8211; An Experiment in Functional Testing</title>
		<link>http://myotherpants.com/2009/09/crouching-donny-iron-cucumber/</link>
		<comments>http://myotherpants.com/2009/09/crouching-donny-iron-cucumber/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 02:00:37 +0000</pubDate>
		<dc:creator>Ball</dc:creator>
				<category><![CDATA[work safe]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[ironruby]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[wpf]]></category>

		<guid isPermaLink="false">http://myotherpants.com/?p=122</guid>
		<description><![CDATA[I accidentally agreed to give a talk later this month.  The subject is IronRuby and it&#8217;s application in the .NET ecosystem.  Seems simple enough.  So, to jazz things up, I want to have a host of demo applications.  This is about one.
A while back, I posted an article with an example [...]]]></description>
			<content:encoded><![CDATA[<p>I accidentally agreed to give a talk later this month.  The subject is IronRuby and it&#8217;s application in the .NET ecosystem.  Seems simple enough.  So, to jazz things up, I want to have a host of demo applications.  This is about one.</p>
<p>A while back, I posted <a href="http://myotherpants.com/2009/06/automatic-for-the-people/">an article with an example of using IronRuby and the White framework</a>.  In it, I appear to have made a promise.  </p>
<blockquote><p>I’ll get to Cucumber. I’ll publish examples. I promise.</p></blockquote>
<p><span id="more-122"></span></p>
<p>I&#8217;m going to talk a lot about Donny.  You&#8217;ll meet Donny, but just be aware, he&#8217;s compiled in Debug, so he&#8217;s a bit shy.  Donny is an app written to give me something to test.  He does nothing of real import, he doesn&#8217;t even save his data to disk.  As for why &#8220;Donny&#8221;, I still don&#8217;t know.  I was in a mood yesterday when outlining my presentation and &#8220;Donny&#8221; stuck.</p>
<p><strong><a href="http://cukes.info/">Cucumber</a></strong> &#8211; n, A functional testing framework for ruby.  Cucumber uses Features and Step Definitions to drive an application via it&#8217;s full stack.</p>
<p>Cucumber does work with IronRuby, but by default it&#8217;s runner has some idiosyncrasies for which you&#8217;ll need to compensate.  The cucumber.bat file lives, for me, in <code>c:\IronRuby\lib\IronRuby\gems\1.8\bin</code>.  Another oddity is that it belives I have a color console.  This is <em>mostly</em> true, but Win32Console doesn&#8217;t work for IronRuby, so you&#8217;ll need to use the <code>--no-color</code> option.  For now.  I have my features in a directory I&#8217;m calling &#8220;features&#8221; with an embedded step definitions directory.  Once I finish the presentation, I&#8217;ll have the whole damn thing published and you can look at it then.  Until then, here&#8217;s the command line I used; <code>cucumber --no-colors features</code>.</p>
<p><strong>Feature</strong> &#8211; n, A tightly formatted Business Natural Language used to describe the preconditions, actions, and expected results in a business scenario.  See also, <a href="http://dannorth.net/whats-in-a-story">Story</a>.</p>
<p>I have two basic scenarios; Donny starts with no data, and Donny moves data from the task form to the task list.</p>
<pre>
Feature: New Task
  In order to correctly bill my client
  as an SEP employee
  I want to add a task to the list

  Scenario: Starting the app
    Then all fields are blank
    And the list contains 0 entries

  Scenario:  Add a new Task
    Given I describe my task as Doing work on the Donny app
    And I'm working on project Academy
    And the day is Monday
    And I worked from 10 to 10:30
    When I press the button
    Then all fields are blank
    And the list contains 1 entry
    And the last entry is Monday 10-10:30 Academy Doing work on the Donny app
</pre>
<p><strong>Step Definition</strong> &#8211; n, a ruby script used to match lines in the Feature BNL to actual executable code.  They can be reused across features.</p>
<p>For each Given, When, or Then I have to have a matching step.  These are essentially ruby functions that use a helper to encapsulate my usage of the White library.  Here is <em>donny_steps.rb</em></p>
<pre name="code" class="ruby">
require 'spec/expectations'
require File.dirname(__FILE__) + "/../../donny_helper.rb"

Before do
  @app = Application.launch "Donny/bin/Debug/donny.exe"
  @win = @app.get_window "Window1"
  @tf = TaskForm.new(@app, @win)
  @tl = TaskList.new(@app, @win)
end

After do
  @win.close
end
Given /I describe my task as (.*)/ do |description|
  @tf.description = description
end

Given "I'm working on project $proj" do |proj|
  @tf.project = proj
end

Given "the day is $day" do |day|
  @tf.day = day
end

Given /I worked from (.*) to (.*)/ do |start_time, end_time|
  @tf.start_time = start_time
  @tf.end_time = end_time
end

When "I press the button" do
  @tf.commit
end

Then "all fields are blank" do
  @tf.description.should be_empty
  @tf.project.should be_empty
  @tf.day.should be_empty
  @tf.start_time.should be_empty
  @tf.end_time.should be_empty
end

Then /the list contains (.*) entr(?:y|ies)/ do |n|
  @tl.task_count.should == n.to_i
end

Then /the last entry is (.*)/ do |result|
  @tl.tasks.last.text.should == result
end
</pre>
<p>Um, you&#8217;re missing a piece.  The part that uses White.  Remember the screens?  This time, I didn&#8217;t call them screens, and I don&#8217;t have a full window proxy, but I still have two helper objects.  Now, with some metaprogramming, I could cut down the code size by defining an attribute and describing the type and automation ID of it&#8217;s associated control, but I&#8217;m lazy.  Maybe for the presentation, but I&#8217;m not making any promises. </p>
<pre name="code" class="ruby">
white_loc = (File.dirname(__FILE__) + "/White_Bin_0.18/")
puts white_loc
$LOAD_PATH << white_loc
require "White.Core.dll"

Application = Core::Application
ComboBox = Core::UIItems::ListBoxItems::ComboBox
ListBox = Core::UIItems::ListBoxItems::ListBox
Window = Core::UIItems::WindowItems::Window
include Core::UIItems

class Window
  def get_button(*args)
    self.method(:get).of(Button).call(*args)
  end
  def get_textbox(*args)
    self.method(:get).of(TextBox).call(*args)
  end
  def get_combobox(*args)
    self.method(:get).of(ComboBox).call(*args)
  end
  def get_listbox(*args)
    self.method(:get).of(ListBox).call(*args)
  end
end
class TaskList
  def initialize(app, win)
    @app = app
    @win = win
  end
  def tasks
    @win.get_listbox('tasklist').items.to_a
  end
  def task_count
    tasks.size
  end
end
class TaskForm
  def initialize(app, win)
    @app = app
    @win = win
  end
  def description
    get_tb 'task'
  end
  def description=(text)
    set_tb 'task', text
  end
  def project
    @win.get_combobox('project').selected_item_text
  end
  def project=(proj)
    @win.get_combobox('project').select proj
  end
  def day
    get_tb 'dayofweek'
  end
  def day=(day)
    set_tb 'dayofweek', day
  end
  def end_time
    get_tb 'endtime'
  end
  def end_time=(et)
    set_tb 'endtime', et
  end
  def start_time
    get_tb 'starttime'
  end
  def start_time=(st)
    set_tb('starttime', st)
  end
  def commit
    @win.get_button('commit').click
  end

  private
  def set_tb(auto_id, value)
    @win.get_textbox(auto_id).set_value value
  end
  def get_tb(auto_id)
    @win.get_textbox(auto_id).text
  end
end
</pre>
<p>And some for some context, Meet Donny!<br />
<a href="http://myotherpants.com/wp-content/uploads/2009/09/Donny.PNG"><img src="http://myotherpants.com/wp-content/uploads/2009/09/Donny.PNG" alt="Donny" title="Donny" width="258" height="176" class="aligncenter size-full wp-image-123" /></a></p>
<p>And, after I enter a task, Donny looks like this.<br />
<a href="http://myotherpants.com/wp-content/uploads/2009/09/Donny1.PNG"><img src="http://myotherpants.com/wp-content/uploads/2009/09/Donny1.PNG" alt="Donny" title="Donny" width="258" height="189" class="aligncenter size-full wp-image-125" /></a></p>
<p>That's really all there is to using Cucumber with IronRuby.  Have fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://myotherpants.com/2009/09/crouching-donny-iron-cucumber/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A letter to the editor &#8211; Do you even READ the internets? More IronRuby and WPF</title>
		<link>http://myotherpants.com/2009/08/a-letter-to-the-editor/</link>
		<comments>http://myotherpants.com/2009/08/a-letter-to-the-editor/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 20:11:57 +0000</pubDate>
		<dc:creator>Ball</dc:creator>
				<category><![CDATA[work safe]]></category>
		<category><![CDATA[gist]]></category>
		<category><![CDATA[ironruby]]></category>
		<category><![CDATA[wpf]]></category>

		<guid isPermaLink="false">http://myotherpants.com/?p=104</guid>
		<description><![CDATA[I&#8217;m writing this in response to a recent post I wrote on my website, A Ruby Cast In Steel.  While I appreciated the insight my experiments gave me into both IronRuby and WPF, the author ended up with a few conclusions I&#8217;d like me to revisit.

Data Binding
You implied that Data Binding IronRuby is broken. [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m writing this in response to a recent post I wrote on my website, <a href="http://myotherpants.com/2009/08/a-ruby-set-in-steel-wpf-and-ironruby/">A Ruby Cast In Steel</a>.  While I appreciated the insight my experiments gave me into both IronRuby and WPF, the author ended up with a few conclusions I&#8217;d like me to revisit.<br />
<span id="more-104"></span></p>
<h3>Data Binding</h3>
<p>You implied that Data Binding IronRuby is broken.  This is untrue as noted by both members of the <a href="http://www.devhawk.net/2008/11/18/IronPython+And+WPF+Part+3+Data+Binding.aspx">IronPython </a>team and the <a href="http://sdlsdk.codeplex.com/WorkItem/View.aspx?WorkItemId=11844">IronRuby </a>team.  As you can see here, <a href="http://msdn.microsoft.com/en-us/library/ms750612.aspx">WPF Data Binding relies on the ICustomDataDefinition</a>, which IronRuby objects implement.  Building on the xaml tools I developed last time, here is an example of Data Binding at work.</p>
<p><script src="http://gist.github.com/172826.js"></script><br />
<script src="http://gist.github.com/172828.js"></script></p>
<p>I would have updated the xaml tools to use <code>load_assembly</code> instead of strong names, but strong names are the only thing that work on my Win7 box.  This is nicely outlined in the IronRuby tutorials that come with the distribution.  I might try them.  I could learn a lot.</p>
<h3>Combining Classes and Xaml</h3>
<p>I found an article about combining an <a href="http://www.designfeed.me/8050">IronRuby class with xaml</a>.  However, this example was suitable for Silverlight 1.0 (look at the control box) and doesn&#8217;t work for me.  I&#8217;ve examined the new Application api that&#8217;s suitable for 3.5, but I&#8217;m not able to generate a suitable Uri for the file.  The Uri needs to be relative, not absolute, and the <code>pack:</code> Uris didn&#8217;t seem to work, probably due to a fundamental misunderstanding on my part.</p>
<p>Looking at the other side, I&#8217;ve not yet found a way to force an IronRuby class out of the engine into the CLR <i>proper</i>, the x:Class should work just find with an existing CLR class.  </p>
<p>More importantly, code-behind is a compromise.  Not even a good one at that.  The development style I used was perfectly acceptable for utility style applications, but larger applications should have a complete divorce between the view and the rest of the code, connected only by binding.  By introducing code-behind into the equation, I&#8217;m letting the rest of my application infect my view, coupling it tightly.</p>
<p>To be fair, my last post was written using IronRuby 0.9, and <a href="http://stackoverflow.com/questions/1319487/how-do-i-implement-an-interface-in-ironruby-that-includes-clr-events">due to the ICommand interface implementing an event, you&#8217;ll need a more recent build</a>.</p>
<p><script src="http://gist.github.com/173878.js"></script></p>
<p>In summary, The concerns for writing WPF apps in IronRuby at the end of my last post have been addressed or made redundant, with out pulling my favorite fear-mongering golden hammer and resorting to Code-Dom.</p>
<p>Thank me for my time,<br />
me</p>
<hr />
<p>On a more serious note, I&#8217;ve learned a lot this past week, with a little bit of the googles and the tutorials.  I think I can start writing a &#8220;REAL&#8221; application in IronRuby, at least as a prototype.  The remaining question is which itch am I going to scratch? </p>
]]></content:encoded>
			<wfw:commentRss>http://myotherpants.com/2009/08/a-letter-to-the-editor/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A Ruby Set in Steel &#8211; WPF and IronRuby</title>
		<link>http://myotherpants.com/2009/08/a-ruby-set-in-steel-wpf-and-ironruby/</link>
		<comments>http://myotherpants.com/2009/08/a-ruby-set-in-steel-wpf-and-ironruby/#comments</comments>
		<pubDate>Sun, 16 Aug 2009 20:27:58 +0000</pubDate>
		<dc:creator>Ball</dc:creator>
				<category><![CDATA[work safe]]></category>
		<category><![CDATA[gist]]></category>
		<category><![CDATA[ironruby]]></category>
		<category><![CDATA[wpf]]></category>

		<guid isPermaLink="false">http://myotherpants.com/?p=96</guid>
		<description><![CDATA[One of the first examples of using IronRuby on the web, possibly the first since it was the announcement of the project, was Scott Guthrie announcing the project and using WPF way back in 2007.
We&#8217;ve come a long way since then.  But that&#8217;s all been internal to IronRuby.  In addition, I&#8217;ve not seen [...]]]></description>
			<content:encoded><![CDATA[<p>One of the first examples of using IronRuby on the web, possibly the first since it was the announcement of the project, was <a href="http://weblogs.asp.net/scottgu/archive/2007/07/23/first-look-at-ironruby.aspx">Scott Guthrie announcing the project and using WPF</a> way back in 2007.</p>
<p>We&#8217;ve come a long way since then.  But that&#8217;s all been internal to IronRuby.  In addition, I&#8217;ve not seen the community truly embrace IronRuby as it has had some growing pains.  I don&#8217;t mean to dis those working on the project, just look at my non-existent commit log to see how much of a leg I have to stand on if I where to dis them.  I mean to say that I&#8217;ve not seen many people talking about using it in production.  And until we see production IronRuby, we won&#8217;t be able to tell the wider .NET world how awesome working in ruby really is.<br />
<span id="more-96"></span></p>
<p>Enough groundwork, what&#8217;s on today&#8217;s menu?  I started writing a quick search box for my chat logs at work.  I picked up IronRuby, since I loves it so, and threw down some WPF.  Then I stood in shock and horror that the commensurate C# code would be much nicer.  Here is IronRuby draft one.</p>
<p><script src="http://gist.github.com/168387.js"></script></p>
<p>Notice the &#8220;Left-Side/Right-Side&#8221; code.  In C#, we fixed this with object initializers.  That&#8217;s what I want in my code, so I added a method to FrameworkElement to use a hash for initialization.  Then I went after how I&#8217;m adding stuff to my StackPanels.  In Ruby, the idiom to add children is the &lt;&lt; operator, so I&#8217;ll add that to Panel, the super class for all layout elements.  Finally, the explicit aliasing in just crazy talk.  Using a namespace is similar to including a ruby Module, so I&#8217;ll just include the namespaces I need.  And the code got better.  I was, in fact, proud of it for a few hours.</p>
<p><script src="http://gist.github.com/167804.js"></script></p>
<p>Then I started wondering, WPF uses Xaml to be declarative.  Can&#8217;t I find a way to declare my UI, then add stuff to it?  I can write Xaml, can&#8217;t I?  Well, I can also use Ruby&#8217;s XmlBuilder to make xaml look like I&#8217;m declaring my UI in ruby.  I&#8217;ll want to wrap some boilerplate to build the xml with xaml specific things, then turn it into a real CLR window.  Then how do I hook up buttons and actions?  I can call find_name on a window to find a child with the x:Name attribute.  More correctly, I can wrap it with Ruby&#8217;s [] operator.</p>
<p><script src="http://gist.github.com/168408.js"></script></p>
<p>At first blush, it seems like the code is getting bigger, but the Xaml class can be gemmed up and reused.  That leaves our application fairly small, which is nice considering it&#8217;s a small window.  The thing that&#8217;s left that&#8217;s getting on my nerves is the fact I&#8217;m not declaring my click action in the Xaml.  Which leads me to the next questions, how do I get Commands and Binding tied in to this?  At that point, I&#8217;m almost doing this &#8220;right&#8221;.</p>
<p>Well, I ran some experiments, and here&#8217;s what doesn&#8217;t work.</p>
<ul>
<li>Data binding doesn&#8217;t work.  I tried to set a ruby object to a windows DataContext, and the labels didn&#8217;t bind.</li>
<li>x:Class doesn&#8217;t play well with <code>XamlReader.Load(xmlReader)</code>.  More exactly, I can&#8217;t create a class in ruby and expect XamlReader to pick up on it.</li>
<li>Adding <code>Click="DoClick"</code> to a button tag causes the XamlReader to blow chunks</li>
<li>Trying to add <code>xmlns:l="clr-namespace:Frontal"</code> and rooting the window on <code>l:Lobe</code>, a ruby class in the Frontal module, doesn&#8217;t work.  XamlReader can&#8217;t find the namespace.</li>
</ul>
<p>No example code, because that would confuse the issue.</p>
<p>I want to get this posted, so I don&#8217;t have a solution yet.  But I&#8217;ve got some ideas percolating.  Unfortunately, most of them involve C# run time code generation (code dom), or writing my own WPF builder and bypass the XamlReader all together.  I really should take a break from getting WPF &#8220;perfect&#8221; and start working on using Lucene.NET to do the actual work for my brain in a box.</p>
]]></content:encoded>
			<wfw:commentRss>http://myotherpants.com/2009/08/a-ruby-set-in-steel-wpf-and-ironruby/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
