Пример #1
0
        public override async Task <VariableValue[]> ReadAllVariablesOfObjectTree(ObjectRef objectID)
        {
            JObject request = MakeSessionRequest();

            request["objectID"] = new JRaw(StdJson.ValueToString(objectID));
            return(await Post <VariableValue[]>("ReadAllVariablesOfObjectTree", request));
        }
Пример #2
0
        /// <summary>
        /// Writes a new value to a variable waiting for the receiving module to complete the write request.
        /// An exception is thrown when the variable does not exist. Check the return value to verify whether
        /// the receiving module successfully processed the write request.
        /// </summary>
        /// <param name="objectID">The object containing the variable</param>
        /// <param name="variableName">The name of the variable to write</param>
        /// <param name="value">The new value</param>
        /// <param name="timeout">Optional timeout</param>
        public virtual async Task <Result> WriteVariableSync(ObjectRef objectID, string variableName, VTQ value, Duration?timeout = null)
        {
            WriteResult res = await WriteVariablesSync(new VariableValues { VariableValue.Make(objectID, variableName, value) }, timeout);

            if (res.Failed())
            {
                return(Result.Failure(res.FailedVariables ![0].Error));
Пример #3
0
        public override async Task <ObjectValue> GetParentOfObject(ObjectRef objectID)
        {
            JObject request = MakeSessionRequest();

            request["objectID"] = new JRaw(StdJson.ValueToString(objectID));
            return(await Post <ObjectValue>("GetParentOfObject", request));
        }
Пример #4
0
        public override async Task HistorianDeleteAllVariablesOfObjectTree(ObjectRef objectID)
        {
            var request = MakeSessionRequest <HistorianDeleteAllVariablesOfObjectTreeReq>();

            request.ObjectID = objectID;
            await PostVoid(request);
        }
Пример #5
0
        public override async Task <ObjectValue> GetParentOfObject(ObjectRef objectID)
        {
            var request = MakeSessionRequest <GetParentOfObjectReq>();

            request.ObjectID = objectID;
            return(await Post <ObjectValue>(request));
        }
Пример #6
0
        public override async Task HistorianDeleteAllVariablesOfObjectTree(ObjectRef objectID)
        {
            JObject request = MakeSessionRequest();

            request["objectID"] = new JRaw(StdJson.ValueToString(objectID));
            await PostJObject("HistorianDeleteAllVariablesOfObjectTree", request);
        }
Пример #7
0
        public override async Task <VariableValues> ReadAllVariablesOfObjectTree(ObjectRef objectID)
        {
            var request = MakeSessionRequest <ReadAllVariablesOfObjectTreeReq>();

            request.ObjectID = objectID;
            return(await Post <VariableValues>(request, binaryDeserializer : BinSeri.VariableValue_Serializer.Deserialize));
        }
Пример #8
0
 public MemberRef(ObjectRef obj, string memberName)
 {
     if (memberName == null)
     {
         throw new ArgumentNullException(nameof(memberName), nameof(memberName) + " may not be null");
     }
     Object = obj;
     Name   = memberName;
 }
Пример #9
0
 public VariableRef(ObjectRef obj, string variableName)
 {
     if (variableName == null)
     {
         throw new ArgumentNullException(nameof(variableName), nameof(variableName) + " may not be null");
     }
     Object = obj;
     Name   = variableName;
 }
Пример #10
0
 public ObjectInfo(ObjectRef id, string name, string className, MemberRefIdx?parent = null, Variable[]?variables = null, LocationRef?location = null)
 {
     ID        = id;
     Name      = name ?? throw new ArgumentNullException(nameof(name), nameof(name) + " may not be null");
     ClassName = className ?? throw new ArgumentNullException(nameof(className), nameof(className) + " may not be null");
     Variables = variables ?? Array.Empty <Variable>();
     Parent    = parent;
     Location  = location;
 }
Пример #11
0
        public override object?ReadJson(JsonReader reader, Type objectType, object?existingValue, JsonSerializer serializer)
        {
            string?str = (string?)reader.Value;

            if (str == null)
            {
                return(null);
            }
            return(ObjectRef.FromEncodedString(str));
        }
Пример #12
0
        internal ObjectRef?GetObjectParent(ObjectRef o)
        {
            if (!mapObjects.ContainsKey(o))
            {
                return(null);
            }
            ObjectInfo info = mapObjects[o];

            if (info.Parent.HasValue)
            {
                return(info.Parent.Value.Object);
            }
            return(null);
        }
Пример #13
0
 public void SetAllObjects(ObjectInfo[] allObjs)
 {
     allObjects = new List <ObjectInfo>(allObjs);
     mapObjects.Clear();
     objectsWithChildren.Clear();
     foreach (ObjectInfo obj in allObjects)
     {
         mapObjects[obj.ID] = obj;
         if (obj.Parent.HasValue)
         {
             ObjectRef parent = obj.Parent.Value.Object;
             objectsWithChildren.Add(parent);
         }
     }
     variables.Sync(allObjects);
 }
Пример #14
0
 /// <summary>
 /// Writes a new value to a variable without waiting for the receiving module to complete the write request.
 /// An exception is thrown when the variable does not exist.
 /// </summary>
 /// <param name="objectID">The object containing the variable</param>
 /// <param name="variableName">The name of the variable to write</param>
 /// <param name="value">The new value</param>
 public virtual async Task WriteVariable(ObjectRef objectID, string variableName, VTQ value)
 {
     await WriteVariables(new VariableValues { VariableValue.Make(objectID, variableName, value) });
 }
Пример #15
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            string str = (string)reader.Value;

            return(ObjectRef.FromEncodedString(str));
        }
Пример #16
0
 /// <summary>
 /// Reads the current value of a variable directly from the containing module.
 /// Throws an exception if the variable does not exist or the timeout expires.
 /// </summary>
 /// <param name="objectID">The object containing the variable</param>
 /// <param name="variableName">The name of the variable to read</param>
 /// <param name="timeout">Optional timeout</param>
 public virtual Task <VTQ> ReadVariableSync(ObjectRef objectID, string variableName, Duration?timeout = null)
 {
     return(ReadVariableSync(VariableRef.Make(objectID, variableName), timeout));
 }
Пример #17
0
 /// <summary>
 /// Reads the current value of all variables of all objects in the tree of objects defined by the given object reference.
 /// </summary>
 /// <param name="objectID">The object defining the root of the object tree</param>
 public abstract Task <VariableValues> ReadAllVariablesOfObjectTree(ObjectRef objectID);
Пример #18
0
 /// <summary>
 /// Returns the entire object value of the parent object for a given object id.
 /// </summary>
 /// <param name="objectID">The id of the object</param>
 public abstract Task <ObjectValue> GetParentOfObject(ObjectRef objectID);
Пример #19
0
        /// <summary>
        /// Reads the current value of a variable from the Mediator cache.
        /// Throws an exception if the variable does not exist.
        /// </summary>
        /// <param name="objectID">The object containing the variable</param>
        /// <param name="variableName">The name of the variable to read</param>
        /// <returns></returns>
        public virtual async Task <VTQ> ReadVariable(ObjectRef objectID, string variableName)
        {
            VTQs tmp = await ReadVariables(new VariableRefs { VariableRef.Make(objectID, variableName) });

            return(tmp[0]);
        }
Пример #20
0
        /// <summary>
        /// Returns an entire object by id.
        /// </summary>
        /// <param name="objectID">The id of the object to return</param>
        public virtual async Task <ObjectValue> GetObjectValueByID(ObjectRef objectID)
        {
            ObjectValues res = await GetObjectValuesByID(objectID);

            return(res[0]);
        }
Пример #21
0
        /// <summary>
        /// Returns the value of an object member.
        /// </summary>
        /// <param name="objectID">The id of the object</param>
        /// <param name="memberName">The name of the member to return</param>
        public virtual async Task <MemberValue> GetMemberValue(ObjectRef objectID, string memberName)
        {
            MemberValues values = await GetMemberValues(new MemberRef[] { new MemberRef(objectID, memberName) });

            return(values[0]);
        }
Пример #22
0
 public static MemberValue Make(ObjectRef obj, string memberName, DataValue value)
 {
     return(new MemberValue(MemberRef.Make(obj, memberName), value));
 }
Пример #23
0
        private void ReadModuleVariables(XmlReader reader)
        {
            map.Clear();

            if (reader.IsEmptyElement)
            {
                return;
            }

            ObjectRef currentObj = new ObjectRef();

            string var_Name    = "";
            string var_Time    = "";
            string var_Quality = "";
            bool   inVar       = false;

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:

                    inVar = false;

                    switch (reader.Name)
                    {
                    case "Obj":
                        currentObj = ObjectRef.Make(moduleID, reader.GetAttribute("id"));
                        break;

                    case "Var":
                        var_Name    = reader.GetAttribute("name");
                        var_Time    = reader.GetAttribute("time");
                        var_Quality = reader.GetAttribute("quality");
                        inVar       = true;
                        break;
                    }
                    break;

                case XmlNodeType.Text:

                    if (inVar)
                    {
                        var t = TimestampFromString(var_Time);
                        var q = QualityFromString(var_Quality);
                        var v = DataValue.FromJSON(reader.Value);

                        var varRef = new VariableRef(currentObj, var_Name);
                        map[varRef] = new VTQ(t, q, v);

                        inVar = false;
                    }
                    break;

                case XmlNodeType.EndElement:
                    inVar = false;
                    if (reader.Name == "Module")
                    {
                        return;
                    }
                    break;
                }
            }
        }
Пример #24
0
 public static MemberValue Make(string moduleID, string localObjectID, string memberName, DataValue value)
 {
     return(new MemberValue(MemberRef.Make(ObjectRef.Make(moduleID, localObjectID), memberName), value));
 }
Пример #25
0
 public static AddArrayElement Make(ObjectRef obj, string arrayMemberName, DataValue valueToAdd)
 {
     return(new AddArrayElement(MemberRef.Make(obj, arrayMemberName), valueToAdd));
 }
Пример #26
0
 public static AddArrayElement Make(string moduleID, string localObjectID, string arrayMemberName, DataValue valueToAdd)
 {
     return(new AddArrayElement(MemberRef.Make(ObjectRef.Make(moduleID, localObjectID), arrayMemberName), valueToAdd));
 }
Пример #27
0
        /// <summary>
        /// Returns an object by id (ObjectRef)
        /// </summary>
        /// <param name="objectID">The object id</param>
        public virtual async Task <ObjectInfo> GetObjectByID(ObjectRef objectID)
        {
            ObjectInfos objects = await GetObjectsByID(objectID);

            return(objects[0]);
        }
Пример #28
0
 public static string ValueToString(ObjectRef value) => JsonConvert.ToString(value.ToEncodedString());
Пример #29
0
 /// <summary>
 /// Returns all objects that are direct children of a specific object
 /// </summary>
 /// <param name="objectID">The id of the parent object</param>
 public virtual async Task <ObjectInfos> GetChildrenOfObject(ObjectRef objectID)
 {
     return(await GetChildrenOfObjects(objectID));
 }
Пример #30
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            ObjectRef ts = (ObjectRef)value;

            writer.WriteValue(ts.ToEncodedString());
        }