示例#1
0
 public DiagnoseItem(string name, string desc, DianoseFunc f)
 {
     m_name   = name;
     m_desc   = desc;
     m_func   = f;
     m_result = new DiagnoseResult();
 }
示例#2
0
        // 说明:命名空间中和类名之间可以用 / 和 . 分隔,但是在<system.web>/<httpHandlers>节点中要注意 / 出现的次数与URL中的次数匹配
        //        IIS的集成模式没有这个问题。

        // 补充说明:以上正则表示式当遇到REST风格时,如果在method位置包含了非字符类的文字作为方法的传入参数,匹配后将会造成数据丢失。
        //          因为是采用的 (?<method>\w+) ,除非换成 (?<method>[^\.]+) ,并且在得到数据后做UrlDecode


        /*
         * 可以解析以下格式的URL:(前一个表示包含命名空间的格式)
         *
         * /service/namespace.Fish.AA.Demo/GetMd5.aspx
         * /service/namespace.Fish.AA/Demo/GetMd5.aspx
         * /service/Demo/GetMd5.aspx
         * /api/aa/Demo/GetMd5
         * /api/aa.b/Demo/GetMd5?ss=a.b
         */


        /// <summary>
        /// 从指定的请求中提取UrlActionInfo
        /// </summary>
        /// <param name="context"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        public virtual UrlActionInfo GetUrlActionInfo(HttpContext context, string path)
        {
            // 扩展点:允许自定义URL解析逻辑

            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }

            Match match = ServiceUrlRegex.Match(path);

            if (match.Success == false)
            {
                DiagnoseResult diagnoseResult = Http404DebugModule.TryGetDiagnoseResult(context);
                if (diagnoseResult != null)
                {
                    diagnoseResult.ErrorMessages.Add("URL解析失败,正则表达式:" + ServiceUrlRegex.ToString());
                }

                return(null);
            }

            return(new UrlActionInfo {
                UrlType = match.Groups["type"].Value,
                Namesapce = match.Groups["namespace"].Value,
                ClassName = match.Groups["name"].Value,
                MethodName = match.Groups["method"].Value,
                ExtName = match.Groups["extname"].Value
            });
        }
示例#3
0
        private async void Diagnose()
        {
            DiagnoseType diagnoseType = this.rbNotNullWithEmpty.Checked ? DiagnoseType.NotNullWithEmpty : DiagnoseType.SelfReferenceSame;

            try
            {
                this.btnStart.Enabled = false;

                DiagnoseResult result = await dbManager.Diagnose(this.DatabaseType, this.ConnectionInfo, diagnoseType);

                if (result.Details.Count > 0)
                {
                    frmDiagnoseResult frmResult = new frmDiagnoseResult()
                    {
                        DatabaseType   = this.DatabaseType,
                        ConnectionInfo = this.ConnectionInfo
                    };

                    frmResult.LoadResult(result);
                    frmResult.ShowDialog();
                }
                else
                {
                    MessageBox.Show("Diagnosis finished, no invalid data found.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ExceptionHelper.GetExceptionDetails(ex), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.btnStart.Enabled = true;
            }
        }
示例#4
0
 public DiagnoseItem(string name, string desc, DianoseFunc f, object param)
 {
     m_name           = name;
     m_desc           = desc;
     m_func           = f;
     m_result         = new DiagnoseResult();
     m_result.m_param = param;
 }
示例#5
0
        public async Task <DiagnoseResult> Diagnose(DatabaseType databaseType, ConnectionInfo connectionInfo, DiagnoseType diagnoseType)
        {
            DbDiagnosis dbDiagnosis = DbDiagnosis.GetInstance(databaseType, connectionInfo);

            dbDiagnosis.OnFeedback += this.Feedback;

            DiagnoseResult result = await dbDiagnosis.Diagnose(diagnoseType);

            return(result);
        }
        public virtual async Task <DiagnoseResult> DiagnoseSelfReferenceSame()
        {
            this.Feedback("Begin to diagnose self reference with same value...");

            DiagnoseResult result = new DiagnoseResult();

            DbInterpreterOption option = new DbInterpreterOption()
            {
                ObjectFetchMode = DatabaseObjectFetchMode.Details
            };

            DbInterpreter interpreter = DbInterpreterHelper.GetDbInterpreter(this.DatabaseType, this.connectionInfo, option);

            this.Feedback("Begin to get foreign keys...");

            List <TableForeignKey> foreignKeys = await interpreter.GetTableForeignKeysAsync();

            this.Feedback("End get foreign keys.");

            var groups = foreignKeys.Where(item => item.ReferencedTableName == item.TableName)
                         .GroupBy(item => new { item.Owner, item.TableName });

            using (DbConnection dbConnection = interpreter.CreateConnection())
            {
                foreach (var group in groups)
                {
                    foreach (TableForeignKey foreignKey in group)
                    {
                        string countSql = this.GetTableColumnReferenceSql(interpreter, foreignKey, true);

                        this.Feedback($@"Begin to get invalid record count for foreign key ""{foreignKey.Name}"" of table ""{foreignKey.TableName}""...");

                        int count = Convert.ToInt32(await interpreter.GetScalarAsync(dbConnection, countSql));

                        this.Feedback($@"End get invalid record count for column ""{foreignKey.Name}"" of table ""{foreignKey.TableName}"", the count is {count}.");

                        if (count > 0)
                        {
                            result.Details.Add(new DiagnoseResultItem()
                            {
                                DatabaseObject = foreignKey,
                                RecordCount    = count,
                                Sql            = this.GetTableColumnReferenceSql(interpreter, foreignKey, false)
                            });
                        }
                    }
                }
            }

            this.Feedback("End diagnose self reference with same value.");

            return(result);
        }
        public virtual async Task <DiagnoseResult> DiagnoseNotNullWithEmpty()
        {
            this.Feedback("Begin to diagnose not null fields with empty value...");

            DiagnoseResult result = new DiagnoseResult();

            DbInterpreterOption option = new DbInterpreterOption()
            {
                ObjectFetchMode = DatabaseObjectFetchMode.Simple
            };

            DbInterpreter interpreter = DbInterpreterHelper.GetDbInterpreter(this.DatabaseType, this.connectionInfo, option);

            this.Feedback("Begin to get table columns...");

            List <TableColumn> columns = await interpreter.GetTableColumnsAsync();

            this.Feedback("End get table columns.");

            var groups = columns.Where(item => DataTypeHelper.IsCharType(item.DataType) && !item.IsNullable)
                         .GroupBy(item => new { item.Owner, item.TableName });

            using (DbConnection dbConnection = interpreter.CreateConnection())
            {
                foreach (var group in groups)
                {
                    foreach (TableColumn column in group)
                    {
                        string countSql = this.GetTableColumnEmptySql(interpreter, column, true);

                        this.Feedback($@"Begin to get invalid record count for column ""{column.Name}"" of table ""{column.TableName}""...");

                        int count = Convert.ToInt32(await interpreter.GetScalarAsync(dbConnection, countSql));

                        this.Feedback($@"End get invalid record count for column ""{column.Name}"" of table ""{column.TableName}"", the count is {count}.");

                        if (count > 0)
                        {
                            result.Details.Add(new DiagnoseResultItem()
                            {
                                DatabaseObject = column,
                                RecordCount    = count,
                                Sql            = this.GetTableColumnEmptySql(interpreter, column, false)
                            });
                        }
                    }
                }
            }

            this.Feedback("End diagnose not null fields with empty value.");

            return(result);
        }
 public static DiagnoseResult[] CreateNormalDiagnoseResult(bool alarmSetting)
 {
     DiagnoseResult[] diagnoseResults = new DiagnoseResult[1];
     diagnoseResults[0] = new DiagnoseResult()
     {
         Code         = "",
         Value        = 40,
         Time         = DateTime.Now,
         State        = DiagnoseDataState.Normal,
         DiagnosticId = alarmSetting ? DATASPIRIT_DIAGNOSE_ID_ALARM_SETTING_ON : DATASPIRIT_DIAGNOSE_ID_ALARM_SETTING_ON
     };
     //var diagnoseDataJson = JsonConvert.SerializeObject(r);
     return(diagnoseResults);
 }
示例#9
0
        public void LoadResult(DiagnoseResult result)
        {
            foreach (DiagnoseResultItem item in result.Details)
            {
                int rowIndex = this.dgvResult.Rows.Add();

                DataGridViewRow row = this.dgvResult.Rows[rowIndex];

                row.Cells[this.colTableName.Name].Value          = this.GetTableName(item.DatabaseObject);
                row.Cells[this.colObjectType.Name].Value         = item.DatabaseObject.GetType().Name;
                row.Cells[this.colObjectName.Name].Value         = item.DatabaseObject.Name;
                row.Cells[this.colInvalidRecordCount.Name].Value = item.RecordCount;

                row.Tag = item;
            }
        }
示例#10
0
        private RouteData GetRoute(HttpContext context, string virtualPath)
        {
            HttpContextWrapper contextWrapper = new HttpContextWrapper(context);


            // 利用ASP.NET Routing解析URL
            RouteData routeData = RouteTable.Routes.GetRouteData(contextWrapper);

            if (routeData == null)
            {
                DiagnoseResult diagnoseResult = Http404DebugModule.TryGetDiagnoseResult(context);
                if (diagnoseResult != null)
                {
                    diagnoseResult.ErrorMessages.Add("URL不能与任何路由配置(RouteTable)匹配:" + virtualPath);
                    diagnoseResult.RouteTestResult = (from x in RouteTable.Routes
                                                      let route = x as Route
                                                                  where route != null
                                                                  select new TestResult {
                        Text = route.Url, IsPass = false
                    }).ToList();
                }
                return(null);
            }

            if (routeData.RouteHandler != null && routeData.RouteHandler is StopRoutingHandler)
            {
                DiagnoseResult diagnoseResult = Http404DebugModule.TryGetDiagnoseResult(context);
                if (diagnoseResult != null)
                {
                    diagnoseResult.ErrorMessages.Add("路由匹配成功,结果是一个StopRoutingHandler");
                }

                return(null);
            }

            return(routeData);
        }
示例#11
0
        public static DiagnoseResult[] CreateManyDiagnoseResults(int days, bool alarmSetting = true)
        {
            DiagnoseResult[] diagnoseResults = new DiagnoseResult[96 * days];
            DateTime         startDateTime   = DateTime.Now.AddDays(-days);
            Random           random          = new Random();
            int interval = 15;

            for (int i = 0; i < diagnoseResults.Length; i++)
            {
                var rdata = random.Next(40, 90);
                interval           = 15 + interval;
                diagnoseResults[i] = new DiagnoseResult()
                {
                    Code         = rdata < 50 ? "" : rdata < 80 ? "701" : "702",
                    Value        = rdata,
                    Time         = startDateTime.AddMinutes(interval),
                    State        = DiagnoseDataState.Normal,
                    DiagnosticId = alarmSetting ? DATASPIRIT_DIAGNOSE_ID_ALARM_SETTING_ON : DATASPIRIT_DIAGNOSE_ID_ALARM_SETTING_OFF
                };
            }

            //var diagnoseDataJson = JsonConvert.SerializeObject(r);
            return(diagnoseResults);
        }
示例#12
0
 protected void AddDiagnosic(DiagnoseResult r)
 {
     Reuslt.Add(r);
 }
示例#13
0
文件: YSP_A.aspx.cs 项目: athree/YSP
        protected void ShowDiagButton_Click(object sender, EventArgs e)
        {
            if (Session["SelectedData"] == null)
            {
                ViewState["ErrorMsg"] = Language.Selected["Alert_SelData"];
                //Response.Write("<script>$(function(){$('#ErrorMsg p').innerText='" + Language.Selected["Alert_SelData"] + "';$('#ErrorMsg').show();})</script>");
                //Response.Write("<script>alert(" + Language.Selected["Alert_SelData"] + "')</script>");

                return;
            }
            if (Session["SelectedAbs"] == null)
            {
                ViewState["ErrorMsg"] = Language.Selected["Alert_SelAbs"];
                //Response.Write("<script>alert(" + Language.Selected["Alert_SelAbs"] + "')</script>");
                return;
            }
            if (Session["SelectedRel"] == null)
            {
                ViewState["ErrorMsg"] = Language.Selected["Alert_SelRel"];
                //Response.Write("<script>alert(" + Language.Selected["Alert_SelRel"] + "')</script>");
                return;
            }

            ContentData data = (ContentData)Session["SelectedData"];
            ContentData abs  = (ContentData)Session["SelectedAbs"];
            ContentData rel  = (ContentData)Session["SelectedRel"];

            if (data.ReadDate <= abs.ReadDate)
            {
                ViewState["ErrorMsg"] = Language.Selected["Alert_TimeErr1"];
                //Response.Write("<script>alert('" + Language.Selected["Alert_TimeErr1"] + "')</script>");
                return;
            }
            if (data.ReadDate <= rel.ReadDate)
            {
                ViewState["ErrorMsg"] = Language.Selected["Alert_TimeErr2"];
                //Response.Write("<script>alert('" + Language.Selected["Alert_TimeErr2"] + "')</script>");
                return;
            }
            ViewState["ErrorMsg"] = "";
            switch (ShowDiagDrop.SelectedValue)
            {
            case "大卫三角形法":
                Session["DiagType"] = "DavidDiag";
                break;

            case "立体图示法":
                Session["DiagType"] = "ThreeShow";
                break;
            }



            AnlyInformation    anlyInfo  = null;
            List <AlarmMsgAll> alarmList = null;

            MongoHelper <Config> _cfg             = new MongoHelper <Config>();
            Expression <Func <Config, bool> > ex  = p => p.DevID == devId && p.Alarm != null;
            Expression <Func <Config, bool> > ex1 = p => p.DevID == devId && p.AnalyPara.EnviSet != null;
            Config cfg = _cfg.FindOneBy(ex);

            if (cfg == null || cfg.Alarm == null || cfg.AnalyPara.EnviSet == null)
            {
                //。。。。。。。。。。。。。从下位机取。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
            }
            AlarmAll           hold    = cfg.Alarm;
            EnvironmentSetting setting = cfg.AnalyPara.EnviSet;

            if (hold == null || setting == null)
            {
                //从下位机取。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
            }
            //告警信息
            alarmList = Diagnose.GasAlarm(data, abs, rel, setting, hold);

            ////故障分析。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
            anlyInfo = Diagnose.GasDiagnose(devId, data, abs, rel, setting, hold.DiagSet);
            DiagnoseResult dr = Diagnose.WrapperAnlyResult(devId, 2, anlyInfo);

            TB_Result.Text = "";

            //TB_Result.Text += "\r\n------告警信息(" + alarmList.Length.ToString() + ")条------\r\n";//ljb:alarmList为空的时候不知道有没有Length这个属性(这个地方一直没法运行下去,估计这就是问题)
            TB_Result.Text += "\r\n------告警信息------\r\n";//ljb
            //有告警信息
            if (alarmList != null && alarmList.Count() != 0)
            {
                TB_Result.Text += "\r\n------告警信息(" + alarmList.Count().ToString() + ")条------\r\n";//ljb
                for (int i = 0; i < alarmList.Count(); i++)
                {
                    string msg = "";
                    msg += Language.Selected["Alarm_Device"] + devId + "\r\n";
                    msg += Language.Selected["Alarm_Gas"] + alarmList[i].GasName + "\r\n";

                    string msgType = "";
                    switch (alarmList[i].Type)
                    {
                    case 0:
                        msgType = Language.Selected["Alarm_Type_Content"];
                        break;

                    case 1:
                        msgType = Language.Selected["Alarm_Type_Abs"];
                        break;

                    case 2:
                        msgType = Language.Selected["Alarm_Type_Rel"];
                        break;

                    default:
                        msgType = Language.Selected["Alarm_Type_Content"];
                        break;
                    }

                    msg += Language.Selected["Alarm_Type"] + msgType + "\r\n";
                    msg += Language.Selected["Alarm_Value"] + alarmList[i].AlarmValue.ToString("F1") + ", " + Language.Selected["Alarm_RealValue"] + alarmList[i].RealValue.ToString("F3") + "\r\n";
                    msg += Language.Selected["Alarm_Level"] + WarringLevel[alarmList[i].Level] + "\r\n";

                    TB_Result.Text += msg + "\r\n";
                }
            }
            else
            {
                TB_Result.Text += "\r\n------无信息------\r\n";
            }

            //有故障信息
            TB_Result.Text += "\r\n------故障诊断信息------\r\n";
            if (anlyInfo != null)
            {
                //最终 诊断结果
                TB_Result.Text += "\r\n" + Language.Selected["Diag_Result"] + "\r\n" + dr.Result + "\r\n";
                //其它诊断中间数据,三比值、大卫三角形、立体图示
                TB_Result.Text += "\r\n" + Language.Selected["ThreeRatio_Diag_Result"] + "\r\n" + dr.ThreeRatioCode + "(" + dr.ThreeRatioResult + ")\r\n";
                TB_Result.Text += "\r\n" + Language.Selected["David_Result"] + "\r\n" + dr.DevidCode + "(" + dr.DevidResult + ")\r\n";
                TB_Result.Text += "\r\n" + Language.Selected["Cube_Diag_Result"] + "\r\n" + dr.CubeCode + "\r\n";

                //
                LB_Ratio.Text = dr.ThreeRatioCode;

                //大卫三角形数据
                //"C2H2:10%, C2H4:20%, CH4:30%"
                string   sr  = dr.DevidCode;
                string[] str = sr.Split(',');
                for (int i = 0; i < str.Length; i++)
                {
                    string[] temp = str[i].Split(':');
                    if (temp[0] == "C2H2" || temp[0] == "C2H4" || temp[0] == "CH4")
                    {
                        Session[temp[0]] = temp[1];
                    }
                }
                if (Session["C2H2"] != null & Session["C2H4"] != null && Session["CH4"] != null)
                {
                    get_temp_Map();
                    Timer1.Enabled = true;
                }

                else
                {
                    Response.Write("<script>alert(" + "session出错,请重新诊断!" + "')</script>");
                }
                //dr = dr.Replace('%', ' ');
                //dr = dr.Replace(',', '&');
                //dr = dr.Replace(":", "=");
                //dr = dr.Replace(" ", "");
                //string str = "javascript:showPopWin('" + Language.Selected["Title_Sample"] + "', 'DevidShow.aspx?";
                //str += dr;
                //str += "',  620, 330, null, true, true);return false;";
                //BT_Devid.OnClientClick = str;
                //BT_Devid.Enabled = true;

                //string str1 = "javascript:showPopWin('" + Language.Selected["CubeShow"] + "', 'ThreeShow.aspx?";
                //str1 += dr;
                //str1 += "',  900, 440, null, true, true);return false;";
                //BT_Cube.OnClientClick = str1;
                //BT_Cube.Enabled = true;
                ////立体图 命令参数
                ////"C2H2/C2H4=1, C2H4/C2H6=1, CH4/H2=1"
//#if false
//                                    //dr = anlyInfo._cubecode;

//                                    //string cmd = anlyInfo.Value.ratio.CH4_H2.ToString() + ",";
//                                    //cmd += anlyInfo.Value.ratio.C2H2_C2H4.ToString() + ",";
//                                    //cmd += anlyInfo.Value.ratio.C2H4_C2H6.ToString();
//                                    //ViewState["CMD"] = cmd;
//#else
//                ViewState["CMD"] = null;//这是谁改的?它和else里面的一样,那ViewState["CMD"]永远为null了,上面这段为什么注释掉?--ljb
//#endif
            }
            else
            {
                TB_Result.Text += "\r\n------无信息------\r\n";

                //ljb
                //BT_Devid.Enabled = true;
                //BT_Devid.Enabled = false;
                //BT_Cube.Enabled = false;

                ViewState["CMD"] = null;
            }
        }
示例#14
0
        internal UrlActionInfo GetUrlActionInfo(RouteData routeData, HttpContext context)
        {
            if (routeData == null)
            {
                throw new ArgumentNullException("routeData");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            // 采用ASP.NET Routing后,这三个参数都应该可以直接获取到,
            // 如果URL没有指定,可以通过默认值,或者DataToken指定,
            // 所以不需要像RestServiceModule那样重新计算
            string nspace    = GetRouteString(routeData, "namespace");
            string className = GetRouteString(routeData, "controller");
            string action    = GetRouteString(routeData, "action");

            if (string.IsNullOrEmpty(className) || string.IsNullOrEmpty(action))
            {
                DiagnoseResult diagnoseResult = Http404DebugModule.TryGetDiagnoseResult(context);
                if (diagnoseResult != null)
                {
                    diagnoseResult.ErrorMessages.Add("不能从URL中提取到controller和action信息");
                }

                return(null);
            }

            if (action == "{HttpMethod}")                       // 允许定义这个特殊变量
            {
                action = context.Request.HttpMethod;
            }


            ControllerResolver controllerResolver = new ControllerResolver(context);

            UrlActionInfo info = new UrlActionInfo();

            info.RoutePattern = (routeData.Route as Route).Url;                         // 转换失败??
            info.Namesapce    = controllerResolver.GetNamespaceMap(nspace);
            info.ClassName    = className;
            info.MethodName   = action;

            info.Action     = action;
            info.Controller = s_recognizer.GetServiceFullName(info);


            // 将路由提取到的其它URL参数,保存到UrlActionInfo实例中。
            foreach (KeyValuePair <string, object> kvp in routeData.Values)
            {
                // 排除3个特定名字。
                if (kvp.Key.IsSame("namespace") || kvp.Key.IsSame("controller") || kvp.Key.IsSame("action"))
                {
                    continue;
                }

                string value = kvp.Value as string;
                if (string.IsNullOrEmpty(value) == false)
                {
                    info.AddParam(kvp.Key, value);
                }
            }

            return(info);
        }