MonoAndroid

I really love MonoAndroid! I got an email from Joseph Hill at Xamarin – asking if we had tested ECO in this environment – I replied that we had glanced at it but I would look at it in more detail. This was the day before Christmas – 4 days later I had everything working – cool beans – and yes I celebrated Christmas just as much as any other Atheist out there (had a few beers and handed out presents).

The MonoAndroid trial is enough for our purposes here until we want to deploy to a real phone.
First spin of ECO on Android. First read this

Open up the sample that comes with ECO:

image

Open up the sln and ignore/ok this:

image_thumb[7]_thumb

You will see this:

image

The ReadMe explains the missing projects but since you are a developer you will probably not read it.

Delete the missing projects. And add new references to MonoAndroidApplication1

image

Choose browse and find the assemblies you downloaded in the PhoneBuilds.zip

image

Define what to start:

image

image

Hit F5 – This windows shows:

image

Start emulator Image: Pick MonoAndroid_API_10

When the Emulator runs:

image

you choose it:

image

And you get this window, the Root directory of our PersistenceServer

image

This is a simple WPF UI that shows the information in our “database”

image

This is the Phone App

image

Press the first button :

image

The text of the button was updated. The code on the phone:

void button_Click(object sender, EventArgs e)
{
    EcoServiceHelper.GetPersistenceService(_ecospace).Refresh(true);
    Button button = FindViewById<Button>(Resource.Id.MyButton);
    IObjectList list = EcoServiceHelper.GetOclPsService(_ecospace).Execute("Class1.allinstances->select(a|a.Class2->notempty)");
    int noOfC1ThatHasC2s = list.Count;
    string extra="";
    if (list.Count > 0)
        extra = list[0].GetValue<Class1>().Attribute1;

    int noOfC1 = EcoServiceHelper.GetExtentService(_ecospace).AllInstances<Class1>().Count;

    button.Text = "db updated, Now C1 Total: " + noOfC1.ToString() + ", Total of C1 that has C2's " + noOfC1ThatHasC2s.ToString() + " " + extra;        
    
}

The code makes use of some ECO services.

The other buttons Code:

void button2_Click(object sender, EventArgs e)
{
    Button button2 = FindViewById<Button>(Resource.Id.MyButton2);
    
    Class1 c1 = new Class1(_ecospace);
    c1.Attribute1 = "Created on android by mono " + DateTime.Now.ToLongTimeString();
    button2.Text = "c1 created";

    _ecospace.UpdateDatabase();
}

We switch back to the WCF app – hit Refresh:

image

You can play around with the WPF app and the Phone app to ensure yourself that objects created in one client can be seen in the other client after a Refresh.

If things does not work consult the WCF trouble-shoot

That is all I am going to show you about the Android Phone right now. Disappointed? Don’t be – we did a lot – strongly typed model driven business objects on the phone with a WCF connection to the server – that persists everything – and lets you find what is on the server.

This entry was posted in Mono, WCF. Bookmark the permalink.

2 Responses to MonoAndroid

  1. william says:

    Mobile development support is nice. However I have turned into REST/JSON for recent projects since
    1) I need server side logic (similar to what MIDAS/DataSnap do in the AppServer)
    2) Integration with/by other non-Eco projects.

    Thus personally I would like to see support for REST in the future 😛

    • Admin says:

      You are free to add REST services to your service side eco apps. I have seen one cool project that turned ViewModel definitions and exposed them as query results. Maybe a cool generic service would be REST-ocl-query+ViewModelName and JSON streamed output…

Leave a Reply

Your email address will not be published. Required fields are marked *

*