static void Main(string[] args) { // Define a component with custom name. This name will be used to access the component on any entity. ComponentPrototype p = new ComponentPrototype("component"); // Add a set of attributes. The names are used to access the attributes on instatiated components p.AddAttribute <float>("numeric"); p.AddAttribute <string>("string"); p.AddAttribute <bool>("boolean"); // Once the protoype and its set of attributes is defined, register it to the global Component Registry ComponentRegistry.Instance.Register(p); // We are now all set to use our defined component on entities. For this, first, we create a new empty entity. Entity e = new Entity(); // Components are automatically instatiated on first access. So we can just set the values on our entity as follow: e["component"]["numeric"].Set(3.14); e["component"]["string"].Set("Hello World"); e["component"]["boolean"].Set(true); // Last, we expose our entity on an HTTP datapoint as Linked Data object. The ECA2LD lib will take care of building the correct // RDF graph, and creating and wiring datapoints for the linked component and attribute instances. var eDP = new EntityDatapoint(e, "http://localhost:12345/entities/e/"); // Our entity is now ready and set to be added to the world. The attributes could have been set as above afterwards as well. // Then events would have informed other parts of the program that our entity was changed. CEC.Instance.Add(e); // This concludes the example. In the future, support to add datapoints on the Entity Collection should be implemented. This // would automatize the process of creating datapoints for each entity manually. Console.ReadKey(); }
static void Main(string[] args) { string host = "localhost"; string port = "12345"; if (args.Length > 0) { if (args.Length != 2) { Console.WriteLine("Please supply exactly two arguments for host configuration: <hostname> <port>. Using default values <localhost> <12345>."); } else { host = args[0]; port = args[1]; try { var uri = new Uri("http://" + host + ":" + port + "/world/"); } catch (Exception e) { Console.WriteLine("Supplied arguments {0}, {1} do not form a valid host specifaction. Using default vaules <localhost> <12345>.", args[0], args[1]); host = "localhost"; port = "12345"; } } } string basePath = "http://" + host + ":" + port + "/world/"; Console.WriteLine("Entities are hosted at " + basePath); SpatialEntityComponent.RegisterComponents(); GeometryComponent.Register(); RobotComponent.Register(); var tisch = buildTisch(); var schrauber = buildSchrauber(); var worker = birthWorker(); var robot = assembleRobot(basePath); // Last, we expose our entity on an HTTP datapoint as Linked Data object. The ECA2LD lib will take care of building the correct // RDF graph, and creating and wiring datapoints for the linked component and attribute instances. var tischDP = new EntityDatapoint(tisch, basePath + "tisch/"); var schraubDP = new EntityDatapoint(schrauber, basePath + "schrauber/"); var workerDP = new EntityDatapoint(worker, basePath + "worker/"); var robotDP = new EntityDatapoint(robot, basePath + "robot/"); var worldDatapoint = new EntityCollectionDatapoint(CEC.Instance, basePath); // Our entity is now ready and set to be added to the world. The attributes could have been set as above afterwards as well. // Then events would have informed other parts of the program that our entity was changed. CEC.Instance.Add(tisch); CEC.Instance.Add(schrauber); CEC.Instance.Add(worker); CEC.Instance.Add(robot); // This concludes the example. In the future, support to add datapoints on the Entity Collection should be implemented. This // would automatize the process of creating datapoints for each entity manually. Console.WriteLine("\n\n Press Key to shutdown"); Console.ReadKey(); }