Debugging the Windows Phone Ad Control


I’ve written previously about my lessons learned of the Windows Phone 7 ad control and it appears as I haven’t learned my lesson yet. About a month ago Champions League Tracker hit the Marketplaceand it appears to be very successful: from 11/28/2011 to 12/17/2011 the app has been downloaded 2,084 times. Go ahead, download it, I’ll wait for you. There is a small problem, though, I haven’t made a single dime yet. Why? Because I decided to go with an ad based model on this one, but the pub center did not register a single impression since launch. To me it seemed weird, because during development I was seeing ads and then at one point they disappeared. I thought it was Microsoft limiting my ads or they figured the app was being used from the emulator so I paid no attention to it and published the app to the Marketplace. Then I realized there was a problem, so I decided to fix it along with other bugs. Sometimes I had ads and sometimes I didn’t. Since I had a fallback mechanism (another post on this later) for when no ads were available I didn’t worry too much. So today was the first day of the new version out in the wild and after checking for ads several times throughout the day I noticed there were still no ads. Furthermore, I asked a few of my peers to check it out and they came back with the same result. So I decided to investigate.

I figured the Ad Control would make some sort of HTTP call, so I decided to fire up Fiddlerand inspect the traffic. I followed this post on how to intercept the traffic from the emulator and started sniffing away. Since the Ad Control uses HTTPS, you also have to install Fiddler’s root cert into the emulator by following these directions. So I fired up the emulator and I’m anxiously watching Fiddler for some data to popup when I see this beautiful sighting:

image

I then went ahead and inspected the request only to see the following URL being used: /v3/Delivery/Placement?pubid=[someguid]&pid=[someid]&adm=2&cfmt=text,image&sft=jpeg,png,gif&w=480&h=80&fmt=json&cltp=app&dim=le&lc=en-US&idtp=mid&uid=[someotherguid].

I copy the URL in my browser and get a JSON response which basically said there were no ads to display. Thank you, Sherlock! So I decided to check the querystirng parameters one by one. As it turns out, pubid is the Application ID. At this moment I decided to compare it with the actual ID and low and behold, it was WRONG! It was very similar, but not exact! Maybe at some point in time of my development I changed the ID by mistake or something. So I change it back to the right one and my ads start working again.

So to conclude, just like I said more than a year ago:

If it doesn’t work on the emulator it will probably not work on the device.

So debug it before you submit to the marketplace!

Happy programming!

author:  | posted @ Friday, December 23, 2011 12:01 AM | Feedback (0)

We must stop the censorship now before it is too late!


I've censored the following, in protest of a bill that gives any corporation and the US government the power to censor the internet--a bill that could pass THIS WEEK. To see the uncensored text, and to stop internet censorship, visit: http://americancensorship.org/posts/11801/uncensor

We ████ ████ the ██████████ now ██████ it is too ████!

Uncensor This

author:  | posted @ Wednesday, December 14, 2011 11:53 AM | Feedback (0)

Create an SMS Task Using the Contact’s Name in Windows Phone


You can use the SmsComposeTask to create an SMS with Windows Phone. As the code below shows, it is very easy to do.

   1: <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
   2:     <Button Content="Number Only" Height="72" HorizontalAlignment="Left" Margin="12,6,0,0" Name="btnNumberOnly" VerticalAlignment="Top" Click="btnNumberOnly_Click" />
   3:     <Button Content="Name Only" Height="72" HorizontalAlignment="Left" Margin="12,84,0,0" Name="btnNameOnly" VerticalAlignment="Top" Click="btnNameOnly_Click" />
   4:     <Button Content="Name and Number - Contact" Height="72" HorizontalAlignment="Left" Margin="12,162,0,0" Name="btnNameAndNumber" VerticalAlignment="Top" Click="btnNameAndNumber_Click" />
   5:     <Button Content="Name and Number - No Contact" Height="72" HorizontalAlignment="Left" Margin="12,240,0,0" Name="btnNameAndNumberNoContact" VerticalAlignment="Top" Click="btnNameAndNumberNoContact_Click" />
   6: </Grid>
   1: private void btnNumberOnly_Click(object sender, RoutedEventArgs e)
   2: {
   3:     SmsComposeTask task = new SmsComposeTask();
   4:     task.Body = "Number Only";
   5:     task.To = "305-555-1212";
   6:     task.Show();
   7: }
   8: private void btnNameOnly_Click(object sender, RoutedEventArgs e)
   9: {
  10:     SmsComposeTask task = new SmsComposeTask();
  11:     task.Body = "Name Only";
  12:     task.To = "Chris Sells";
  13:     task.Show();
  14: }
  15:  
  16: private void btnNameAndNumber_Click(object sender, RoutedEventArgs e)
  17: {
  18:     SmsComposeTask task = new SmsComposeTask();
  19:     task.Body = "Name and Number - Contact";
  20:     task.To = "Chris Sells <206-555-0003>";
  21:     task.Show();
  22: }
  23:  
  24: private void btnNameAndNumberNoContact_Click(object sender, RoutedEventArgs e)
  25: {
  26:     SmsComposeTask task = new SmsComposeTask();
  27:     task.Body = "Name and Number - No Contact";
  28:     task.To = "Chris Sells <206-444-0000>";
  29:     task.Show();
  30: }

The first “Number Only” button creates a new task and sets the To to a number. This generates the following SMS:

Capture0    Capture1

When clicking on the number, the phone prompts us with some options where we can open the contact and see the contact’s information:

Capture2     Capture3

In this case we can see that since the number doesn’t exist in the contacts address book we are displayed with a temporary contact’s card (unknown). Furthermore, if the number were to belong to a contact it would display that contact’s information:

Capture4     Capture5

It is also important to notice that the formatting of the number doesn’t affect the OS’s ability to relate it to an existing contact. As you can see the SMS was created with the format xxx-xxx-xxxx and the contact was saved with the format (xxx)xxxxxxx. Very nice and expected detail for the Redmond guys!

The next button, “Name Only”, creates a new SMS with a name. For some reason, the OS is not capable of tying this name to a contacts (even though it exists):

Capture6    Capture7

As you can see it linked to a temporary contact and treats the To as an email. Weird.

Continuing to the next button, “Name and Number – Contact”, we are creating a new SMS specifying the To in the format of “Name <Number>” (similar to the email format: “Name <Email>”). In this case the result is similar to the number only, but with the exception that the To line of the SMS app shows the name instead of the number. A much better user experience for your users:

Capture8    Capture5

Finally, the “Name and Number – No Contact” button, creates a new SMS the same way as the previous case, but using the name of a contact that exists and a phone number of a contact that doesn’t exists. This results in an unknown contact:

Capture9    Capture10

It is very important to mention that the OS always ignores the name and uses the number as a link to a contact. For example, using the same example as above using “John Doe <206-555-0003>” will result in Chris Sells contact card to appear, but John Doe’s name will show in the SMS app.

Happy Programming!

author:  | posted @ Thursday, November 24, 2011 9:00 AM | Feedback (0)

Querying Contacts After Converting to WP7 Mango


If you are working in an application that has been converted from WP7 to WP7.1 (Mango) and are trying to query the contacts like the code below you might get a helpless exception of type System.Exception with the message “Exception”, no InnerException and a StackTrace similar to:

at Microsoft.Phone.UserData.QueryDataEnumerable`1.EnsureInteropInit()
at Microsoft.Phone.UserData.QueryDataEnumerable`1.GetNextBatch(Int32 nextIndex)
at Microsoft.Phone.UserData.QueryDataEnumerator`1.MoveNext()
at Microsoft.Phone.UserData.Contacts.GetContacts(Object state)
at System.Threading.ThreadPool.WorkItem.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadPool.WorkItem.doWork(Object o)
at System.Threading.Timer.ring()

   1: Contacts contacts = new Contacts();
   2: contacts.SearchCompleted += (s, e) =>
   3: {
   4:     //Some Code Here
   5: };
   6: contacts.SearchAsync("John", FilterKind.DisplayName, null);

Not very useful!

The problem is that you haven’t indicated Windows Phone to give you capabilities to access the user’s contacts. During the migration from 7.0 to 7.1 Microsoft forgot to append the new capabilities to the WMAppManifest.xml and hence the error.

To solve this simply add the capability to the WMAppManifest.xml

   1: <Capability Name="ID_CAP_CONTACTS"/>


Happy programming!

author:  | posted @ Wednesday, November 23, 2011 9:03 AM | Feedback (0)

Debugging Tombstoning with WP7 (Mango)


A new feature of Mango (WP 7.5) is fast app switching, a much needed feature, which every developer should implement in their apps. Before mango, every time the application was deactivated the developer had to maintain state and restore it once the application was re activated. That resulted in very slow transitions between apps and a bad user experience. With fast app switching and the WP 7.1 SDK, the phone maintains all state of the app when it is deactivated and when the user activates it again the app starts right away. It is a much better user experience! Windows Phone tries it’s best to maintain the state, but it is not 100% sure that when the user comes back to your app the state will be preserved, so we can check whether the state is still there and if not restore it ourselves.

   1: private void Application_Activated(object sender, ActivatedEventArgs e)
   2: {
   3:     if (!e.IsApplicationInstancePreserved)
   4:     {
   5:         RestoreState();
   6:     }
   7: }

Very easy to do! This is great, but it doesn’t mean we don’t have to implement tomstoning (please note the article refers to WP 7.0, not 7.1), since we still want to maintain a good user experience, we should restore everything as it was even if the phone wasn’t able to persist the state. You can read the article linked above and it’s second part for a great explanation of how to do so.

The question then arises, how do we debug tombstoning if the application is persisted every time we reactivate the app? We have two options:

  1. Deactivate the app and play around the emulator (or phone) by opening as many apps as you can and pray the phone doesn’t preserve the state when it is reactivated.
  2. Right click on your project file and go to properties. Navigate to the Debug tab and check the “Tombstone upon deactivation while debugging”.

image_thumb4

As you might imagine option 2 is the recommended approach as it is probably a much more efficient way to debug tombstoning! Next time your application is activated e.IsApplicationInstancePreserved will be false.

Happy Tombstoning!

author:  | posted @ Friday, November 18, 2011 11:44 AM | Feedback (0)

Multiple Language Keyboard in Windows Phone 7.5


I’m loving my Mango update on Windows Phone 7. With many new features incorporated into the phone there is one that I was really looking forward to: The multiple language soft keyboard. I’m used to having a hard keyboard on my phones and therefore I got the Dell Venue Pro because of the awesome vertical keyboard. The more I used the phone the more I noticed that the soft keyboard did a great job in auto correcting my spelling and found myself using the hardware keyboard less and less. The only problem I had was that I use my phone both in English and Spanish and I have my phone culture setup to English. So typing in Spanish with the soft keyboard resulted in incorrectly autocorrected words. Therefore I was still tied to the hard keyboard. With Mango I can now setup the keyboard to have multiple languages and change the language within the keyboard making my hardware keyboard useless.

To setup the multiple languages go to Settings – Keyboard and check all the languages you want to have:

Keyboard2_thumb Keyboard_thumb

Then while the software keyboard is opened you can press on the bottom right button (ENU while in English) to switch between languages:

SoftKeyboard_thumb SoftKeyboard3_thumb SoftKeyboard2_thumb

Notice in the picture above, that while in Spanish the keyboard even added an “Ñ”. You can also press and hold to list all possible values as the third picture shows

Now you can see that the auto correction automatically uses the selected language:

SoftKeyboard4_thumb SoftKeyboard5_thumb

Update 10/10/2011
It seems as if the current version of the OS only remembers the last language you used. If you want the OS to remember the language on a per user basis, then make your voice heard by voting on this feature suggestion.

I now know that my next Windows Phone will not have a physical keyboard. Happy Typing!

author:  | posted @ Thursday, October 06, 2011 12:37 PM | Feedback (0)

Talking About Windows 8 at BUILD


I recently attended the BUILD Windows conference in Aneheim, CA. There Microsoft unveiled the next generation of it’s OS: Windows 8. Here’s a Spanish interview I did with Seth Juarez from Devexpress about Windows 8. Enjoy!

http://tv.devexpress.com/#BUILDJonasStawski;Build+Conference.tag;1

author:  | posted @ Monday, October 03, 2011 2:52 PM | Feedback (0)

ASP.NET Custom Expression Builder For Azure


ASP.NET 2.0 brought a new feature called Expression Builder, which allows you to assign dynamic values to a control’s property. The syntax is very similar to the well known <%= value %> and <%# bind(“property”) %>:

<%$ expression %>


Please note the “$”. This syntax can be found mostly for connection strings when doing some declarative binding with ASP.NET:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnectionString %>" />


This built in Expression uses the connection string MyConnectionString found in the Web.Config.

It is a fact that with Azure it is better to store the AppSettings and Connection Strings in the CSCFG file, because the web.config is not changeable at run time due to the nature of Azure deployment model. Therefore we can’t use the ConnectionStrings Expression Builder.

The solution is to use Custom Expression Builders. All we need is a class that inherits from ExpressionBuilder and overrides the GetCodeExpression method. So to solve our problem and retrieve the ConnectionString from the CSCFG file we need the following class:

using System.CodeDom;
using System.Web.Compilation;
using System.Web.UI;
using Microsoft.WindowsAzure.ServiceRuntime;

public class AzureSettingsExpressionBuilder : ExpressionBuilder
{
    public override CodeExpression GetCodeExpression(BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
    {
        return new CodePrimitiveExpression(RoleEnvironment.GetConfigurationSettingValue(entry.Expression));
    }
} 

We basically wrap the usual GetConfigurationSettingValue used with Azure with a CodePrimitiveExpression object.

We then register the Custom Expression Builder in the web.config:

<compilation>
  <expressionBuilders>
    <add expressionPrefix="AzureSettings" type="AzureSettingsExpressionBuilder"/>
  </expressionBuilders>
</compilation>


And use it from our aspx pages:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ AzureSettings:MyConnectionString %>" />


WARNING: this will break the QueryBuilder UI of the Configure Data Source wizard.

Happy Programming!

author:  | posted @ Thursday, September 22, 2011 11:41 AM | Feedback (0)

MSDN Subscription and Windows Azure Offer


As an MVP we get a free Visual Studio Ultimate MSDN Subscription and with it a nice offer for Windows Azure. Since offers change often and some links may be broken let me copy the offer here:

Current offer* Updated Offer after April 12, 2011
Services Ultimate, Premium & BizSpark* Ultimate
BizSpark
Premium Professional
Compute 750 hrs Small compute instance 1,500 hrs Small compute instance 1,500 hrs Extra Small compute instance 750 hrs Extra Small compute instance
Storage 10 GB 30GB 25 GB 20 GB
Storage Trans 2,000K 2,000K 1,000K 250K
SQL Azure 5 GB of 
Web edition DB
5 GB of 
Web edition DB
1 GB 
(Web edition)
1 GB 
(Web edition)
Access Control Transactions** 1,000K 500K 200K 100K
Service Bus Connections 5 (1 pack of 5) 5 (1 pack of 5) 5 (1 pack of 5) 2 connections
Caching*** 128 MB cache 128 MB cache 128 MB cache 128 MB cache
Data transfer
out
14 GB (NA/Europe) / 
5 GB (Asia)
35 GB (WW) 30 GB (WW) 25 GB (WW)
Data transfer
in
7 GB (NA/Europe) / 
5 GB (Asia)
35 GB (WW) 30 GB (WW) 25 GB (WW)

If you look under Ultimate/BizSpark, you will notice a 1500 hrs of Small compute instance. So I decided to start taking advantage of this nice offer and spun 2 Extra Small instances to test some things. All nice and dandy, but yesterday I received the following complimentary email from Microsoft Online Services:

Dear Jonas Stawski,

This e-mail notification comes to you as a courtesy to update you on your Windows Azure platform usage.  Our records indicate that your subscription has exceeded 125% of the extra small compute hours amount included with your offer for your current billing period.  Any hours in excess of the amount included with your offer will be charged at standard rates.

We show that you have so far utilized the following extra small instance compute hours (or their equivalent) during this billing period:

Subscription start date: 1/12/2011 12:00:00 AM
Offer Name: Windows Azure Platform MSDN Premium
Subscription Name: Digital Idea Solutions

Total Consumed*                                         32.000000 XS Compute Hours
Amount included with your offer                    0 XS Compute Hours
Amount over (under) your monthly average    32.000000 XS Compute Hours

No action is required unless this usage is unexpected.  If this usage is unexpected, please log into the Windows Azure Dev Portal to view your running services and make any needed changes to those services to bring your usage back in line.

At any time, you can login to the Microsoft Online Services Customer Portal to view your subscription's usage at https://mocp.microsoftonline.com.  You can also click here for detailed instructions on how to view and understand your usage statements and bills.

Please do not reply directly to this e-mail as this mailbox is not monitored.   For customer support, please feel free to connect with one of our Customer Partner Care agents by clicking on this
link
.

Thank you for choosing Microsoft.

Sincerely,
Microsoft Online Services Support


WHAT?!?!? I thought I had 1500 hours free of Small Instance, since Extra Small is a smaller option I would have imagined that I would get at least the same as a Small instance. So I called the billing department and this is what they’ve told me (I’m paraphrasing):

Extra Small instances are computed differently than any other instance. Your offer includes 1500 hrs of a Small instance, not Extra Small, therefore we have to charge you for it.

Here’s a table of equivalency for each instance based on the offer

Instance Type Equivalency Hours
Extra Small N/A N/A
Small 1 Small 1500
Medium 2 Small 750
Large 4 Small 375
Extra Large 8 Small 187.5

Thanks to the complimentary and early email sent to Microsoft I was able to quickly take action and correct the “problem”. Needless to say, my testing had already finished, so I deleted all instances. I only accrued $5!

Happy Azuring!

author:  | posted @ Friday, August 26, 2011 10:50 AM | Feedback (0)

Visual Studio 2010 Shortcuts


Lately my right hand has been sored due to too much use of the mouse. For the past 18 years I’ve been a heavy mouse user and yesterday I decided that was enough. I set a personal goal to use the mouse the least possible. Not an easy task in today’s computerized world, but since I’m a developer and spend about 85% of my time in Visual Studio, it certainly is doable. I must say that after 1 day of doing so, my pain has not gone away completely, but it has gotten better. I haven’t seen a drastic change in efficiency, but I guess I will see that as I get used to the shortcuts and get past the learning curb. So, without further do, I present to you a list of the my most used shortcuts with Visual Studio (Chrome, and Windows).

Debugging/Compiling

CTRL + SHIFT + B Build solution
SHIFT + F6 Build current project
F5 Start/Continue debugging
CTRL + F5 Start without debugging
SHIFT + F5 Stop debugging
F10 Step over
F11 Step in
SHIFT + F11 Step out
ALT + A Attach to process. Created by me (ref)
F9 Toggle breakpoint

Navigation

CTRL + TAB Move through opened tabs (and panes)
CTRL + SHIFT + TAB Move through opened tabs (and panes) in reverse
CTRL + , Navigate To (Extremely important for large solutions)
F12 Go to definition
CTRL + F4 Close current tab
CTRL + F Find
CTRL + H Find and replace
CTRL + SHIFT + F Find in files
CTRL + SHIFT + H Find and replace in files

Editor

CTRL + M + M Collapse/expand current section.
CTRL + M + O Collapse all
CTRL + M + L Expand all

Windows

ALT + TAB Change active program

Google Chrome

ALT + D Highlight address bar
CTRL + T New tab
CTRL + TAB Move through opened tabs
CTRL + F4 Close current tab

I will update this list as I learn new keyboards and find them useful on my quest to avoid usage of the mouse as much as possible.

EDIT: as Joe Healy, aka DevFish, points out, Russ' ToolShed Network, Inc has a Windows Phone 7 app for Visual Studio shortcuts. Just search for Shortcuts VS in the MarketPlace

Happy programming (without the mouse, of course)!

author:  | posted @ Friday, August 12, 2011 10:08 AM | Feedback (5)