static void Main(string[] args) { Console.WriteLine("Hello World!"); ValueResource <int> testResource = new ValueResource <int>(3, "http://127.0.0.1:3333/int/"); ValueResource <XmlBool> test2 = new ValueResource <XmlBool>(new XmlBool(true), "http://127.0.0.1:3333/bool/"); WebsocketSubscription wsSubscription = new WebsocketSubscription("ws://stuff"); WebHookSubscription whSubscription = new WebHookSubscription("http://test"); ObservableCollection <int> c = new ObservableCollection <int>(); CollectionResource <ObservableCollection <int>, int> r = new CollectionResource <ObservableCollection <int>, int>(c, "http://localhost:12345/c/"); testResource.Subscribe(whSubscription); testResource.Subscribe(wsSubscription); Console.WriteLine("Any key to change int to 12 ..."); Console.ReadKey(); testResource.Value = 12; r.Subscribe(whSubscription); r.Subscribe(wsSubscription); Console.WriteLine("Any key to add 12 to Collection..."); Console.ReadKey(); r.Value.Add(12); Console.WriteLine("Any key to close application..."); Console.ReadKey(); }
public void AddSubscriptionRoute(string path, WebsocketSubscription subscription) { try { server.AddWebSocketService(path, () => new WsBehaviour(subscription)); } catch (Exception e) { Console.WriteLine("Failed to add WebSocketService for path {0} : {1}", path, e.Message); } }
/// <summary> /// Constructor. /// </summary> /// <param name="attribute"><seealso cref="ECABaseModel.Attribute"/> that is to be represented by the RDF endpoint</param> /// <param name="uri">Endpoint listener URI</param> public AttributeDatapoint(ECABaseModel.Attribute attribute, string uri) : base(uri) { this.attribute = attribute; // In case we store an Entity as attribute, the resulting Resource should rather point to the datapoint that is created for it. bool isEntity = attribute.Type.Equals(typeof(ECABaseModel.Entity)); bool isEntityCollection = attribute.Type.Equals(typeof(ECABaseModel.EntityCollection)); // In case that the attribute contains another entity, we have to check whether there is already a Datapoint set up for it. If not, // we take care of this here. This follows the idea of automatic recursive Datapoint generation. if (isEntity && !((ECABaseModel.Entity)attribute.Value).HasDatapoint()) { ECABaseModel.Entity child = (ECABaseModel.Entity)attribute.Value; var childEntityDP = new EntityDatapoint(child, this.Route.TrimEnd('/') + "/" + child.Guid + "/"); var childGraph = childEntityDP.graph.RDFGraph; childGraph.Assert(new VDS.RDF.Triple( childGraph.CreateUriNode(new Uri(this.Route.TrimEnd('/') + "/" + child.Guid + "/")), childGraph.CreateUriNode("dct:isPartOf"), childGraph.CreateUriNode(new Uri(attribute.ParentComponent.ContainingEntity.GetDatapoint().Route)) )); } if (isEntityCollection && !((ECABaseModel.EntityCollection)attribute.Value).HasDatapoint()) { var child = (ECABaseModel.EntityCollection)attribute.Value; var childExDP = new EntityCollectionDatapoint(child, this.Route.TrimEnd('/') + "/" + child.Guid + "/"); } // The RDF Graph vor the Attribute Node needs to point to this entity resource accordingly, instead of assuming a separate // attribute datapoint if (!(isEntity || isEntityCollection)) { graph = new AttributeLDPGraph(new Uri(uri), attribute); } else if (isEntity) { graph = new AttributeLDPGraph(new Uri(uri), attribute, ((ECABaseModel.Entity)attribute.Value).GetDatapoint().Route); } else { graph = new AttributeLDPGraph(new Uri(uri), attribute, ((ECABaseModel.EntityCollection)attribute.Value).GetDatapoint().Route); } // if we have any other type of attribute, we go on to generate a datapoint for the attribute value based on the type of the attribute by // reflection if (!isEntity && !isEntityCollection) { Type valueResourceType = typeof(ValueResource <>).MakeGenericType(attribute.Type); Uri datapointUri = new Uri(uri); Uri wsUri = new Uri("ws://" + datapointUri.Host + ":" + (datapointUri.Port + 1) + datapointUri.PathAndQuery + "/ws/"); WebsocketSubscription ws = new WebsocketSubscription(wsUri.ToString()); ConstructorInfo constructor = valueResourceType.GetConstructor(new Type[] { attribute.Type, typeof(string) }); valueResource = constructor.Invoke(new object[] { attribute.Value, (uri + "/value/") }); EventInfo eventInfo = valueResourceType.GetEvent("ValueChanged"); eventInfo.AddEventHandler(valueResource, new EventHandler <EventArgs>(HandleValueChanged)); MethodInfo subscribe = valueResourceType.GetMethod("Subscribe"); subscribe.Invoke(valueResource, new object[] { ws }); } attribute.SetDatapoint(this); }
public WsBehaviour(WebsocketSubscription subscription) { this.subscription = subscription; subscription.Behaviour = this; }