コード例 #1
0
ファイル: frmMain.cs プロジェクト: shod/Uniterm
        /// <summary>
        /// Demo regime
        /// </summary>
        private void TerminalRefreshDemo()
        {
            Config cConf = new Config();
            arrInfoLine = new ArrayList();
            String strLine;
            String[] arrLine;
            string DirPath = cConf.getappSettings(Config.SettingField.DataSyncDir.ToString());
            CFile FileDemo = new CFile(DirPath+"/demo_act.txt");
            CFile FileDemoNew = new CFile(DirPath + "/demo_act.txt");
            arrLineDemo = FileDemo.Read();

            /* Прогресс */
            statusProgress.Visible = true;
            statusProgress.Value = 0;

            TermFile cFileObj = new TermFile();

            int c_count = arrLineDemo.Count;
            int c_Rand;
            Random fixRand = new Random();
            c_Rand = fixRand.Next(1, 7);
            for (int i = 0; i < c_count; i++)
            {
                Thread.Sleep(1000);
                statusProgress.Step = (80 / c_count);
                statusProgress.PerformStep();
                //arrInfoLine.Add(arrLineDemo[i]);
                strLine = arrLineDemo[i];
                //strLine = strLine.Replace(".", ",");
                arrLine = strLine.Split(';');
                strLine = "";

                double dd;
                int idd;

                int l_count = arrLine.Length;
                for (int a = 0; a < l_count; a++)
                {
                    if (a == 2)
                    {
                        arrLine[a] = DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second;
                    }

                    //if (a == 13 || a==14 ||a==15)
                    if (a >10 && Char.IsDigit(Convert.ToChar(arrLine[a].Substring(0,1))))
                    {
                        try
                        {
                            dd = Convert.ToDouble(arrLine[a]);
                            dd = dd + (dd / 100 * 0.5);
                            arrLine[a] = dd.ToString();
                        }
                        catch
                        {
                            idd = Convert.ToInt16(arrLine[a]);
                            idd = idd + (idd / 100 * l_count);
                            arrLine[a] = idd.ToString();
                        }

                    }
                }
                strLine = String.Join(";", arrLine);
                strLine = strLine.Replace(",", ".");

                if (i <= c_Rand-1)
                {
                    cFileObj.AddLine(strLine);
                }

                FileDemoNew.AddLine(strLine);
            }
            cFileObj.Write();
            FileDemoNew.Write(false);

            _tCount++;
            LogFileSave(arrInfoLine);
            statusProgress.Visible = false;
            lblTCount.Text = _tCount.ToString();
            lblError.Text = _tError.ToString();
        }
コード例 #2
0
ファイル: frmMain.cs プロジェクト: shod/Uniterm
        /// <summary>
        /// Опрос терминалов
        /// </summary>
        private void TerminalRefresh()
        {
            statusMessage.Text = DateTime.Now.ToString( "H:mm:f");

            try
            {

                lblInfo.Text = "Система в работе.";
                Config.SysObject SysObject, Sterm;
                Config cConf = new Config();
                string strDemo = "";

                strDemo = cConf.getappSettings(Config.SettingField.Demo.ToString());

                if (strDemo != "")
                {
                    if (Convert.ToBoolean(strDemo))
                    {
                        TerminalRefreshDemo();
                        return;
                    }

                }

                int c_count;
                CTerm cTermObj;
                int cAttempt = 0;
                _Attempt = Convert.ToInt16(cConf.getappSettings(Config.SettingField.AttemptCount.ToString()));

                cConf.getappSettings("Period");
                String strTermData;
                c_count = arrObject.Count;
                bool FlagNoTerm = false;

                for (int ia = 0; ia < c_count; ia++)
                {
                    Sterm = (Config.SysObject)arrObject[ia];
                    if (_TermIndex > 0 && Sterm.Index != _TermIndex)
                    {
                        FlagNoTerm = true;
                    }
                    else
                    {
                        FlagNoTerm = false;
                        break;
                    }
                }

                if (FlagNoTerm)
                {
                    lblInfo.Text = "Терминал с номером №" + _TermIndex + " не зарегистрирован в системе.";
                    return;
                }

                //TermFile cFileObj = new TermFile();
                strTermData = "";
                //_tError = 0;

                arrInfoLine = new ArrayList();
                ArrayList arrResponseLine = new ArrayList();
                ArrayList arrErrorLine = new ArrayList() ; // Массив строк для записи ошибок
                bool FlagError = false;

                /* Прогресс */
                statusProgress.Visible = true;
                statusProgress.Value = 0;

                for (int i = 0; i < c_count; i++)
                {
                    statusProgress.Step = (80 / c_count);
                    statusProgress.PerformStep();

                    SysObject = (Config.SysObject)arrObject[i];

                    FlagError = false;
                    if (_TermIndex == SysObject.Index || _TermIndex == -1)
                    {
                        /* Опрос терминалов */
                        cTermObj = new CTerm(SysObject.Index, SysObject.Type);
                        cTermObj.TermProtocolIndex = _TermProtocolIndex;
                        _TermProtocolIndex = _TermProtocolIndex; //-1 Сброс индекса протокола
                        cTermObj.RequestParam = _cTermReqParam;
                        cTermObj.Refresh(cPort);

                        if (cTermObj.isDataError())
                        {
                            FlagError = true;
                            arrErrorLine.Add("[" + SysObject.Index + "]" + cTermObj.getDataResponseHex());
                            //statusProgress.Value = statusProgress.Value - _Attempt;
                            statusProgress.Step = 1;

                            while (cAttempt <= _Attempt)
                            {
                                statusProgress.PerformStep();

                                cTermObj.Refresh(cPort);
                                Thread.Sleep((cAttempt + 1) * 200);
                                strTermData = cTermObj.getDataString();
                                if (cTermObj.isDataError() == false)
                                {
                                    strTermData = cTermObj.getDataString();
                                    FlagError = false;
                                    arrErrorLine.Clear();
                                    break;
                                }
                                arrErrorLine.Add("[" + SysObject.Index + "]" + cTermObj.getDataResponseHex());
                                arrResponseLine.Add("[" + SysObject.Index + "][" + cAttempt + "]" + cTermObj.getDataResponseHex());
                                cAttempt++;
                            }
                        }
                        else
                        {
                            //MessageBox.Show(cTermObj.getDataString());
                            strTermData = cTermObj.getDataString();
                        }

                        //Оригинальные ответы
                        arrResponseLine.Add("[" + SysObject.Index + "]"+cTermObj.getDataResponseHex());
                        //arrInfoLine.Add(strTermData.ToString());
                        /* Запись строк в массив */
                        if (FlagError == false)
                        {
                            arrInfoLine.Add(strTermData.ToString());
                        }
                        else
                        {
                            _tError++;
                        }

                    }

                    /* Запись оригинальных ответов */
                    if (Convert.ToBoolean(cConf.getappSettings(Config.SettingField.LogResponse.ToString()))
                        & arrResponseLine.Count>0)
                    {

                        LogFileSave(arrResponseLine);
                    }
                    _tCount++;
                }

                /* Запись в файл, если это не отчет*/
                if (_cTermReqParam.ReportType == null)
                {
                    if (arrInfoLine.Count > 0)
                    {
                        TermFile cFileObj = new TermFile();

                        foreach (string Line in arrInfoLine)
                        {
                            cFileObj.AddLine(Line);
                        }
                        cFileObj.Write();
                    }
                }

                /* Запись ошибок опросов */
                LogErrorFileSave(arrErrorLine);

                if (_cTermReqParam.ReportType !=  "")
                {
                    ReportFileSave(strTermData.Split('='), _cTermReqParam.ReportCode);
                }

            }
            catch(Exception e)
            {
            StartStopProcess(Convert.ToBoolean(TerminalAct.Stop));
            MessageBox.Show(e.Message, "Ошибка!",MessageBoxButtons.OK, MessageBoxIcon.Stop);
            lblInfo.Text = "Ошибка в работе системы!";
            }
            statusProgress.Visible = false;
            lblTCount.Text = _tCount.ToString();
            lblError.Text = _tError.ToString();
        }