public QSCalcsCtl SetCalcParams(string calcsMethod, string scope, string stat, int seriesOrder) { this.CalcsMethod = calcsMethod; string[] scopeArgs = WebSiteCommon.SplitString(scope, '|'); string[] statArgs = WebSiteCommon.SplitString(stat, '|'); try { this.MetricScope = scopeArgs[0]; if (scopeArgs.Length > 1) { this.SubScope = scopeArgs[1]; } else { this.SubScope = ""; } if (statArgs.Length > 1) { this.Calculation = statArgs[0]; this.Stat = (SStat)Enum.Parse(typeof(SStat), statArgs[1], true); } else { this.Calculation = ""; this.Stat = (SStat)Enum.Parse(typeof(SStat), statArgs[0], true); } this.Seriesorder = (SeriesOrder)seriesOrder; } catch { this.Stat = SStat.sum; this.Seriesorder = SeriesOrder.SumAll; } return(this); }
static string OverdueTaskNotifications(DateTime currentTime) { string nextStep = ""; DateTime openFromDate = new DateTime(2000, 1, 1); DateTime localTime; int execAtHour = 10; // set exec time default to 5 am EST WriteLine("OVERDUE TASK NOTIFICATIONS Started: " + DateTime.UtcNow.ToString("hh:mm MM/dd/yyyy")); SETTINGS setting = null; List <SETTINGS> sets = SQMSettings.SelectSettingsGroup("AUTOMATE", ""); try { // execute at specified hour of day (e.g. TASKNOTIFY_TIME == 01:00) if ((setting = sets.Where(x => x.SETTING_CD == "TASKNOTIFY_TIME").FirstOrDefault()) != null) { // throwing an error here if the setting format was incorrect will be helpful for debugging execAtHour = int.Parse(WebSiteCommon.SplitString(setting.VALUE, ':').First()); } entities = new PSsqmEntities(); List <PLANT> plantList = SQMModelMgr.SelectPlantList(entities, 1, 0); PLANT plant = null; List <TaskItem> openTaskList = TaskMgr.SelectOpenTasks(currentTime, openFromDate); if (openTaskList.Count > 0) { WriteLine("Open Tasks ..."); foreach (TaskItem taskItem in openTaskList) { try { if (taskItem.Task.RECORD_TYPE == (int)TaskRecordType.HealthSafetyIncident) { INCIDENT incident = EHSIncidentMgr.SelectIncidentById(entities, taskItem.Task.RECORD_ID); if (incident != null && (plant = plantList.Where(l => l.PLANT_ID == incident.DETECT_PLANT_ID).FirstOrDefault()) != null) { if (execAtHour == WebSiteCommon.LocalTime(currentTime, plant.LOCAL_TIMEZONE).Hour) { WriteLine("Task: " + taskItem.Task.TASK_ID.ToString() + " RecordType: " + taskItem.Task.RECORD_TYPE.ToString() + " " + "RecordID:" + taskItem.Task.RECORD_ID.ToString() + " Status = " + taskItem.Task.STATUS); // notify assigned person and escalation person if over-over due EHSNotificationMgr.NotifyIncidentTaskStatus(incident, taskItem, ((int)SysPriv.action).ToString()); System.Threading.Thread.Sleep(timer); //will wait for 2 seconds to allow Google Mail to process email requests if (taskItem.Taskstatus >= SQM.Website.TaskStatus.Overdue) { // send to notification list for plant, BU, ... //EHSNotificationMgr.NotifyIncidentStatus(incident, taskItem.Task.TASK_STEP, ((int)SysPriv.notify).ToString(), ""); //System.Threading.Thread.Sleep(timer); //will wait for 2 seconds to allow Google Mail to process email requests } } } else { WriteLine("Task: " + taskItem.Task.TASK_ID.ToString() + " RecordType: " + taskItem.Task.RECORD_TYPE.ToString() + " " + "RecordID:" + taskItem.Task.RECORD_ID.ToString() + " Status = " + taskItem.Task.STATUS + " This task does not have a corresponding incident or plant record"); } } else if (taskItem.Task.RECORD_TYPE == (int)TaskRecordType.PreventativeAction) { INCIDENT incident = EHSIncidentMgr.SelectIncidentById(entities, taskItem.Task.RECORD_ID); if (incident != null && (plant = plantList.Where(l => l.PLANT_ID == incident.DETECT_PLANT_ID).FirstOrDefault()) != null) { if (execAtHour == WebSiteCommon.LocalTime(currentTime, plant.LOCAL_TIMEZONE).Hour) { WriteLine("Task: " + taskItem.Task.TASK_ID.ToString() + " RecordType: " + taskItem.Task.RECORD_TYPE.ToString() + " " + "RecordID:" + taskItem.Task.RECORD_ID.ToString() + " Status = " + taskItem.Task.STATUS); // notify assigned person and escalation person if over-over due EHSNotificationMgr.NotifyPrevActionTaskStatus(incident, taskItem, ((int)SysPriv.action).ToString()); System.Threading.Thread.Sleep(timer); //will wait for 2 seconds to allow Google Mail to process email requests } } else { WriteLine("Task: " + taskItem.Task.TASK_ID.ToString() + " RecordType: " + taskItem.Task.RECORD_TYPE.ToString() + " " + "RecordID:" + taskItem.Task.RECORD_ID.ToString() + " Status = " + taskItem.Task.STATUS + " This task does not have a corresponding preventative action or plant record"); } } else if (taskItem.Task.RECORD_TYPE == (int)TaskRecordType.Audit) { AUDIT audit = EHSAuditMgr.SelectAuditById(entities, taskItem.Task.RECORD_ID); if (audit != null && (plant = plantList.Where(l => l.PLANT_ID == audit.DETECT_PLANT_ID).FirstOrDefault()) != null) { if (execAtHour == WebSiteCommon.LocalTime(currentTime, plant.LOCAL_TIMEZONE).Hour) { WriteLine("Task: " + taskItem.Task.TASK_ID.ToString() + " RecordType: " + taskItem.Task.RECORD_TYPE.ToString() + " " + "RecordID:" + taskItem.Task.RECORD_ID.ToString() + " Status = " + taskItem.Task.STATUS); if (taskItem.Task.TASK_STEP == "0") { EHSNotificationMgr.NotifyAuditStatus(audit, taskItem); System.Threading.Thread.Sleep(timer); //will wait for 2 seconds to allow Google Mail to process email requests } else { EHSNotificationMgr.NotifyAuditTaskStatus(audit, taskItem, ((int)SysPriv.action).ToString()); System.Threading.Thread.Sleep(timer); //will wait for 2 seconds to allow Google Mail to process email requests } } } else { WriteLine("Task: " + taskItem.Task.TASK_ID.ToString() + " RecordType: " + taskItem.Task.RECORD_TYPE.ToString() + " " + "RecordID:" + taskItem.Task.RECORD_ID.ToString() + " Status = " + taskItem.Task.STATUS + " This task does not have a corresponding audit or plant record"); } } } catch (Exception ex) { WriteLine("Error: " + ex.ToString()); } } } } catch (Exception ex) { WriteLine("OVERDUE TASK NOTIFICATIONS Error - " + ex.ToString()); } WriteLine("OVERDUE TASK NOTIFICATIONS Completed: " + DateTime.UtcNow.ToString("hh:mm MM/dd/yyyy")); return(nextStep); }