private static void SaveReport(ReportInfo report) { //save pdf to report folder string path = report.GetReportPath(); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string file = Path.Combine(path, "Report.pdf"); //if(report.ExistReportAction == ExistReportAction.Overwrite) { using (FileStream fs = new FileStream(file, FileMode.CreateNew)) { fs.Write(report.PdfReport, 0, report.PdfReport.Length); fs.Flush(); } } //else { } //save txt and jpg file. }
private static void HandleReport(ReportInfo report, NetworkStream socket) { Utils.Log("Start handle report with status:{0}, id:{1}, thread:{2}", report.Status, report.Id, Thread.CurrentThread.ManagedThreadId); if (report.Status == ReportStatus.SubmitInitial) { //save report SaveReport(report); string patientId = ParsePatientId(report); report.PatientId = patientId; Utils.Log("Try parse PatientId, and patientId is: " + patientId); if (string.IsNullOrEmpty(patientId)) { Utils.Log("Failed parse patientId, send to client to confirm"); report.Status = ReportStatus.FailedGetPatientId; ReportSendReceiver.SendReport(report, socket); return; } //check exist report byte[] existReport = GetExistReport(patientId); if (existReport != null) { Utils.Log("Patient already has report, send client to confirm"); report.PdfReportExist = existReport; report.Status = ReportStatus.ConfirmExistReport; ReportSendReceiver.SendReport(report, socket); return; } //all is OK, let client confirm whether the patientId is correct. Utils.Log("All is OK, send client to confirm"); report.Status = ReportStatus.ConfirmPatientId; ReportSendReceiver.SendReport(report, socket); } else if (report.Status == ReportStatus.SubmitNewPatientId) { Utils.Log("Client changed patientId, the new patienId is: " + report.PatientId); byte[] existReport = GetExistReport(report.PatientId); if (existReport != null) { Utils.Log("Patient already has report, send client to confirm"); report.PdfReportExist = existReport; report.Status = ReportStatus.ConfirmExistReport; ReportSendReceiver.SendReport(report, socket); return; } Utils.Log("Client confirmed OK, report handle finish!"); report.Status = ReportStatus.ConfirmOK; if (ReportReceiveEvent != null) { ReportReceiveEventArg arg = new ReportReceiveEventArg(); arg.IsOverwriteExist = report.ExistReportAction == ExistReportAction.Overwrite; arg.PatientId = report.PatientId; arg.CallingIP = report.CallingIP; arg.ReportPath = report.GetReportPath(); ReportReceiveEvent(arg); } ReportSendReceiver.SendReport(report, socket); } else if (report.Status == ReportStatus.SubmitOK) { Utils.Log("Client confirmed OK, report handle finish!"); report.Status = ReportStatus.ConfirmOK; if (ReportReceiveEvent != null) { ReportReceiveEventArg arg = new ReportReceiveEventArg(); arg.IsOverwriteExist = report.ExistReportAction == ExistReportAction.Overwrite; arg.PatientId = report.PatientId; arg.CallingIP = report.CallingIP; arg.ReportPath = report.GetReportPath(); ReportReceiveEvent(arg); } ReportSendReceiver.SendReport(report, socket); } }