Beispiel #1
0
        public static MachineVariables ParseHealthyCommand(String hString)
        {
            MachineVariables mvar = new MachineVariables("", new List <Variables>());
            String           t    = hString.Replace("{[", "").Replace("]}", "");

            String[] arr = t.Split(new String[] { "][" }, StringSplitOptions.None);
            foreach (String ele in arr)
            {
                String[]  arr1 = ele.Split(' ');
                Variables var  = new Variables("", arr1[1], arr1[2], arr1[4], arr1[6]);
                var.Order = arr1[0];
                String uc = arr1[3];
                if (uc.Equals("1"))
                {
                    var.UnhealthyCondition = 1;
                }
                if (uc.Equals("0"))
                {
                    var.UnhealthyCondition = 0;
                }
                if (uc.Equals("-1"))
                {
                    var.UnhealthyCondition = -1;
                }
                uc = arr1[5];
                if (uc.Equals("1"))
                {
                    var.StopedCondition = 1;
                }
                if (uc.Equals("0"))
                {
                    var.StopedCondition = 0;
                }
                if (uc.Equals("-1"))
                {
                    var.StopedCondition = -1;
                }
                mvar.variables.Add(var);
            }
            return(mvar);
        }
Beispiel #2
0
        public static List <MachineVariables> getMachineVariables()
        {
            List <MachineVariables> _machines = new List <MachineVariables>();

            try
            {
                SqlConnection conn = new SqlConnection(Program.connString);
                conn.Open();
                SqlCommand    cmd = new SqlCommand("select * from machine_settings", conn);
                SqlDataReader dr  = cmd.ExecuteReader();
                while (dr.Read())
                {
                    String           type  = dr["type"].ToString();
                    String           param = dr["parameter"].ToString();
                    MachineVariables mv    = new MachineVariables(type, new List <Variables>());
                    mv.inputString = param;
                    _machines.Add(mv);
                }
                dr.Close();
                conn.Close();
            }
            catch (Exception ex)
            {
                return(null);
            }

            try
            {
                foreach (MachineVariables machine in _machines)
                {
                    String[] arrTemp = machine.inputString.Split(new String[] { "][" }, StringSplitOptions.None);
                    for (int i = 0; i < arrTemp.Length; i++)
                    {
                        arrTemp[i] = arrTemp[i].Replace("[", "").Replace("]", "");
                    }
                    List <Parameter> lstpars = ManageParameters.getAllParameters(PAR_CATEGORY.STATUS);
                    foreach (Parameter parm in lstpars)
                    {
                        if (parm.CheckForHealthy)
                        {
                            String hf = "", ht = "", uh = "", st = "";
                            foreach (String pfdb in arrTemp)
                            {
                                if (pfdb.ToLower().Contains(parm.Name.ToLower()))
                                {
                                    String[] arr = pfdb.Split(new String[] { "," }, StringSplitOptions.None);
                                    if (arr.Length == 5)
                                    {
                                        hf = arr[1];
                                        ht = arr[2];
                                        uh = arr[3];
                                        st = arr[4];
                                    }
                                    break;
                                }
                            }
                            machine.variables.Add(new Variables(parm.Name, hf, ht, uh, st));
                        }
                    }
                }
            }
            catch (Exception ex) { return(null); }

            return(_machines);
        }
Beispiel #3
0
        private void lstMachines_SelectedIndexChanged(object sender, EventArgs e)
        {
            lstMachines.Enabled = false;
            if (lstMachines.SelectedItems.Count > 0)
            {
                txtProblems.Text = "";
                lblStatus.Text   = "Searching problem ...";
                ListViewItem li      = lstMachines.SelectedItems[0];
                Machine      machine = new Machine(li.SubItems[1].Text.Trim(), Program.connString, ManageParameters.getAllParameters(PAR_CATEGORY.STATUS), ManageParameters.getAllParameters(PAR_CATEGORY.SETTINGS), UserSetting.StatusMessageFormat, UserSetting.SettingMessageFormat);
                if (machine.Error != MCError.NULL)
                {
                    if (machine.Error == MCError.INVALID_IDENTIFIER)
                    {
                        updateProblem("Machine ID invalid.");
                    }
                    else if (machine.Error == MCError.SQL_ERROR)
                    {
                        updateProblem("Mind error.");
                    }
                    else if (machine.Error == MCError.PARSE_FAILED)
                    {
                        updateProblem("Machine's entries invalid.");
                    }
                    else if (machine.Error == MCError.SETTING_ERROR)
                    {
                        if (machine.Settings.ErrorMessage == MCFormat_ERROR.NULL)
                        {
                            updateProblem("Machine setting is not updated yet or invalid settings parameters.");
                        }
                        else if (machine.Settings.ErrorMessage == MCFormat_ERROR.FORMAT_MISMATCH)
                        {
                            updateProblem("Machine setting message isn't matched with given format.");
                        }
                        else if (machine.Settings.ErrorMessage == MCFormat_ERROR.FORMAT_NOT_ACCEPTED)
                        {
                            updateProblem("Machine setting message has errors.");
                        }
                        else if (machine.Settings.ErrorMessage == MCFormat_ERROR.INVALID_FORMAT)
                        {
                            updateProblem("Machine setting message has invalid format.");
                        }
                        else if (machine.Settings.ErrorMessage == MCFormat_ERROR.PARAMETER_COUNT)
                        {
                            updateProblem("Machine setting message's received parameters count isn't matched with format.");
                        }
                        else if (machine.Settings.ErrorMessage == MCFormat_ERROR.SEPARATOR_NOT_FOUND)
                        {
                            updateProblem("Machine setting message hasn't any separator.");
                        }
                        else
                        {
                            updateProblem("Machine setting message has error.");
                        }
                    }
                    else if (machine.Error == MCError.STATUS_ERROR)
                    {
                        if (machine.Status.ErrorMessage == MCFormat_ERROR.NULL)
                        {
                            updateProblem("Machine status is not updated yet or invalid status parameters.");
                        }
                        else if (machine.Status.ErrorMessage == MCFormat_ERROR.FORMAT_NOT_ACCEPTED)
                        {
                            updateProblem("Machine status message's has errors.");
                        }
                        else if (machine.Status.ErrorMessage == MCFormat_ERROR.FORMAT_MISMATCH)
                        {
                            updateProblem("Machine status message's format isn't matched with given format.");
                        }
                        else if (machine.Status.ErrorMessage == MCFormat_ERROR.INVALID_FORMAT)
                        {
                            updateProblem("Machine status message has invalid format.");
                        }
                        else if (machine.Status.ErrorMessage == MCFormat_ERROR.PARAMETER_COUNT)
                        {
                            updateProblem("Machine status message's received parameters count not macthed with given format.");
                        }
                        else if (machine.Status.ErrorMessage == MCFormat_ERROR.SEPARATOR_NOT_FOUND)
                        {
                            updateProblem("Machine status message's separator not found.");
                        }
                        else
                        {
                            updateProblem("Machine status message's has error.");
                        }
                    }
                    else
                    {
                        updateProblem("Unknown problem id=1.");
                    }
                }

                if (true)
                {
                    if (machine.Status.Error)
                    {
                        updateProblem("Invalid received machine status parameters.");
                    }
                    else
                    {
                        List <MachineVariables> mparams = ParameterVariables.getMachineVariables();
                        if (mparams != null)
                        {
                            MachineVariables macParam  = Program.ParseHealthyCommand(machine.HealthySetting);
                            List <Parameter> chkValues = machine.Status.parameters;

                            foreach (Variables var in macParam.variables)
                            {
                                Parameter par = chkValues.Find(x => (x.Order == var.Order));
                                if (par != null)
                                {
                                    int result = checkParameter(par, var);
                                    //0 stoped, 1 unhealthy, 2 green, 3 unknown. -1 error
                                    if (result == 0)
                                    {
                                        updateProblem(par.Name + " indicates NOT_WORKING SIGNAL.");
                                    }
                                    else if (result == 1)
                                    {
                                        updateProblem(par.Name + " indicates UNHEALTHY SIGNAL.");
                                    }
                                    else if (result == 2)
                                    {
                                        updateProblem(par.Name + " indicates HEALTHY SIGNAL.");
                                    }
                                    else if (result == 3)
                                    {
                                        updateProblem(par.Name + " indicates NOT_MATCHED SIGNAL.");
                                    }
                                    else if (result == 1)
                                    {
                                        updateProblem(par.Name + " indicates ERROR SIGNAL.");
                                    }
                                }
                            }
                        }
                        else
                        {
                            updateProblem("Error in reading parameters from mind.");
                        }
                    }
                }
            }
            lblStatus.Text      = "Problem displayed.";
            lstMachines.Enabled = true;
        }
Beispiel #4
0
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            String           oldText = "", newText = "";
            MachineVariables mac = null;

            foreach (MachineVariables machine in machines)
            {
                String _T = comboBox1.Items[comboBox1.SelectedIndex].ToString();
                if (machine.Type.ToLower() == _T.ToLower())
                {
                    mac = machine;
                    break;
                }
            }
            if (mac == null)
            {
                return;
            }
            if (previousSelected > -1)
            {
                oldText = listBox1.Items[previousSelected].ToString();
                foreach (Variables param in mac.variables)
                {
                    if (param.Name.Equals(oldText))
                    {
                        if (txt1.Text.Trim().Length > 0 && txt2.Text.Trim().Length > 0 && txt3.Text.Trim().Length > 0 && txt4.Text.Trim().Length > 0)
                        {
                            param.Health_From = txt1.Text.Trim().Replace(".", "").Replace("/", "").Replace(":", "");
                            param.Health_To   = txt2.Text.Trim().Replace(".", "").Replace("/", "").Replace(":", "");
                            param.Unhealthy   = txt3.Text.Trim().Replace(".", "").Replace("/", "").Replace(":", "");
                            param.Stoped      = txt4.Text.Trim().Replace(".", "").Replace("/", "").Replace(":", "");
                        }
                    }
                }
            }
            if (listBox1.SelectedIndex > -1)
            {
                previousSelected = listBox1.SelectedIndex;
                Parameter selParam = (Parameter)listBox1.SelectedItem;
                newText = selParam.ToString();
                if (mac != null)
                {
                    foreach (Variables param in mac.variables)
                    {
                        if (param.Name.Equals(newText))
                        {
                            String fmt = selParam.Format;
                            if (selParam.Format.Contains("{"))
                            {
                                fmt = "";
                            }
                            txt1.Mask = txt2.Mask = txt3.Mask = txt4.Mask = fmt;
                            txt1.Text = param.Health_From;
                            txt2.Text = param.Health_To;
                            txt3.Text = param.Unhealthy;
                            txt4.Text = param.Stoped;
                            txt1.Focus();
                        }
                    }
                }
            }
        }