2011年12月21日 星期三

Finding the Unique Device ID in Windows Phone 7 (And Device Manufacturer And Anonymous Windows Live ID)


  • Device Manufacturer ID
    • DeviceExtendedProperties.TryGetValue(“DeviceManufacturer”, out someObject);
    • example: “HTC”
  • Device ID
    • DeviceExtendedProperties.TryGetValue(“DeviceUniqueId”, out someObject);
    • requires ID_CAP_IDENTITY_DEVICE in the app manifest which will trigger a warning to users when they install the app
    • a byte[], converter to a string will looks like
      “12345678901234567890123456789012345678901234567890123”
  • Anonymous Windows Live ID
    • A 32 character subset at offset 2  of the results of
      “UserExtendedProperties.TryGetValue(“ANID”, out someObject)
    • requires ID_CAP_IDENTITY_USER in the app manifest which will trigger a warning to users when they install the app
    • looks like “00FF00FF00FF00FF00FF00FF00FF00FF”
However, if you just need any unique identifier (not necessarily a device ID), you can always set and store a new global unique identifier using:
Guid.NewGuid();
which will return a 128-bit integer that will look something like this:
“e81644f1-46b6-4994-2903-1d1f1440c130″
This will not cause warnings to appear when the app is downloaded because it isn’t a constant identifier to that specific device.
Reference To:

SQLite on WP7


“C# Sqlite Port for Windows phone 7 and possibly Silverlight 3, 4. The core engine was slightly modified to be used with IsolatedStorage and SqliteClient were ported by using missing codes from Mono project in order to maximize usability and portability from desktop.”
Although sterling works great, it is essentially an object-based database (NoSql-like)… If you truly need a relational database or if your application currently uses SQLite and you want to port it to Windows Phone 7, this might just be the answer!
Let’s get started… As with traditional ADO.NET, we first need to create a connection:
using (SqliteConnection conn = 
 new SqliteConnection("Version=3,uri=file:Super14Database.db"))
{
    conn.Open();
    // Use the connection here...
}
And now we can start using the database with “normal” SQL statements… Let’s create a table.
using (SqliteCommand cmd = conn.CreateCommand())
{
    cmd.CommandText = "CREATE TABLE matches ( [id] INTEGER PRIMARY KEY, _
 [team1] TEXT, [score1] INTEGER, [team2] TEXT, [score2] TEXT, [date] TEXT)";
    cmd.ExecuteNonQuery();
}
And to insert data:
cmd.Transaction = conn.BeginTransaction();
cmd.CommandText = "INSERT INTO matches(score1, team1, 
 score2, team2, date) VALUES(@score1, @team1, @score2, @team2, @date);";

cmd.Parameters.Add("@score1",  null);
cmd.Parameters.Add("@team1", null);
cmd.Parameters.Add("@score2",  null);
cmd.Parameters.Add("@team2",  null);
cmd.Parameters.Add("@date",  null);

cmd.Parameters["@score1"].Value = 20;
cmd.Parameters["@team1"].Value =  "Blues";
cmd.Parameters["@score2"].Value =  34;
cmd.Parameters["@team2"].Value =  "Hurricanes";
cmd.Parameters["@date"].Value =  "12/02/10";
cmd.ExecuteNonQuery();


cmd.Parameters["@score1"].Value =  15;
cmd.Parameters["@team1"].Value =  "W Force";
cmd.Parameters["@score2"].Value =  24;
cmd.Parameters["@team2"].Value =  "Brumbies";
cmd.Parameters["@date"].Value =  "12/02/10";
cmd.ExecuteNonQuery();

cmd.Parameters["@score1"].Value =  34;
cmd.Parameters["@team1"].Value =  "Cheetahs";
cmd.Parameters["@score2"].Value =  51;
cmd.Parameters["@team2"].Value =  "Bulls";
cmd.Parameters["@date"].Value =  "12/02/10";
cmd.ExecuteNonQuery();

cmd.Parameters["@score1"].Value =  32;
cmd.Parameters["@team1"].Value =  "Crusaders";
cmd.Parameters["@score2"].Value =  17;
cmd.Parameters["@team2"].Value =  "highlanders";
cmd.Parameters["@date"].Value =  "12/02/10";
cmd.ExecuteNonQuery();

cmd.Parameters["@score1"].Value =  28;
cmd.Parameters["@team1"].Value =  "Reds";
cmd.Parameters["@score2"].Value =  30;
cmd.Parameters["@team2"].Value =  "Waratahs";
cmd.Parameters["@date"].Value =  "12/02/10";
cmd.ExecuteNonQuery();

cmd.Parameters["@score1"].Value =  13;
cmd.Parameters["@team1"].Value =  "Lions";
cmd.Parameters["@score1"].Value =  26;
cmd.Parameters["@team2"].Value =  "Stomers";
cmd.Parameters["@date"].Value =  "12/02/10";
cmd.ExecuteNonQuery();

cmd.Parameters["@score1"].Value =  18;
cmd.Parameters["@team1"].Value =  "Sharks";
cmd.Parameters["@score2"].Value =  19;
cmd.Parameters["@team2"].Value =  "Chiefs";
cmd.Parameters["@date"].Value =  "12/02/10";
cmd.ExecuteNonQuery();
                    
cmd.Transaction.Commit();
NOTE: Notice the transaction support build in!
To fetch data from the database:
cmd.CommandText = "SELECT * FROM matches";
using (SqliteDataReader reader = cmd.ExecuteReader())
{
    while (reader.Read())
    {
        var team1 = reader.GetValue(1);
        var score1 = reader.GetValue(2);
        var team2 = reader.GetValue(3);
        var score2 = reader.GetValue(4);
        var date = reader.GetValue(5);
    }
}
And that’s it! It is more verbose but it does work great and the translation from a normal desktop application that used SQLite should be simple!


Reference To:
http://www.codeproject.com/Articles/151179/SQLite-on-WP7

Windows Phone 7 Emulator Skin Switcher 1.0 Beta


In the last few weeks several people started creating their own skins for the Windows Phone 7 Emulator. Switching between different skins was a lot of work by copying files manually to the emulator directory every time you wanted to switch. From now on this is not needed anymore because you can use the Windows Phone 7 Emulator Skin Switcher application I’ve created.
wp7EmulatorSkinSwitcher
You can download the application here: Download
This version is the first beta release with my first set of skins. I added 2 skins from Georg Kalus: the Blue Nokia Lumia 800 and the White/Pink Nokia Lumia 710. I’ve also included the Black Nokia Lumia 800 skin from Pedro Lamas
The complete list of skins included in the application now are:
I’m planning on adding more skins in the near future but didn’t have time for it yet. If you have skins I can use please let me know by comment or on twitter
lumia710whitelumia800pinklumia710black

Hopefully this will make your Windows Phone 7 projects even more fun to test!

2011年12月19日 星期一

How To Change Your Windows Phone Emulator?


Today, I discovered that Pedro Lamas had released a skin for the Windows Phone emulator that allowed it to look like the Nokia Lumia 800.  (You can see it here.)
This inspired me to create another new skin for my current phone, the HTC Arrive.  (Click here to download the HTC Arrive Windows Phone Emulator skin.)  To use either of them, you simply need to copy the contents of the zip file to a specific folder on your computer (make sure to save a copy of the original files):

C:\Program Files (x86)\Microsoft XDE\1.0\

Once you’ve done that, your emulator can look like one of the images below!
Nokia-Lumia-800-skin-for-Windows-Phone-Emulator[1]                                  image
Reference To:http://www.jeffblankenburg.com/2011/12/17/want-to-change-your-windows-phone-emulator/