static void Debug() { //AUP.UploadZip("44186", "47777", @"d:\temp\1.3.12.2.1107.5.1.4.65115.3000001603240736279390001264491.zip", "henryknipe", "20160411091821_henryknipe", "1.3.12.2.1107.5.8.9.13.26.65.26.126.218.77882191"); APetaPoco.SetConnectionString("cn1"); var bm = APetaPoco.PpRetrieveOne <DbCase>("Cases", "[case_id] = '20160607180814_frank'"); var pcase = (DbCase)bm.Data; bm = APetaPoco.PpRetrieveList <DbStudy>("Studies", "[case_id] = '20160607180814_frank'"); pcase.study_list = (List <DbStudy>)bm.Data; foreach (var st in pcase.study_list) { bm = APetaPoco.PpRetrieveList <DbSeries>("Series", "[case_id] = '20160607180814_frank' AND [study_uid] = '" + st.study_uid + "'"); st.series = (List <DbSeries>)bm.Data; //ADCM.DownloadStudy(st); LOG.Write("Converting DCM to PNG..."); AIMG.MultiFrameProcess(st); bool convertComplete = AIMG.ConvertDcmToPng(st); //if (!convertComplete) //{ // ACASE.ClearCaseFiles(pcase); // throw new Exception("Unable to convert study to PNG"); //} LOG.Write("Completed image conversion"); LOG.Write("Optimizing PNG's for study..."); AIMG.OptiPng(st); LOG.Write("Completed optimization."); //AIMG.ZipSeries(st); } //ACASE.ProcessCase(pcase); }
public static void ProcessCase(DbCase pcase) { try { LOG.Write("Checking user quotas..."); if (!CheckQuotas(pcase)) { throw new Exception("Quota exceeded"); } LOG.Write("Creating case on Radiopaedia..."); pcase.r_case_id = AUP.CreateCase(pcase); if (string.IsNullOrEmpty(pcase.r_case_id)) { throw new Exception("Unable to create case id, cannot continue"); } LOG.Write("Case created id: " + pcase.r_case_id); if (pcase.study_list == null || pcase.study_list.Count < 1) { pcase.study_list = GetStudiesForCase(pcase.case_id); if (pcase.study_list == null || pcase.study_list.Count < 1) { throw new Exception("No studies in case: " + pcase.case_id); } } foreach (var st in pcase.study_list) { LOG.InsertEvent("Starting to process case: " + pcase.case_id, "AGENT", null, pcase.case_id); LOG.Write("Creating Radiopaedia Study..."); st.r_study_id = AUP.CreateStudy(st, pcase.username, pcase.r_case_id); if (string.IsNullOrEmpty(st.r_study_id)) { throw new Exception("Unable to create study id on Radiopaedia"); } LOG.Write("Study ID created: " + st.r_study_id); LOG.Write("Study: " + st.description + "[" + st.modality + "]"); LOG.Write("Downloading..."); bool downloadComplete = ADCM.DownloadStudy(st, 0); if (!downloadComplete) { ClearCaseFiles(pcase); throw new Exception("Unable to download study - can't continue"); } LOG.Write("Download finished"); LOG.Write("Converting DCM to PNG..."); AIMG.MultiFrameProcess(st); bool convertComplete = AIMG.ConvertDcmToPng(st); if (!convertComplete) { ClearCaseFiles(pcase); throw new Exception("Unable to convert study to PNG"); } LOG.Write("Completed image conversion"); LOG.Write("Deleting excess images..."); AIMG.DeleteExcessImages(st); LOG.Write("Completed deleting excess images."); LOG.Write("Optimizing PNG's for study..."); AIMG.OptiPng(st); LOG.Write("Completed optimization."); bool zipComplete = AIMG.ZipSeries(st); if (!zipComplete) { throw new Exception("Unable to create zips for study"); } string outPath = Path.Combine(ADCM.GetStoreString(), "OUTPUT", pcase.case_id, st.study_uid); var zips = Directory.GetFiles(outPath, "*.zip"); foreach (var z in zips) { string fileName = Path.GetFileName(z); string[] sizes = { "B", "KB", "MB", "GB" }; double len = new FileInfo(z).Length; int order = 0; while (len >= 1024 && ++order < sizes.Length) { len = len / 1024; } LOG.Write(string.Format("Uploading: {2} ({0:0.##} {1})", len, sizes[order], fileName)); bool uploadedZip = AUP.UploadZip2(pcase.r_case_id, st.r_study_id, z, pcase.username, pcase.case_id, st.study_uid); if (!uploadedZip) { try { LOG.Write("Retry maxed out, copying zip to error output"); string errorFolder = Path.Combine(@".\Error_uploads\", pcase.case_id); if (!Directory.Exists(errorFolder)) { Directory.CreateDirectory(errorFolder); } string errorPath = Path.Combine(errorFolder, fileName); File.Copy(z, errorPath); } catch { continue; } } LOG.Write("Finished uploading"); } } LOG.Write("Marking case as completed"); AUP.MarkCaseComplete(pcase.r_case_id, pcase.username, pcase.case_id); SetCaseStatus(pcase, "COMPLETED", "Case fully uploaded: http://radiopaedia.org/cases/" + pcase.r_case_id); System.Threading.Thread.Sleep(1000); LOG.Write("Finished with case: " + pcase.case_id); ClearCaseFiles(pcase); LOG.InsertEvent("Finished with case: " + pcase.case_id, "AGENT", null, pcase.case_id); } catch (Exception ex) { string errorString = "Error at :" + System.Reflection.MethodBase.GetCurrentMethod().Name; LOG.Write(errorString); LOG.Write(ex.Message); LOG.InsertEvent(errorString, "AGENT", ex.Message, pcase.case_id); SetCaseStatus(pcase, "ERROR", ex.Message); ClearCaseFiles(pcase); } finally { GC.Collect(); } }