F5 Debug…

Building & Debugging the Technology!!!

Learn Windows Phone 7 Development in 31 Days

Posted by Karthikeyan Anbarasan on January 30, 2012


Welcome to the 31 Days of Windows Phone 7 Development (Mango Edition). Each day in the month of February 2012 we are going to see a topic on Windows Phone 7 development. These topics will range from level 100 to level 400 for Novice to Professionals to gets ideas on Windows Phone 7 application development and deployment to the Market Place with ease, to pass all the certification check lists that should be followed.

Each day you can expect the article to be published by 7:00 AM IST. Members can subscribe to the series and get the article directly to the subscribed mail id for easy accessibility. This page will be the HOME Page to access the articles list, each day when an article is published the respective day’s tile will be enabled and you can navigate to the respective article.

Readers can download the article source code and the article as pdf for offline reading from the options provided at the top of each article that are going to be published. In the list below, I have covered almost all the major topics which are required to develop an application with Windows Phone SDK 7.1(Mango). If you feel any other topic that will be useful but missing here, do leave me a comment so that I can include it as well.

Note – Issues related to downloading of PDF files and Source codes for Day 24 to Day 30 has been fixed with the right files. Thanks to the readers who noted the issue and reported.

Windows Phone 7 Articles

Getting Started with Windows Phone 72 Hello World3 Expression Blend4 Application Bar5 Alarms6 Contacts7 Calendar8 Camera9 Panaroma10 Pivot11 Media12 Toast Notification13 Tile Notification14 Raw Notification15 Tiles16 Launchers17 Choosers18 Navigation19 Web Browser20 Orientations21 BING Map22 Device Info23 Themes24 Isolated Storage25 Files and Folders26 Local Database27 OData Service28 WCF Service29 Security30 WP7 Tool Kit31 Market Place

Titles:

Learn Windows Phone 7 Development in 31 Days – Day 1 – Overview and Requirements of WP7
Learn Windows Phone 7 Development in 31 Days – Day 2 – Creating a Hello World Silverlight Application in WP7
Learn Windows Phone 7 Development in 31 Days – Day 3 – Using Expression Blend to Design the WP7 Application
Learn Windows Phone 7 Development in 31 Days – Day 4 – Working with Application Bar in WP7
Learn Windows Phone 7 Development in 31 Days – Day 5 – Working with Alarms/Reminders in WP7
Learn Windows Phone 7 Development in 31 Days – Day 6 – Working with Contacts in WP7
Learn Windows Phone 7 Development in 31 Days – Day 7 – Working with Calendar in WP7
Learn Windows Phone 7 Development in 31 Days – Day 8 – Working with Camera in WP7
Learn Windows Phone 7 Development in 31 Days – Day 9 – Working with Panorama Control in WP7
Learn Windows Phone 7 Development in 31 Days – Day 10 – Working with Pivot Application Control in WP7
Learn Windows Phone 7 Development in 31 Days – Day 11 – Working with Media in WP7
Learn Windows Phone 7 Development in 31 Days – Day 12 – Working with Toast Notification in WP7
Learn Windows Phone 7 Development in 31 Days – Day 13 – Working with Tile Notification in WP7
Learn Windows Phone 7 Development in 31 Days – Day 14 – Working with Raw Notification in WP7
Learn Windows Phone 7 Development in 31 Days – Day 15 – Working with Tiles in WP7
Learn Windows Phone 7 Development in 31 Days – Day 16 – Working with Launchers in WP7
Learn Windows Phone 7 Development in 31 Days – Day 17 – Working with Choosers in WP7
Learn Windows Phone 7 Development in 31 Days – Day 18 – Working with Navigation in WP7
Learn Windows Phone 7 Development in 31 Days – Day 19 – Working with Web Browser Control in WP7
Learn Windows Phone 7 Development in 31 Days – Day 20 – Working with Screen Orientation in WP7
Learn Windows Phone 7 Development in 31 Days – Day 21 – Working with BING Map Control in WP7
Learn Windows Phone 7 Development in 31 Days – Day 22 – Working with Device Information in WP7
Learn Windows Phone 7 Development in 31 Days – Day 23 – Working with Themes in WP7
Learn Windows Phone 7 Development in 31 Days – Day 24 – Working with Isolated Storage’s in Wp7
Learn Windows Phone 7 Development in 31 Days – Day 25 – Working with Files and Folders in WP7
Learn Windows Phone 7 Development in 31 Days – Day 26 – Working with Creating a Local Database in WP7
Learn Windows Phone 7 Development in 31 Days – Day 27 – Working with Consuming an ODATA Service in WP7
Learn Windows Phone 7 Development in 31 Days – Day 28 – Working with Consuming a WCF Service in WP7
Learn Windows Phone 7 Development in 31 Days – Day 29 – Working with Encrypting Data for Security in WP7
Learn Windows Phone 7 Development in 31 Days – Day 30 – Installing and using WP7 Tool kit for Silverlight
Learn Windows Phone 7 Development in 31 Days – Day 31 – Deploying the application to the WP7 Market place

Thanks for reading this tutorial and providing continuous support. If you like my blog and if you are interested in getting the latest updates on new articles, kindly follow me through one of these options.

F5Debug FacebookF5debug LinkedInF5debug TwitterF5debug GooglePlusF5debug RSSFeed

Posted in Windows Phone 7 | Tagged: , , , , , , , , , , , , , , , | 30 Comments »

101 How to’s on Windows Phone – Update to Readers

Posted by Karthikeyan Anbarasan on June 29, 2012


 

Friends,

I am keeping this series on hold for the release of the Windows Phone 8 update so that we can explore more on the new features. Initially when I started with Windows Phone and start with 2 series “Learn Windows Phone 7 Development in 31 Days” and “101 How to’s on Windows Phone” it was good that I got good response from the readers that things are put up easy to read and explore. With Microsoft news release on the new Windows Phone 8 in the Windows Phone Summit there will be a lot of enhancements that can be addressed with the new SDK. So we are going to hold this series for a while and once the new release is available we will start with the series once again and complete the 101 how to’s on Windows Phone.

Keep looking into the blog for the latest updates until then Keep Programming!!!

Posted in Mobile Technology, Windows Phone 7 | Tagged: , , , , , | Leave a Comment »

Getting Started with Windows Azure Media Services – Upload a media file (Asset) to Azure Media Service – #Meet Azure Edition

Posted by Karthikeyan Anbarasan on June 27, 2012


In this tutorial we are going to see how to upload a Video media file to the Windows Azure Media Service programmatically from the code using the Azure Media Services SDK for .Net. In Windows Azure Media Service the process of Uploading a media file or the asset to the Media Service is termed as Ingesting the Asset or media file. Basically when we upload a media file to the media service we use the IAsset to interface which has the collection of objects that has the metadata of the media file which we are going to upload. We need to use Asset to upload the media file and process the media, and at the same time we need to use the Asset again to output the media file to any device or any delivery medium.

Uploading the Asset we can do that in many ways like we can upload a single media file, or upload a collection of media files to a single asset or we can as well encrypt the asset and upload it to the media service based on the requirement. Encrypting a media file asset and uploading to the media service we have 3 possible options as AssetCreationoption enumeration which are None, StorageEncrypted and CommonEncryptionProtected.

  • None – Used when we want to provide the encryption option but the file should not be encrypted we can specify None.
  • StorageEncrypted  – Used when we want to encrypt a file and upload to the storage service (blob) we can specify this option.
  • CommonEncryptionProtected – Used when we want to encrypt a file which is already encrypted using Common Encryption Protected scheme

In order to start uploading the vide media file (Asset) to the Windows Azure media services we need to use the server context which we have used and connected to the Media Service in our earlier article (). Once we able to connect to the Media Services with the Account name and Account key we can upload the asset easily to the media service. Let us see the step by step on how to upload the video media file to the Windows Azure Media Services. Open the Media Services sample project which we used in our earlier article (Getting Started with Windows Azure Media Services – Connecting to Azure Media Services Programmatically – #Meet Azure Edition) and create a button control where on click event we will write our code to upload a sample video file to the Azure Media Services as shown in the screen below.

image

Now we are going to write a wrapper class which plays a major role in our application, this wrapper class will have the complete code listing for connecting to the Azure Media Services, Uploading and downloading Assets, Creating jobs, Streaming asset etc. which we will be keep on adding one by one in this series. First let us add the code to upload a media file, where we hardcode the media file which we are going to upload in the code itself as shown in the screens below.

image

Code:

private static CloudMediaContext cmContext = null;
private static readonly string strMsAccountName = ConfigurationManager.AppSettings["msAccountName"];
private static readonly string strMsAccountKey = ConfigurationManager.AppSettings["msAccountKey"];

MediaSevicesWrappercs msWrapper = new MediaSevicesWrappercs();

//Sample Implementations:
private static readonly string strSupportFiles = ConfigurationManager.AppSettings["msConfigFolder"];
private static readonly string strsingleInputFilePath = strSupportFiles + @"\MediaFiles\Video2.wmv";

private static readonly string strprimaryFilePath = strSupportFiles + @"\MediaFiles\Video1.wmv";
private static readonly string strinputFilesFolder = strSupportFiles + @"\MediaFiles";

 

Now let us add the wrapper class where we are going to implement the Asser upload method using the IAsset interface as shown in the code below.

Code:

public string CreateAndUploadAsset(CloudMediaContext CloudContext, string inputMediaFilePath)
        {
            string strResult;
            IAsset theAsset = CloudContext.Assets.Create(inputMediaFilePath);
            strResult = "AssetName :- " + theAsset.Name.ToString() + " \n" + "Asset Created Time :- " +  theAsset.Created.Date.ToString();
            return strResult;
        }
image

The above code will upload a single Asset to the Media Service, say if want to upload a number of media files from a directory we can use the below method which loops through the folder and uploads to the Media Services one by one as shown in the code below.

Code:

public string CreateAndUploadAssetsFromDirectory(CloudMediaContext CloudContext, string inputMediaFilesFolder, string primaryFilePath)
        {
            string strResult;

            strResult = "Files are uploading!!! \n";
           
            IAsset theAsset = CloudContext.Assets.CreateFromDirectory(inputMediaFilesFolder, primaryFilePath);

            strResult += "Finished uploading!!! \n";
            strResult += "Uploaded Asset ID :- " + theAsset.Id + "\n";
            strResult += "******FILES IN ASSET****** \n";

            foreach (IFileInfo file in theAsset.Files)
            {
                strResult += "File name :- " + file.Name + "\n";
                strResult += "Is a primary file :- " + file.IsPrimary + "\n";
                strResult += "File size :- " + file.ContentFileSize + "\n";
            }

            return strResult;
        }

image

The above code will internally loop through the folder and upload the media files as Assets to the Azure Media Services one by one. Also we can customize our code to check the uploading progress where we can see how much bytes are transferred for each and every upload limit. IAsset interface plays the key role in uploading the asset files to the media service with Method and CreateFromDirCreate ectory methods.

In the above codes we have seen the uploading of Assets which are plain without encryptions, if we want to upload by assigning an encryption method we need to make use of the below code which basically encrypts the file before uploading to the media service. Encryption options varies as we discussed in the above section as None, StorageEncrypted and CommonEncryptionProtected.

Code:

public string CreateAndUploadEncryptedAsset(CloudMediaContext CloudContext, string inputMediaFilePath)
        {           
            string strResult;
            IAsset theAsset = CloudContext.Assets.Create(inputMediaFilePath, AssetCreationOptions.StorageEncrypted);

            strResult = "Asset name :- " + theAsset.Name + "\n";
            strResult += "Time created :- " + theAsset.Created.Date.ToString() + "\n";
            strResult += "Encrypted status :- " + theAsset.Options.ToString() + "\n";

            return strResult;
        }

image

We can see we have assigned the encryption method as StorageEncrypted, this is the default encryption mechanism used. If we are not specifying any option also by default the SDK takes StorageEncrypted as the encryption mechanism. Now we need to write code to specify which media file to be used for uploading and which folder we will be used where media files resides. We are going to use the Azure Storage Explorer to identify if the media files are uploaded correctly. Write the below code which calls the wrapper and provide the required parameters that are very much required to process the Assets as shown in the code below.

Code:

private void button2_Click(object sender, RoutedEventArgs e)
        {
            if (cmContext == null)
            {
                cmContext = GetContext();
            }

            string strresult = msWrapper.CreateAndUploadAsset(cmContext, strsingleInputFilePath);
            tbResult.Text = strresult.ToString();           
        }

        private void button3_Click(object sender, RoutedEventArgs e)
        {
            if (cmContext == null)
            {
                cmContext = GetContext();
            }

            string strresult = msWrapper.CreateAndUploadAssetsFromDirectory(cmContext, strinputFilesFolder, strprimaryFilePath);
            tbResult.Text = strresult.ToString();   
        }

        private void button4_Click(object sender, RoutedEventArgs e)
        {
            if (cmContext == null)
            {
                cmContext = GetContext();
            }

            string strresult = msWrapper.CreateAndUploadEncryptedAsset(cmContext, strsingleInputFilePath);
            tbResult.Text = strresult.ToString();  

        }

image

Complete Code Listing:

MainWindow.Xaml.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using System.Configuration;
using Microsoft.WindowsAzure.MediaServices.Client;

namespace MeetAzureMediaServices
{
    public partial class MainWindow : Window
    {
        private static CloudMediaContext cmContext = null;
        private static readonly string strMsAccountName = ConfigurationManager.AppSettings["msAccountName"];
        private static readonly string strMsAccountKey = ConfigurationManager.AppSettings["msAccountKey"];

        MediaSevicesWrappercs msWrapper = new MediaSevicesWrappercs();

        //Sample Implementations:
        private static readonly string strSupportFiles = ConfigurationManager.AppSettings["msConfigFolder"];
        private static readonly string strsingleInputFilePath = strSupportFiles + @"\MediaFiles\Video2.wmv";

        private static readonly string strprimaryFilePath = strSupportFiles + @"\MediaFiles\Video1.wmv";
        private static readonly string strinputFilesFolder = strSupportFiles + @"\MediaFiles";

        public MainWindow()
        {
            InitializeComponent();
        }

        static CloudMediaContext GetContext()
        {
            return new CloudMediaContext(strMsAccountName, strMsAccountKey);
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                cmContext = GetContext();
                tbResult.Text = "Connection Successful!!!";
            }
            catch
            {
                tbResult.Text = "Connection Failed!!!";
            }
           
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            if (cmContext == null)
            {
                cmContext = GetContext();
            }

            string strresult = msWrapper.CreateAndUploadAsset(cmContext, strsingleInputFilePath);
            tbResult.Text = strresult.ToString();           
        }

        private void button3_Click(object sender, RoutedEventArgs e)
        {
            if (cmContext == null)
            {
                cmContext = GetContext();
            }

            string strresult = msWrapper.CreateAndUploadAssetsFromDirectory(cmContext, strinputFilesFolder, strprimaryFilePath);
            tbResult.Text = strresult.ToString();   
        }

        private void button4_Click(object sender, RoutedEventArgs e)
        {
            if (cmContext == null)
            {
                cmContext = GetContext();
            }

            string strresult = msWrapper.CreateAndUploadEncryptedAsset(cmContext, strsingleInputFilePath);
            tbResult.Text = strresult.ToString();  

        }

    }
}

MediaServicesWrapper.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.WindowsAzure.MediaServices.Client;

namespace MeetAzureMediaServices
{
    public class MediaSevicesWrappercs
    {
        //
        public string CreateAndUploadAsset(CloudMediaContext CloudContext, string inputMediaFilePath)
        {
            string strResult;
            IAsset theAsset = CloudContext.Assets.Create(inputMediaFilePath);
            strResult = "AssetName :- " + theAsset.Name.ToString() + " \n" + "Asset Created Time :- " +  theAsset.Created.Date.ToString();
            return strResult;
        }
       
        //
        public string CreateAndUploadAssetsFromDirectory(CloudMediaContext CloudContext, string inputMediaFilesFolder, string primaryFilePath)
        {
            string strResult;

            strResult = "Files are uploading!!! \n";
           
            IAsset theAsset = CloudContext.Assets.CreateFromDirectory(inputMediaFilesFolder, primaryFilePath);

            strResult += "Finished uploading!!! \n";
            strResult += "Uploaded Asset ID :- " + theAsset.Id + "\n";
            strResult += "******FILES IN ASSET****** \n";

            foreach (IFileInfo file in theAsset.Files)
            {
                strResult += "File name :- " + file.Name + "\n";
                strResult += "Is a primary file :- " + file.IsPrimary + "\n";
                strResult += "File size :- " + file.ContentFileSize + "\n";
            }

            return strResult;
        }

        public string CreateAndUploadEncryptedAsset(CloudMediaContext CloudContext, string inputMediaFilePath)
        {           
            string strResult;
            IAsset theAsset = CloudContext.Assets.Create(inputMediaFilePath, AssetCreationOptions.StorageEncrypted);

            strResult = "Asset name :- " + theAsset.Name + "\n";
            strResult += "Time created :- " + theAsset.Created.Date.ToString() + "\n";
            strResult += "Encrypted status :- " + theAsset.Options.ToString() + "\n";

            return strResult;
        }
    }
}

Now we are done with our code, as we mentioned we are going to use Azure Storage Explorer by connection to the storage services. Initially we don’t see any of the files available with in the storage services as we see in the below screen.

image

 

Now let us run the code and try to explore by clicking on each of the buttons which upload single asset file, multiple asset file and asset files with encryption one by one.

Single File Upload:

imageimage

 

Multiple File Upload:

imageimage

 

Encryption File Upload :

 

imageimage

Posted in Azure, SQL Azure, Windows Azure | Tagged: , , , , | Leave a Comment »

Getting Started with Windows Azure Media Services – Connecting to Azure Media Services Programmatically – #Meet Azure Edition

Posted by Karthikeyan Anbarasan on June 26, 2012


 

In this tutorial we are going to see how to programmatically connect to the Windows Azure Media Services using the Windows Azure Media Services SDK for .NET application development. In our earlier articles we have seen What is Windows Azure Media Services () and What are the steps to configure the Windows Azure Media Services Account (). Now in this tutorial we will write some code using the Visual Studio 2010 IDE and see how to connect to the Windows Azure Media Services and create a Cloud Context which is the key which holds all the necessary information of the entities that are used with the Azure Media Services from the application development perspective.

Open Visual Studio 2010 IDE and create a new Windows Application project or a WPF project with a valid project name, which be used in this series to explore the Windows Azure Media Services core features one by one as shown in the screen below.

image

Now let us design the page with some controls which basically required to connect to the Windows Azure Media Services using the CloudMediaContext class. The Server context provides the complete access to all the entities that are required to access the media objects like assets, files, jobs, tasks etc. Once we designed our screen it looks like below.

image

Next step is to add the Media Services reference, we can see the reference dll (Microsoft.WindowsAzure.MediaServices.Client.dll) available on the location of the SDK installed in the development environment i.e. C:\Program Files (x86)\Microsoft SDKs\Windows Azure Media Services\Services\v1.0 as shown in the screen below.

image

Next step is to add a APP.Config file where we are going to provide the Account Name and Account Key as the configuration which can be changed later based on the needs as shown in the screen below.

image

Now in the code behind declare a private variable and get the account name and the account key which can be used while creating an instance of the CloudMediaContext as shown in the code below. CloudMediaContext class provides the complete details of the entities that can be used in the application to manipulate the media object to its needs.

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Configuration;
using Microsoft.WindowsAzure.MediaServices.Client;

namespace MeetAzureMediaServices
{
    public partial class MainWindow : Window
    {
        private static CloudMediaContext cmContext = null;
        private static readonly string strMsAccountName = ConfigurationManager.AppSettings["msAccountName"];
        private static readonly string strMsAccountKey = ConfigurationManager.AppSettings["msAccountKey"];

        public MainWindow()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            cmContext = GetContext();                     
        }

        static CloudMediaContext GetContext()
        {
            return new CloudMediaContext(strMsAccountName, strMsAccountKey);
        }
    }
}

image

Now we are done with the code, we can build and execute the project, we can see the application run successfully without any errors. We will not see any expected output as we are not catching any of the details to show as an output, but yes we have created a CloudMediaContext which has all the entities that can be utilized as per the requirement which we can see the list of entities available using the debugging mode as shown in the screen below.

image

So here in this tutorial we have seen how to programmatically connect to the Windows Azure Media Service and create a context holding the entities that are used to manipulate the required media objects as per the requirement. That’s it from this tutorial, see you all in the next blog of this series until then Happy Programming!!!

Posted in Azure, SQL Azure, Windows Azure | Tagged: , , , , | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.

Join 88 other followers

%d bloggers like this: