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/

2011年11月29日 星期二

HowTo - 在 Windows 7 、Vista 忘記 Administrator 密碼


To reset a forgotten administrator password, follow these steps:

  1. Boot from Windows PE or Windows RE and access the command prompt.
  2. Find the drive letter of the partition where Windows is installed. In Vista and Windows XP, it is usually C:, in Windows 7, it is D: in most cases because the first partition contains Startup Repair. To find the drive letter, type C: (or D:, respectively) and search for the Windows folder. Note that Windows PE (RE) usually resides on X:.
  3. Type the following command (replace “c:” with the correct drive letter if Windows is not located on C:):
    copy c:\windows\system32\sethc.exe c:\
    This creates a copy of sethc.exe to restore later.
  4. Type this command to replace sethc.exe with cmd.exe:
    copy /y c:\windows\system32\cmd.exe c:\windows\system32\sethc.exeReboot your computer and start the Windows installation where you forgot the administrator password.
  5. After you see the logon screen, press the SHIFT key five times.
  6. You should see a command prompt where you can enter the following command to reset the Windows password (see screenshot above):
    net user your_user_name new_password
    If you don’t know your user name, just type net user to list the available user names.
  7. You can now log on with the new password.
I recommend that you replace sethc.exe with the copy you stored in the root folder of your system drive in step 3. For this, you have to boot up again with Windows PE or RE because you can’t replace system files while the Windows installation is online. Then you have to enter this command:
copy /y c:\sethc.exe c:\windows\system32\sethc.exe

2011年10月27日 星期四

把瀏覽器當虛擬平台?

每次要跑虛擬機時,都要有一個Hypervisor,不管是原生或寄居架構,但不管是哪一種架構,總要有一個硬體平台吧?總要分配CPU、記憶體或磁碟空間吧?下面這個Linux,卻是真正把VM的層次拉高到最上層:瀏覽器。這是一個用Javascript重寫的Linux核心,而Javascript的執行平台正是瀏覽器!曾經有人懷疑這只是一個模擬Linux的介面而已,但現在已證實是真正的Linux核心了。


Fabrice Bellard是誰應該不用介紹了,是ffmpeg、QEMU的原創人,高中時就開發出LZEXE這個壓縮軟體,不但是有名的電腦工程師,也是有名的數學家,這邊可以看到Fabrice Bellard的維基介紹。

這個用Javascript寫出來的Linux不但可以執行,更可以用來學習Linux的指令,如vi等。大家就到

http://bellard.org/

到這邊來玩玩吧!

Reference:
http://vaemon.com/article/1363.html
http://www.softwarequalityconnection.com/2011/03/fabrice-bellard-portrait-of-a-superproductive-programmer/

不得不說,WP7開發的資料真的是太少了,國內有句話叫「天下文章一大抄」,查Application.GetResourceStream的用法,找遍了整個網絡,無非就那一兩篇,而且寫得還不完整,包括微軟官方的例子。在花了近半天的時間後,終於解決問題。
我們可以預先把程序中用到的資源,如圖片,音樂等放入項目中,打包進XAP文檔,需要的時候再從中取用。下面就說說具體實現方法。

第一步,把資料存進項目。
1、右鍵點擊項目名稱-新增-新建資料夾,這裡文件夾名以 Images 為例,把需要的圖片拖進來,當然你也可以不建,直接把圖片拖到根目錄底下。
2、選中剛剛拖進去的圖片,看右下角的屬性標籤,如果沒有,右鍵點圖片,選屬性,確認圖片屬性中的建置動作為 Resource。

第二步,程式呼叫。
1
System.IO.Stream src = Application.GetResourceStream(new Uri("/PhoneAppX;component/Images/abc.png", UriKind.Relative)).Stream;
關鍵在 Uri 的格式,PhoneAppX 是項目名稱,component 是固定路徑,Images/abc.jpg 才是圖片資源相對路徑,得到的是 Stream,在微軟官方的例子中,使用下面的方法來轉換成圖片:
1
2
3
4
            BitmapImage bi = new BitmapImage();
            bi.SetSource(src);
            Image img = new Image();
            img.Source = bi;
網路上的文章基本上都沒寫第一步,常常就卡在這裡,新增圖片還好,但是屬性的建置動作沒設好或改成其他屬性,導致程式在 Run 的時候常常丟出 Exception!


Reference To: http://www.pocketdigi.com/20110925/498.html