Monthly Archives: September 2011

HOW TO: Use Await In Windows 8 Style Metro Coding

With the release of the new Visual Studio 11, and Microsoft 8, comes a new display and coding style targeting Metro. Metro is a display system that was modeled after a Swiss system of subway trains that allowed users to interact and purchase their tickets quickly and efficiently. A new very exciting keyword is being presented with the demos that are up called Await. What this keyword allows us to do is execute an asynchronous function or subroutine and move on with our code. This option is available very easily and does not require any timers or threading to handle any complex processes.
Here is a great example of how to use Await while reading a feed from a blog.

VB.NET

Private Async Function GetFeedAsync(FeedUriString As String) As Task
' Imports Windows.Web.Syndication
Dim Client As New SyndicationClient
Dim FeedUri As New Uri(FeedUriString)
Try
Dim Feed As SyndicationFeed = Await Client.RetrieveFeedAsync(FeedUri)
Dim FeedData As New FeedData
FeedData.Title = Feed.Title.Text

For Each Item As SyndicationItem In Feed.Items
Dim FeedItem As New FeedItem
FeedItem.Title = Item.Title.Text
FeedItem.PubDate = Item.PublishedDate.DateTime
FeedItem.Author = Item.Authors(0).Name.ToString()

If Feed.SourceFormat = SyndicationFormat.Atom10 Then
FeedItem.Content = Item.Content.Text
ElseIf Feed.SourceFormat = SyndicationFormat.Rss20 Then
FeedItem.Content = Item.Summary.Text
End If

FeedData.Items.Add(FeedItem)
Next

Me.DataContext = FeedData
ItemListView.SelectedIndex = 0
Catch Ex As Exception
' Log Error.
TitleText.Text = Ex.Message
End TryEnd Function

C#

private async Task GetFeedAsync(string feedUriString){
// using Windows.Web.Syndication;
SyndicationClient client = new SyndicationClient();
Uri feedUri = new Uri(feedUriString);

try {
SyndicationFeed feed = await client.RetrieveFeedAsync(feedUri);
FeedData feedData = new FeedData();
feedData.Title = feed.Title.Text;

foreach (SyndicationItem item in feed.Items)
{
FeedItem feedItem = new FeedItem();
feedItem.Title = item.Title.Text;
feedItem.PubDate = item.PublishedDate.DateTime;
feedItem.Author = item.Authors[0].Name.ToString();
if (feed.SourceFormat == SyndicationFormat.Atom10)
{
feedItem.Content = item.Content.Text;
}
else if (feed.SourceFormat == SyndicationFormat.Rss20)
{
feedItem.Content = item.Summary.Text;
}
feedData.Items.Add(feedItem);
}
this.DataContext = feedData;
ItemListView.SelectedIndex = 0;
}
catch (Exception ex)
{
// Log Error.
TitleText.Text = ex.Message;
}
}

Test Driven Development

Eureeka!

Fellow developers, I have had my TDD epiphany.  I have been a software developer for a very long time and never felt that I fully grasped the concepts behind Test Driven Development.  Today,  I came across a performance issue which involved a client complaining about an application taking 20 hours to process a certain number of records.  I was panicking and thinking of ways to reproduce the problem and how we can measure the performance so we can improve it, but what I did not have was a goal.  I started thinking, why is it a problem that it takes 20 hours to process these products?  Then it dawned on me.

What is the expectation of my code?

At this point in the development cycle, I had no tests that asked this very important question. I had only an expectation of myself of how well my code should perform.  I asked my boss during this performance discussion this very question, and we both kind of looked at each other without a clue.

This very question could have solved the development life cycle issue the entire time, and could potentially save this issue.  How many records should my application process?  What is the expectation of the client?  If we don’t know, we need to do research and find out.  This lead to a whole host of questions that will improve our application and rang the word through my ears, Eureeka!

By finding out what a client expectation, I can develop tests against my code to see if I am meeting that expectation, and if not I won’t release code to a client that does not meat their expectation.  This will result in the overall quality of my code to improve drastically.  To everyone who has ever tried to tell me about test driven development and had it fall on confused and deaf ears, I apologize.  Let’s get to work!

HOW TO: Enable Extended Pricing In Dynamics GP 2010

A little known feature of Dynamics GP is extended pricing.  Most customers believe that by default it is enabled, but in fact the price levels that we look at are standard GP pricing.  Extended pricing allows you to do many things including using Price Books to create promotional time sensitive sales and assign pricing to a specific customer as opposed to a customer level.

To enable this feature in GP, navigate to Tools -> Setup -> Sales -> Extended Pricing. This screen is very simple and simply allows you to enable or disable extended pricing.

gp 2010 extended pricing
Pricing Setup

Once this is enabled, you must get everyone out of GP and restart your clients.  At this point, you will see a new Extended Pricing tab under the inventory screen.  There is an advanced flow to how these are assigned, see below for a basic diagram to get an idea of how to setup your customers.

gp 2010 extended pricing
If you are interested in more information about Dynamics GP setup and usage, please contact Integrated Systems Solutions.

HOW TO: Get A Date From A DatePicker

If you are writing an Android application, you likely have come across some form of the DatePicker object. This object exposes a UI that allows a phone user to pick a month, day and year. Unfortunately, the object itself does not expose any methods to turn this into a date object. Unlike similar controls across other languages, you must construct the date object yourself. While this does cause burden, you can also create your own DatePicker class and implement this method if you prefer. To do this, you can create the following method to return back a date object:

public Date getDate() {
    	return new Date(this.getYear() + 1900, this.getMonth(), this.getDayOfMonth());
}

Otherwise, you will have to create a new date object every time you want to fetch this information from the DatePicker. Cheers!

HOW TO: Make a MDI child window start up in center of parent window

When creating a new instance of a MDI child form, the form will load in cascading order in relation to the open forms by default. Most of the time this is acceptable, but if you run into a situation where you want to load it in the center of the parent you may run into a bit of trouble.The default property for showing a form in the center of a parent looks like this:

C#

MdiChildUI form = new MdiChildUI();
form.MdiParent = this;
form.StartPosition = FormStartPosition.CenterParent;
form.Show();

VB.NET

Dim form As New MdiChildUI
form.MdiParent = Me
form.StartPosition = FormStartPosition.CenterParent
form.Show()

To make the window show by default in the center of a MDI parent, you must set the StartPosition to be CenterScreen as opposed to CenterParent. In a MDI environment, child forms consider the parent MDI window to be their screen.

C#

form.StartPosition = FormStartPosition.CenterScreen;

VB.NET

form.StartPosition = FormStartPosition.CenterScreen