Xamarin Mobile Applications Unpacked – Video Release

inStruct event recorded at Riverside Hotel, 10 March 2015.

KitKat, Jelly Bean, iOS, Windows Mobile … where on earth do you start when you get into mobile development.

Mobile applications development is an ever shifting space, and transitioning into this environment means a steep learning curve. Differing operating platforms and the various development environments add layers of complexity.

The Kaleidocode team faced a mountain of questions when we started mobile development on a large enterprise driven application. In an attempt to modify the extremity of learning required and accommodate the myriad of operating platforms, we reached for Xamarin Studio.

In this session we look at;

  • Xamarin Studio, why did we select this particular tooling?
  • A demonstration on writing an iOS and Android app using a common C# code base.
  • The good, the bad and downright ugly truth about developing mobile apps.
  • The future of Xamarin using Xamarin Forms.
Advertisements

Free Instruct Event – Xamarin Mobile Apps Unpacked

instruct_small

Join us for a coffee and muffin Instruct event hosted by Chris Tite (entrepreneur, architect and speaker) and joined by Kaleidocode Developers, Steven van der Merwe and Divan Visagie on Xamarin Mobile Apps Unpacked.

Eventbrite - Xamarin Mobile Apps Unpacked

KitKat, Jelly Bean, iOS, Windows Mobile …

Where on earth do you start when you get into mobile development!

Mobile applications development is an ever shifting space, and transitioning into this environment means a steep learning curve. Differing operating platforms and the various development environments add layers of complexity!

The Kaleidocode team faced a mountain of questions when we started mobile development on a large enterprise driven application. In an attempt to modify the extremity of learning required and accommodate the myriad of operating platforms, we reached for Xamarin Studio.

Join us for coffee and muffins as we share the tales of trials and triumphs we experienced when embarking on this journey.

In this session we look at;

  • Xamarin Studio, why this particular tooling?
  • A demonstration on writing an iOS and Android app using a common C# code base.
  • The good, the bad and downright ugly truth about developing mobile apps.
  • The future of Xamarin using Xamarin Forms.

For more information about Chris please see christite.net.

For an invitation contact Chris at chris.tite@kaleidocode.co.za or Rory at rory.clarke@kaleidocode.co.za / 031 303 2299 or register below.

Eventbrite - Xamarin Mobile Apps Unpacked

To review the video of the last KC Instruct event, Domain Driven Design go to http://youtu.be/BPAZwFNxgrg or catch up with all past events at https://www.youtube.com/user/instructchannel/videos

BROUGHT TO YOU BY

@kaleidocode
Kaleidocode Pty Ltd
Office 200, 295 Florida Rd Morningside Durban

Session Resources – NoSQL Explained – Demo 3: Connecting to MongoDB using .Net

Using .Net to insert a document into MongoDB

To run this demo please ensure that your MongoDB instance is running before starting. If you are unsure how to get an instance of MongoDB running please view the Session Resources – NoSQL Explained – Running an MongoDB instance page for details on how to get an instance of MongoDB running on your machine.

This demo was prepared using the 10gen MongoDB driver, ensure that your project references MongoDB.Bson and MongoDB.Driver.

Use NuGet to install the correct MongoDB supporting dlls.

I am going to start off the Demo code by defining an Employee class that I will use as my document structure in MongoDB. Recall that MongoDB is a document database so all data entities are referred to as documents which are found in collections. A document in MongoDB often has nested documents thus creating a fairly complex document structure. In this demo we are not going to create any complex structure we are going to work with a very simple flat document which will define an Employee in our system.


    public class Employee
    {
        public ObjectId Id { get; set; }
        public string Name { get; set; }
        public string Surname { get; set; }
        public DateTime DateAdded { get; set; }
    }

Adding your first document using .Net

Now that we have a class that defines our document we can look at the code to insert the document into the MongoDB. Below I have added a few lines of code which will connect to an instance of MongoDB and insert the Employee document into the Employees collection.


	private string AddEmployee(string name, string surname, DateTime dateAdded)
	{
		//using the client connect to the server
		string connectionString = "mongodb://localhost";
		MongoClient mongoClient = new MongoClient(connectionString);

		//using a server connection get a hook to the database
		MongoServer server = mongoClient.GetServer();
		MongoDatabase database = server.GetDatabase("Demo3");

		//Create an employee object
		Employee employee = new Employee {Name = name, Surname = surname,
                   DateAdded = dateAdded};

		//Get a reference to the Employees collection
		MongoCollection employees = database.GetCollection("Employees");

		//Add the document to the collection
		employees.Insert(employee);

		//return the MongoDB unique identifier
		return employee.Id.ToString();
	}

So what is actually happening in the code above?

The code breaks down as follows.

The first four lines of code establish a connection to an instance of MongoDB using the database Demo3. Next we create an new Employee document setting the attributes to the correct values (name, surname and date added). We then get a reference to the Employees collection and finally insert the Employee document into the Employees collection.
We now have an employee document in the Employees collection of the Demo3 database.

Finding the Inserted document

Now that we have an Employee document in our database we would need to find it to be able to provide any form of useful business application. Finding a document is equally as simple as inserting one, the code below shows just how simple it is.

</pre>
     private string FindEmployeeByName(string employeeName)
     {
         //using the client connect to the server
         string connectionString = "mongodb://localhost";
         MongoClient mongoClient = new MongoClient(connectionString);

         //using a server connection get a hook to the database
         MongoServer server = mongoClient.GetServer();
         MongoDatabase database = server.GetDatabase("Demo3");

         //Create a query, find an employee whose name is equal
         //to that supplied in the variable employeeName
         var query = Query.EQ(emp => emp.Name, employeeName);

         //Get a reference to the Employees collection
         MongoCollection employees = database.GetCollection("Employees");

         //Apply query, using the findOne command
         Employee employee = employees.FindOne(query);

         //Return the result
         if (employee != null)
         {
             //Return a concatenated version of the record
             return employee.Name + " " + employee.Surname + " - Added on "
                  + employee.DateAdded;
         }

         return "Not Found!";

     }

The code breaks down as follows.

The first four lines of code establish a connection to an instance of MongoDB using the database Demo3, much like we did when we were inserting a document. For purposes of demonstration I have included these four lines again, when writing actual production code this connection logic would be managed in a separate connection manager class to encourage code reuse.

Next we create a query, telling MongoDB that we wish to find an Employee document where the name is equal (EQ) to the name supplied. We then get a reference to the Employees collection and run the query against the Employees collection, using a findOne command.

Note that we could have used the find command to return a collection of documents which met our search criteria.

We should now have an Employee document, we check if we have a returned document, if so return the required information, in this case a “flattened” version of the record.