示例#1
0
        /// <summary>
        /// 缓存结果
        /// </summary>
        /// <param name="info"></param>
        /// <param name="item"></param>
        private static void CacheResult(ApiGatewayUrl item, DataContext db, ReturnModel info = null, Dictionary <string, object> dic = null)
        {
            var model = new ApiGatewayCache();

            model.Key     = item.Key.ToLower();
            model.TimeOut = DateTime.Now.AddDays(item.CacheTimeOut.ToStr().ToDouble(0)).AddHours(8);

            if (info != null)
            {
                model.result = BaseJson.ModelToJson(info.msg);
            }

            if (dic != null)
            {
                model.result = BaseJson.ModelToJson(dic);
            }

            if (FastRead.Query <ApiGatewayCache>(a => a.Key.ToUpper() == model.Key.ToUpper()).ToCount(db) <= 0)
            {
                FastWrite.Add(model);
            }
            else
            {
                FastWrite.Update <ApiGatewayCache>(model, a => a.Key.ToUpper() == model.Key.ToUpper(), a => new { a.result, a.TimeOut }, db);
            }
        }
示例#2
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            dbConn = BaseLink.GetConnStr(dbType, txtUserName, txtPwd, txtHostName, txtPort, txtServerName);

            if (!BaseLink.CheckLink(dbType, dbConn))
            {
                CodeBox.Show("连接数据库失败!", this);
            }
            else
            {
                var buildLink = BaseLink.ControlsToData(dbType, txtHostName, txtUserName, txtPwd, txtPort, txtServerName, labServerName, true, txtLinkName);
                buildLink.LinkName = buildLink.LinkName == "" ? BaseLink.GetLinkName(buildLink) : buildLink.LinkName;
                buildLink.Id       = Guid.NewGuid().ToString();
                AppCache.SetLink(buildLink);

                if (FastRead.Query <Data_Source>(a => a.LinkName == buildLink.LinkName).ToCount() == 1)
                {
                    FastWrite.Update <Data_Source>(buildLink, a => a.LinkName == buildLink.LinkName,
                                                   a => new { a.Host, a.PassWord, a.Port, a.ServerName, a.Type, a.UserName });
                }
                else
                {
                    FastWrite.Add(buildLink);
                }

                CodeBox.Show("连接数据库成功!", this);
            }
        }
示例#3
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            using (var db = new DataContext())
            {
                var success = false;
                var main    = Dic.SelectedItem as Data_Dic;
                if (string.IsNullOrEmpty(main.Id))
                {
                    main.Id = Guid.NewGuid().ToString();
                    success = FastWrite.Add(main).IsSuccess;
                }
                else
                {
                    success = FastWrite.Update(main, a => a.Id == main.Id, a => new { a.Name }).IsSuccess;
                }

                foreach (var item in DicLeaf.Items)
                {
                    var temp = item as Data_Dic_Details;

                    if (temp == null)
                    {
                        continue;
                    }

                    temp.DicId = main.Id;

                    if (temp != null)
                    {
                        if (string.IsNullOrEmpty(temp.Value))
                        {
                            CodeBox.Show("字典值不能为空", this);
                            continue;
                        }
                        if (string.IsNullOrEmpty(temp.ContrastValue))
                        {
                            CodeBox.Show("字典对照值不能为空", this);
                            continue;
                        }

                        if (string.IsNullOrEmpty(temp.Id))
                        {
                            temp.Id = Guid.NewGuid().ToString();
                            if (success)
                            {
                                success = db.Add(temp).writeReturn.IsSuccess;
                            }
                        }
                        else
                        {
                            success = db.Update(temp, a => a.Id == temp.Id, a => new { a.Name, a.Value, a.ContrastValue }).writeReturn.IsSuccess;
                        }
                    }
                }
            }

            CodeBox.Show("保存成功", this);
        }
示例#4
0
        /// <summary>
        /// 处理请求
        /// </summary>
        /// <param name="downparam">下游</param>
        /// <param name="param">请求参数</param>
        /// <param name="content">请求参数body</param>
        /// <returns></returns>
        private static ReturnModel GetReuslt(ApiGatewayDownParam downparam, string param, string key, int isTextLog, int isDbLog, DataContext db, HttpContext context, string ActionId, int OrderBy, IHttpClientFactory client)
        {
            var info = FastRead.Query <ApiGatewayWait>(a => a.Key.ToLower() == key.ToLower() && a.Url.ToLower() == downparam.Url.ToLower()).ToItem <ApiGatewayWait>(db) ?? new ApiGatewayWait();

            if (info.Key.ToStr().ToLower() == key.ToLower() && DateTime.Compare(info.NextAction, DateTime.Now) > 0)
            {
                //return time out
                var dic = new Dictionary <string, object>();
                dic.Add("success", false);
                dic.Add("result", "等待恢复");
                return(new ReturnModel {
                    msg = BaseJson.ModelToJson(dic), status = 408
                });
            }
            else
            {
                var result    = new ReturnModel();
                var stopwatch = new Stopwatch();
                stopwatch.Start();

                if (downparam.Protocol.ToLower() == "soap")
                {
                    result = BaseUrl.SoapUrl(downparam.Url, downparam.SoapParamName, downparam.SoapMethod, param, client, key, downparam.SoapNamespace);
                }
                else if (downparam.Protocol.ToLower() == "http")
                {
                    //http
                    if (downparam.Method.ToStr().ToLower() == "post")
                    {
                        if (downparam.IsBody == 1)
                        {
                            result = BaseUrl.PostContent(downparam.Url, param, key, client);
                        }
                        else
                        {
                            result = BaseUrl.PostUrl(downparam.Url, param, key, client);
                        }
                    }
                    else if (downparam.Method.ToStr().ToLower() == "get")
                    {
                        result = BaseUrl.GetUrl(downparam.Url, param, key, client);
                    }
                }
                //else if (downparam.Protocol.ToLower() == "mq")
                //    //mq
                //    result = BaseUrl.RabbitUrl(downparam.QueueName, param);
                else
                {
                    result.status = 408;
                }

                if (result.status == 408)
                {
                    //time out
                    var wait = new ApiGatewayWait();
                    wait.Key        = key;
                    wait.Url        = downparam.Url;
                    wait.WaitHour   = downparam.WaitHour.ToInt(0);
                    wait.ErrorMsg   = result.msg;
                    wait.NextAction = DateTime.Now.AddHours(wait.WaitHour.ToStr().ToDouble(0));

                    FastWrite.Add(wait, db);
                }
                else if (info.Key.ToStr().ToLower() == key.ToLower())
                {
                    FastWrite.Delete <ApiGatewayWait>(a => a.Key.ToLower() == key.ToLower(), db);
                }

                stopwatch.Stop();

                var logInfo = new ApiGatewayLog();
                logInfo.ActionId     = ActionId;
                logInfo.OrderBy      = OrderBy;
                logInfo.Key          = key;
                logInfo.ActionTime   = DateTime.Now;
                logInfo.Url          = downparam.Url;
                logInfo.Protocol     = downparam.Protocol;
                logInfo.Success      = result.status == 200 ? 1 : 0;
                logInfo.Result       = result.msg;
                logInfo.Milliseconds = stopwatch.Elapsed.TotalMilliseconds;
                logInfo.ActionIp     = GetClientIp(context);
                logInfo.ActionParam  = param;

                if (isDbLog == 1)
                {
                    FastWrite.Add(logInfo, null, DbApi);
                }

                if (isTextLog == 1)
                {
                    BaseLog.SaveLog(BaseJson.ModelToJson(logInfo), logInfo.Key);
                }

                return(result);
            }
        }