Announcement for Windows Azure at Build : What is new ?

In Build couple of interesting stuff on Windows Azure got announced. They are as below,

image

 

Windows Azure Toolkit for Windows 8

Download: http://watwindows8.codeplex.com/

 

image

 

It helps to create Metro style applications that may harness capability of Windows Azure . This toolkit contains

  • Application creation guidance
  • Tooling support for Visual studio project template
  • Code as reusable service and libraries

Toolkit supports

  • HTML 5
  • Javascript
  • Net
  • C#
  • C++
  • VB

Windows Azure SDK 1.5

image

Windows Azure SDK 1.5 is having updates as below,

  • New Emulator for better adherence between local and cloud development
  • Ability to upload service certificate to csupload.exe
  • Enhance Windows Azure tools for development and debugging
  • ASP.Net MVC 3.0 web roles
  • Multiple service configurations in one cloud project
  • Improved Windows Azure package to catch common errors

Windows Azure Storage

image

Updated version is having below features

  • Geo replication for Azure table and BLOB. This will replicate data between two locations.
  • New version of REST API to enable functionality improvements for Windows azure Blob, Tables and Queues

 

Windows Azure Management API

Updated Windows Azure Management API having features as below

  • Ability to roll back in progress configuration updates.
  • Ability to roll back in progress service updates.
  • Ability to perform multiple writes operation on ongoing deployment.
  • . More descriptive status for role instances
  • New API method : Get Subscription

Windows Azure Marketplace

 

image

  • New Windows Azure Marketplace would be available in 25 different countries
  • Microsoft Translator API will be available through Market Place
  • Translator can translate in 35 different languages.

Service Bus

image

 

  • Improved pub/sub messaging by new features Queues
  • Improved pub/sub messaging by new features Topics
  • Improved pub/sub messaging by new features Subscriptions
  • Improved pub/sub messaging by new features Rules
  • Asynchronous cloud eventing
  • Event driven Service Oriented architecture
  • Advanced intra app messaging

Enjoy Smile new Windows Azure features.  Smile

 

I hope this post was useful. Thanks for reading J If you find my blogs useful you may like to follow me on twitter http://twitter.com/debug_mode or may like Facebook page of this blog http://www.facebook.com/DebugMode.Net

If you want to see post on a particular topic please do write on FB page or tweet me about that, I would love to help you.

Silverlight 5 Multi Column and Linked Text

If you are designer of text and love to play around text formatting’s, then you would love to use Multi Columns and Link text in Rich Text Box. This feature gives your ability to display overflowed content in next box or column rather than using scroll bar to read through all the content.

While working with RichText Box you had option that If paragraphs and text is more than height and width of RichText Box you show then using scroll bars. Now in Silverlight 5, you can link overflowed content to next column or box.

If you link text in multi columns, you will get expected output as below,

image

All columns [You may say box as well] all linked to each other. You can put boxes as you want. In above case three boxes are in three different columns, if you want you can put Column2 and Column 3 in same columns.

If you have a RichTextBox like below and this may be having many contents.

image

Now you want to link this RichText Box with RichTextOverFlow such that overflow content will be displayed in next box.

image

It can be done as below,

image

This is very nice feature you can use to create multicolumn content. For your reference source code of output, I shown earlier is given blow,


<UserControl x:Class="SilverlightApplication9.MainPage"
xmlns="<a href="http://schemas.microsoft.com/winfx/2006/xaml/presentation"></a>"
xmlns:x="<a href="http://schemas.microsoft.com/winfx/2006/xaml">http://schemas.microsoft.com/winfx/2006/xaml</a>"
xmlns:d="<a href="http://schemas.microsoft.com/expression/blend/2008"></a>"
xmlns:mc="<a href="http://schemas.openxmlformats.org/markup-compatibility/2006"></a>"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">

<Grid x:Name="LayoutRoot" Background="White">
<RichTextBlock x:Name="FirstBox"
HorizontalAlignment="Left"
Width="100"

OverflowContentTarget="{Binding ElementName=SecondBox}"
Margin="33,0,0,0">
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
<Paragraph>what we are going to do with our attitude does matter ...</Paragraph>
<Paragraph>what we are going to do with our attitude does matter.</Paragraph>
</RichTextBlock>
<RichTextBlockOverflow  x:Name="SecondBox" HorizontalAlignment="Right"
Width="100"
OverflowContentTarget="{Binding ElementName=ThirdBox}"
Margin="0,0,45,250">

</RichTextBlockOverflow>
<RichTextBlockOverflow x:Name="ThirdBox"
HorizontalAlignment="Right"
Width="100"
Margin="0,0,194,195">
</RichTextBlockOverflow>
</Grid>
</UserControl>

I hope this post was useful. Thanks for reading Smile

If you find my blogs useful you may like to follow me on twitter http://twitter.com/debug_mode or may like Facebook page of this blog http://www.facebook.com/DebugMode.Net

If you want to see post on a particular topic please do write on FB page or tweet me about that, I would love to help you.

Context switching in Windows Phone 7

Note : This post has not adhered to the  best practice to acheive  Context Switching….. This is not best practice

Very first let us understand what I mean by word “Context Switching “here?

Context switching in context of this post is essentially, navigate back to the page from where application got deactivated.

image

There are three steps we need to do to perform above task  Smile

  1. Find the URL of current page while deactivating the application
  2. Save the URL in isolated storage while deactivating the application
  3. At application activating or launching set the start page of application dynamically by reading URL of the page from isolated state.

Define isolated storage setting globally in app.xaml


public IsolatedStorageSettings isoStorage = IsolatedStorageSettings.ApplicationSettings;

Find URL of current page and store in application deactivated event

You can find URL of current page in deactivated event as below in Application Deactivated event. Read it and store it in isolated storage.


 private void Application_Deactivated(object sender, DeactivatedEventArgs e)
        {
            Uri currentUri = ((App)Application.Current).RootFrame.CurrentSource;
            isoStorage["data"] = currentUri.OriginalString;

        }

Read and set the start page in application activated event

Next step you need to do is on the application activated event

  1. Read value of current URI from isolated storage
  2. If read value is null then set the MainPage.xaml as start page of the application
  3. Else set the read value as start page of the application

   private void Application_Activated(object sender, ActivatedEventArgs e)
        {

            string CurrentURI = (string)isoStorage["data"];
            if (CurrentURI != "")
            {
                Uri uritoNavigate = new Uri(CurrentURI, UriKind.Relative);
                ((App)Application.Current).RootFrame.Navigate(uritoNavigate);
            }
            else
            {

                 Uri nUri = new Uri("/MainPage.xaml", UriKind.Relative);
                ((App)Application.Current).RootFrame.Navigate(nUri);

            }

You need to perform same steps in application launching event also as of application activated event.


   private void Application_Launching(object sender, LaunchingEventArgs e)
        {
            if (IsolatedStorageSettings.ApplicationSettings.Contains("data") == false)
            {
                isoStorage.Add("data", "/MainPage.xaml");
            }
            string CurrentURI = (string)isoStorage["data"];
            if (CurrentURI != "")
            {
                Uri nUri = new Uri(CurrentURI, UriKind.Relative);

                ((App)Application.Current).RootFrame.Navigate(nUri);
            }
            else
            {

                Uri nUri = new Uri("/MainPage.xaml", UriKind.Relative);
                ((App)Application.Current).RootFrame.Navigate(nUri);

            }

        }

Remove isolated storage value in application closing event


  private void Application_Closing(object sender, ClosingEventArgs e)
        {
            isoStorage["data"] = "";
            isoStorage.Remove("Data");
        }

This is all you need to add in App.Xaml.cs file to perform context switching in your application.

Getting URL of current page in Windows Phone dynamically through code

Have you ever come across the requirement to fetch the URL of content current displaying on? Let us say there are 5 pages in your application and user is navigating across them. At any point of time if you want to fetch the URL of current page you can very much do that.

image

Above line of code will fetch URL of current page.

Imagine a scenario in which you need to fetch current page while deactivating the application. So you may do that as below,

 


private void Application_Deactivated(object sender, DeactivatedEventArgs e)
        {
            Uri currentUri = ((App)Application.Current).RootFrame.CurrentSource;


        }



This was all about getting the current page URL in Windows Phone application. I hope this quick post was useful. Thanks for reading Smile

Setting start page of Windows Phone dynamically through code

I will start with saying , this post is small and sweet J I was working and come across a requirement to set start page of Windows Phone Application through code or dynamically.

Essentially this one line of code will set the start page of the application.

image

Say, you have a page called Page1.xaml and you want to set it as start page of application. Then you will have to set start page in App.Xaml.cs as below.


    private void Application_Launching(object sender, LaunchingEventArgs e)
        {

                Uri nUri = new Uri("/Page1.xaml", UriKind.Relative);
                ((App)Application.Current).RootFrame.Navigate(nUri);

        }

Last thing you need to do is remove entry of default task from WMAppManifest.xml file. If you notice entry for default navigation page is empty.


  <Tasks>
      <DefaultTask  Name ="_default" NavigationPage=""/>
    </Tasks>
    <Tokens>
      <PrimaryToken TokenID="liveTilesToken" TaskName="_default">
        <TemplateType5>
          <BackgroundImageURI IsRelative="true" IsResource="false">Background.png</BackgroundImageURI>
          <Count>0</Count>
          <Title>liveTiles</Title>
        </TemplateType5>
      </PrimaryToken>
    </Tokens>

This was all about setting the start page in Windows Phone application. I hope this quick post was useful. Thanks for reading Smile

Delete Secondary Tiles in Windows Phone 7.5 or Mango Phone

Before we will see the way to delete secondary tiles, I strongly suggest you to read these two articles

Live Tiles in Windows Phone 7.5 or Mango phone

Restore and Preserve Page State for Windows Phone 7.5 or Mango Phone

Assume we are navigating to a page called Page1.xaml from the secondary tile.

image

A common requirement you may come across to delete the secondary tiles once user has navigated to the application page.

Essentially you need to perform two steps

  1. Query for the secondary tile and delete it
  2. Perform delete operation on OnNavigatedTo function of application page

Function to delete the tile


private void DeleteTile()
        {
            var uri = new Uri("/Page1.xaml?state= Live Tile", UriKind.Relative);
            ShellTile tileToUpdate = ShellTile.ActiveTiles.Where(t => t.NavigationUri == uri).FirstOrDefault();
            tileToUpdate.Delete();

        }


Simply we are querying for the tile and then deleting it.

Calling it to OnNavigatedTo function


 protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            DeleteTile();
        }


This was all required to delete secondary tiles.

I hope this post was useful. Thanks for reading Smile

Restore and Preserve Page State for Windows Phone 7.5 or Mango Phone

In this post we will show you the way to Restore and Preserve Page state for windows phone application page.

image

Let us put some control on the phone application page.


<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

            <TextBox x:Name="txtValue" Height="100" Margin="12,37,58,470" />
            <CheckBox x:Name="chkValue" Height="100" Margin="251,144,0,364"
                      HorizontalAlignment="Left" Width="134" />
            <Slider x:Name="sldValue" Value="30"
                    Height="100" Margin="28,383,58,124" />

        </Grid>



To bind values of these controls, let us create Data class as below,

image

There are three properties to bind values to three controls of the page. Next we need to add PropertyChanged event and implementing a method called NotifyPropertyChanged, which raises the PropertyChanged event.

clip_image002

Next we need to create properties for each control. We need to call NotifyPropertyChanged event in the setter of property to notify when value changed at the control. Control value would be bind with two ways binding with these properties. Eventually Data class will be as below,

 


using System.Runtime.Serialization;
using System.ComponentModel;

namespace RestorePageState
{
    [DataContract]
    public class Data : INotifyPropertyChanged
    {

        private string textValue;
        private bool chckValue;
        private double sliderValue;

        public string TextValue
        {
            get
            {
                return textValue;

            }
            set
            {
                textValue = value;
                NotifyPropertyChanged("TextValue");

            }
        }

        public bool ChckValue
        {
            get
            {
                return chckValue;

            }
            set
            {
                chckValue = value;
                NotifyPropertyChanged("ChckValue");

            }
        }
        public double SliderValue
        {
            get
            {
                return sliderValue;

            }
            set
            {
                sliderValue = value;
                NotifyPropertyChanged("SliderValue");

            }
        }


        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(string propertyName)
        {
            if (null != PropertyChanged)
              PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

    }
}




As of now Data class is in place. Next we need to write code to preserve the page state. We need two variables in code behind,

  1. One bool variable to check whether new instance of page or not?
  2. Object of Data class to bind values to controls.

image

Next we need to override OnNavigatedFrom function of page class to persist value in state dictionary

image

Now we need to override OnNavigatedTo function. This function is called when used navigates to this page.

image

Essentially there are three tasks we are performing in above function

  1. Checking if it is new instance of the page.
  2. If yes then checking if value of data control [object of data class ] is null
  3. If null then reading from the state else creating new instance of that.

Full source code behind to preserve page value is as below,

 


using Microsoft.Phone.Controls;

namespace RestorePageState
{
    public partial class MainPage : PhoneApplicationPage
    {

        Data dataToBindControls;
        bool isNewInstanceofPage;

        public MainPage()
        {
            InitializeComponent();
            isNewInstanceofPage = true;
        }

        protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
        {
            if (e.NavigationMode != System.Windows.Navigation.NavigationMode.Back)
              {
                    State["Data"] = dataToBindControls;
              }
         }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
         {
           if (isNewInstanceofPage)
             {
                if (dataToBindControls == null)
                   {
                      if (State.Count > 0)
                         {
                             dataToBindControls = (Data)State["Data"];
                         }
                      else
                         {
                                 dataToBindControls = new Data();
                         }
                    }
                 DataContext = dataToBindControls;
              }
             isNewInstanceofPage = false;
         }

    }
}


We have code behind now bind the value of the controls, bind the value with mode two way as below,


<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

            <TextBox x:Name="txtValue" Height="100" Margin="12,37,58,470"
                      Text="{Binding TextValue,Mode=TwoWay}"/>
            <CheckBox x:Name="chkValue" Height="100" Margin="251,144,0,364"
                      HorizontalAlignment="Left" Width="134"
                      IsChecked="{Binding ChckValue,Mode=TwoWay}"/>
            <Slider x:Name="sldValue"
                    Height="100" Margin="28,383,58,124"
                    Value="{Binding SliderValue,Mode=TwoWay}"/>

        </Grid>



Before debugging last step we need to perform is enable Tombstone upon deactivation while debugging in the properties page.

image

Now press F5 to run the application.

image

In this way you can preserve page state in Windows Phone 7.5 or mango phone.

I hope this post was useful. Thanks for reading Smile

CRUD operation on Windows Azure table storage as WCF Service

You may have come across requirement of performing CRUD operation on Windows Azure table storage many times. If you have encapsulated functions performing CRUD operation on Azure Table Storage as operation contract of WCF Service then any type of client can work against azure table storage.

You may always want to architecture your application as below,

image

Assume we have Azure table called Student as below,

image

There are 5 columns

  1. Partition Key
  2. Row Key
  3. Timestamp
  4. Name
  5. RollNumber

We need to perform CRUD operation on Student table.

Creating Data Contract

Very first let us create a DataContract representing Azure table.


[DataContract]
    [DataServiceEntity]
    public class Student
    {
        [DataMember]
        public string RollNumber { get ; set;}
        [DataMember]
        public string Name { get ; set;}
        public string PartitionKey { get; set; }
        public string RowKey { get; set; }
    }



There is two of points to be noted in above Data Contract

  1. Student class is attributed with DataServiceEntity
  2. Partitionkey and Rowkey are not exposed as Data Member. At the service side only we will set its values with random string values.

Creating Operation Contract


    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        List<Student> GetStudents();
        [OperationContract]
        bool InsertStudent(Student s);
        [OperationContract]
        bool DeleteStudent(string RollNumber);
        [OperationContract]
        bool UpdateStudent(string RollNumber);

    }



We have created four operation contract for corresponding CRUD operation.

Implementing Service

Before implementing the service add below references to project,

  1. Microsoft.WindowsAzure.DevelopmentStorage.Store.dll
  2. Microsoft.WindowsAzure.StorageClient.dll
  3. System.Data.Services.Client.dll

Make sure to put your own connection string to azure storage to parse.

image

Include below namespaces,

image

Retrieving records




 public List<Student> GetStudents()
        {
            CloudStorageAccount account = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=uraccount;AccountKey=abcdefgh=");
            DataServiceContext context = account.CreateCloudTableClient().GetDataServiceContext();
            var result = from t in context.CreateQuery<Student>("Student") select t;
            return result.ToList();
        }



This is simple LINQ retrieving all the records

Insert Entity

</span>
<pre>

 public bool InsertStudent(Student s)
        {

            try
            {
                CloudStorageAccount account = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=uraccount;AccountKey=abcdefgh=");
                DataServiceContext context = account.CreateCloudTableClient().GetDataServiceContext();
                s.PartitionKey = RandomString(9, true);
                s.RowKey = RandomString(9, true);
                context.AddObject("Student", s);
                context.SaveChanges();
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }

        }



We are putting random string as value of partition key and row key.

Random string function is taken from Mahesh Chand article and it is as below,

</span>
<pre>

 private string RandomString(int size, bool lowerCase)
        {
            StringBuilder builder = new StringBuilder();
            Random random = new Random();
            char ch;
            for (int i = 0; i < size; i++)
            {
                ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
                builder.Append(ch);
            }
            if (lowerCase)
                return builder.ToString().ToLower();
            return builder.ToString();
        }





Update Entity

 


public bool UpdateStudent(string RollNumber)
        {
            try
            {
                CloudStorageAccount account = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=uraccount;AccountKey=abcdefgh=");
                DataServiceContext context = account.CreateCloudTableClient().GetDataServiceContext();
                Student result = (from t in context.CreateQuery<Student>("Student") select t).FirstOrDefault();
                result.Name = "UpdatedName";
                context.UpdateObject(result);
                context.SaveChanges();
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }




We are passing roll number to update. First we are fetching the entity to be updated and then updating it.

Delete Entity

 

 

public bool DeleteStudent(string RollNumber)
        {
            try
            {
                CloudStorageAccount account = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=uraccount;AccountKey=abcdefgh=");
                DataServiceContext context = account.CreateCloudTableClient().GetDataServiceContext();
                Student result = (from t in context.CreateQuery<Student>("Student") select t).FirstOrDefault();
                context.DeleteObject(result);
                context.SaveChanges();
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }


        }



We are passing roll number to delete. First we are fetching the entity to be deleted and then deleting it.

Consuming at managed client

Get the Students

</span><span class="Apple-style-span" style="color: #222222; font-size: 15px; line-height: 21px; white-space: pre; background-color: #eeeeee;">Service1Client proxy = new Service1Client();</span>
<pre>            var result = proxy.GetStudents();
            foreach (var r in result)
            {
                Console.WriteLine(r.Name);
            }



Insert Student

</span>
<pre>
Service1Client proxy = new Service1Client();
 bool b = proxy.InsertStudent(new Student { RollNumber = "34", Name = "DK" });
            if (b)
                Console.WriteLine("Inserted");
            else
                Console.WriteLine("Sorry");



Update Student

</span>
<pre>
Service1Client proxy = new Service1Client();
bool b2 = proxy.UpdateStudent("34");
            if (b2)
                Console.WriteLine("Updated");
            else
                Console.WriteLine("Sorry");


Delete Student


Service1Client proxy = new Service1Client();
bool b1 = proxy.DeleteStudent("34");
            if (b1)
                Console.WriteLine("Deleted");
            else
                Console.WriteLine("Sorry");



This is all you have to do to perform CRUD operation on Azure Table. In next post we will consume WCF Service from a Silverlight client.

I hope this post was useful. Thanks for reading Smile

Schedule the Tile update in Windows Phone 7.5 or Mango Phone

Read here about Live Tiles in Windows Phone 7.5 or Mango phone

You may have a requirement to schedule the update of the tiles. It is very much possible in Windows Phone 7.5 or Mango phone.

 

image

 

You can set UpdateIntravel as below,

image

You can set UpdateRecurrence as below,

clip_image001

In last post we discussed the way to update a tile by querying the tile using query string of the tile URI. Here again we will query tile in same way and schedule the update.

image

Below function will schedule a tile update.

 


private void ScheduletilesUpdate()
        {
            var uri = new Uri("/LiveTileUserControl.xaml?state= Live Tile", UriKind.Relative);
            ShellTile tileToUpdate = ShellTile.ActiveTiles.Where(t => t.NavigationUri == uri).FirstOrDefault();
            ShellTileSchedule SampleTileSchedule = new ShellTileSchedule(tileToUpdate);
            SampleTileSchedule.Recurrence = UpdateRecurrence.Interval;
            SampleTileSchedule.Interval = UpdateInterval.EveryHour;
            var tilesUpdatedData = new StandardTileData
            {
                Title = "Created Tiles Updated ",
                Count = 450,
                BackTitle = "Back Title"

            };

            tileToUpdate.Update(tilesUpdatedData);


        }


 

This was all about scheduling update of tiles.

image

 

I hope this post was useful. Thanks for reading Smile

Live Tiles in Windows Phone 7.5 or Mango phone

In Windows Phone 7 Live tiles was only possible through Push notification. However Windows Phone 7.5 (code name: Mango) allows to update, create primary and secondary tiles without push notification. In this post, we will walkthrough on the same.

image

To create and update live tiles essentially you need to work with below classes

StandardTileData and ShellTile

You can get the instance of current tile for application as below,

clip_image002

You can set data for tile as below,

clip_image004

StandardTileData class has following properties. You can set value of these properties to set as data of live tiles.

  1.  public Uri BackBackgroundImage
  2. public string BackContent
  3. public Uri BackgroundImage
  4. public string BackTitle
  5. public int? Count

Update a Live Tile

Below code snippet will update a live tiles with title and count.


using System.Linq;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;

namespace liveTiles
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            UpdateLiveTiles();
        }

        private void UpdateLiveTiles()
        {
            ShellTile currentTiles = ShellTile.ActiveTiles.First();
            var tilesUpdatedData = new StandardTileData
                                  {
                                      Title = "Live Tiles ",
                                      Count = 10,
                                      BackTitle ="Back Title"

                                  };

            currentTiles.Update(tilesUpdatedData);

        }
    }
}



Live tile will get updated as below,

image

Create a Live Tile

Below code snippet will create a new live tiles. Creation of live tile is exactly same as updating of live tile but to call Create function.


private void CreateLiveTile()
        {
            var newTile = new StandardTileData()
            {
                Title = "Blogs Update",
                BackgroundImage = new Uri("background.png", UriKind.Relative),
                Count = 42,
            };
            var uri = "/LiveTileUserControl.xaml?state= Live Tile";
            ShellTile.Create(new Uri(uri, UriKind.Relative), newTile);
        }




Important point to note in above code snippet is uri. On click of create live tile user will navigate to given xaml.

clip_image001

Updating created Live Tile

To update a particular tile, first you need to fetch the tile with query string as below,



private void UpdatingCreatedTile()
        {
            var uri = new Uri("/LiveTileUserControl.xaml?state= Live Tile", UriKind.Relative);
            ShellTile  tileToUpdate = ShellTile.ActiveTiles.Where(t => t.NavigationUri == uri).FirstOrDefault();
            var tilesUpdatedData = new StandardTileData
            {
                Title = "Created Tiles Updated ",
                Count = 45,
                BackTitle = "Back Title"

            };

            tileToUpdate.Update(tilesUpdatedData);

        }


Tile will get updated as below,

clip_image001[6]

This was all about basic of live tiles in windows phone 7.5 without using push notification.

I hope this post was useful. Thanks for reading Smile