コード例 #1
0
        private void timerUI_Update_Tick(object sender, EventArgs e)
        {
            DateTime tNow    = DateTime.Now;
            String   timeLog = tNow.ToString("MM-dd HH:mm:ss");

            Boolean bUpdated = false;

            while (_logList.Count > 0)
            {
                string log = "";
                if (_logList.TryDequeue(out log))
                {
                    bUpdated = true;
                    DebugLog(LOG_INFO, log);
                    this.listBoxLog.Items.Add(timeLog + " " + log);
                }
            }

            List <String> logList = RemoteCall.GetLog();

            for (int i = 0; i < logList.Count; i++)
            {
                bUpdated = true;
                DebugLog(LOG_INFO, logList[i]);
                this.listBoxLog.Items.Add(timeLog + " " + logList[i]);
            }

            if (_StressTester != null)
            {
                logList = _StressTester.GetLog();
                for (int i = 0; i < logList.Count; i++)
                {
                    bUpdated = true;
                    DebugLog(LOG_INFO, logList[i]);
                    this.listBoxLog.Items.Add(timeLog + " " + logList[i]);
                }
            }

            TimeSpan tSpan = tNow - _dtLastUpdated;

            if (tSpan.TotalMilliseconds > 200)
            {
                if (_CadmTaskID > 0)
                {
                    OnCadmTimer();
                }
                if (_reqSession.IsSigned())
                {
                    if (!String.IsNullOrEmpty(_TaskID))
                    {
                        StringBuilder progress = new StringBuilder();
                        if (RESTClient.RemoteCall.OrderProgress(_reqSession, _TaskID, progress))
                        {
                            int nProgress = Convert.ToInt32(progress.ToString());
                            Debug.WriteLine("Order Progress: {0}", nProgress);

                            if ((nProgress >= 100) && (nProgress != 999))
                            {
                                StringBuilder resultFile = new StringBuilder(32768);
                                if (_TaskType.Equals("CreatePart"))
                                {
                                    if (RESTClient.RemoteCall.GetObjectData("ProcessData", _TaskID, resultFile, ""))
                                    {
                                        Debug.WriteLine(resultFile);

                                        //String resultContent = File.ReadAllText(xmlFile.ToString());
                                        //Debug.WriteLine(resultContent.Substring(0, Math.Min(resultContent.Length, 256)));
                                    }
                                }
                                else if (_TaskType.Equals("PartForm"))
                                {
                                    if (RESTClient.RemoteCall.OrderDataset(_reqSession, _TaskID, resultFile))
                                    {
                                        Debug.WriteLine(resultFile);
                                    }
                                }
                                else if (_TaskType.Equals("CreateProjectData"))
                                {
                                    if (RESTClient.RemoteCall.OrderDataset(_reqSession, _TaskID, resultFile))
                                    {
                                        Debug.WriteLine(resultFile);
                                    }
                                }
                                else if (_TaskType.Equals("OrderDirect"))
                                {
                                    if (RESTClient.RemoteCall.OrderResult(_reqSession, _TaskID, resultFile))
                                    {
                                        Debug.WriteLine(resultFile);

                                        StringBuilder error = new StringBuilder();
                                        RESTClient.RemoteCall.OrderRemove(_reqSession, _TaskID, error);
                                    }
                                }
                                _TaskID   = "";
                                _TaskType = "";
                            }
                            else if (nProgress < 0)
                            {
                                _TaskID   = "";
                                _TaskType = "";
                            }
                        }
                        else
                        {
                            _TaskID   = "";
                            _TaskType = "";
                        }
                    }
                }
                else
                {
                    if (!this.checkBoxAPI.Checked)
                    {
                        _CadmTaskID = -1;
                    }

                    this.buttonSubmit.Text = "提交任务";
                    _TaskID = "";
                }

                _dtLastUpdated = tNow;

                this.textBoxFinished.Text = FinishedFiles.ToString();

                if (_StressTester != null)
                {
                    tSpan = tNow - tStressStarted;
                    this.textBoxElapsed.Text = tSpan.ToString(@"dd\.hh\:mm\:ss");
                }
            }

            if (bUpdated)
            {
                if (this.listBoxLog.Items.Count > 1000)
                {
                    int nCount = 100;
                    while (--nCount > 0)
                    {
                        this.listBoxLog.Items.RemoveAt(0);
                    }
                }

                this.listBoxLog.SelectedIndex = this.listBoxLog.Items.Count - 1;
            }

            if (!_reqSession.IsSigned() && !this.checkBoxAPI.Checked)
            {
                if (this.buttonSign.Text.Equals("注 销"))
                {
                    _CadmTaskID = -1;
                    _TaskID     = "";

                    this.buttonSubmit.Text = "提交任务";
                    this.buttonSign.Text   = ("登 录");
                    UpdateButtonState();
                }
            }
            else
            {
                if (this.buttonSign.Text.Equals("登 录"))
                {
                    this.buttonSign.Text = ("注 销");
                    UpdateButtonState();
                }
            }
        }