示例#1
0
        static string GetExceptionText(Exception ex, string strType)
        {
            // Exception ex = (Exception)e.Exception;
            string   strError   = "发生未捕获的" + strType + "异常: \r\n" + ExceptionUtil.GetDebugText(ex);
            Assembly myAssembly = Assembly.GetAssembly(typeof(Program));

            strError += "\r\ndp2Circulation 版本: " + myAssembly.FullName;
            strError += "\r\n操作系统:" + Environment.OSVersion.ToString();
            strError += "\r\n本机 MAC 地址: " + StringUtil.MakePathList(SerialCodeForm.GetMacAddress());

            // TODO: 给出操作系统的一般信息

            MainForm.WriteErrorLog(strError);
#if NO
            // MainForm main_form = Form.ActiveForm as MainForm;
            if (_mainForm != null)
            {
                _mainForm.TryWriteErrorLog(strError);
            }
            else
            {
                WriteWindowsLog(strError, EventLogEntryType.Error);
            }
#endif

            return(strError);
        }
示例#2
0
        // 工作线程
        /*public virtual*/ void ThreadMain()
        {
            try
            {
                WaitHandle[] events = new WaitHandle[2];

                events[0] = eventClose;
                events[1] = eventActive;

                while (true)
                {
                    int index = WaitHandle.WaitAny(events, PerTime, false);

                    if (index == WaitHandle.WaitTimeout)
                    {
                        // 超时
                        eventActive.Reset();
                        Worker();
                    }
                    else if (index == 0)
                    {
                        break;
                    }
                    else
                    {
                        // 得到激活信号
                        eventActive.Reset();
                        Worker();
                    }

                    /*
                     * // 是否循环?
                     * if (this.Loop == false)
                     *  break;
                     * */
                }

                eventFinished.Set();
            }
            catch (Exception ex)
            {
                string strErrorText = "PassGateForm ThreadMain() 出现异常: " + ExceptionUtil.GetDebugText(ex);
                MainForm.TryWriteErrorLog(strErrorText);
            }
        }
示例#3
0
        // listview imageindex 0:尚未初始化 1:已经初始化 2:出错

        // 工作线程每一轮循环的实质性工作
        void Worker()
        {
            try
            {
                string strError = "";

                for (int i = this.m_nTail; i < this.listView_list.Items.Count; i++)
                {
                    // ListViewItem item = this.listView_list.Items[i];
                    ListViewItem item = GetItem(i);

                    if (item.ImageIndex == 1)
                    {
                        continue;
                    }

                    // string strBarcode = item.Text;
                    ReaderInfo info       = (ReaderInfo)item.Tag;
                    string     strBarcode = info.ReaderBarcode;

                    stop.OnStop += new StopEventHandler(this.DoStop);
                    stop.Initial("正在初始化浏览器组件 ...");
                    stop.BeginLoop();

                    string strTypeList = "xml";
                    int    nTypeCount  = 1;

                    if (this.checkBox_displayReaderDetailInfo.Checked == true)
                    {
                        strTypeList += ",html";

                        if (StringUtil.CompareVersion(Program.MainForm.ServerVersion, "2.25") >= 0)
                        {
                            strTypeList += ":noborrowhistory";
                        }

                        nTypeCount = 2;
                    }

                    try
                    {
                        string[] results = null;
                        long     lRet    = Channel.PassGate(stop,
                                                            strBarcode,
                                                            this.textBox_gateName.Text, // strGateName
                                                            strTypeList,
                                                            out results,
                                                            out strError);
                        if (lRet == -1)
                        {
                            OnError(item, strError);
                            goto CONTINUE;
                        }

                        // this.textBox_counter.Text = lRet.ToString();
                        SetCounterText(lRet);

                        if (results.Length != nTypeCount)
                        {
                            strError = "results error...";
                            OnError(item, strError);
                            goto CONTINUE;
                        }

                        string strXml = results[0];

                        string strReaderName = "";
                        string strState      = "";
                        int    nRet          = GetRecordInfo(strXml,
                                                             out strReaderName,
                                                             out strState,
                                                             out strError);
                        if (nRet == -1)
                        {
                            OnError(item, strError);
                            goto CONTINUE;
                        }

                        info.ReaderName = strReaderName;

                        if (this.checkBox_hideReaderName.Checked == true)
                        {
                            string strText = "";
                            // item.SubItems[1].Text = strText.PadLeft(strReaderName.Length, '*');
                            SetItemText(item, 1, strText.PadLeft(strReaderName.Length, '*'));
                        }
                        else
                        {
                            // item.SubItems[1].Text = strReaderName;
                            SetItemText(item, 1, strReaderName);
                        }

                        // item.SubItems[2].Text = strState;
                        SetItemText(item, 2, strState);

                        // item.ImageIndex = 1;    // error
                        SetItemImageIndex(item, 1);

                        if (this.checkBox_displayReaderDetailInfo.Checked == true &&
                            results.Length == 2)
                        {
                            this.m_webExternalHost.StopPrevious();
                            this.webBrowser_readerInfo.Stop();

                            // this.HtmlString = results[1];

                            // API.PostMessage(this.Handle, WM_SETHTML, 0, 0);
                            StartSetHtml(results[1]);
                        }
                    }
                    finally
                    {
                        stop.EndLoop();
                        stop.OnStop -= new StopEventHandler(this.DoStop);
                        stop.Initial("");
                    }

CONTINUE:
                    this.m_nTail = i;
                }
            }
            catch (Exception ex)
            {
                string strErrorText = "PassGateForm Worker() 出现异常: " + ExceptionUtil.GetDebugText(ex);
                MainForm.TryWriteErrorLog(strErrorText);
            }
        }
示例#4
0
        // 工作线程每一轮循环的实质性工作
        public override void Worker()
        {
            try
            {
                int nOldCount            = 0;
                List <SummaryTask> tasks = new List <SummaryTask>();
                // List<SummaryTask> remove_tasks = new List<SummaryTask>();
                if (this.m_lock.TryEnterReadLock(m_nLockTimeout) == false)
                {
                    throw new LockException("锁定尝试中超时");
                }
                try
                {
                    nOldCount = this._tasks.Count;
                    foreach (SummaryTask task in this._tasks)
                    {
                        tasks.Add(task);
                    }
                }
                finally
                {
                    this.m_lock.ExitReadLock();
                }

                if (tasks.Count > 0)
                {
#if NO
                    stop.OnStop += new StopEventHandler(this.DoStop);
                    stop.Initial("进行一轮获取摘要的处理...");
                    stop.BeginLoop();
#endif
                    try
                    {
                        foreach (SummaryTask task in tasks)
                        {
                            if (this.Stopped == true)
                            {
                                // this.Container.SetColorList();  // 促使“任务已经暂停”显示出来
                                return;
                            }

#if NO
                            if (stop != null && stop.State != 0)
                            {
                                this.Stopped = true;
                                // this.Container.SetColorList();  // 促使“任务已经暂停”显示出来
                                return;
                            }
#endif

                            if (task.State == "finish")
                            {
                                continue;
                            }

                            // bool bStop = false;
                            // 执行任务
                            if (task.Action == "get_item_summary")
                            {
                                LoadItemSummary(task);
                            }
                        }
                    }
                    finally
                    {
#if NO
                        stop.EndLoop();
                        stop.OnStop -= new StopEventHandler(this.DoStop);
                        stop.Initial("");
#endif
                    }
                }

                //bool bChanged = false;
                if (tasks.Count > 0)
                {
                    if (this.m_lock.TryEnterWriteLock(m_nLockTimeout) == false)
                    {
                        throw new LockException("锁定尝试中超时");
                    }
                    try
                    {
                        foreach (SummaryTask task in tasks)
                        {
                            RemoveTask(task, false);
                        }
                    }
                    finally
                    {
                        this.m_lock.ExitWriteLock();
                    }
                }
            }
            catch (Exception ex)
            {
                string strText = "SummaryList Worker() 出现异常: " + ExceptionUtil.GetDebugText(ex);
                MainForm.TryWriteErrorLog(strText);
                if (this.Container != null)
                {
                    this.Container.ShowMessage(strText, "red", true);
                }
            }
        }