public async Task <IActionResult> Get(string id)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                this.logger.LogWarning($"{this.HttpContext.Connection.RemoteIpAddress} 请求查询空 ID 的 {typeof(TModel).Name} 数据");

                return(this.StatusCode(StatusCodes.Status406NotAcceptable));
            }
            try
            {
                var model = await this.context.Set <TModel>().FindAsync(id);

                if (model == null)
                {
                    this.logger.LogWarning($"{this.HttpContext.Connection.RemoteIpAddress} 请求查询 ID 不存在的 {typeof(TModel).Name} 数据");

                    return(this.StatusCode(StatusCodes.Status406NotAcceptable));
                }
                else
                {
                    this.logger.LogDebug($"{this.HttpContext.Connection.RemoteIpAddress} 请求查询 ID 为 {id} 的 {typeof(TModel).Name} 数据");

                    return(this.Content(JsonConvertHelper.SerializeObject(model)));
                }
            }
            catch (Exception ex)
            {
                this.logger.LogError(ex, $"{this.HttpContext.Connection.RemoteIpAddress} 请求查询 ID 为 {id} 的 {typeof(TModel).Name} 数据遇到异常");

                return(this.StatusCode(StatusCodes.Status417ExpectationFailed, ex.Message));
            }
        }
    public string ReadStatus()
    {
        JArray Monthstatusjarr = JArray.Parse(this._MonthstatusStr);
        Dictionary <string, ListStatusByFac> MonthstatusObj = BuildMonthObj(Monthstatusjarr);

        return(JsonConvertHelper.SerializeObject(MonthstatusObj));
    }
Exemple #3
0
        public async Task <OAuthToken> RefreshToken(string refreshToken)
        {
            Dictionary <string, string> contentDict = new Dictionary <string, string>()
            {
                { "grant_type", "refresh_token" },
                { "refresh_token", refreshToken }
            };

            string requestContent = JsonConvertHelper.SerializeObject(contentDict);

            OAuthToken oAuthToken = await RequestToken(contentDict);

            return(oAuthToken);
        }
        public IActionResult Query(string key)
        {
            this.logger.LogDebug($"{this.HttpContext.Connection.RemoteIpAddress} 请求查询所有 {typeof(TModel).Name} 数据,关键字 = {key}");

            var enumerable = this.context.Set <TModel>().AsEnumerable();

            if (!string.IsNullOrWhiteSpace(key))
            {
                enumerable = this.CreateQueryPerdicate(enumerable, key);
            }

            var models = enumerable.ToList();

            return(this.Content(JsonConvertHelper.SerializeObject(models)));
        }
Exemple #5
0
        public override void Update(ModelType model)
        {
            try
            {
                if (model == null)
                {
                    throw new ArgumentNullException("model");
                }

                this.DbContext.SaveChanges();
            }
            catch
            {
                EIMLog.Logger.Error("DataProvider Update Error:" + JsonConvertHelper.SerializeObject(model));
                throw;
            }
        }
Exemple #6
0
        public async Task <OAuthToken> GetAccessToken(string callbackUrl)
        {
            //TODO hasn't handled error issue

            Uri uri = new Uri(callbackUrl);

            HttpValueCollection queryString = HttpUtility.ParseQueryString(uri.Query);

            string callbackCode = queryString["code"];

            Dictionary <string, string> contentDict = new Dictionary <string, string>()
            {
                { "code", callbackCode },
                { "grant_type", "authorization_code" }
            };

            string requestContent = JsonConvertHelper.SerializeObject(contentDict);

            OAuthToken oAuthToken = await RequestToken(contentDict);

            return(oAuthToken);
        }
    public static string AnalyseCheckInfo(string jsonobj)
    {
        List <CheckInfoListbyFac> Slist = new List <CheckInfoListbyFac>();
        JArray SceInsList = JArray.Parse(jsonobj);

        foreach (JObject i in SceInsList)
        {
            CheckInfoDetail newinfo = new CheckInfoDetail(i["时间"].ToString(), i["车间"].ToString(), i["合格"].ToString(), i["详情"].ToString(), i["Id"].ToString());
            int             hasname = Slist.FindIndex(delegate(CheckInfoListbyFac sch) { return(sch.Name == newinfo.Fac); });
            if (hasname == -1)              //新的车间
            {
                CheckInfoListbyFac newfac = new CheckInfoListbyFac();
                newfac.InfoList.Add(newinfo);
                Slist.Add(newfac);
            }
            else
            {
                Slist[hasname].InfoList.Add(newinfo);
            }
        }
        return(JsonConvertHelper.SerializeObject(Slist));
    }
    public string CreateStatus()
    {
        string DBcommand;
        string source          = ConfigurationManager.ConnectionStrings["EPInfoSys"].ConnectionString.ToString();
        JArray Monthstatusjarr = JArray.Parse(this._MonthstatusStr);
        Dictionary <string, ListStatusByFac> MonthstatusObj = BuildMonthObj(Monthstatusjarr);
        string ListRulesStr = this.ReadRules();
        JArray LRulesObj    = JArray.Parse(ListRulesStr);

        foreach (JObject Ruleobj in LRulesObj)
        {
            //看Monthstatus有没有这个规则结果。如果有,那么更新则使用update语句,如果没有这个Id的规则结果,则使用insert语句
            string ObjFactory = Ruleobj["车间"].ToString();
            string ObjTime    = this._Time;
            string KeyStr     = ObjFactory + "|" + ObjTime;
            string Objid      = Ruleobj["RuleId"].ToString();
            int    hasrule;
            if (MonthstatusObj.ContainsKey(KeyStr))
            {
                hasrule = MonthstatusObj[KeyStr].Factory_List_Status.FindIndex(delegate(ListStatusbyRule sch) { return(sch.RuleId == Objid); });
            }
            else
            {
                hasrule = -1;
            }
            //不管有没有这个规则,都需要先实例化由rule生成的规则结果类,以录入或覆盖原来的规则
            ListStatusbyRule newLStatu = new ListStatusbyRule(Ruleobj["RuleId"].ToString(), ObjTime, ObjFactory, Ruleobj["项目"].ToString(), Ruleobj["规则"].ToString(), float.Parse(((JValue)Ruleobj["阀值"]).Value.ToString()), true);
            newLStatu.GetCValueFromDB();
            newLStatu.ListValue = newLStatu.SetListValue();
            int ifauto;
            int lvalue;
            if (newLStatu.IfAuto)
            {
                ifauto = 1;
            }
            else
            {
                ifauto = 0;
            }
            if (newLStatu.ListValue)
            {
                lvalue = 1;
            }
            else
            {
                lvalue = 0;
            }
            if (hasrule == -1)                          //没有这个规则
            {
                if (MonthstatusObj.ContainsKey(KeyStr)) //有车间无规则,直接在车间里面加这个规则
                {
                    MonthstatusObj[KeyStr].Factory_List_Status.Add(newLStatu);
                }
                else                  //规则车间都没有
                {
                    ListStatusByFac newfac = new ListStatusByFac(ObjFactory, ObjTime);
                    newfac.Factory_List_Status.Add(newLStatu);
                    MonthstatusObj.Add(KeyStr, newfac);
                }
                DBcommand =
                    @"INSERT INTO [EPInfoSystem].[dbo].[ListStatus]
											   ([时间]
											   ,[车间]
											   ,[项目]
											   ,[RuleId]
											   ,[规则类]
											   ,[阀值]
											   ,[采集值]
											   ,[自动]
											   ,[挂牌])
										 VALUES
											   ('"                                             + this._Time + @"'
											   ,'"                                             + ObjFactory + @"'
											   ,'"                                             + newLStatu.Type + @"'
											   ,'"                                             + newLStatu.RuleId + @"'
											   ,'"                                             + newLStatu.RuleType + @"'
											   ,'"                                             + newLStatu.ThresHold + @"'
											   ,'"                                             + newLStatu.CollectionValue + @"'
											   ,"                                             + ifauto + @"
											   ,"                                             + lvalue + @"
												)"                                                ;
            }
            else              //有这个规则,修改Month类中的这个规则,然后使用update语句而不是insert
            {
                MonthstatusObj[KeyStr].Factory_List_Status[hasrule] = newLStatu;
                DBcommand = @"
								UPDATE [EPInfoSystem].[dbo].[ListStatus]
								   SET 
									   [车间] = '"                                     + ObjFactory + @"'
									  ,[项目] = '"                                     + newLStatu.Type + @"'									
									  ,[规则类] = '"                                     + newLStatu.RuleType + @"'
									  ,[阀值] = "                                     + newLStatu.ThresHold + @"
									  ,[采集值] ="                                     + newLStatu.CollectionValue + @"
									  ,[自动] = "                                     + ifauto + @"
									  ,[挂牌] = "                                     + lvalue + @"
								 WHERE [时间] ='"                                 + this._Time + "'AND [RuleId]=" + newLStatu.RuleId;
            }
            DBOper dbcom = new DBOper(source, DBcommand);
            string _ret  = dbcom.ReturnRows();
        }
        return(JsonConvertHelper.SerializeObject(MonthstatusObj));
    }