Detecting theme on Windows Phone 7

0

This blog post is going to teach you how do we detect if we are on dark or light theme on Windows Phone 7. I realised that this will be useful because I have quite some friends who are asking me about it because they didn’t get the right resources online. If you happened to come across a resource that asks you to get from App.xaml, that doesnt work anymore as its removed after the RC build.

Based on Theme Resources for Windows Phone, under Theme Visibility and Opacity.
By checking Resources, I am able to check if its Visible or Collapsed for the dark or White theme by doing this

Visibility isLight = (Visibility)Resources["PhoneLightThemeVisibility"]; // for light theme
Visibility isDark = (Visibility)Resources["PhoneDarkThemeVisibility"]; // for dark theme

Then we use if else to check,

if (isLight == System.Windows.Visibility.Visible)
{
//We are on light theme
}

Light Theme

or

if (isDark == System.Windows.Visibility.Visible)
{
//We are on dark theme
}

Dark Theme

Attached is a sample code to show how do I detect Windows Phone 7 theme, before the Mango buuild ( I am unsure if there is a change after Mango ).
Detect Theme on Windows Phone 7 Sample

Interesting fan-made “We Love Windows Phone” video!

0

Was watching it this morning! Cool. Video done by Brandon Foy! :)

Cannot ping Windows Server 2008 R2

0

Earlier this week, Kay Howe and I are trying to troubleshoot the connectivity between the server and the client and we realised that we cant ping the ip from command prompt but we were *so certain* that there is nothing that is blocking it and the LAN are connected properly. After some struggle, we realise that Windows Firewall does not allow incoming ICMP Echo messages, and therefore the computer cannot send an ICMP Echo Reply in response.

Allowing incoming ICMP Echo messages in Windows Firewall will allow others to ping your computer but note that your server might then be vulnerable to attackes that make uses of ICMP Echo messages like Ping Flood. Do disable it when you dont need them.

To enable ICMP Echo messages, enable the inbound custom rules to allow ICMPv4 and ICMPv6 Echo Request packets.

1. Go to Control Panel

Windows Server 2008 R2 Control Panel

Windows Server 2008 R2 Control Panel

2. Go to System and Security

Windows Server 2008 R2 System and Security

Windows Server 2008 R2 System and Security

3. Select Windows Firewall

Windows Server 2008 R2 Windows Firewall

Windows Server 2008 R2 Windows Firewall

4. Select Inbound Rules

Windows Firewall Inbound Rules

Windows Firewall Inbound Rules

5. Under File and Printer Sharing (Echo Request – ICMPv4-In) , right click on it and enable rules.

Windows Firewall Enable Rules

Windows Firewall Enable Rules

6. Under File and Printer Sharing (Echo Request – ICMPv6-In) , right click on it and enable rules.

Afterwhich, you should be able to ping the server, its recommended that you disable the rule after use.

Slime Sweeper

0

In March, the Windows Phone 7 game created by Juan Kristoffer Mancuyas Sanio, Delconi Quek Si Qi, Lim Guo Hong and Steven Li Yan, interns of Microsoft School Technology Innovation Center is finally released to the Windows Phone 7 Marketplace! Its one of our mini-project which we decided to do during our free time.

Slime Sweeper Title Page

Slime Sweeper Title Page

Slime Sweeper Game Play

Slime Sweeper Game Play

Slime Sweeper Game Over Page

Slime Sweeper Game Over Page

Slime Sweeper How to Play Screen

Slime Sweeper How to Play Screen

I understand from reviews that this application seems to be crashing on some of the phone, I am looking into it and hope to release another version to fix that bug. :)

We have looking into creating more slime related games! Stay tune! Contact me if you are interested. :)

Download Link to Slime Sweeper on Zune

Connecting to SQL Azure with PHP

2

To start, I would like to first say that although many PHP developers usually recommend MySQL as the accompanying database for PHP, it is not difficult to interface PHP with other databases such as SQL Azure, Microsoft’s cloud-based relational database offering.

PHP connects with SQL Azure in a similar manner as how it does with Microsoft SQL Server, ie through an interface known as the Open Database Connectivity (ODBC), which is actually the standard software interface for accessing databases. Each platform and database has its own implementation following the ODBC standard but for this tutorial, I’ll focus on PHP.

There are a few ways to connect your php site to MS SQL but the 2 main approaches are as shown in Figure 1.0.

1. Using the “php_mssql.dll” php extension requiring MS SQL Client Tools installed (Figure 1.0, right column).
2. Using the “sqlsrv” driver (“Microsoft Drivers for PHP for SQL Server”) requiring MS SQL Native Client installed (Figure 1.0, left column)


Figure 1.0

I will be using the 2nd approach for this tutorial because it supports both PHP 5.2 and 5.3, unlike the 1st which is not available for PHP 5.3.

Microsoft Drivers for PHP for SQL Server
As of 1 February 2011, the latest version of the driver is version 2.0.1 (30 November 2010).
You can grab it from http://www.microsoft.com/downloads/en/details.aspx?FamilyID=80e44913-24b4-4113-8807-caae6cf2ca05
Once you have installed the drivers, you should see the following in the installation directory:


Figure 2.0

We will be using the “php_sqlsrv_53_nts_vc9.dll” library for this tutorial.
• “php_sqlsrv” –> Driver name
• “53” –> PHP 5.3
• “nts” –> Non-thread safe (The PHP FastCGI Handler of IIS handles thread-safe operations for PHP, use the non-thread safe version to reduce performance issues)
• “vc9” –> Library compiled using VS 2008, use vc6 (VS 6) if PHP is running on Apache
Configure PHP
1. Copy “php_sqlsrv_53_nts_vc9.dll” into the “ext” folder of your php installation directory.
2. Edit the php.ini to include the library


Figure 3.0


Microsoft SQL Server 2008 R2 Native Client
In order for the PHP for SQL Server Drivers to work, the necessary SQL Server ODBC drivers must be installed on the web server.
The version of the ODBC driver needed for SQL Azure comes with the SQL Server 2008 R2 Native Client.
You can grab it from http://www.microsoft.com/downloads/en/details.aspx?FamilyID=ceb4346f-657f-4d28-83f5-aae0c5c83d52

PHP Syntax
After all the preparation and configuration, here comes the actual thing -> Coding!
This tutorial showcases how to do simple CRUD (Create, Retrieve, Update, Delete) commands.
1. Connect to Database:

$serverName = “servername.database.windows.net”;
$connInfo = array(“UID”=>”username@servername”,
“PWD”=>”password”,
“Database”=>”databasename”);
$conn = sqlsrv_connect($serverName, $connInfo);

2. Insert data to Database (taking data from a html form text field):

$comment = $_POST["txtComment"];
$comm = “INSERT INTO commentsqlazure (commentContent) VALUES (?)”;
$stmt = sqlsrv_prepare($conn, $comm, array(&$comment));
$result = sqlsrv_execute($stmt);

3. Update data in Database:

$Id = $_POST["txtUpdateId"];
$comment = $_POST["txtUpdateComment"];
$comm = “UPDATE commentsqlazure SET commentContent = ? WHERE id = ?”;
$stmt = sqlsrv_prepare($conn, $comm, array(&$comment, &$Id));
$result = sqlsrv_execute($stmt);

4. Remove data from Database:

$Id = $_POST["txtRemoveId"];
$comm = “DELETE FROM commentsqlazure WHERE id = ?”;
$stmt = sqlsrv_prepare($conn, $comm, array(&$Id));
$result = sqlsrv_execute($stmt);

5. Retrieve data from Database:

$comm = “SELECT id, commentContent FROM commentsqlazure”;
$stmt = sqlsrv_query($conn, $comm);
while($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC))
{
echo $row["id"].” “.$row["commentContent"].”
“;
}

6. Close connection and release resources:

sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);

You can download the project file from here.
http://cid-29f099c37b76ca59.office.live.com/browse.aspx/Blog/Code%20Guide/SQL%20Azure?uc=1

Please take note that you have to change the Server Name, Username, Password at the connection string to make this work. You should run the following script to the table first.
http://cid-29f099c37b76ca59.office.live.com/self.aspx/Blog/Code%20Guide/SQL%20Azure/SQLAzureConnection.sql

Credit to Luke Ng.

Connecting to SQL Azure with ASP.NET

0

Recently, I have been working with Windows Azure and SQL Azure for my new project and because of this, a good amount of developer friends came to me and wanted me to share more about it hence I decided to write it down as a blog post for anyone who is interested to know about it.

What is SQL Azure?
SQL Azure is Microsoft’s Relational Database offering on the Cloud. It is build from the foundation of SQL Server It helps to actually ease the provisioning and deployment of many databases. It is easily scalable per se.

This blog post is going to show you how easy is it for you to connect to SQL Azure, it actually works the same way as a normal SQL Server Connection, the main difference is the connection string. The username is your username setup at SQL Azure @ Server name. You can download the full sample project with CRUD ( Create, Retrieve, Update, Delete ) at the end of this post.

///
/// Connection to SQL Azure Database
///
public void ConnectToDatabase()
{

//Connection String
//data source=SERVER URL;
//initial catalog= Database name;
//User ID=User ID @ Server Name;
//Password=Password;
string connectionString = “data source=quxm9ku7nz.database.windows.net;initial catalog=fiveaboutme;User ID=guohong@quxm9ku7nz;Password=*****;”;
if (conn.State != ConnectionState.Open)
{
conn.ConnectionString = connectionString;
conn.Open();
comm.Connection = conn;
}
comm.Parameters.Clear();
}

You can download the project file from here.
http://cid-29f099c37b76ca59.office.live.com/self.aspx/Blog/Code%20Guide/SQL%20Azure/SqlAzureConnection.zip

Please take note that you have to change the Server Name, Username, Password at the connection string to make this work. You should run the following script to the table first.
http://cid-29f099c37b76ca59.office.live.com/self.aspx/Blog/Code%20Guide/SQL%20Azure/SQLAzureConnection.sql

How to use Back Button on Windows Phone 7

1

Credit to Steven, http://www.sticapac.com for allowing me to post this up on my blog.

Recently, I worked on an app for the Windows Phone 7 platform and submitted it to the marketplace for certification. I’ve learnt many things and gained many insights after going through this process and would like to share one of these with you, developers and potential developers of the Windows Phone 7 platform.

Throughout this post, I will be making references to the official Windows Phone 7 Application Certification Requirements document (WP7ACR) which can be downloaded athttp://go.microsoft.com/?linkid=9730558.

Under Section 5.2.4 of the WP7ACR, clause a, it is stated that:

Pressing the Back button from the first screen of an application must exit the application.

Developers who are creating apps with multiple pages must give special attention to this clause because pressing the back button automatically brings the user to the previous page, regardless of whether the user is at the first screen or not. Consider the following example:

In this app, there are 2 pages. Page1 goes to Page2 via a button with the following logic:

NavigationService.Navigate(new Uri(“/Page2.xaml”, UriKind.Relative));

Page2 goes back to Page1 via a button with the following logic:

NavigationService.Navigate(new Uri(“/Page1.xaml”, UriKind.Relative));

Each time that line of code is executed, it is actually creating a new instance of the page defined under the new Uri. Therefore if the user navigates in this manner:

  1. User starts the app.
  2. User navigates to Page2 via button.
  3. User navigates to Page1 via button.

At this point in time, the user is at the first page of the application. If the user presses the back button, he will be brought back to Page2 instead of exiting the app, which is wrong and will result in a failure of the certification process.

There is no API in the Windows Phone 7 SDK similar to the Application.Exit() function found in the average C#.NET Windows Forms application. For this reason, we must overcome this problem by navigation by page hierarchy. That is to say, when the user navigates from Page2 to Page1 via the button, instead of treating Page1 as a new page, the developer should instead use this line of code for the navigation purpose from Page2 back to Page1:

NavigationService.GoBack();

By doing this, the developer is essentially coding the button to function exactly like what the back button does on the Windows Phone. In this way, the app will always exit when the back button is pressed on the first page because the first page is always the only record under the action history when the user is on the first page. The diagram will then look like this:

Therefore we have successfully adhered to Section 5.2.4 of the WP7ACR, clause a. This is how we can effectively use the Back button and pass certification for functions relating to the back button.

Congratulation

0

As some of you might know, I did wushu last time. Wushu is a sport which I am still very passionate about. On Sunday, I went down to support my brothers and friends whom are competiting in the 3rd World Junior Wushu Championships held in Singapore, Jurong East Sports Complex.

I see the routine which they performed out on the blue carpet is of highest international standard, all the competitiors spent alot of time, sweat and even blood to ensure that the routine they demostrate is of the competitive standard. I know the type of hardship they underwent. No matter you win or lose, congratulate to everyone of you.

Special mention to Jaryl, Jowen, Ren Zoe, Hui Xin. =) Sorry that I didnt make it down to support everyone of you during your events.

Blog reopen and 7 tips to be happy

0

Well, I somehow got my blog reopen again but I lost 3 months worth of data… good job Guo Hong.
I am moving this blog back to Hostgator soon then do some rework on this blog.

Was reading the newspaper a moment ago and they are saying about 7 tips on how to be happy, useful for me.

  1. Do more volunteer work.
  2. Interact with your family and friends at least 6 hours a day.
  3. Average work hour per week at 37 hours and at least 6 weeks of holiday every year.
  4. At least 2k salary monthly ( I don’t know why.. )
  5. Breakfast should not contain any meat.
  6. Sleep at least 7-8 hours daily.
  7. Exercise at least half an hour daily, preferably before noon time.

Continuing codeXtremeApp Application

0

After talking to Mr Yeak, it seems like we will continue and fix all the bugs of the application which we had created during the codeXtremeApp 2010 competition, A green application. :) Great! Our focus of our major project will still be Savior though.

On 2 side note,
1. Seems like I am really going to be sick soon, keep coughing. Esp after watching Inception. It wasnt that bad this afternoon. Inception is a nice movie!
2. Finally, i am only left with mysql to move before I can move limguohong.com to a Windows Server! Hope that the index.php problem will not happen.

Go to Top