예제 #1
0
        void ReportClient_ReportSendEventHandler(ReportSendEventArg arg)
        {
            if (arg.HasError)
            {
                this.notifyIcon.ShowBalloonTip(2000, arg.ErrorMessage, "v1.0.0", ToolTipIcon.Info);
                return;
            }

            ReportInfo report = arg.Report;

            if (report.NeedConfirm())
            {
                //should notify UI and let doctor to decide, now just test without UI
                if (report.Status == ReportStatus.FailedGetPatientId)
                {
                    report.PatientId = "newPatientID";
                    report.Status    = ReportStatus.SubmitNewPatientId;

                    this.notifyIcon.ShowBalloonTip(10000, "请手动输入病人Id", "v1.0.0", ToolTipIcon.Error);
                }
                else if (report.Status == ReportStatus.ConfirmPatientId)
                {
                    report.Status = ReportStatus.SubmitOK;
                    this.notifyIcon.ShowBalloonTip(10000, "请确认报告信息", "v1.0.0", ToolTipIcon.Warning);
                }
                else if (report.Status == ReportStatus.ConfirmExistReport)
                {
                    report.ExistReportAction = ExistReportAction.Append;
                    report.Status            = ReportStatus.SubmitExistReportAction;

                    this.notifyIcon.ShowBalloonTip(10000, "请确认报告信息", "v1.0.0", ToolTipIcon.Warning);
                }

                ReportClient.SetReportConfirmed(report);
            }
            else if (report.HasError())
            {
                this.notifyIcon.ShowBalloonTip(2000, report.ErrorMessage, "v1.0.0", ToolTipIcon.Info);
            }
            else if (report.IsServerDone())
            {
                this.notifyIcon.ShowBalloonTip(5000, "报告提交成功", "v1.0.0", ToolTipIcon.Info);
            }
        }
예제 #2
0
        private static void ThreadFunc(object ctx)
        {
            while (true)
            {
                try
                {
                    if (_stopSignal)
                    {
                        break;
                    }

                    //1. get new pdf file
                    string pdfFile = QueryPdfFile();
                    if (string.IsNullOrEmpty(pdfFile))
                    {
                        Thread.Sleep(2000);
                        continue;
                    }

                    //2. start handle report
                    ReportInfo report = new ReportInfo();
                    report.PdfReport = File.ReadAllBytes(pdfFile);
                    report.Status    = ReportStatus.SubmitInitial;

                    Utils.Log("Start to handle new report, id:{0}, path:{1}", report.Id, pdfFile);

                    bool reportDone = false;
                    do
                    {
                        TcpClient client = new TcpClient();
                        //client.SendTimeout = 5000;//5s
                        //client.ReceiveTimeout = 5000;//5s
                        client.Connect(IPAddress.Parse(ServerIP), ServerPort);//it will throw an exception if failed to connect.

                        using (NetworkStream socketStream = client.GetStream())
                        {
                            Utils.Log("Send report with status: " + report.Status);
                            ReportSendReceiver.SendReport(report, socketStream);

                            report = ReportSendReceiver.ReceiveReport(socketStream);
                            Utils.Log("Receive report with status: " + report.Status);

                            if (report.IsServerDone() || report.HasError())
                            {
                                reportDone = true;
                            }
                            else
                            {
                                _reportConfirmedSignal.Reset();
                                _reportToConfirm = report;

                                if (ReportSendEvent != null)
                                {
                                    ReportSendEvent(new ReportSendEventArg()
                                    {
                                        HasError = false, Report = report, NeedConfirm = report.NeedConfirm()
                                    });
                                }

                                _reportConfirmedSignal.WaitOne();
                                _reportToConfirm = null;
                            }
                        }

                        client.Close();
                    }while (!reportDone);

                    //4. clear work
                    if (ReportSendEvent != null)
                    {
                        ReportSendEvent(new ReportSendEventArg()
                        {
                            HasError = report.HasError(), Report = report, NeedConfirm = report.NeedConfirm()
                        });
                    }

                    Utils.Log("Report done with status: " + report.Status);

                    if (report.HasError())
                    {
                        //move to error report folder
                        Utils.Log("Report has error, will send to errorbox. error: " + report.ErrorMessage);

                        string targetFile = Path.Combine(PdfReportFolder, "Errorbox", Path.GetFileName(pdfFile));
                        File.Move(pdfFile, targetFile);
                    }
                    else
                    {
                        File.Delete(pdfFile);
                    }
                }
                catch (Exception ex)
                {
                    if (ReportSendEvent != null)
                    {
                        ReportSendEvent(new ReportSendEventArg()
                        {
                            HasError = true, ErrorMessage = ex.Message
                        });
                    }

                    Utils.Log("Exception happen from Report Client main thread, message: " + ex.Message);
                    Utils.Log(ex.StackTrace);

                    Thread.Sleep(1000);
                }
            }

            _isRunning = false;
            Utils.Log("Report Client stopped");
        }