Showing posts with label Windows 8. Show all posts
Showing posts with label Windows 8. Show all posts

Tuesday, 26 February 2013

Windows Azure Mobile Services- Intro

Introduction:


Integration of Windows 8 and Azure Services started with Windows Azure toolkit for Windows 8 , but then Microsoft renamed it as Windows Azure Mobile Services. So, now if you are planning to develop Windows Store Application using Windows Azure then you need to understand Windows Azure Mobile Services thoroughly.

As with Windows Azure Service , the Windows Azure Mobile Services enables developers to provision, configure, and consume scalable backend services.

If you are new to Windows Azure , don't get panic-ed , followin section is for you. If you already know Windows Azure please skip the next section.

Windows Azure: In few lines.

Windows Azure is nothing but a cloud-computing platform  from Microsoft that can:
a.  run applications
b. store data in the cloud.
So that the development team can do their work without worrying about the underlying infrastructure and can concentrate more on application development rather than thinking about how to manage the operating system.

Following are a few capabilities of Windows Azure than can help a developer/development team as such:

 a. Availability of on-demand compute services,
 b. Availability of on-demand storage services,
 c. Availability of on-demand  networking services,
 d. Content-delivery capabilities.


Since , the scope of this article is not to explain or introduce you to Windows Azure as such , so I am restricting my explanation here.

We are discussing about blending Windows 8 and Azure together.

In case you don't know what a Windows 8 App is , you can read the following section , else skip it.

Windows 8 apps in few lines:


Windows 8 apps are the applications created with metro style UI , or using Microsoft UI Design guidelines that can be brought on to Windows 8 platform irrespective of whether a PC , a tablet , a mobile or any other type of devices. You can refer to my blogs on developing Windows 8 app to get a holostic knowledge on development of these apps.

Now, wgen Windows 8 Apps are used with Azure , the architecture of the apps as such changes a little , instead of depending on SQLite ot text file as storage  , the app connects to Microsoft Cloud Services and gives you a feel of an app that is mobile and is always connected.

Architecture of Windows 8 App with Azure:


This type of Architecture basically takes advantage of Windows Push Notification Services.

Following is a basic outline of how the architecture of Windows 8 Cloud connected app looks like:

 We will look at the Windows Notification Services in next article.

Wednesday, 30 January 2013

Conatainer Panels in XAML

Container Panels for XAML:

a. Canvas
b. Stack Panel
c. Grid

The above containers can be used both in Windows 8 and Windows 8 Phones as well.
If you are a Silverlight/WPF developer , you will not find these new , but in case you are into xaml development for the first time. Here is a brief description of these panels for you.

Canvas :


Defines an area within which you can explicitly position child objects by using coordinates that are relative to the area.
A Canvas is one of the Panel elements that enable layout. Each child object is rendered within the Canvas area.
The controls are specified inside a canvas using the x and y positions.
The positions are defined in logical pixels.
The x and y coordinates are often specified by using the Canvas.Left and Canvas.Top attached properties.
A Canvas can contain nested objects.
When objects are placed inside the canvas they are positioned relative to the canvas.Only UIElements can be put inside the canvas tags.
You can nest Canvas objects, because a Canvas is a type of UIElement.
In many cases, a Canvas is used solely as a container for other objects and does not have any visible properties.
You can control the visibility of a canavas by using height/width/Background/Opcaity/Visibility/Ancestor Objects.


Stack Panel :


StackPanel is one of the Panel elements that enable layout.
Stack panels help arranging child elements into a single line that can be oriented horizontally or vertically.
Stack panels are useful when you have a menu kind of application / browser kind of application.
The default for both HorizontalAlignment and VerticalAlignment of content in a StackPanel is Stretch.


Grid :

Grid defines a flexible grid area that consists of columns and rows.
Grid enables complex layout.You can define rows and columns inside a grid. By default the grid has one row and one column.
You can position objects in specific cells of the Grid by using the Grid.Column and Grid.Row attached properties.Instead of giving definite sizes to the grid you can specify start sizing/
Star sizing to distributes space proportionally.

Conclusion


Grids are used mostly for almost all kinds of apps.
If you are developing a gaming or a animation app , canvas is the best.
For menus and a hide and show type of controls stack panels are best.

 

Tuesday, 22 January 2013

Windows 8 Apps : Guidelines

Recently we are trying to push a few of our apps on to windows 8 app store. Before we push the apps the store the app needs to undergo some basic guideline checks.

Microsoft team definitely does those checks , but you can also ensure that your app adheres to all the guidelines set across. To do this we follow a two step process.

Step 1: Run certification kit on your app.

Step 2: Ensure that your app adheres to all the Windows store guidelines set at msdn.

I have captured them here for my reference. You too can use this.

You can also download the document from gdocs.


Category Guidance A few facts
Windows Store apps provide value to the customer Your app must offer customers unique, creative value or utility in all the languages and markets that it supports  
Your app must be fully functional when the customer gets it from the Windows Store
Your app’s trial functionality must reasonably resemble its full functionality
Each app must display only one tile after it is installed
Windows Store apps can display ads but are more than just ads or websites Your app must not display only ads  
Ads in your apps must comply with our content policies
Your app must not use its description, tiles, notifications, app bar, or the swipe-from-edge interactions to display ads
The primary experiences your app provides must take place within the app
Ads must not execute program code that didn't come from the ad provider
Windows Store apps behave predictably You must use only the Windows Runtime APIs to implement the features of your Windows Store app
Your app must not stop responding, end unexpectedly, or contain programming errors
 Your app must provide the same user experience on all processor types that it supports
Updates must not decrease your app’s functionality in a way that would be unexpected to a reasonable customer
Your app must fully support touch input, and fully support keyboard and mouse input
 Your app must use the mechanisms provided by the system for those features that have them
Your app must meet the basic performance criteria on a low-power computer The app must launch in 5 seconds or less

The app must suspend in 2 seconds or less
All app logic must originate from, and reside in, your app package  
Direct3D apps must support a minimum feature level
If your app contains Windows Runtime components, they must conform to the Windows Runtime type system Must be located in the package file with the longest namespace-matching name.
Must be the only types with public visibility in a Windows Metadata (.winmd) file.
Must have a unique, case insensitive name.
Must not be located in the Windows or global namespace. 
Must have public visibility unless the type is an interface marked as exclusive to a specific runtime class.
Must be sealed unless the type is a runtime class marked as composable.
Must compose an unsealed system class, if the type is a composable runtime class.
Must not include write-only properties.
Must not implement interfaces that are marked as exclusive to another class.
Must not be generic or parameterized.
Must not define methods that overload operators.
Must not change signature or parameter names between interface and runtime method declarations.
Must not include default values for method parameters.
Must not include property getters that take input parameters.
Must not include property setters that take more than the single set value parameter.
Must not define factory methods with additional out parameters beyond the return value.
Must not use IReferenceArray<T> or IReference<string> as a parameter type.
Must not use the signed byte fundamental type. 
Must define enums with an underlying type of Int32 or UInt32 only.
Must apply the FlagsAttribute to UInt32 enums.
Must not apply the FlagsAttribute to Int32 enums.
Windows Store apps put the customer in control Your app must comply with the following privacy-related requirements:  
 Your app must have a privacy statement if it is network-capable
 Your app must obtain opt-in or equivalent consent to share personal information
Your app must respect system settings for notifications and remain functional when they are disabled
Your app must not jeopardize or compromise the security or functionality of the Windows system
Your app must not be designed or marketed to perform, instruct, or encourage tasks that could cause physical harm to a customer or any other person
Your app must protect customers from unintentional large data transfers over metered networks
Your app must comply with Windows Push Notification Service (WNS) requirements if it uses WNS notifications You may only use WNS for apps distributed through the Windows Store. Notifications provided through WNS are considered app content and are subject to all Windows Store app policies, including the certification requirements.
Your app must be associated with only one Package Security Identifier.
You may not obscure or try to disguise the source of any WNS message or Package Security Identifier, or other unique referral identifier.
You may not include in a notification any info a customer would reasonably consider to be confidential or sensitive.
Your app must not use excessive network capacity or WNS bandwidth, or otherwise unduly burden the Windows system with WNS notifications. For example, using WNS to stream content or transfer files violates this requirement.
If you use a commerce transaction provider other than the Store's, you must identify the provider at the time of the transaction or whenever you collect any payment information from the customer  
 Your app must prompt the user for authentication to allow a commerce transaction to be accomplished. 
If your app collects credit card info or uses a third-party payment processor that collects credit card info, the payment processing must meet the current PCI Data Security Standard (PCI DSS)
Windows apps are appropriate for a global audience Your app must conform to our content and age rating guidelines, and metadata must be appropriate for everyone
Your app must not contain content that advocates discrimination, hatred, or violence based on membership in a particular racial, ethnic, national, linguistic, religious, or other social group, or based on a person’s gender, age, or sexual orientation

Your app must not contain content or functionality that encourages, facilitates or glamorizes illegal activity in the real world

Your app must not contain or display content that a reasonable person would consider to be obscene or pornographic

Your app must not contain content that is defamatory, libelous or slanderous, or threatening
Your app must not contain content that facilitates or glamorizes excessive or irresponsible use of alcohol or tobacco products, drugs or weapons
Your app must not contain content that facilitates or glamorizes extreme or gratuitous violence, human rights violations, or the creation or illegal use of weapons against a person or animal in the real world
Your app must not contain excessive or gratuitous profanity
Windows Store apps are easily identified and understood Your app must have a unique name
Your app must have a Windows age rating, and you must submit third-party ratings for your app if you have them
You must provide technical support info for your app
 You must list your app in at least one of the Windows Store's geographic markets
 You must list your app in at least one of the Windows Store's geographic markets
The capabilities you declare must relate to the core functions and value proposition of your Windows Store app, and the use of those declarations must be compliant with our app capability declarations
You must describe any changes to your app when you submit an update to the Store
You must provide localized screenshots of your app for each language your app supports
Your Windows Store app’s packages must have a correct app manifest
Your Windows Store app’s packages must be correctly formatted
The app's category and subcategory must correspond to the character or purpose of your app
Desktop apps must follow additional requirements The purchase page link provided for your app must send users to a location where they can directly download the app, and must not lead users to another intermediary site or a site that spoofs the purchase page
The information you provide to the Store about your app must match the information used on the purchase page for that app. That includes your app or company logo, the app name, price and major and minor version numbers
 

Friday, 4 January 2013

Windows 8 : Contact Picker

Suppose you want to create an application which uses mailing , messaging , appointments and social networking.  And you want to access existing contacts rather than adding your own contact, in this case Windows 8 provides you with the Contact Picker API.

Using Contact Picker API you can:
  • Add a contact
  • Pick a contact
  • Pick multiple contacts

Basically the Contact Picker API and ContactPicker class enables apps that to select and acquire info about contacts.

Namespace used is: Windows.ApplicationModel.Contacts

Following are the various classes in this namespace:

Contact
Creates a new contact.
ContactField
Shows a piece of contact data.
ContactFieldFactory
Creates fields that contain information about a contact.
ContactInformation
Contains the information about a contact.
ContactInstantMessageField
Defines a field that is an instant messaging (IM) address.
ContactLocationField
Contains information about a user's location and address.
ContactPicker
Controls how the Contact Picker user interface opens and what information it shows.
KnownContactField
A static class that contains the names of contact fields for storing commonly requested information like email address and phone numbers.

 

In the following example we will use:
  • ContactPicker class
  • ContactInformation class

In this demo I am trying to:
  • Open all the contact information available with me.
  • Select single information.
  • Display the data fetched from the contact information.

The namespaces I added for this sample are:
  • using Windows.ApplicationModel.Contacts;
  • using System.Text;
  • using Windows.Storage.Streams;
  • using Windows.UI.Xaml.Media.Imaging;

In the xaml file , I have six text blocks and one button called ‘pick single contact’

 

When the button is clicked , user is prompted with a screen which lists all the contacts that I have on my Windows 8 device.
I can select a single contact and on clicking the OK button the screen details the contact details of the contact selected in the previous screen.
For the above contact there is no address added, so the address field is empty. If the address fields are present in the contact information the address is also shown.

Now, let us look the xaml code.

<Page
    x:Class="ContactPicker.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:ContactPicker"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
 
    <Grid Background="#FFF73131">
        <Image x:Name="OutputThumbnail" Grid.Column="0" Stretch="None" VerticalAlignment="Top" HorizontalAlignment="Left"/>
        <Button Content="Pick Single Contact " HorizontalAlignment="Left" Margin="581,145,0,0" VerticalAlignment="Top" Width="299" Name="PickContact" Click="PickContact_Click" Height="105" FontFamily="Segoe UI Light" FontSize="24" IsDoubleTapEnabled="False">
              <Button.Projection>
                     <PlaneProjection RotationX="-4" RotationY="-6"/>
              </Button.Projection>
        </Button>
        <TextBlock HorizontalAlignment="Left" Margin="704,270,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Height="56" Width="391" Visibility="Collapsed" Name="contactName" RenderTransformOrigin="0.502,5.966" FontFamily="Segoe UI Light" FontSize="32"/>
        <TextBlock HorizontalAlignment="Left" Margin="411.73,271.356,0,0" TextWrapping="Wrap" Text="Contact Name" VerticalAlignment="Top" Height="60.337" Width="247.325" Visibility="Visible" x:Name="contactNameLabel" RenderTransformOrigin="0.502,5.966" FontFamily="Segoe UI Light" FontSize="32" UseLayoutRounding="False" d:LayoutRounding="Auto">
            <TextBlock.RenderTransform>
                <CompositeTransform Rotation="0.166"/>
            </TextBlock.RenderTransform>
        </TextBlock>
        <TextBlock HorizontalAlignment="Left" Margin="413.223,351.953,0,0" TextWrapping="Wrap" Text="Email" VerticalAlignment="Top" Height="60.337" Width="247.325" Visibility="Visible" x:Name="Email" RenderTransformOrigin="0.502,5.966" FontFamily="Segoe UI Light" FontSize="32" UseLayoutRounding="False" d:LayoutRounding="Auto">
            <TextBlock.RenderTransform>
                <CompositeTransform Rotation="0.166"/>
            </TextBlock.RenderTransform>
        </TextBlock>
        <TextBlock HorizontalAlignment="Left" Margin="698,348,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="117" Width="582" Visibility="Visible" x:Name="EmailValue" RenderTransformOrigin="0.502,5.966" FontFamily="Segoe UI Light" FontSize="32"/>
        <TextBlock HorizontalAlignment="Left" Margin="413.223,516.132,0,0" TextWrapping="Wrap" Text="Address" VerticalAlignment="Top" Height="60.337" Width="247.325" Visibility="Visible" x:Name="Address" RenderTransformOrigin="0.502,5.966" FontFamily="Segoe UI Light" FontSize="32" UseLayoutRounding="False" d:LayoutRounding="Auto">
            <TextBlock.RenderTransform>
                <CompositeTransform Rotation="0.166"/>
            </TextBlock.RenderTransform>
        </TextBlock>
        <TextBlock HorizontalAlignment="Left" Margin="682,464,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="241" Width="589" Visibility="Visible" x:Name="AddressValue" RenderTransformOrigin="0.502,5.966" FontFamily="Segoe UI Light" FontSize="32"/>
 
 
    </Grid>
</Page>

 

The xaml code is nothing but a very simple xaml page.

Now , Let us do the button click event:

1.       Create an object of the Contact class

var contactPicker = new Windows.ApplicationModel.Contacts.ContactPicker();

2.       Now , we need to fetch the contact information using the ContactInformation class:

ContactInformation contact = await contactPicker.PickSingleContactAsync();

 

PickSingleContactAsync(); is the method which internally collates all the contact information from my OS and presents to me on the UI.

 

When implementing PickSingleContactAsync();This method has no parameters. Using this method I can select only one contact at a time.

 

Once , I have selected a contact , the contact information is now available , we need to fetch the information and show them in appropriate format.

 

                contactName.Visibility = Visibility.Visible;

                AddressValue.Text = string.Empty;

                contactName.Text = contact.Name;

                EmailValue.Visibility = Visibility.Visible;

                EmailValue.Text = contact.Emails[0].Value.ToString();

                if (contact.Locations.Count > 0)

                {

                    string street = contact.Locations[0].Street.ToString();

                    string city = contact.Locations[0].City.ToString();

                    string category = contact.Locations[0].Category.ToString();

                    string region = contact.Locations[0].Region.ToString();

                    string country = contact.Locations[0].Country.ToString();

 

                    string postalCode = contact.Locations[0].PostalCode.ToString();

                    string address = street + city + region + country + postalCode;

                    AddressValue.Visibility = Visibility.Visible;

                    AddressValue.Text = address;

           }

 

Although , I can get the all the contact information using this, I cannot get the thumbnail information using contact class.

So,  Let us try to fetch the thumbnail information.

To fetch the thumbnail information ,

 IRandomAccessStreamWithContentType stream = await contact.GetThumbnailAsync();

 

And once , you have fetched the image stream use following:

               if (stream != null && stream.Size > 0)

                {

                    BitmapImage bitmap = new BitmapImage();

                    bitmap.SetSource(stream);

                    OutputThumbnail.Source = bitmap;

                }

                else

                {

                    OutputThumbnail.Source = null;

         }

 

So,  the .cs file now looks like:

 

using System;

using System.Collections.Generic;

using System.IO;

using System.Linq;

using Windows.Foundation;

using Windows.Foundation.Collections;

using Windows.UI.Xaml;

using Windows.UI.Xaml.Controls;

using Windows.UI.Xaml.Controls.Primitives;

using Windows.UI.Xaml.Data;

using Windows.UI.Xaml.Input;

using Windows.UI.Xaml.Media;

using Windows.UI.Xaml.Navigation;

using Windows.ApplicationModel.Contacts;

using System.Text;

using Windows.Storage.Streams;

using Windows.UI.Xaml.Media.Imaging;

 

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

 

namespace ContactPicker

{

    /// <summary>

    /// An empty page that can be used on its own or navigated to within a Frame.

    /// </summary>

    public sealed partial class MainPage : Page

    {

        public MainPage()

        {

            this.InitializeComponent();

        }

 

        /// <summary>

        /// Invoked when this page is about to be displayed in a Frame.

        /// </summary>

        /// <param name="e">Event data that describes how this page was reached.  The Parameter

        /// property is typically used to configure the page.</param>

        protected override void OnNavigatedTo(NavigationEventArgs e)

        {

        }

 

     

        private async void PickContact_Click(object sender, RoutedEventArgs e)

        {

            var contactPicker = new Windows.ApplicationModel.Contacts.ContactPicker();

            ContactInformation contact = await contactPicker.PickSingleContactAsync();

            if (contact != null)

            {

                contactName.Visibility = Visibility.Visible;

                AddressValue.Text = string.Empty;

                contactName.Text = contact.Name;

                EmailValue.Visibility = Visibility.Visible;

                EmailValue.Text = contact.Emails[0].Value.ToString();

                if (contact.Locations.Count > 0)

                {

                    string street = contact.Locations[0].Street.ToString();

                    string city = contact.Locations[0].City.ToString();

                    string category = contact.Locations[0].Category.ToString();

                    string region = contact.Locations[0].Region.ToString();

                    string country = contact.Locations[0].Country.ToString();

 

                    string postalCode = contact.Locations[0].PostalCode.ToString();

                    string address = street + city + region + country + postalCode;

                    AddressValue.Visibility = Visibility.Visible;

                    AddressValue.Text = address;

                }

 

                IRandomAccessStreamWithContentType stream = await contact.GetThumbnailAsync();

                if (stream != null && stream.Size > 0)

                {

                    BitmapImage bitmap = new BitmapImage();

                    bitmap.SetSource(stream);

                    OutputThumbnail.Source = bitmap;

                }

                else

                {

                    OutputThumbnail.Source = null;

                }

 

            }

       }

           

    }

 

  

  

}