static void Main(string[] args) { //Create a user var user = new User { Name = "Steven" }; //Create a device var device = new Device { DeviceType = DeviceType.Desktop, DevicePortability = DevicePortability.Stationary, Owner = user }; //create databaseconfiguration var databaseConfiguration = new DatabaseConfiguration("127.0.0.1", 8080, "test"); //create activitysystem: this is the main component that provides an activity- //centric wrapper over a pure datastore. This system cam be used by the UI //directly through events or be exposed to a REST service using the activityservice //and accessed on other devices by using the activityclient activitySystem = new ActivitySystem(databaseConfiguration,false) { Device = device }; //add handlers to the system for local UI support. activitySystem.ActivityAdded+=activitySystem_ActivityAdded; activitySystem.DeviceAdded += activitySystem_DeviceAdded; activitySystem.UserAdded += activitySystem_UserAdded; //Start a activityservice which wraps an activity system into a REST service var activityService = new ActivityService(activitySystem, "127.0.0.1", 8060); activityService.Start(); //make the system discoverable on the LAN activityService.StartBroadcast(DiscoveryType.Zeroconf, "activitySystem", "mycompany","1234"); activitySystem.StartLocationTracker(); activitySystem.Tracker.TagEnter += Tracker_TagEnter; //Wait for one second to allow the service to start Thread.Sleep(1000); //Use the discoverymanager to find the activityservice and connect to it //using an activityclient. This should be used to connect to the //activity system from a different device. var disco = new DiscoveryManager(); disco.DiscoveryAddressAdded += (sender, e) => { if (e.ServiceInfo.Code != "1234") return; var foundWebConfiguration = new WebConfiguration(e.ServiceInfo.Address); //Note that you don't have to use discovery but can connect directly //if you know the IP var activityClient = new ActivityClient(foundWebConfiguration.Address, foundWebConfiguration.Port, device); activityClient.ActivityAdded += activityClient_ActivityAdded; activityClient.UserAdded += activityClient_UserAdded; activityClient.DeviceAdded += activityClient_DeviceAdded; activityClient.FileResourceAdded += (o, i) => { Console.WriteLine("Resource {0} update received from activityclient over http", i.Resource.Id); using (var stream = activityClient.GetFileResource(i.Resource)) { var fileStream = File.Create(@"C:\Users\Public\Pictures\Sample Pictures\Desert-"+DateTime.Now.ToShortDateString()+".jpg", (int)stream.Length); var bytesInStream = new byte[stream.Length]; stream.Read(bytesInStream, 0, bytesInStream.Length); fileStream.Write(bytesInStream, 0, bytesInStream.Length); fileStream.Close(); } }; var act = new Activity(); activityClient.AddActivity(act); //activityClient.AddFileResource( // act, // "IMG", // Path.GetFileName(@"C:\Users\Public\Pictures\Sample Pictures\Desert.jpg"), // new MemoryStream(File.ReadAllBytes(@"C:\Users\Public\Pictures\Sample Pictures\Desert.jpg"))); }; disco.Find(DiscoveryType.Zeroconf); //To produce test data while (true) { Console.WriteLine("Press a + enter for new activity, press u + enter for new user"); var input = Console.ReadLine(); if(input == "a") activitySystem.AddActivity(new Activity()); if(input == "u") activitySystem.AddUser(new User()); } }
public bool Equals(Activity act) { return Id == act.Id; }