Esempio n. 1
0
        public override async Task WriteVariables(VariableValue[] values)
        {
            JObject request = MakeSessionRequest();

            request["values"] = new JRaw(StdJson.ObjectToString(values));
            await PostJObject("WriteVariables", request);
        }
Esempio n. 2
0
        public override async Task <VTQ[]> ReadVariablesSync(VariableRef[] variables, Duration?timeout = null)
        {
            if (variables == null)
            {
                throw new ArgumentNullException(nameof(variables));
            }
            JObject request = MakeSessionRequest();

            request["variables"] = new JRaw(StdJson.ObjectToString(variables));
            if (timeout.HasValue)
            {
                request["timeout"] = new JRaw(StdJson.ValueToString(timeout.Value));
            }
            Task <VTQ[]> task = Post <VTQ[]>("ReadVariablesSync", request);

            if (timeout.HasValue)
            {
                if (task == await Task.WhenAny(task, Task.Delay(timeout.Value.ToTimeSpan())))
                {
                    return(await task);
                }
                else
                {
                    throw new Exception("Timeout");
                }
            }
            else
            {
                return(await task);
            }
        }
Esempio n. 3
0
        public override async Task HistorianDeleteVariables(params VariableRef[] variables)
        {
            JObject request = MakeSessionRequest();

            request["variables"] = new JRaw(StdJson.ObjectToString(variables));
            await PostJObject("HistorianDeleteVariables", request);
        }
Esempio n. 4
0
        public override async Task <WriteResult> WriteVariablesSync(VariableValue[] values, Duration?timeout = null)
        {
            JObject request = MakeSessionRequest();

            request["values"] = new JRaw(StdJson.ObjectToString(values));
            if (timeout.HasValue)
            {
                request["timeout"] = new JRaw(StdJson.ValueToString(timeout.Value));
            }
            Task <WriteResult> task = Post <WriteResult>("WriteVariablesSync", request);

            if (timeout.HasValue)
            {
                if (task == await Task.WhenAny(task, Task.Delay(timeout.Value.ToTimeSpan())))
                {
                    return(await task);
                }
                else
                {
                    throw new Exception("Timeout");
                }
            }
            else
            {
                return(await task);
            }
        }
Esempio n. 5
0
        public override async Task EnableVariableHistoryChangedEvents(params VariableRef[] variables)
        {
            JObject request = MakeSessionRequest();

            request["variables"] = new JRaw(StdJson.ObjectToString(variables));
            await PostJObject("EnableVariableHistoryChangedEvents", request);
        }
Esempio n. 6
0
        public override async Task EnableVariableValueChangedEvents(SubOptions options, params ObjectRef[] idsOfEnabledTreeRoots)
        {
            JObject request = MakeSessionRequest();

            request["options"] = new JRaw(StdJson.ObjectToString(options));
            request["idsOfEnabledTreeRoots"] = new JRaw(StdJson.ValueToString(idsOfEnabledTreeRoots));
            await PostJObject("EnableVariableValueChangedEvents", request);
        }
Esempio n. 7
0
        public override Task <DataValue> CallMethod(string moduleID, string methodName, params NamedValue[] parameters)
        {
            JObject request = MakeSessionRequest();

            request["moduleID"]   = moduleID;
            request["methodName"] = methodName;
            request["parameters"] = new JRaw(StdJson.ObjectToString(parameters));
            return(Post <DataValue>("CallMethod", request));
        }
Esempio n. 8
0
        public override async Task HistorianModify(VariableRef variable, ModifyMode mode, params VTQ[] data)
        {
            JObject request = MakeSessionRequest();

            request["variable"] = new JRaw(StdJson.ObjectToString(variable));
            request["data"]     = new JRaw(StdJson.ObjectToString(data));
            request["mode"]     = new JRaw(StdJson.ValueToString(mode));
            await PostJObject("HistorianModify", request);
        }
Esempio n. 9
0
        public override async Task <VTTQ?> HistorianGetLatestTimestampDB(VariableRef variable, Timestamp startInclusive, Timestamp endInclusive)
        {
            JObject request = MakeSessionRequest();

            request["variable"]       = new JRaw(StdJson.ObjectToString(variable));
            request["startInclusive"] = new JRaw(StdJson.ValueToString(startInclusive));
            request["endInclusive"]   = new JRaw(StdJson.ValueToString(endInclusive));
            return(await Post <VTTQ?>("HistorianGetLatestTimestampDB", request));
        }
Esempio n. 10
0
        public override async Task <long> HistorianDeleteInterval(VariableRef variable, Timestamp startInclusive, Timestamp endInclusive)
        {
            JObject request = MakeSessionRequest();

            request["variable"]       = new JRaw(StdJson.ObjectToString(variable));
            request["startInclusive"] = new JRaw(StdJson.ValueToString(startInclusive));
            request["endInclusive"]   = new JRaw(StdJson.ValueToString(endInclusive));
            return(await Post <long>("HistorianDeleteInterval", request));
        }
Esempio n. 11
0
        public override async Task <VTTQ[]> HistorianReadRaw(VariableRef variable, Timestamp startInclusive, Timestamp endInclusive, int maxValues, BoundingMethod bounding)
        {
            JObject request = MakeSessionRequest();

            request["variable"]       = new JRaw(StdJson.ObjectToString(variable));
            request["startInclusive"] = new JRaw(StdJson.ValueToString(startInclusive));
            request["endInclusive"]   = new JRaw(StdJson.ValueToString(endInclusive));
            request["maxValues"]      = new JRaw(StdJson.ValueToString(maxValues));
            request["bounding"]       = new JRaw(StdJson.ValueToString(bounding));
            return(await Post <VTTQ[]>("HistorianReadRaw", request));
        }
Esempio n. 12
0
        public override async Task <MemberValue[]> GetMemberValues(MemberRef[] member)
        {
            if (member == null)
            {
                throw new ArgumentNullException(nameof(member));
            }
            JObject request = MakeSessionRequest();

            request["member"] = new JRaw(StdJson.ObjectToString(member));
            return(await Post <MemberValue[]>("GetMemberValues", request));
        }
Esempio n. 13
0
        public override async Task <VTQ[]> ReadVariables(VariableRef[] variables)
        {
            if (variables == null)
            {
                throw new ArgumentNullException(nameof(variables));
            }
            JObject request = MakeSessionRequest();

            request["variables"] = new JRaw(StdJson.ObjectToString(variables));
            return(await Post <VTQ[]>("ReadVariables", request));
        }
Esempio n. 14
0
        public override Task <BrowseResult> BrowseObjectMemberValues(MemberRef member, int?continueID = null)
        {
            JObject request = MakeSessionRequest();

            request["member"] = new JRaw(StdJson.ObjectToString(member));
            if (continueID.HasValue)
            {
                request["continueID"] = new JRaw(StdJson.ValueToString(continueID.Value));
            }
            return(Post <BrowseResult>("BrowseObjectMemberValues", request));
        }
Esempio n. 15
0
        public override async Task UpdateConfig(ObjectValue[] updateOrDeleteObjects, MemberValue[] updateOrDeleteMembers, AddArrayElement[] addArrayElements)
        {
            JObject request = MakeSessionRequest();

            if (updateOrDeleteObjects != null && updateOrDeleteObjects.Length > 0)
            {
                request["updateOrDeleteObjects"] = new JRaw(StdJson.ObjectToString(updateOrDeleteObjects));
            }
            if (updateOrDeleteMembers != null && updateOrDeleteMembers.Length > 0)
            {
                request["updateOrDeleteMembers"] = new JRaw(StdJson.ObjectToString(updateOrDeleteMembers));
            }
            if (addArrayElements != null && addArrayElements.Length > 0)
            {
                request["addArrayElements"] = new JRaw(StdJson.ObjectToString(addArrayElements));
            }
            await PostJObject("UpdateConfig", request);
        }
Esempio n. 16
0
        protected async Task <JObject> PostJObject(string path, JObject obj)
        {
            var payload = new StringContent(StdJson.ObjectToString(obj), Encoding.UTF8);

            HttpResponseMessage response = null;

            try {
                response = await client.PostAsync(path, payload);
            }
            catch (TaskCanceledException) {
                OnConnectionBroken();
                throw new ConnectivityException("Time out");
            }
            catch (Exception exp) {
                OnConnectionBroken();
                throw new ConnectivityException(exp.Message, exp);
            }

            using (response) {
                if (response.IsSuccessStatusCode)
                {
                    try {
                        string content = await response.Content.ReadAsStringAsync();

                        if (string.IsNullOrEmpty(content))
                        {
                            return(new JObject());
                        }
                        return(StdJson.JObjectFromString(content));
                    }
                    catch (Exception exp) {
                        OnConnectionBroken();
                        throw new ConnectivityException(exp.Message, exp);
                    }
                }
                else
                {
                    await ThrowError(response);

                    return(null); // never come here
                }
            }
        }
Esempio n. 17
0
 public static DataValue FromObject(object obj, bool indented = false) => new DataValue(StdJson.ObjectToString(obj, indented: indented));