Documentation : Windows Phone 7 Simple Tutorial

This is a simple example where we describe how to sync blog entries between devices. To develop this case you should:

  • design simple model with two fields
  • deploy our simple app on test enviroment
  • configure your app on the mobile
  • use our API to sync designed model between devices

Create your App

Start working with the Mobeelizer. Create your FREE account.

Let's design your first App. Open the Mobeelizer App Designer and login with your account. Then, press CREATE NEW APPLICATION button and insert it's name blog.

Design your App Schema

In your applications designer panel enter Models section on the left. Then create new model Blog and add two text fields to it.



Deploy your App into the test environment

In your applications designer panel enter Models section on the left. Then create new model Blog and add two text fields to it.

Get the Mobeelizer SDK

Prepare plain Windows Phone 7 project, get the Mobeelizer SDK, unzip it, unblock all dll files and add them as a project references, also remember to add System.Data.Linq to your project references.

Get your App definition

Download App definition and add it into the project as "application.xml". Open file properties and set 'Build Action' property to Content.

Confligure your App

Create "app.config" file and add it into project. Open file properties and set 'Build Action' property to Content. Configure your App.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="mobeelizer-configuration"
        type="Com.Mobeelizer.Mobile.Wp7.Configuration.MobeelizerConfigurationSection, wp7-sdk" />
    </configSections>
    <mobeelizer-configuration>
        <properties>
            <add name="mode" value="test"/>
            <add name="developmentRole" value="users-mobile"/>
            <add name="entitiesNamespace" value="yourEntitiesNamespace, yourAssemblyName" /> 
            <add name="device" value="mobile"/>
        </properties>
    </mobeelizer-configuration>
</configuration>

Want to know what these metadata mean? Check the documentation for detailed description.

Create Blog object

Create class "Blog" in "yourEntitiesNamespace" namespace.

using System;
using Com.Mobeelizer.Mobile.Wp7.Api;
using System.Data.Linq.Mapping;
 
namespace yourEntitiesNamespace
{
    [Table]
    public class Blog : MobeelizerWp7Model
    {
        [Column(IsPrimaryKey = true)]
        public override String Guid { get; set; }

        [Column()]
        public override String Owner { get; set; }

        [Column()]
        public override bool Conflicted { get; set; }

        [Column()]
        public override bool Deleted { get; set; }

        [Column()]
        public override bool Modified { get; set; }
 
        [Column()]
        public String Content { get; set; }
 
        [Column()]
        public String Title { get; set; }
    }
}

Looking for information how to convert schema definition into objects? Check the documentation for detailed description.

Use the Mobeelizer SDK

Open App class and handle Mobeelizer application lifetime methods.

private void Application_Launching(object sender, LaunchingEventArgs e)
{
    Mobeelizer.OnLaunching();
}
 
private void Application_Activated(object sender, ActivatedEventArgs e)
{
    Mobeelizer.OnActivated(e.IsApplicationInstancePreserved);
}
 
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
    Mobeelizer.OnDeactivated();
}
 
private void Application_Closing(object sender, ClosingEventArgs e)
{
    Mobeelizer.OnClosing();
}

 

Before any object will be stored the device must be authenticated.

 

Mobeelizer.Login("user", "password", (error) => {
       	if(error == null)
		{
		}
		else
		{
			Console.Out.WriteLine("Error code is: {0} \nMessage: {1}", error.Code, error.Message);
		}
    });

 

Once you are logged in you have access to the database.

 

IMobeelizerDatabase database = Mobeelizer.GetDatabase();

 

Let's create a Blog object and store it in the database.

 

Blog blog = new Blog();
blog.Title = "First entry";
blog.Content = "I'm proud to announce that my first application is working properly.";
using (var transaction = database.BeginTransaction())
{
    transaction.GetModelSet<Blog>().InsertOnSubmit(blog);
    transaction.SubmitChanges();
}

 

So we have stored our very first object. Let's check it.

using (var transaction = database.BeginTransaction())
{
    var query = from b in transaction.GetModelSet<Blog>() select b;
	int count = query.ToList().Count; // => count == 1
	var getQuery = from b in transaction.GetModelSet<Blog>() where b.Guid == blog.Guid select b;
	Blog blogFromDatabase =getQuery.Single(); // => blogFromDatabase != null
}

 

Is our Blog entry shared in the cloud? It will be soon.

Mobeelizer.Sync(error => {
	    if(error == null)
		{

		}
		else
		{
			Console.Out.WriteLine("Error code is: {0} \nMessage: {1}", error.Code, error.Message);
		}
});

 

Remember to logout before closing the application.

 

Mobeelizer.Logout();

 

Run the App on the device

That's all. Compile your App and deploy it to the device. Then create a blog entry and sync it with the cloud. It will be visible by other devices.

Attachments:

insert_model_name.png (image/png)
download_wp7_sdk.png (image/png)
download_wp7_sdk.png (image/png)
insert_application_name.png (image/png)
newModel.png (image/png)
newField1.png (image/png)
newField2.png (image/png)
deploy.png (image/png)