What’s new in Windows Phone 8.1 Update GDR 1 & specialised code structures of Universal Apps for Windows Store 8.1 & Windows Phone 8.1 app


Recently, there is a new update of Windows Phone 8.1 GDR 1 is available which embeds few new features on existing Windows Phone 8.1 emulator. You can the download it from here. After downloading the pack, let’s check what’s new in this update.

First , you will be prompted with one folder called ‘packages‘ & ‘MobileTools_EmulatorWP81GDR1‘.

MobEmulatorOn clicking, the ‘packages‘ folder, you will be prompted with GDR1 update packages & .cab files.

Update

Now, go ahead with the installation of ‘MobileTools_EmulatorWP81GDR1′ & make sure before proceeding that you should have visual studio 2013 update 2 (at least) to be installed.

Installation

Upon installation, check the available emulators list in visual studio , there are additional emulators are available as ‘Emulator 8.1 U1‘ extension.

Emulators

Let’s checkout a sample Universal app on Windows Store 8.1 & Windows Phone 8.1 app on webview using C#. The project simply consists of Windows Store 8.1, Phone 8.1 & a shared project which consists of app.xaml & shared configuration details.

 

using System.Collections.Generic;
using Windows.UI.Xaml.Controls;

using System;

namespace SDKTemplate
{
public partial class MainPage : Page
{
// Change the string below to reflect the name of your sample.
// This is used on the main page as the title of the sample.
public const string FEATURE_NAME = “XAML WebView control sample”;

// Change the array below to reflect the name of your scenarios.
// This will be used to populate the list of scenarios on the main page with
// which the user will choose the specific scenario that they are interested in.
// These should be in the form: “Navigating to a web page”.
// The code in MainPage will take care of turning this into: “1) Navigating to a web page”
#if WINDOWS_PHONE_APP
List scenarios = new List
{
new Scenario() { Title = “Navigate to a URL”, ClassType = typeof(Controls_WebView.Scenario1) },
new Scenario() { Title = “Navigate to a String”, ClassType = typeof(Controls_WebView.Scenario2) },
new Scenario() { Title = “Navigate to package and local state”, ClassType = typeof(Controls_WebView.Scenario3) },
new Scenario() { Title = “Navigate with custom stream”, ClassType = typeof(Controls_WebView.Scenario4) },
new Scenario() { Title = “Invoke script”, ClassType = typeof(Controls_WebView.Scenario5) },
new Scenario() { Title = “Using ScriptNotify”, ClassType = typeof(Controls_WebView.Scenario6) },
new Scenario() { Title = “Using CaptureBitmap”, ClassType = typeof(Controls_WebView.Scenario8) }
};
#else
List scenarios = new List
{
new Scenario() { Title = “Navigate to a URL”, ClassType = typeof(Controls_WebView.Scenario1) },
new Scenario() { Title = “Navigate to a String”, ClassType = typeof(Controls_WebView.Scenario2) },
new Scenario() { Title = “Navigate to package and local state”, ClassType = typeof(Controls_WebView.Scenario3) },
new Scenario() { Title = “Navigate with custom stream”, ClassType = typeof(Controls_WebView.Scenario4) },
new Scenario() { Title = “Invoke script”, ClassType = typeof(Controls_WebView.Scenario5) },
new Scenario() { Title = “Using ScriptNotify”, ClassType = typeof(Controls_WebView.Scenario6) },
new Scenario() { Title = “Supporting the Share contract”, ClassType = typeof(Controls_WebView.Scenario7) },
new Scenario() { Title = “Using CaptureBitmap”, ClassType = typeof(Controls_WebView.Scenario8) }
};
#endif
}

public class Scenario
{
public string Title { get; set; }

public Type ClassType { get; set; }

public override string ToString()
{
return Title;
}
}
}

SampleConfiguration.cs

  • The ‘Controls_WebView.Shared’ project also consists of a default ‘SuspensionManager.cs’ file contains Session states data in form of Dictionary<string,object> key/value pair.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using Windows.ApplicationModel;
using Windows.Storage;
using Windows.Storage.Streams;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace SDKTemplate.Common
{
///
/// SuspensionManager captures global session state to simplify process lifetime management
/// for an application. Note that session state will be automatically cleared under a variety
/// of conditions and should only be used to store information that would be convenient to
/// carry across sessions, but that should be discarded when an application crashes or is
/// upgraded.
///

internal sealed class SuspensionManager
{
private static Dictionary<string, object> _sessionState = new Dictionary<string, object>();
private static List _knownTypes = new List();
private const string sessionStateFilename = “_sessionState.xml”;

///
/// Provides access to global session state for the current session. This state is
/// serialized by and restored by
/// , so values must be serializable by
/// and should be as compact as possible. Strings
/// and other self-contained data types are strongly recommended.
///

public static Dictionary<string, object> SessionState
{
get { return _sessionState; }
}

///
/// List of custom types provided to the when
/// reading and writing session state. Initially empty, additional types may be
/// added to customize the serialization process.
///

public static List KnownTypes
{
get { return _knownTypes; }
}

///
/// Save the current . Any instances
/// registered with will also preserve their current
/// navigation stack, which in turn gives their active an opportunity
/// to save its state.
///

/// An asynchronous task that reflects when session state has been saved.
public static async Task SaveAsync()
{
try
{
// Save the navigation state for all registered frames
foreach (var weakFrameReference in _registeredFrames)
{
Frame frame;
if (weakFrameReference.TryGetTarget(out frame))
{
SaveFrameNavigationState(frame);
}
}

// Serialize the session state synchronously to avoid asynchronous access to shared
// state
MemoryStream sessionData = new MemoryStream();
DataContractSerializer serializer = new DataContractSerializer(typeof(Dictionary<string, object>), _knownTypes);
serializer.WriteObject(sessionData, _sessionState);

// Get an output stream for the SessionState file and write the state asynchronously
StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync(sessionStateFilename, CreationCollisionOption.ReplaceExisting);
using (Stream fileStream = await file.OpenStreamForWriteAsync())
{
sessionData.Seek(0, SeekOrigin.Begin);
await sessionData.CopyToAsync(fileStream);
}
}
catch (Exception e)
{
throw new SuspensionManagerException(e);
}
}

///
/// Restores previously saved . Any instances
/// registered with will also restore their prior navigation
/// state, which in turn gives their active an opportunity restore its
/// state.
///

///An optional key that identifies the type of session.
/// This can be used to distinguish between multiple application launch scenarios. /// An asynchronous task that reflects when session state has been read. The
/// content of should not be relied upon until this task
/// completes.
public static async Task RestoreAsync(String sessionBaseKey = null)
{
_sessionState = new Dictionary<String, Object>();

try
{
// Get the input stream for the SessionState file
StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync(sessionStateFilename);
using (IInputStream inStream = await file.OpenSequentialReadAsync())
{
// Deserialize the Session State
DataContractSerializer serializer = new DataContractSerializer(typeof(Dictionary<string, object>), _knownTypes);
_sessionState = (Dictionary<string, object>)serializer.ReadObject(inStream.AsStreamForRead());
}

// Restore any registered frames to their saved state
foreach (var weakFrameReference in _registeredFrames)
{
Frame frame;
if (weakFrameReference.TryGetTarget(out frame) && (string)frame.GetValue(FrameSessionBaseKeyProperty) == sessionBaseKey)
{
frame.ClearValue(FrameSessionStateProperty);
RestoreFrameNavigationState(frame);
}
}
}
catch (Exception e)
{
throw new SuspensionManagerException(e);
}
}

private static DependencyProperty FrameSessionStateKeyProperty =
DependencyProperty.RegisterAttached(“_FrameSessionStateKey”, typeof(String), typeof(SuspensionManager), null);
private static DependencyProperty FrameSessionBaseKeyProperty =
DependencyProperty.RegisterAttached(“_FrameSessionBaseKeyParams”, typeof(String), typeof(SuspensionManager), null);
private static DependencyProperty FrameSessionStateProperty =
DependencyProperty.RegisterAttached(“_FrameSessionState”, typeof(Dictionary<String, Object>), typeof(SuspensionManager), null);
private static List<WeakReference> _registeredFrames = new List<WeakReference>();

///
/// Registers a instance to allow its navigation history to be saved to
/// and restored from . Frames should be registered once
/// immediately after creation if they will participate in session state management. Upon
/// registration if state has already been restored for the specified key
/// the navigation history will immediately be restored. Subsequent invocations of
/// will also restore navigation history.
///

///An instance whose navigation history should be managed by
/// ///A unique key into used to
/// store navigation-related information. ///An optional key that identifies the type of session.
/// This can be used to distinguish between multiple application launch scenarios. public static void RegisterFrame(Frame frame, String sessionStateKey, String sessionBaseKey = null)
{
if (frame.GetValue(FrameSessionStateKeyProperty) != null)
{
throw new InvalidOperationException(“Frames can only be registered to one session state key”);
}

if (frame.GetValue(FrameSessionStateProperty) != null)
{
throw new InvalidOperationException(“Frames must be either be registered before accessing frame session state, or not registered at all”);
}

if (!string.IsNullOrEmpty(sessionBaseKey))
{
frame.SetValue(FrameSessionBaseKeyProperty, sessionBaseKey);
sessionStateKey = sessionBaseKey + “_” + sessionStateKey;
}

// Use a dependency property to associate the session key with a frame, and keep a list of frames whose
// navigation state should be managed
frame.SetValue(FrameSessionStateKeyProperty, sessionStateKey);
_registeredFrames.Add(new WeakReference(frame));

// Check to see if navigation state can be restored
RestoreFrameNavigationState(frame);
}

///
/// Disassociates a previously registered by
/// from . Any navigation state previously captured will be
/// removed.
///

///An instance whose navigation history should no longer be
/// managed. public static void UnregisterFrame(Frame frame)
{
// Remove session state and remove the frame from the list of frames whose navigation
// state will be saved (along with any weak references that are no longer reachable)
SessionState.Remove((String)frame.GetValue(FrameSessionStateKeyProperty));
_registeredFrames.RemoveAll((weakFrameReference) =>
{
Frame testFrame;
return !weakFrameReference.TryGetTarget(out testFrame) || testFrame == frame;
});
}

///
/// Provides storage for session state associated with the specified .
/// Frames that have been previously registered with have
/// their session state saved and restored automatically as a part of the global
/// . Frames that are not registered have transient state
/// that can still be useful when restoring pages that have been discarded from the
/// navigation cache.
///

/// Apps may choose to rely on to manage
/// page-specific state instead of working with frame session state directly.
///The instance for which session state is desired. /// A collection of state subject to the same serialization mechanism as
/// .
public static Dictionary<String, Object> SessionStateForFrame(Frame frame)
{
var frameState = (Dictionary<String, Object>)frame.GetValue(FrameSessionStateProperty);

if (frameState == null)
{
var frameSessionKey = (String)frame.GetValue(FrameSessionStateKeyProperty);
if (frameSessionKey != null)
{
// Registered frames reflect the corresponding session state
if (!_sessionState.ContainsKey(frameSessionKey))
{
_sessionState[frameSessionKey] = new Dictionary<String, Object>();
}
frameState = (Dictionary<String, Object>)_sessionState[frameSessionKey];
}
else
{
// Frames that aren’t registered have transient state
frameState = new Dictionary<String, Object>();
}
frame.SetValue(FrameSessionStateProperty, frameState);
}
return frameState;
}

private static void RestoreFrameNavigationState(Frame frame)
{
var frameState = SessionStateForFrame(frame);
if (frameState.ContainsKey(“Navigation”))
{
frame.SetNavigationState((String)frameState[“Navigation”]);
}
}

private static void SaveFrameNavigationState(Frame frame)
{
var frameState = SessionStateForFrame(frame);
frameState[“Navigation”] = frame.GetNavigationState();
}
}
public class SuspensionManagerException : Exception
{
public SuspensionManagerException()
{
}

public SuspensionManagerException(Exception e)
: base(“SuspensionManager failed”, e)
{

}
}
}

WebControl

Universal App : Windows Phone 8.1 webview app

screenshot_08092014_002735Universal App: Windows Store 8.1 WebView app

Advertisements

A Quick Walk-through on Azure Storage(SQL, NoSQL, NewSQL)


It’s always imaginable that developers are always flexible to proceed with relational databases while migrating an existing on-premise app to Azure platform while leveraging best possible architectural guidelines on migration to cloud. But, still forth in real-time cases , typical scenarios like suboptimal performance, high expenses, or worse case scenario because, NOSQL db can handle some tasks more efficiently than relational databases can. In few enterprise cases, it’s encountered a critical data storage problem, as because NOSQL solution implementation have been better off before deploying its app to production.

Moreover, there’s no single best data management choice for all data storage tasks, different data management solutions are optimized for different tasks. Let’s have a quick walk-through on various data storage option models supported on Microsoft Azure.

AzureDB

 

 

Let’s start first by four types of NOSQL db supported now Azure.

  • Key/value pair databases: store a single serialized object for each key value. They’re good for storing large volumes of data in situations where you want to get one item for a given key value and you don’t have to query based on other properties of the item.
  • Azure Blob Storage : It’s also a key/value based data storage which is same like as file system in functionality where you could search a file based on it’s folder/file name as key not file content as key. Blob offers read-write storage options (aka Block Blob) for storing large media files as well as for standard streaming purpose facilitates the usage of VHDs as Page Blob(aka Azure Drive).
  • Azure Table Storage : A standard key-value pair based NOSQL storage option prevailed from Azure storage inception phase. Each value is called an entity (similar to a row, identified by a partition key and row key) and contains multiple properties (similar to columns, but not all entities in a table have to share the same columns). Querying on columns other than the key is extremely inefficient and should be avoided.
  • Document Databases : Popular key/value databases in which the values are documents. “Document” here isn’t used in the sense of a Word or an Excel document but means a collection of named fields and values, any of which could be a child document. For example, in an order history table, an order document might have order number, order date, and customer fields, and the customer field might have name and address fields. The database encodes field data in a format such as XML, YAML, JSON, or BSON, or it can use plain text. One feature that sets document databases apart from other key/value databases is the capability they provide to query on nonkey fields and define secondary indexes, which makes querying more efficient. This capability makes a document database more suitable for applications that need to retrieve data on the basis of criteria more complex than the value of the document key.

Example : Mongo DB.

  • Column-family databases : key/value pair based data storage enables to structure data based on collections of columns called ‘Column families‘. For example, a population database consists of one group of column called ‘Persons’ (containing firstname, middlename, lastname) , one group for person’s address & another for profile info. The database can then store each column family in a separate partition while keeping all of the data for one person related to the same key. You can then read all profile information without having to read through all of the name and address information as well.

Example : Cassendra , Apache HBase (in preview supported with HDInsight as NOSQL Blob Storage)

  • Graph databases : Stores data in form of objects & relationships.The purpose of a graph database is to enable an application to efficiently perform queries that traverse the network of objects and the relationships between them. For example, the objects might be employees in a human resources database, and you might want to facilitate queries such as “find all engineers who directly or indirectly work for Product Manager.”

Example : Neo4j Graph Database.

Compared with relational databases, the NoSQL options offer far greater scalability and are more cost effective for storage and analysis of unstructured data. The tradeoff is that they don’t provide the rich querying and robust data integrity capabilities of relational databases. NoSQL options would work well for IIS log data, which involves high volume with no need for join queries. NoSQL options would not work so well for banking transactions, which require absolute data integrity and involve many relationships to other account-related data.

  • A brief about NewSQL : Combines the scalability features of NOSQL along with distributed querying & transactional integrity of OldSQL.
  • The first type of NewSQL systems are completely new database platforms. These are designed to operate in a distributed cluster of shared-nothing nodes, in which each node owns a subset of the data. Though many of the new databases have taken different design approaches, there are two primary categories evolving. The first type of system sends the execution of transactions and queries to the nodes that contain the needed data. SQL queries are split into query fragments and sent to the nodes that own the data. These databases are able to scale linearly as additional nodes are added.
  • General-purpose databases
    These maintain the full functionality of traditional databases, handling all types of queries. These databases are often written from scratch with a distributed architecture in mind, and include components such as distributed concurrency control, flow control, and distributed query processing. This includes Google Spanner, Clustrix, FoundationDB, NuoDB,TransLattice, ActorDB,andTrafodion.
    In-memory databases
    The applications targeted by these NewSQL systems are characterized as having a large number of transactions that (1) are short-lived (i.e., no user stalls), (2) touch a small subset of data using index lookups (i.e., no full table scans or large distributed joins), and (3) are repetitive (i.e. executing the same queries with different inputs).
    These NewSQL systems achieve high performance and scalability by eschewing much of the legacy architecture of the original IBM System R design, such as heavyweight recovery or concurrency control algorithms.
    Example systems in this category are:VoltDB, Pivotal‘s SQLFire and GemFire XD, SAP HANA.
    Example : NuoDB is supported in Azure as NewSQL.
    • Key Points to Consider while choosing the Data Storage Options :

Data semantic


What is the core data storage and data access semantic (are you storing relational or unstructured data)?
Unstructured data such as media files fits best in Blob storage; a collection of related data such as products, inventories, suppliers, customer orders, etc., fits best in a relational database.
Query support


How easy is it to query the data?
What types of questions can be efficiently asked?
Key/value data stores are very good at getting a single row when given a key value, but they are not so good for complex queries. For a user-profile data store in which you are always getting the data for one particular user, a key/value data store could work well. For a product catalog from which you want to get different groupings based on various product attributes, a relational database might work better.
NoSQL databases can store large volumes of data efficiently, but you have to structure the database around how the app queries the data, and this makes ad hoc queries harder to do. With a relational database, you can build almost any kind of query.
Functional projection


Can questions, aggregations, and so on be executed on the server?
If you run SELECT COUNT(*) from a table in SQL, the DBMS will very efficiently do all the work on the server and return the number you’re looking for. If you want the same calculation from a NoSQL data store that doesn’t support aggregation, this operation is an inefficient “unbounded query” and will probably time out. Even if the query succeeds, you have to retrieve all the data from the server and bring it to the client and count the rows on the client.
What languages or types of expressions can be used?
With a relational database, you can use SQL. With some NoSQL databases, such as Azure Table storage.

Ease of scalability


How often and how much will the data need to scale?
Does the platform natively implement scale-out?
How easy is it to add or remove capacity (size and throughput)?
Relational databases and tables aren’t automatically partitioned to make them scalable, so they are difficult to scale beyond certain limitations. NoSQL data stores such as Azure Table storage inherently partition everything, and there is almost no limit to adding partitions. You can readily scale Table storage up to 200 terabytes, but the maximum database size for Azure SQL Database is 500 gigabytes. You can scale relational data by partitioning it into multiple databases, but setting up an application to support that model involves a lot of programming work.
Instrumentation and Manageability


How easy is the platform to instrument, monitor, and manage?
You need to remain informed about the health and performance of your data store, so you need to know up front what metrics a platform gives you for free and what you have to develop yourself.
Operations


How easy is the platform to deploy and run on Azure? PaaS? IaaS? Linux?
Azure Table storage and Azure SQL Database are easy to set up on Azure. Platforms that aren’t built-in Azure PaaS solutions require more effort.
API Support


Is an API available that makes it easy to work with the platform?
The Azure Table Service has an SDK with a .NET API that supports the .NET 4.5 asynchronous programming model. If you’re writing a .NET app, the work to write and test the code will be much easier for the Azure Table Service than for a key/value column data store platform that has no API or a less comprehensive one.
Transactional integrity and data consistency


Is it critical that the platform support transactions to guarantee data consistency?
For keeping track of bulk emails sent, performance and low data-storage cost might be more important than automatic support for transactions or referential integrity in the data platform, making the Azure Table Service a good choice. For tracking bank account balances or purchase orders, a relational database platform that provides strong transactional guarantees would be a better choice.
Business continuity


How easy are backup, restore, and disaster recovery?
Sooner or later production data will become corrupted and you’ll need an undo function. Relational databases often have more fine-grained restore capabilities, such as the ability to restore to a point in time. Understanding what restore features are available in each platform you’re considering is an important factor to consider.
Cost


If more than one platform can support your data workload, how do they compare in cost?
For example, if you use ASP.NET Identity, you can store user profile data in Azure Table Service or Azure SQL Database. If you don’t need the rich querying facilities of SQL Database, you might choose Azure Table storage in part because it costs much less for a given amount of storage.

%d bloggers like this: