Posts
133
Comments
328
Trackbacks
0
March 2011 Entries
Producing and Consuming OData in a Silverlight and Windows Phone 7 application. (Part 2 )

This article is Part 2 of the series “Producing and Consuming OData in a Silverlight and Windows Phone 7 application.”

  1. Producing and Consuming OData in a Silverlight and Windows Phone 7 application. (Part 1) – Creating our first OData Data Source and querying data through the web browser and LinqPad.
  2. Producing and Consuming OData in a Silverlight and Windows Phone 7 application. (Part 2 ) – Consuming OData in a Silverlight Application.
  3. Producing and Consuming OData in a Silverlight and Windows Phone 7 application. (Part 3)  – Consuming OData in a Windows Phone 7 Application.
  4. Producing and Consuming OData in a Silverlight and Windows Phone 7 application. (Part 4)  – Consuming OData in a Windows Phone 7 Application (Mango).

To refresh your memory on what OData is:

The Open Data Protocol (OData) is simply an open web protocol for querying and updating data. It allows for the consumer to query the datasource (usually over HTTP) and retrieve the results in Atom, JSON or plain XML format, including pagination, ordering or filtering of the data.

To recap what we learned in the previous section:

  • We learned how you would produce an OData Data Source starting from File->New Project and selecting empty ASP.NET Application.
  • We generated a SQL Compact 4 Edition DB and populated it with data.
  • We created our Entity Framework 4 Model and OData Data Service.
  • Finally, we learned about basic sorting and filtering of the OData Data Source using the web browser and a free utility called LinqPAD.

In this article, I am going to show you how to consume an OData Data Source using Silverlight 4. In the third and final part of the series, we will consume the data using Windows Phone 7. Read the complete series of articles to have a deep understanding of OData and how you may use it in your own applications.
Download the source code for part 2 | Download the slides

    The Full Article

    The full article is hosted on SilverlightShow and you can access it by clicking here. Don’t forget to rate it and leave comments or email me [michael[at]michaelcrump[dot]net if you have any problems.

    alt Subscribe to my feed

    Posted On Monday, March 28, 2011 9:36 AM | Feedback (0)
    Producing and Consuming OData in a Silverlight and Windows Phone 7 application (Part 1)

    I have started a new series on SilverlightShow.net called Producing and Consuming OData in a Silverlight and Windows Phone 7 application.  I decided that I wanted to create a very simple and easy to understand article that not only guides you step-by-step but includes a video and full source code. I personally believe this is the best way to teach someone something and I hope you enjoy the series. I also want to thank SilverlightShow for giving me this opportunity to help other developers get up to speed quickly with OData.

    The table of contents for the series is listed below.

    1. Producing and Consuming OData in a Silverlight and Windows Phone 7 application. (Part 1) – Creating our first OData Data Source and querying data through the web browser and LinqPad.
    2. Producing and Consuming OData in a Silverlight and Windows Phone 7 application. (Part 2 ) – Consuming OData in a Silverlight Application.
    3. Producing and Consuming OData in a Silverlight and Windows Phone 7 application. (Part 3)  – Consuming OData in a Windows Phone 7 Application.
    4. Producing and Consuming OData in a Silverlight and Windows Phone 7 application. (Part 4)  – Consuming OData in a Windows Phone 7 Application (Mango).

    What is OData?

    The Open Data Protocol (OData) is simply an open web protocol for querying and updating data. It allows for the consumer to query the datasource (usually over HTTP) and retrieve the results in Atom, JSON or plain XML format, including pagination, ordering or filtering of the data.

    In this series of articles, I am going to show you how to produce an OData Data Source and consume it using Silverlight 4 and Windows Phone 7. Read the complete series of articles to have a deep understanding of OData and how you may use it in your own applications.

    The Full Article

    The full article is hosted on SilverlightShow and you can access it by clicking here. Don’t forget to rate it and leave comments or email me [michael[at]michaelcrump[dot]net if you have any problems.

    alt Subscribe to my feed

    Posted On Thursday, March 24, 2011 8:55 AM | Feedback (0)
    Adding Analytics to your Windows Phone 7 App with Preemptive Solutions

    I have always been interested in learning which features of my application users are using as well as if they are using it.  I have done this with other applications by using my own “home-grown” version of web services, etc. Since I have been working a lot with Windows Phone 7 lately, I decided to learn how to do this and share with the community. Before you get started you will be pleased to know that you won’t have to spend any money *at least until 2012* to do this with your existing phone apps.

    To get started: 

    Download Dotfuscator at http://www.preemptive.com/windowsphone7.html. After it is downloaded you will want to add your WP7 .XAP file to Dotfuscator. This will allow you to setup analytics and obfuscation of your application.

    image

    After it is loaded then you will want to click on the Input tab and take a look at the .DLL’s referenced in your project.  You will want to exclude any third party dll’s from the package. Don’t worry as they are not excluded entirely. The only thing you want left in here is your main application .dll and the Package Artifacts. So in the example below, I removed the Telerik 3rd party controls and only left my michaelcrump.net.dll and Package Artifacts.

    image

    You will now want to click on Settings and look for Instrumentation. Make sure that the first three are set to Yes. 

    SNAGHTML11e103b

    Now we are going to click on the Instrumentation Tab and right click our main application .dll and add an attribute.

    SNAGHTML11f99b5

    Select “PreEmptive.Attributes.Application.Attribute”.

    SNAGHTMLeb5f820

    You should have this screen now. This allows you to setup the Application Type and give it a name that you can see in your Preemptive Solution Dashboard. Go ahead and fill in your applications info. You can uniquely generate a GUID by clicking on the ellipse button in the right hand corner box.

    SNAGHTML1215fc1

    Once that is complete you are going to want to add a BusinessAttribute. So right click again and select BusinessAttribute.

    SNAGHTMLeb5f820

    At this point, you will want to fill in your company name as well as the CompanyKey that was provided in an email from Preemptive Solutions.

    SNAGHTML1226231

    Now that we have included our Application and Business information to our project. We will need to setup our SetupAttribute and TearDown Attribute.

    Starting with the SetupAttribute:

    Navigate inside your Application until you get to App –> Then InitializeComponent: void(). Right click on this field and add a SetupAttribute. You will want to make sure the Custom EndPoint is set to wp7data.runtimeintelligence.com/PreEmptive.Web.Services.Messaging/MessagingServiceV2.asmx. This is a selectable option, so you will not have to type it. This is basically a web service that will collect data as your users click on different items in your application.

    SNAGHTML12370e1

    Now the TeardownAttribute:

    Navigate inside your Application until you get to App –> Then Application_Closing event. Right click on this field and add a TearDownAttribute. You can leave all the options on this page as the default.

    SNAGHTML1245f64

    Now comes the fun part, adding Attributes to the features you want to track. 

    So for example: In my application I have four buttons on the main page. I have added the following attributes to track when a user clicks on each of them.

    So right click on your click event and add a FeatureAttribute. In the example below you will see that I added 4 FeatureAttributes to my project.

    SNAGHTML12533e1

    You should name them where you can easily find them in the Preemptive Dashboard (screenshots coming up). For example on my AboutButton, I named it AboutButtonClicked.

    image

    Now all you will need to do is hit the Run Button and your application will recompile with the necessary files/references needed to communicate with Preemptive’s webservice.

     

    After you run your application a few times you can go and check your results by going to the portal site at: http://wp7.runtimeintelligence.com/portal/Security/Logon

    This will give you a snapshot of your application and queued data. You can drill in to see more info.

    image

    I drilled into michaelcrump.net and found exactly how many times users were clicking on my button. This new version of my app had only been out a few days and I quickly realized that most people use my RssFeed button than any other feature of my app. This is valuable information as it could tell you what features to drop or which ones you should improve on.

    image

    You also get a nice little graph at the bottom of the dashboard that tells what locations your users are in. You can hover over each one more more stats. 

    image

    What was very interesting to me was during application certification, I could see the location of the testers. This was very cool to see.

    Overall I’m very impressed with the services that Preemptive Solution provided. From everything that I gathered this service was going to be free until January 2012. If you decide not to pay then you won’t have to resubmit your application. It will still work, you just won’t have any access to the data it provides.

     

    Thanks for reading and please subscribe to my blog or follow me on twitter.

    alt Subscribe to my feed

    Posted On Tuesday, March 22, 2011 6:51 AM | Feedback (9)
    A quick tip for those working with the Windows Phone 7 AD SDK.

    One thing that I’ve noticed in several apps in the Windows Phone 7 marketplace is the ad chopping off on the right hand side. I decided that my next Windows Phone 7 app will be ad supported so why not sign up for the Advertising SDK and investigate this issue. *Note: If you want to see this in an actual app then download the free app called “Road Rage”.

    So here is an example of what I am talking about:

    SNAGHTMLc5e07

    You will notice that the right hand side of the AD is chopped off using the default ad banner. You can see the border on the left hand side clearly. So, what exactly is going on? Let’s take a look at this in the designer.

    image

    From this image we can see it clearer, the margin of the grid that the ad is contained in needs to be removed.

    By default, the ContentPanel in a Windows Phone Page has a margin already set on it. See below for an example of this:

    <!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
    </Grid>

    If you simply remove that margin then your ad will display properly as shown below.

    SNAGHTML245512

    It’s strange that I’ve seen this in multiple WP7 applications in the marketplace. If you are trying to make money off Ads, you would probably want to make sure the full ad is displayed. I am hoping this short post helped someone. 

    alt Subscribe to my feed

    Posted On Wednesday, March 16, 2011 6:46 AM | Feedback (1)
    Profiling Silverlight Applications after installing Visual Studio 2010 Service Pack 1

    Introduction

    Now that the dust has settled and everyone has downloaded and installed Visual Studio 2010 Service Pack 1, its time to talk about a new feature included that will help Silverlight Developers profile their applications. Let’s take a look at what the official documentation says about it:

    Performance Wizard for Silverlight – taken from VS2010 SP1 KB.

    Visual Studio 2010 SP1 enables you to tune the Silverlight application performance by profiling the code. A traditional code profiler cannot tune the rendering performance for Silverlight applications. Many higher-level profilers are added to Visual Studio 2010 SP1 so that you can better determine which parts of the application consume time.

    So, how do you do it?

    After you finish installing VS2010 SP1, make sure it took by going to Help –> About. You should see SP1Rel under Visual Studio 2010 as shown below.

    SNAGHTML92dcca

    Now, that we have verified you are on the most current release, let’s load up a Silverlight Application.

    I’m going to take my hobby Silverlight project that I created a month or so ago. The reason that I’m picking this project is that I didn’t focus so much on performance as it was just built for fun and to see what I could do with Silverlight. I believe this makes the perfect application to profile. 

    After the project is loaded, click on Analyze then Launch Performance Wizard.

    image

    Go ahead and click on CPU Sampling (recommended).

    SNAGHTML9aa22a

    You will notice that it ask which application to target. By Default, it will select the .Web project in an Silverlight Application. Go ahead and leave the default Web Project checked.

    SNAGHTML9c5dfa

    We are going to leave the client as Internet Explorer.

    SNAGHTML9eab10

    Now, go ahead and click finish.

    SNAGHTML9f2f8b

    Now your Silverlight Application will launch.

    image

    While your application is running, you will see the following inside of Visual Studio 2010.

    SNAGHTMLa14c2f

    Here is where you will need to attach your Silverlight Application to the web application that is current being profiled. Simply click on the  Attach/Detach button below and find your application to attach to the profiler. In my case, I am using IE8 and could find it by the title.

    image

    After you close your browser, you will notice it generated a report:

    These files will end with a .VSP

    image

    If you click on the .VSP you will it generated the following report:

    image

    We could turn off “Just My Code” but it may pick up things that we didn’t want to profile as shown below:

    image

    One other feature to note is that you may want to export the data to a CSV or XML. You can do that by looking at the toolbar and clicking the button highlighted below.

    image

    SNAGHTMLa935c2

    Conclusion

    The profiler for Silverlight is a great addition to an already great product. So before you ship a Silverlight Application run it through the profile and see what comes up. Since its included and free I can’t see a reason not to do this. Thanks again for reading and I hope you subscribe to my blog or follow me on Twitter for more Silverlight/WP7 fun.

    alt Subscribe to my feed

    Posted On Friday, March 11, 2011 8:42 AM | Feedback (3)
    Changing the Default Windows Phone 7 Deployment Target In Visual Studio 2010

    After you download and install the January 2011 Windows Phone update, you will notice one annoying thing.

    The default deployment target for Windows Phone Projects in Visual Studio changes to Windows Phone 7 Device. Before the update, it defaulted to the Emulator.

    image

    I found this extremely annoying as I’m more than likely going to test with the emulator before putting it on my actual device.

    Now to make things fair, Microsoft told you they were going to switch the default and even provided a solution, but you will have to check a tiny paragraph in the release notes.

    image

    The good news is that its very easy to do:

    Simply navigate out to : %LocalAppData%\Microsoft\Phone Tools\CoreCon

    SNAGHTML5441179

    See the folder named, “10.0”? Go ahead and delete it. Now, the folder will be completely empty and if you fire up Visual Studio 2010 you will see we are now defaulting to the Emulator again.

    image

    In my opinion, this should have been left at Emulator. Now, new WP7 developers will get a build error when they first start a WP7 project and will not know why until they read the error list.

    alt Subscribe to my feed

    Posted On Saturday, March 05, 2011 10:39 AM | Feedback (2)
    Tag Cloud