Presented in Barcamp9 and Global Windows Azure Boot camp

On Saturday 27th April 2013 I presented in two different events in Gurgaon India.

image

Cross Platform Mobile App Development

This was my first session of day. It was in SAP lab Gurgaon. To be honest this event surprised me lot. There was around 200+ audience. My session was in Track 2. I had around 100+ audience in my session. Audience were very active and their participation was overwhelming. I started my presentation in my usual way from story and then concluded with demo. In session I covered following topics,

  • What is Cross Platform Mobile Application
  • How it is different than Native Apps
  • Introducing PhoneGap and Icenium
  • In demo creating Twitter Search Application

Windows Azure Mobile Service

This was my second session of day. It was in Microsoft Gurgaon. This event was led by Windows Azure MVP Gaurav Mantri. He hosted whole day with great professionalism and effectiveness. In this global event I had an opportunity to present on Windows Azure Mobile Service. I focused on Data part of Windows Azure Mobile Service. In session I covered following topics

  • Introduction to Windows Azure Mobile Services
  • Getting stated with Windows Azure Mobile Services Data
  • Data from Windows Azure Mobile Services in XAML based Windows Store App
  • Data from Windows Azure Mobile Services in JavaScript based Windows Store App

Find below presentation from session,

See you soon in next seminar.

Fetching Windows Azure Mobile Services Data in XAML based Windows Store Application

In last post we started learning about Windows Azure Mobile Service in XAML based Windows Store Application. Read it here

In last post we learnt

  • Configuring Window Azure Mobile Service in portal
  • Consuming Windows Azure Mobile Service in Windows Store Application
  • Insert a record from application in Windows Azure Mobile Service data table.

In this post we will take a look on fetching records from table. I recommend you to follow Part 1 of this series here . I will start from where I left in part 1.

Let us design application page. There are two buttons. On click of first button we will fetch all data. On click of second button filtered data will fetched. Let us design application page as following


<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}" >
 <Grid.RowDefinitions>
 <RowDefinition Height="*" />
 <RowDefinition Height="*" />

 </Grid.RowDefinitions>

<StackPanel Orientation="Vertical" Grid.Row="0">
 <Button x:Name="btnFetch" Click="btnFetch_Click_1" Content="Get Data" Height="72" Width="233"/>
 <GridView x:Name="lstBloggers" >
 <GridView.ItemTemplate>
 <DataTemplate>
 <StackPanel Orientation="Horizontal">
 <TextBlock Text="{Binding Name}" />
 <TextBlock Text="{Binding Technology}" />
 </StackPanel>
 </DataTemplate>
 </GridView.ItemTemplate>
 </GridView>
 </StackPanel>
 <StackPanel Orientation="Vertical" Grid.Row="1">
 <StackPanel Orientation="Horizontal">
 <TextBox x:Name="txtSearch" Height="59" Width="436" />
 <Button x:Name="btnFilterfetch" Click="btnFilterfetch_Click_1" Content="Get Filtered Data" Height="72" Width="233"/>
 </StackPanel>
 <ListView x:Name="lstFilterBloggers" Margin="368,20,271,-599">
 <ListView.ItemTemplate>
 <DataTemplate>
 <StackPanel Orientation="Horizontal">
 <TextBlock Text="{Binding Name}" />
 <TextBlock Text="{Binding Technology}" />
 </StackPanel>
 </DataTemplate>
 </ListView.ItemTemplate>
 </ListView>
 </StackPanel>
 </Grid>

Yes this is not one of the best UI we can create but any way creating highly immersive UI is not purpose of this post. Right now UI will look like below image

image

Now to fetch all the records you need to follow following steps

Define Global variables


MobileServiceClient client;
 MobileServiceCollectionView<TechBloggers> items;
 MobileServiceCollectionView<TechBloggers> filteredItems;
 IMobileServiceTable<TechBloggers> bloggerstable;


You need to create mobile service table client in application. That can be created as following


public MainPage()
 {
 this.InitializeComponent();
 MobileServiceClient client = new MobileServiceClient("https://youappurl", "appkey");
 bloggerstable = client.GetTable<TechBloggers>();

 }

&nbsp;

Next you need to create entity class representing table from the Windows Azure Mobile Service. Let us create entity class as following. We are creating entity class TechBloggers.


public class TechBloggers
 {
 public int id { get; set; }
 [DataMember(Name="name")]
 public string Name { get; set; }
 [DataMember(Name = "technology")]
 public string Technology { get; set; }

}

On click event of button you can fetch all data from Mobile Service Table as following


private void btnFetch_Click_1(object sender, RoutedEventArgs e)
 {

items = bloggerstable.ToCollectionView();
 lstBloggers.ItemsSource = items;

}

You can fetch filtered data as following. We are filtering data on search term given in textbox.

private void btnFilterfetch_Click_1(object sender, RoutedEventArgs e)
 {
 filteredItems = bloggerstable.Where
 (blogger => blogger.Technology == txtSearch.Text)
 .ToCollectionView();
 lstFilterBloggers.ItemsSource = filteredItems;

 }

&nbsp;

When you run application you will find all data and filtered data as following

image

In this way we can fetch data from Windows Azure Mobile Service. In next post we will get into update and deletion of record. I hope this post useful. Thanks for reading.

Step by Step working with Windows Azure Mobile Service Data in XAML based Windows Store Apps

In this post we will take a look on working with Windows Azure Mobile Service in XAML based Windows Store Application. We will follow step by step approach to learn goodness of Windows Azure Mobile Service. In first part of post we will configure Windows Azure Mobile Service in Azure portal. In second part of post we will create a simple XAML based Windows Store application to insert records in data table. This is first post of this series and in further posts we will learn other features of Windows Azure Mobile Services.

Configure Windows Azure Mobile Service on Portal

Step 1

Login to Windows Azure Management Portal here

Step 2

Select Mobile Services from tabs in left and click on CREATE NEW MOBILE SERVICE

image

Step 3

In this step provide URL of mobile service. You have two choice either to create mobile service in existing database or can create a new database. Let us go ahead and create a new database. In DATABSE drop down select option of Create New SQL database instance. Select SUBSCRIPTION and REGION from drop down as well.

image

Step 4

On next screen you need to create database. Choose either existing database server or create a new one. You need to provide credential to connect with database servers.

image

Step 5

After Successful creation of mobile services you need to select platform. Let us go ahead and choose Windows Store as platform

image

Step 6

After selecting platform click on Data in menu. After selecting Data click on ADD A TABLE

image

Next you need to provide Table name. You can provide permission on table. There are three options available

  1. Anybody with Application Key
  2. Only Authenticated Users
  3. Only Scripts and Admins

Let us leave default permission level for the table.

image

Step 7

Next click on tables. You will be navigated to table dashboard. When you click on Columns you will find one default created column id. This column gets created automatically. This column must be there in Windows Azure Mobile Service table.

image

On enabling of dynamic schema when you will add JSON objects from client application then columns will get added dynamically.

Create Windows Store Application in XAML

Very first you need to install Windows Azure SDK for Windows Phone and Windows 8.

image

After installing create a Windows Store Application by choosing Blank App template.

image

Before we move ahead to create Windows Store App let us go back to portal and mange App URL and key. You need key and application URL to work with Windows Azure Mobile Services from Windows Store application. You will find key and application URL at the portal.

image

Now go ahead and add following namespaces on MainPage.xaml.cs


using Microsoft.WindowsAzure.MobileServices;
using System.Runtime.Serialization;

Next you need to create entity class representing table from the Windows Azure Mobile Service. Let us create entity class as following. We are creating entity class TechBloggers.


public class TechBloggers
 {
 public int id { get; set; }
 [DataMember(Name="name")]
 public string Name { get; set; }
 [DataMember(Name = "technology")]
 public string Technology { get; set; }

}

After creating entity class go ahead and global variables.


MobileServiceClient client;
 IMobileServiceTable<TechBloggers> bloggerstable;

Once global variable is defined in the constructor of page you need to create instance of MobileServiceClient and MobileServiceTable. Let us go ahead and create that in constructor of the page.


public MainPage()
 {
 this.InitializeComponent();
 MobileServiceClient client = new MobileServiceClient("https://youappurl", "appkey");
 bloggerstable = client.GetTable<TechBloggers>();

 }

Now let us go back and design app page. On XAML let us put two textboxes and one button. On click event of button we will insert bloggers in the table.


<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}" >
 <Grid.RowDefinitions>
 <RowDefinition Height="100" />
 <RowDefinition Height="100" />
 <RowDefinition Height="100" />
 </Grid.RowDefinitions>
 <StackPanel Grid.Row="0" Orientation="Horizontal" Margin="40,40,0,0">
 <TextBlock Text="Name" FontSize="40" />
 <TextBox x:Name="txtName" VerticalAlignment="Top" Width="400" />
 </StackPanel>
 <StackPanel Orientation="Horizontal" Grid.Row="1" Margin="40,40,0,0">
 <TextBlock Text="Technology" FontSize="40" />
 <TextBox x:Name="txtTechnology" VerticalAlignment="Top" Width="400" />
 </StackPanel>

 <Button Grid.Row="2" x:Name="btnInsert" Click="btnInsert_Click_1" Content="Insert Record" Height="72" Width="233" Margin="248,42,0,-14" />

 </Grid>

Application will look like as given in below image. I know this is not best UI. Any way creating best UI is not purpose of this post

image

On click event of button we can insert a record to table using Windows Azure Mobile Services using following code


private void btnInsert_Click_1(object sender, RoutedEventArgs e)
 {

TechBloggers itemtoinsert = new TechBloggers
 {
 Name = txtName.Text,
 Technology = txtTechnology.Text
 };

InserItem(itemtoinsert);

}

InsertItem function is written like following,

private async void InserItem(TechBloggers itemtoinsert)
 {

await bloggerstable.InsertAsync(itemtoinsert);

 }

On click event of button you can insert records in Windows Azure Mobile Service data table. To verify inserted records browse to portal and click on table.

image

In further posts we will learn update, delete and view of the records. I hope you find this post useful. Thanks for reading.

Steps to Enable Windows Azure Mobile Services

In this post we will take a step by step look on enabling Windows Azure Mobile Services in Windows Azure portal. To enable it login to Windows Azure Management Portal
After successful login to the portal in the bottom click on the New button.

 

image

On clicking of the NEW button under the COMPUTE tab, you need to select MOBILE SERVICES

image

You will get a screen with description of Mobile Services. Click on Try Now to enable Window Azure Mobile Services

image

In last step you will be prompted to select subscription and provide quick access token. However quick access token is optional.

image

In this way we can enable Windows Azure Mobile Services. I hope you find this post useful. Thanks for reading.