Beispiel #1
0
 public static AttributeDatapoint GetDatapoint(this ECABaseModel.Attribute attribute)
 {
     if (!attribute.HasDatapoint())
     {
         Console.WriteLine("WARNING: NO DATAPOINT FOUND FOR ATTRIBUTE {0}:{1}:{2}\n{3}",
                           attribute.ParentComponent.ContainingEntity.Guid,
                           attribute.ParentComponent.Name,
                           attribute.Prototype.Name,
                           new StackTrace().ToString());
         return(null);
     }
     lock (datapoints)
         return(datapoints[attribute.ParentComponent.Guid.ToString() + "." + attribute.Prototype.Name]);
 }
Beispiel #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);
        }
Beispiel #3
0
 public static bool HasDatapoint(this ECABaseModel.Attribute attribute)
 {
     lock (datapoints)
         return(datapoints.ContainsKey(attribute.ParentComponent.Guid.ToString() + "." + attribute.Prototype.Name));
 }
Beispiel #4
0
 public static void SetDatapoint(this ECABaseModel.Attribute attribute, AttributeDatapoint datapoint)
 {
     lock (datapoints)
         datapoints.Add(attribute.ParentComponent.Guid.ToString() + "." + attribute.Prototype.Name, datapoint);
 }
Beispiel #5
0
 public AttributeLDPGraph(Uri u, ECABaseModel.Attribute a) : base(u)
 {
     attribute = a;
     BuildRDFGraph();
 }
Beispiel #6
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)
 {
     graph = new AttributeLDPGraph(new Uri(uri), attribute);
 }