Ejemplo n.º 1
0
 private void createDatapointOnEntity(Entity e)
 {
     if (!e.HasDatapoint())
     {
         var entityDatapoint = new EntityDatapoint(e, route.TrimEnd('/') + "/" + e.Guid + "/");
     }
 }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
 public static void SetDatapoint(this Entity entity, EntityDatapoint datapoint)
 {
     lock (datapoints)
         datapoints.Add(entity.Guid, datapoint);
 }