Changes

New page: The objective of this Lab is to develop a new Sugar activity using C# and Mono. You will learn consecutively how to use MonoDevelop to write the source code of your activity, build a packa...
The objective of this Lab is to develop a new Sugar activity using C# and Mono. You will learn consecutively how to use MonoDevelop to write the source code of your activity, build a package, test your activity on Sugar and on a XO.

= Step 1: Create your MonoDevelop project =

* Launch MonoDevelop (Applications/Programming/MonoDevelop)
* Create a new solution (File/New Solution…)
* Choose a "C# / Gtk# 2.0 Project" template. Fill the form with "LabActivity" as name. Uncheck the "Create separate Solution Directory"

[[Image:Lab1_1.png|400px]]

* Click the "Forward" button.
* In the next window, don't change any option. Don't change the Gtk# version suggested. Don't check any checkbox. Then click on "OK".

The solution is now created. We're going to setup it.

* Add reference on Sugar. Right click on References, "Edit References…", choose the ".Net Assemblies" sheet. Select "Sugar.dll" in the "/home/user/Prerequisites" directory. Click on the "+Add" button then OK.

[[Image:Lab1_2.png|400px]]

* Remove the file "Main.cs" from the solution: right click on the Main.cs file, then choose "Remove" and check the "Delete from disk" box.


= Step 2: Create a simple Window =

* Update the content of the file MainWindow.cs like below. Note than this file is available on the "/home/user/LabSource/lab1/step2" directory.

using System;
using System.Collections;
using Gtk;
using Sugar;

namespace LabActivity
{
public class MainWindow : Sugar.Window
{
public new static string activityId="";
public new static string bundleId="";

public MainWindow(string activityId, string bundleId) : base("Lab",activityId, bundleId)
{
this.SetDefaultSize(400, 400);
this.Maximize();
this.DeleteEvent += new DeleteEventHandler(OnMainWindowDelete);

VBox vbox=new VBox();
vbox.BorderWidth = 8;
Label _text = new Label("Hello Lab Activity");
vbox.Add(_text);
Button _button = new Button();
_button.Label = "Quit";
_button.Clicked += new EventHandler(OnClick);
vbox.Add(_button);

this.Add(vbox);

ShowAll();
}

void OnMainWindowDelete (object sender, DeleteEventArgs a)
{
Application.Quit();
a.RetVal = true;
}

void OnClick(object sender, EventArgs a)
{
Application.Quit();
}

public static void Main(string[] args)
{
System.Console.Out.WriteLine("Lab Activity for OLPC");

if (args.Length>0) {
IEnumerator en= args.GetEnumerator();
while (en.MoveNext()) {
if (en.Current.ToString().Equals("-s ugarActivityId")) {
if (en.MoveNext()) {
activityId=en.Current.ToString();
}
}
if (en.Current.ToString().Equals("-sugarBundleId")) {
if (en.MoveNext()) {
bundleId=en.Current.ToString();
}
}
}
}

Application.Init();
new MainWindow(activityId, bundleId);
Application.Run();
}

}
}

* Save the file: "File/Save"
* Open the "User Interface" part of the solution, remove the file "LabActivity.MainWindow": right clic, choose "Delete", UNCHECK THE BOX "Also remove the 'MainWindow.cs'.
* Launch the build "Project/Build Solution"
* You don't any any error. Don't run the project for the moment.

Then copy libraries need to run the activity:
* Open a Terminal window (Applications/Accessories/Terminal).
* Change path to the binary directory (in /home/user/LabActivity/bin/Debug).
* Create a new subdirectory named "bin" using command "mkdir bin". Change path to this new directory.
* Copy in this directory all the shared libraries (.so) found in the "/home/user/Prerequisites" directory. For example with the command "cp /home/user/Prerequisites/*.so .":
** libgdksharpglue-2.so
** libgladesharpglue-2.so
** libglibsharpglue-2.so
** libgtksharpglue-2.so
** libMonoPosixHelper.so
** libpangosharpglue-2.so
** uiX11Util.so
* Run the new application: "Project/Run", you should obtain this:

[[Image:Lab1_3.png|500px]]

* Click on the button to quit.