//private static List<DbColumn> _dbColList = new List<DbColumn>(); static void Main(string[] args) { if (args.Length > 0) { } Logger.Info("Starting CGM Import Service"); var basePath = AppDomain.CurrentDomain.BaseDirectory; //get sites and load into list of siteInfo var sites = GetSites(); var skips = GetCgmSkips(); //iterate sites foreach (var si in sites) { //TODO - comment this out //if (si.Id != 2) // continue; Console.WriteLine("Site: " + si.Name); //get site randomized studies - return list of ChecksImportInfo var randList = GetRandimizedStudies(si.Id); //get the list of uploaded checks files in upload directory var cgmFileList = GetCgmFileInfos(si.Name); //iterate randomized list foreach (var subjectImportInfo in randList) { //check for uploaded file var fileInfo = cgmFileList.Find(x => x.SubjectId == subjectImportInfo.SubjectId); if (fileInfo != null) fileInfo.IsRandomized = true; //if already imported then skip if (subjectImportInfo.IsCgmImported) { Console.WriteLine("Subject already imported: " + subjectImportInfo.SubjectId); continue; } //check if completed - if not then skip if (!subjectImportInfo.SubjectCompleted) { Console.WriteLine("Subject not completed: " + subjectImportInfo.SubjectId); continue; } if (fileInfo == null) { var emailNote = new EmailNotification { Message = "CGM file not uploaded." }; subjectImportInfo.EmailNotifications.Add(emailNote); Console.WriteLine("Upload file not found: " + subjectImportInfo.SubjectId); continue; } fileInfo.IsImportable = true; Console.WriteLine("Subject is importable: " + subjectImportInfo.SubjectId); } //end of foreach (var subjectImportInfo in randList) //iterate file list //get list of files not on randomized list var notificationList = new List<EmailNotification>(); foreach (var cgmFileInfo in cgmFileList) { if (!cgmFileInfo.IsRandomized) { Console.WriteLine("CGM file is not randomized: " + cgmFileInfo.SubjectId); notificationList.Add(new EmailNotification { Message = "CGM file is not randomized: ", SubjectId = cgmFileInfo.SubjectId }); continue; } if (cgmFileInfo.IsImportable) { if (!IsValidFile(cgmFileInfo)) { Console.WriteLine("CGM file is not a valid format: " + cgmFileInfo.FileName); notificationList.Add(new EmailNotification { Message = "CGM file is not a valid format: ", SubjectId = cgmFileInfo.SubjectId }); continue; } if (cgmFileInfo.SubjectId == "08-0160-5") { ; } var dbRows = ParseFile(cgmFileInfo); if (!(dbRows.Count > 0)) { Console.WriteLine("CGM file has no rows: " + cgmFileInfo.FileName); notificationList.Add(new EmailNotification { Message = "CGM file has no rows: ", SubjectId = cgmFileInfo.SubjectId }); continue; } var subjRandInfo = randList.Find(x => x.SubjectId == cgmFileInfo.SubjectId); string message = string.Empty; if (! skips.Contains(subjRandInfo.SubjectId)) { if (!IsValidDateRange(dbRows, cgmFileInfo, subjRandInfo, out message)) { notificationList.Add(new EmailNotification { Message = message, SubjectId = cgmFileInfo.SubjectId }); Console.WriteLine(message); continue; } } if (message.Length > 0) { Console.WriteLine(message); } if (ImportToDatabase(dbRows, subjRandInfo)) { SetImportToCompleted(subjRandInfo.RandomizeId, subjRandInfo.SubjectId); Logger.Info("Subject " + subjRandInfo.SubjectId + " was successfully imported."); notificationList.Add(new EmailNotification { Message = "File was successfully imported", SubjectId = cgmFileInfo.SubjectId }); } else { notificationList.Add(new EmailNotification { Message = "File import failed", SubjectId = cgmFileInfo.SubjectId }); } } }//end foreach (var cgmFileInfo in cgmFileList) //send emails //Check to see if there are any notifications for this site var anyNotifications = randList.FindAll(x => x.EmailNotifications.Count > 0); if (anyNotifications.Count == 0 && notificationList.Count == 0) continue; var toEmails = GetStaffForEvent(15, si.Id); SendEmailNotification(toEmails.ToArray(), anyNotifications, notificationList, basePath, si.Name); //Console.WriteLine("-----Email Notifications-----"); //foreach (var subjectImportInfo in randList) //{ // var notifs = notificationList.FindAll( // en => en.SubjectId == subjectImportInfo.SubjectId); // if (subjectImportInfo.EmailNotifications.Count == 0 && notifs.Count == 0) // { // continue; // } // Console.WriteLine("Subject:" + subjectImportInfo.SubjectId); // //Console.WriteLine("________________________________________"); // foreach (var emn in subjectImportInfo.EmailNotifications) // { // Console.WriteLine(" " + emn.Message); // } // if (notifs.Count > 0 ) // { // foreach (var emailNotification in notifs) // { // emailNotification.IsNotified = true; // Console.WriteLine(" " + emailNotification.Message); // } // } //}//end foreach (var subjectImportInfo in randList) send emails }//end foreach (var si in sites) //Console.Read(); }
//private static List<DbColumn> _dbColList = new List<DbColumn>(); static void Main(string[] args) { if (args.Length > 0) { } Logger.Info("Starting CGM Import Service"); var basePath = AppDomain.CurrentDomain.BaseDirectory; //get sites and load into list of siteInfo var sites = GetSites(); var skips = GetCgmSkips(); //iterate sites foreach (var si in sites) { //TODO - comment this out //if (si.Id != 2) // continue; Console.WriteLine("Site: " + si.Name); //get site randomized studies - return list of ChecksImportInfo var randList = GetRandimizedStudies(si.Id); //get the list of uploaded checks files in upload directory var cgmFileList = GetCgmFileInfos(si.Name); //iterate randomized list foreach (var subjectImportInfo in randList) { //check for uploaded file var fileInfo = cgmFileList.Find(x => x.SubjectId == subjectImportInfo.SubjectId); if (fileInfo != null) { fileInfo.IsRandomized = true; } //if already imported then skip if (subjectImportInfo.IsCgmImported) { Console.WriteLine("Subject already imported: " + subjectImportInfo.SubjectId); continue; } //check if completed - if not then skip if (!subjectImportInfo.SubjectCompleted) { Console.WriteLine("Subject not completed: " + subjectImportInfo.SubjectId); continue; } if (fileInfo == null) { var emailNote = new EmailNotification { Message = "CGM file not uploaded." }; subjectImportInfo.EmailNotifications.Add(emailNote); Console.WriteLine("Upload file not found: " + subjectImportInfo.SubjectId); continue; } fileInfo.IsImportable = true; Console.WriteLine("Subject is importable: " + subjectImportInfo.SubjectId); } //end of foreach (var subjectImportInfo in randList) //iterate file list //get list of files not on randomized list var notificationList = new List <EmailNotification>(); foreach (var cgmFileInfo in cgmFileList) { if (!cgmFileInfo.IsRandomized) { Console.WriteLine("CGM file is not randomized: " + cgmFileInfo.SubjectId); notificationList.Add(new EmailNotification { Message = "CGM file is not randomized: ", SubjectId = cgmFileInfo.SubjectId }); continue; } if (cgmFileInfo.IsImportable) { if (!IsValidFile(cgmFileInfo)) { Console.WriteLine("CGM file is not a valid format: " + cgmFileInfo.FileName); notificationList.Add(new EmailNotification { Message = "CGM file is not a valid format: ", SubjectId = cgmFileInfo.SubjectId }); continue; } if (cgmFileInfo.SubjectId == "08-0160-5") { ; } var dbRows = ParseFile(cgmFileInfo); if (!(dbRows.Count > 0)) { Console.WriteLine("CGM file has no rows: " + cgmFileInfo.FileName); notificationList.Add(new EmailNotification { Message = "CGM file has no rows: ", SubjectId = cgmFileInfo.SubjectId }); continue; } var subjRandInfo = randList.Find(x => x.SubjectId == cgmFileInfo.SubjectId); string message = string.Empty; if (!skips.Contains(subjRandInfo.SubjectId)) { if (!IsValidDateRange(dbRows, cgmFileInfo, subjRandInfo, out message)) { notificationList.Add(new EmailNotification { Message = message, SubjectId = cgmFileInfo.SubjectId }); Console.WriteLine(message); continue; } } if (message.Length > 0) { Console.WriteLine(message); } if (ImportToDatabase(dbRows, subjRandInfo)) { SetImportToCompleted(subjRandInfo.RandomizeId, subjRandInfo.SubjectId); Logger.Info("Subject " + subjRandInfo.SubjectId + " was successfully imported."); notificationList.Add(new EmailNotification { Message = "File was successfully imported", SubjectId = cgmFileInfo.SubjectId }); } else { notificationList.Add(new EmailNotification { Message = "File import failed", SubjectId = cgmFileInfo.SubjectId }); } } }//end foreach (var cgmFileInfo in cgmFileList) //send emails //Check to see if there are any notifications for this site var anyNotifications = randList.FindAll(x => x.EmailNotifications.Count > 0); if (anyNotifications.Count == 0 && notificationList.Count == 0) { continue; } var toEmails = GetStaffForEvent(15, si.Id); SendEmailNotification(toEmails.ToArray(), anyNotifications, notificationList, basePath, si.Name); //Console.WriteLine("-----Email Notifications-----"); //foreach (var subjectImportInfo in randList) //{ // var notifs = notificationList.FindAll( // en => en.SubjectId == subjectImportInfo.SubjectId); // if (subjectImportInfo.EmailNotifications.Count == 0 && notifs.Count == 0) // { // continue; // } // Console.WriteLine("Subject:" + subjectImportInfo.SubjectId); // //Console.WriteLine("________________________________________"); // foreach (var emn in subjectImportInfo.EmailNotifications) // { // Console.WriteLine(" " + emn.Message); // } // if (notifs.Count > 0 ) // { // foreach (var emailNotification in notifs) // { // emailNotification.IsNotified = true; // Console.WriteLine(" " + emailNotification.Message); // } // } //}//end foreach (var subjectImportInfo in randList) send emails }//end foreach (var si in sites) //Console.Read(); }