Exemple #1
0
        static void Main(string[] args)
        {
            PIPoint pIPoint = new PIPoint();

            PropertyInfo[] propertys = pIPoint.GetType().GetProperties();
            string         jsonFile  = "D:/vs2019proj/PIData/PIDataSave/PIDataSave/tagName.json";

            using (System.IO.StreamReader file = System.IO.File.OpenText(jsonFile))
            {
                using (JsonTextReader reader = new JsonTextReader(file))
                {
                    JArray jArray = (JArray)JToken.ReadFrom(reader);

                    foreach (JObject o in jArray)
                    {
                        IEnumerable <JProperty> properties = o.Properties();
                        foreach (JProperty item in properties)
                        {
                            string  key = item.Name;
                            JToken  val = item.Value;
                            JObject obj = JObject.Parse(val.ToString());
                            foreach (PropertyInfo property in propertys)
                            {
                                if (property.Name != "id" && property.Name != "time" && obj.ContainsKey(property.Name))
                                {
                                    string a     = obj[property.Name].ToString();
                                    string value = WebService.PIRead(
                                        $"select value from piarchive..piavg where tag = '{a}'  and  time BETWEEN '*-1h' AND '*'",
                                        key);
                                    JArray arr = (JArray)JsonConvert.DeserializeObject(value);

                                    foreach (JObject jo in arr)
                                    {
                                        string joValue = jo.Value <string>("value");
                                        property.SetValue(pIPoint, double.Parse(joValue), null);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            pIPoint.time = DateTime.Now.ToLocalTime().ToString();

            //Program.WebService.PIRead("", "");


            string dbPath = "Data Source =" + Environment.CurrentDirectory + "/test.db";

            //conn.Close();
            SimpleCRUD.SetDialect(SimpleCRUD.Dialect.SQLite);
            using (IDbConnection db = new SQLiteConnection(dbPath))
            {
                db.Open();
                IDbTransaction tran = db.BeginTransaction();

                db.Insert(pIPoint, transaction: tran);
                tran.Commit();
            }
        }
        /// <summary>Update a point.</summary>
        public ApiResponseObject UpdateWithHttpInfo(string webId, PIPoint pointDTO)
        {
            if (string.IsNullOrEmpty(webId) == true)
            {
                webId = null;
            }
            if (webId == null)
            {
                throw new ApiException(400, "Missing required parameter 'webId'");
            }
            if (pointDTO == null)
            {
                throw new ApiException(400, "Missing required parameter 'pointDTO'");
            }

            var    localVarPath         = "/points/{webId}";
            var    localVarPathParams   = new Dictionary <String, String>();
            var    localVarQueryParams  = new CustomDictionaryForQueryString();
            var    localVarHeaderParams = new Dictionary <String, String>(Configuration.DefaultHeader);
            var    localVarFormParams   = new Dictionary <String, String>();
            var    localVarFileParams   = new Dictionary <String, FileParameter>();
            Object localVarPostBody     = null;

            String[] localVarHttpContentTypes = new String[] { };
            String   localVarHttpContentType  = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            String[] localVarHttpHeaderAccepts = new String[] { "application/json", "text/json", "text/xml" };
            String   localVarHttpHeaderAccept  = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            localVarPathParams.Add("format", "json");

            if (webId != null)
            {
                localVarPathParams.Add("webId", Configuration.ApiClient.ParameterToString(webId));
            }
            if (pointDTO != null && pointDTO.GetType() != typeof(byte[]))
            {
                localVarPostBody = Configuration.ApiClient.Serialize(pointDTO);
            }
            else
            {
                localVarPostBody = pointDTO;
            }

            IRestResponse localVarResponse = (IRestResponse)Configuration.ApiClient.CallApi(localVarPath,
                                                                                            Method.PATCH, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                            localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (ExceptionFactory != null)
            {
                Exception exception = ExceptionFactory("Update", localVarResponse);
                if (exception != null)
                {
                    throw exception;
                }
            }

            return(new ApiResponseObject(localVarStatusCode,
                                         localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
                                         (Object)Configuration.ApiClient.Deserialize(localVarResponse, typeof(Object))));
        }