Ejemplo n.º 1
0
            /// <summary>
            /// 更新cbInput
            /// </summary>
            private void updatecbInput()
            {
                String strLine;

                listWarning.Clear();
                cbInput.Items.Clear();
                try
                {
                    FileStream   dataFile = new FileStream(Path.Combine(GlobalSettings.Path_data, "WarningValue.dat"), FileMode.Open);
                    StreamReader sr       = new StreamReader(dataFile);
                    strLine = sr.ReadLine();
                    while (strLine != null)
                    {
                        WarningValue warning   = BinarySerializer.Decode64(strLine) as WarningValue;
                        String       warningId = warning.getId();
                        this.cbInput.Items.Add(warningId);
                        listWarning.Add(warningId, warning);
                        strLine = sr.ReadLine();
                    }
                    sr.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
Ejemplo n.º 2
0
            /// <summary>
            /// 读取界面上的值,创建WarningValue对象
            /// </summary>
            /// <returns></returns>
            private WarningValue getFormValve()
            {
                String name = tbName.Text;
                String rate = cbRate.Text;

                double incloSum;

                double.TryParse(tbIncliSum.Text, out incloSum);
                double incloVelo;

                double.TryParse(tbIncliVelo.Text, out incloVelo);
                WarningIncli incli = new WarningIncli(incloSum, incloVelo);

                double setlSum;

                double.TryParse(tbGSetlSum.Text, out setlSum);
                double setlVelo;

                double.TryParse(tbGSetlVelo.Text, out setlVelo);
                WarningGSetle setle = new WarningGSetle(setlSum, setlVelo);

                double forceRate;

                double.TryParse(tbForceRatio.Text, out forceRate);
                WarningForce force = new WarningForce(forceRate);

                //创建警戒值类
                WarningValue warning = new WarningValue(name, rate, incli, setle, force);

                return(warning);
            }
Ejemplo n.º 3
0
        public MonitorState GetCurrentState()
        {
            string outputFormat = "F2";
            float  value        = 0;

            value             = GetNextValue();
            CurrentAgentValue = value;
            if (value > 9999)
            {
                outputFormat = "F0";
            }
            else if (value > 99)
            {
                outputFormat = "F1";
            }
            MonitorState currentState = new MonitorState()
            {
                ForAgent         = Description,
                CurrentValue     = value.ToString(outputFormat),
                State            = GetState(value),
                CurrentValueUnit = OutputValueUnit
            };

            if (currentState.State == CollectorState.Error)
            {
                currentState.RawDetails = string.Format("(Trigger {0})", ErrorValue.ToString(outputFormat));
            }
            else if (currentState.State == CollectorState.Warning)
            {
                currentState.RawDetails = string.Format("(Trigger {0})", WarningValue.ToString(outputFormat));
            }

            return(currentState);
        }
Ejemplo n.º 4
0
            private void cbInput_SelectedIndexChanged(object sender, EventArgs e)
            {
                WarningValue warning = listWarning[cbInput.Text];

                tbName.Text         = warning.name;
                cbRate.SelectedItem = warning.rate;
                tbIncliSum.Text     = warning.warningIncli.sum.ToString();
                tbIncliVelo.Text    = warning.warningIncli.velo.ToString();
                tbGSetlSum.Text     = warning.warningGSetle.sum.ToString();
                tbGSetlVelo.Text    = warning.warningGSetle.velo.ToString();
                tbForceRatio.Text   = warning.warningForc.ratio.ToString();
            }
Ejemplo n.º 5
0
        public MonitorState GetCurrentState()
        {
            string       outputFormat = "F2";
            float        value        = 0;
            MonitorState currentState = new MonitorState()
            {
                ForAgent = Description
            };

            try
            {
                value             = GetNextValue();
                CurrentAgentValue = value;
                if (value > 9999)
                {
                    outputFormat = "F0";
                }
                else if (value > 99)
                {
                    outputFormat = "F1";
                }

                currentState.CurrentValue     = value.ToString(outputFormat);
                currentState.State            = GetState(value);
                currentState.CurrentValueUnit = OutputValueUnit;
                if (currentState.State == CollectorState.Error)
                {
                    currentState.RawDetails = string.Format("(Trigger {0})", ErrorValue.ToString(outputFormat));
                }
                else if (currentState.State == CollectorState.Warning)
                {
                    currentState.RawDetails = string.Format("(Trigger {0})", WarningValue.ToString(outputFormat));
                }
            }
            catch (Exception ex)
            {
                currentState.State = CollectorState.Error;
                if (ex.Message.Contains("Instance") && ex.Message.Contains("does not exist in the specified Category"))
                {
                    currentState.CurrentValue = "Instance not found!";
                }
                currentState.RawDetails = ex.Message;
            }

            return(currentState);
        }
Ejemplo n.º 6
0
            private void button1_Click(object sender, EventArgs e)
            {
                //得到界面的值
                WarningValue warning   = getFormValve();
                String       warningId = warning.getId();

                //重复命名即为修改,没有重复即添加
                if (listWarning.ContainsKey(warningId) == true)
                {
                    listWarning[warningId] = warning;
                }
                else
                {
                    listWarning.Add(warningId, warning);
                }

                try
                {
                    //保存
                    FileStream   dataFile = new FileStream(Path.Combine(GlobalSettings.Path_data, "WarningValue.dat"), FileMode.Create);
                    StreamWriter sw       = new StreamWriter(dataFile);
                    foreach (var ele in listWarning)
                    {
                        String warningEleEncode = BinarySerializer.Encode64(ele.Value);
                        sw.WriteLine(warningEleEncode);
                    }
                    sw.Close();
                    //当前的选择
                    FileStream   dataFileUsing      = new FileStream(Path.Combine(GlobalSettings.Path_data, "WarningValueUsing.dat"), FileMode.Create);
                    StreamWriter swUsing            = new StreamWriter(dataFileUsing);
                    String       warningUsingEncode = BinarySerializer.Encode64(warning);
                    swUsing.WriteLine(warningUsingEncode);
                    swUsing.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    this.Close();
                }
                updatecbInput();
                this.Close();
            }
Ejemplo n.º 7
0
        public void SetRequestWarning(string request, Warnings warning, object data)
        {
            DataGridViewRow  row;
            DataGridViewCell cell;

            if (!requests.TryGetValue(request, out row))
            {
                requests[request] = row = (DataGridViewRow)gridRequests.RowTemplate.Clone();
                row.CreateCells(gridRequests);
                cell       = row.Cells[columnUrl.Index];
                cell.Value = request;

                row.Cells[columnDetails.Index].Value = "Details";


                gridRequests.Rows.Add(row);
            }

            cell = row.Cells[columnStatus.Index];

            WarningValue value;

            if (cell.Value != null)
            {
                value = (WarningValue)cell.Value;
                if (value.Warning != warning)
                {
                    gridRequests.InvalidateCell(cell);
                }
            }
            else
            {
                cell.Value = value = new WarningValue();
            }
            value.Data = data;

            value.Warning = warning;
            value.Count++;
        }
Ejemplo n.º 8
0
            private void btnDele_Click(object sender, EventArgs e)
            {
                //得到界面的值
                WarningValue warning   = getFormValve();
                String       warningId = warning.getId();

                listWarning.Remove(warningId);

                //保存
                FileStream   dataFile = new FileStream(Path.Combine(GlobalSettings.Path_data, "WarningValue.dat"), FileMode.Create);
                StreamWriter sw       = new StreamWriter(dataFile);

                foreach (var ele in listWarning)
                {
                    String warningEleEncode = BinarySerializer.Encode64(ele.Value);
                    sw.WriteLine(warningEleEncode);
                }
                sw.Close();

                //更新
                updatecbInput();
                return;
            }
Ejemplo n.º 9
0
        public CollectorState EvaluateValue(object value)
        {
            CollectorState result = CollectorState.Good;

            if (value == null || value == DBNull.Value)
            {
                if (ErrorValue == "[null]")
                {
                    result = CollectorState.Error;
                }
                else if (WarningValue == "[null]")
                {
                    result = CollectorState.Warning;
                }
                else if (SuccessValue == "[null]")
                {
                    result = CollectorState.Good;
                }
                else if (SuccessValue != "[any]")
                {
                    result = CollectorState.Error;
                }
            }
            else if (value.ToString() == "[notExists]")
            {
                if (ErrorValue == "[notExists]")
                {
                    result = CollectorState.Error;
                }
                else if (WarningValue == "[notExists]")
                {
                    result = CollectorState.Warning;
                }
                else if (SuccessValue == "[notExists]")
                {
                    result = CollectorState.Good;
                }
                else
                {
                    result = CollectorState.Error;
                }
            }
            else //non empty value but it DOES exist
            {
                if (!ReturnValueIsNumber || !ReturnValueInARange) //so it's not a number
                {
                    if (value.GetType().IsArray)
                    {
                        value = FormatUtils.FormatArrayToString(value);
                        //StringBuilder sb = new StringBuilder();
                        //if (value is Byte[]) //binary data
                        //{
                        //    Byte[] valArr = (Byte[])value;
                        //    for(int i = 0; i < valArr.Length; i++)
                        //    {
                        //        sb.AppendFormat("{0:x2}", valArr[i]).Append(",");
                        //    }
                        //    value = sb.ToString().Trim(',');
                        //}
                        //else if (value is string[])
                        //{
                        //    string[] valArr = (string[])value;
                        //    foreach (string line in valArr)
                        //        sb.AppendLine(line);
                        //    value = sb.ToString().TrimEnd('\r','\n');
                        //}
                    }

                    //first eliminate matching values
                    if (SuccessValue == value.ToString())
                    {
                        result = CollectorState.Good;
                    }
                    else if (value.ToString() == ErrorValue)
                    {
                        result = CollectorState.Error;
                    }
                    else if (value.ToString() == WarningValue)
                    {
                        result = CollectorState.Warning;
                    }

                    //test for [contains] <value>, [beginswith] <value> or [endswith] <value>
                    else if (SuccessValue.StartsWith("[contains]") && value.ToString().Contains(SuccessValue.Substring(("[contains]").Length).Trim()))
                    {
                        result = CollectorState.Good;
                    }
                    else if (SuccessValue.StartsWith("[beginswith]") && value.ToString().StartsWith(SuccessValue.Substring(("[beginswith]").Length).Trim()))
                    {
                        result = CollectorState.Good;
                    }
                    else if (SuccessValue.StartsWith("[endswith]") && value.ToString().EndsWith(SuccessValue.Substring(("[endswith]").Length).Trim()))
                    {
                        result = CollectorState.Good;
                    }
                    else if (WarningValue.StartsWith("[contains]") && value.ToString().Contains(WarningValue.Substring(("[contains]").Length).Trim()))
                    {
                        result = CollectorState.Good;
                    }
                    else if (WarningValue.StartsWith("[beginswith]") && value.ToString().StartsWith(WarningValue.Substring(("[beginswith]").Length).Trim()))
                    {
                        result = CollectorState.Good;
                    }
                    else if (WarningValue.StartsWith("[endswith]") && value.ToString().EndsWith(WarningValue.Substring(("[endswith]").Length).Trim()))
                    {
                        result = CollectorState.Good;
                    }
                    else if (ErrorValue.StartsWith("[contains]") && value.ToString().Contains(ErrorValue.Substring(("[contains]").Length).Trim()))
                    {
                        result = CollectorState.Good;
                    }
                    else if (ErrorValue.StartsWith("[beginswith]") && value.ToString().StartsWith(ErrorValue.Substring(("[beginswith]").Length).Trim()))
                    {
                        result = CollectorState.Good;
                    }
                    else if (ErrorValue.StartsWith("[endswith]") && value.ToString().EndsWith(ErrorValue.Substring(("[endswith]").Length).Trim()))
                    {
                        result = CollectorState.Good;
                    }

                    //Existing tests
                    else if (ErrorValue == "[exists]")
                    {
                        result = CollectorState.Error;
                    }
                    else if (WarningValue == "[exists]")
                    {
                        result = CollectorState.Warning;
                    }
                    else if (SuccessValue == "[exists]")
                    {
                        result = CollectorState.Good;
                    }

                    //Any tests
                    else if (ErrorValue == "[any]")
                    {
                        result = CollectorState.Error;
                    }
                    else if (WarningValue == "[any]")
                    {
                        result = CollectorState.Warning;
                    }

                    //Not matching success
                    else if (SuccessValue != "[any]")
                    {
                        result = CollectorState.Warning;
                    }
                }
                else if (!value.IsNumber()) //value must be a number!
                {
                    result = CollectorState.Error;
                }
                else //so it is a number and must be inside a range
                {
                    if (ErrorValue != "[any]" && ErrorValue != "[null]" &&
                        (
                            (!ReturnValueInverted && double.Parse(value.ToString()) >= double.Parse(ErrorValue)) ||
                            (ReturnValueInverted && double.Parse(value.ToString()) <= double.Parse(ErrorValue))
                        )
                        )
                    {
                        result = CollectorState.Error;
                    }
                    else if (WarningValue != "[any]" && WarningValue != "[null]" &&
                             (
                                 (!ReturnValueInverted && double.Parse(value.ToString()) >= double.Parse(WarningValue)) ||
                                 (ReturnValueInverted && double.Parse(value.ToString()) <= double.Parse(WarningValue))
                             )
                             )
                    {
                        result = CollectorState.Warning;
                    }
                }
            }

            return(result);
        }
        public CollectorState EvaluateValue(object value)
        {
            CollectorState result = CollectorState.Good;

            if (value == null || value == DBNull.Value)
            {
                if (ErrorValue == "[null]")
                {
                    result = CollectorState.Error;
                }
                else if (WarningValue == "[null]")
                {
                    result = CollectorState.Warning;
                }
                else if (SuccessValue == "[null]")
                {
                    result = CollectorState.Good;
                }
                else if (SuccessValue != "[any]")
                {
                    result = CollectorState.Error;
                }
            }
            else if (value.ToString() == "[notExists]")
            {
                if (ErrorValue == "[notExists]")
                {
                    result = CollectorState.Error;
                }
                else if (WarningValue == "[notExists]")
                {
                    result = CollectorState.Warning;
                }
                else if (SuccessValue == "[notExists]")
                {
                    result = CollectorState.Good;
                }
                else
                {
                    result = CollectorState.Error;
                }
            }
            else //non empty value but it DOES exist
            {
                if (!ReturnValueIsNumber || !ReturnValueInARange) //so it's not a number
                {
                    if (value.GetType().IsArray)
                    {
                        value = FormatUtils.FormatArrayToString(value);
                    }

                    //first eliminate matching values
                    if (SuccessValue == value.ToString())
                    {
                        result = CollectorState.Good;
                    }
                    else if (value.ToString() == ErrorValue)
                    {
                        result = CollectorState.Error;
                    }
                    else if (value.ToString() == WarningValue)
                    {
                        result = CollectorState.Warning;
                    }

                    //test for [contains] <value>, [beginswith] <value> or [endswith] <value>
                    else if (SuccessValue.StartsWith("[contains]") && value.ToString().Contains(SuccessValue.Substring(("[contains]").Length).Trim()))
                    {
                        result = CollectorState.Good;
                    }
                    else if (SuccessValue.StartsWith("[beginswith]") && value.ToString().StartsWith(SuccessValue.Substring(("[beginswith]").Length).Trim()))
                    {
                        result = CollectorState.Good;
                    }
                    else if (SuccessValue.StartsWith("[endswith]") && value.ToString().EndsWith(SuccessValue.Substring(("[endswith]").Length).Trim()))
                    {
                        result = CollectorState.Good;
                    }
                    else if (WarningValue.StartsWith("[contains]") && value.ToString().Contains(WarningValue.Substring(("[contains]").Length).Trim()))
                    {
                        result = CollectorState.Good;
                    }
                    else if (WarningValue.StartsWith("[beginswith]") && value.ToString().StartsWith(WarningValue.Substring(("[beginswith]").Length).Trim()))
                    {
                        result = CollectorState.Good;
                    }
                    else if (WarningValue.StartsWith("[endswith]") && value.ToString().EndsWith(WarningValue.Substring(("[endswith]").Length).Trim()))
                    {
                        result = CollectorState.Good;
                    }
                    else if (ErrorValue.StartsWith("[contains]") && value.ToString().Contains(ErrorValue.Substring(("[contains]").Length).Trim()))
                    {
                        result = CollectorState.Good;
                    }
                    else if (ErrorValue.StartsWith("[beginswith]") && value.ToString().StartsWith(ErrorValue.Substring(("[beginswith]").Length).Trim()))
                    {
                        result = CollectorState.Good;
                    }
                    else if (ErrorValue.StartsWith("[endswith]") && value.ToString().EndsWith(ErrorValue.Substring(("[endswith]").Length).Trim()))
                    {
                        result = CollectorState.Good;
                    }

                    //Existing tests
                    else if (ErrorValue == "[exists]")
                    {
                        result = CollectorState.Error;
                    }
                    else if (WarningValue == "[exists]")
                    {
                        result = CollectorState.Warning;
                    }
                    else if (SuccessValue == "[exists]")
                    {
                        result = CollectorState.Good;
                    }

                    //Any tests
                    else if (ErrorValue == "[any]")
                    {
                        result = CollectorState.Error;
                    }
                    else if (WarningValue == "[any]")
                    {
                        result = CollectorState.Warning;
                    }

                    //Not matching success
                    else if (SuccessValue != "[any]")
                    {
                        result = CollectorState.Warning;
                    }
                }
                else if (!value.IsNumber()) //value must be a number!
                {
                    result = CollectorState.Error;
                }
                else //so it is a number and must be inside a range
                {
                    if (ErrorValue != "[any]" && ErrorValue != "[null]" &&
                        (
                            (!ReturnValueInverted && double.Parse(value.ToString()) >= double.Parse(ErrorValue)) ||
                            (ReturnValueInverted && double.Parse(value.ToString()) <= double.Parse(ErrorValue))
                        )
                        )
                    {
                        result = CollectorState.Error;
                    }
                    else if (WarningValue != "[any]" && WarningValue != "[null]" &&
                             (
                                 (!ReturnValueInverted && double.Parse(value.ToString()) >= double.Parse(WarningValue)) ||
                                 (ReturnValueInverted && double.Parse(value.ToString()) <= double.Parse(WarningValue))
                             )
                             )
                    {
                        result = CollectorState.Warning;
                    }
                }
            }

            return(result);
        }