private void UpdateSubscriberList(string strNotifType, string strSubscribers, string sAddRemove) { try { if (sAddRemove.ToUpper() == "ADD") { m_ipNotifConfig = m_ipDatabase.ConfigurationManager as IJTXNotificationConfiguration; m_ipNotifType = m_ipNotifConfig.GetNotificationType(strNotifType); sList = strSubscribers.Split(','); for (int i = 0; i < sList.Length; i++) { m_ipNotifType.Subscribe(sList[i]); } m_ipNotifType.Store(); } else { for (int i = 0; i < sList.Length; i++) { m_ipNotifType.UnSubscribe(sList[i]); } m_ipNotifType.Store(); } } catch (Exception ex) { throw new Exception("An error occurred updating subscriber list!: " + ex.Message); } }
static void Main(string[] args) { JTXReportNotification prog = new JTXReportNotification(); if (prog.CheckoutLicense()) { // Arguments list // /ReportID:<Report ID to execute> // /NotifType:<Notification type to send> // example: JTXReportNotification.exe /NotifType:ReportNotification /ReportID:401 object[] pArgObjects = args as object[]; // Get some variables ready int iReportID = 0; string sReportID = ""; string sNotificationTypeName = ""; StepUtilities.GetArgument(ref pArgObjects, "ReportID", true, out sReportID); if (!int.TryParse(sReportID, out iReportID)) { Console.WriteLine("Invalid Report ID entered"); return; } StepUtilities.GetArgument(ref pArgObjects, "NotifType", true, out sNotificationTypeName); if (sNotificationTypeName == "") { Console.WriteLine("A notification type must be entered."); } IJTXDatabaseManager jtxDBMan = new JTXDatabaseManagerClass(); IJTXDatabase pJTXDB = jtxDBMan.GetActiveDatabase(false); IJTXConfiguration2 jtxConfig = pJTXDB.ConfigurationManager as IJTXConfiguration2; string sReportOutput = prog.RunReport(jtxConfig, iReportID); // if there's output, send the notification if (sReportOutput != "") { IJTXNotificationConfiguration pNotificationConfig = (IJTXNotificationConfiguration)jtxConfig; IJTXNotificationType pNotificationType = pNotificationConfig.GetNotificationType(sNotificationTypeName); if (pNotificationType == null) { Console.WriteLine("Please enter a valid notification type."); return; } // Update the message string sMessageBefore = pNotificationType.MessageTemplate; pNotificationType.MessageTemplate = sReportOutput; pNotificationType.Store(); // Send it! JTXUtilities.SendNotification(sNotificationTypeName, pJTXDB, null, null); // Set the message back. pNotificationType.MessageTemplate = ""; pNotificationType.Store(); } else { Console.WriteLine("Please enter a valid report ID."); } prog.CheckinLicense(); } }
/// <summary> /// Required by IGPFunction2 interface; this function is called when the GP tool is ready to be executed. /// </summary> /// <param name="paramValues"></param> /// <param name="trackCancel"></param> /// <param name="envMgr"></param> /// <param name="msgs"></param> public override void Execute(IArray paramValues, ITrackCancel trackCancel, IGPEnvironmentManager envMgr, IGPMessages msgs) { // Do some common error-checking base.Execute(paramValues, trackCancel, envMgr, msgs); try { // Ensure that the current user has admin access to the current Workflow Manager DB if (!CurrentUserIsWmxAdministrator()) { throw new WmauException(WmauErrorCodes.C_USER_NOT_ADMIN_ERROR); } IJTXSpatialNotificationManager snManager = this.WmxDatabase.SpatialNotificationManager; IJTXSpatialNotifierNameSet allSnNames = snManager.SpatialNotifiers; IJTXNotificationConfiguration notificationConfig = this.WmxDatabase.ConfigurationManager as IJTXNotificationConfiguration; // Create a new spatial notification IJTXChangeRule2 changeRule = snManager.AddChangeRule() as IJTXChangeRule2; // Set the name changeRule.Name = m_snName; // Set the notifier IJTXNotificationType srcNotifType = notificationConfig.GetNotificationType(m_emailNotifier); // Set the properties of the spatial notification's e-mail notification to match that // of the source e-mail notification (phew!) IJTXEmailSpatialNotifier emailNotifier = this.CreateSpatialNotifierByName(C_TYPE_EMAIL_NOTIFIER) as IJTXEmailSpatialNotifier; emailNotifier.Subject = srcNotifType.SubjectTemplate; emailNotifier.Body = srcNotifType.MessageTemplate; emailNotifier.SenderEmail = srcNotifType.SenderTemplate; emailNotifier.SenderDisplayName = srcNotifType.SenderDisplayNameTemplate; string[] subscribers = srcNotifType.get_Subscribers(); IStringArray subscribersObj = new StrArrayClass(); foreach (string subscriber in subscribers) { subscribersObj.Add(subscriber); } emailNotifier.Subscribers = subscribersObj; changeRule.Notifier = emailNotifier as IJTXSpatialNotifier; // Set the description, if applicable if (!string.IsNullOrEmpty(m_snDescription)) { changeRule.Description = m_snDescription; } // Set the summarization behavior changeRule.SummarizeNotifications = m_summarize; // Store the resulting change rule changeRule.Store(); // Update the output parameter WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameterEdit3 outParam = paramMap.GetParamEdit(C_PARAM_OUT_NAME); IGPString strValue = new GPStringClass(); strValue.Value = m_snName; outParam.Value = strValue as IGPValue; msgs.AddWarning("To avoid database corruption, at least one dataset or area evaluator must be added to notification '" + m_snName + "' immediately!"); msgs.AddMessage(Properties.Resources.MSG_DONE); } catch (WmauException wmEx) { try { msgs.AddError(wmEx.ErrorCodeAsInt, wmEx.Message); } catch { // Catch anything else that possibly happens } } catch (Exception ex) { try { WmauError error = new WmauError(WmauErrorCodes.C_SN_CREATION_ERROR); msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message); } catch { // Catch anything else that possibly happens } } finally { // Release any COM objects here! } }
static void Main(string[] args) { JTXOverdueNotification prog = new JTXOverdueNotification(); if (prog.CheckoutLicense()) { try { // Arguments list // /NotifType:<Notification type to send> // example: JTXOverdueNotification.exe /NotifType:OverdueJob object[] pArgObjects = args as object[]; // Get some variables ready string sNotificationTypeName = ""; StepUtilities.GetArgument(ref pArgObjects, "NotifType", true, out sNotificationTypeName); if (sNotificationTypeName == "") { Console.WriteLine("A notification type must be entered."); return; } IJTXDatabaseManager jtxDBMan = new JTXDatabaseManagerClass(); IJTXDatabase pJTXDB = jtxDBMan.GetActiveDatabase(false); IJTXConfiguration pJTXConfig = pJTXDB.ConfigurationManager; // Create a simple query to find jobs that were due before today IQueryFilter pQF = new QueryFilterClass(); // NOTE #1: Verify the date format matches your selected RDBMS // NOTE #2: Verify the status id for 'Closed' with the JTX Administrator pQF.WhereClause = "DUE_DATE < '" + DateTime.Today.ToString() + "'" + " AND STATUS <> 9"; Console.WriteLine(pQF.WhereClause); // Get the notification type for the notification that will be sent IJTXNotificationConfiguration pNotificationConfig = pJTXConfig as IJTXNotificationConfiguration; IJTXNotificationType pNotificationType = pNotificationConfig.GetNotificationType(sNotificationTypeName); if (pNotificationType == null) { Console.WriteLine("Please enter a valid notification type."); return; } // Get the job manager to execute the query and find the jobs in question IJTXJobManager pJobManager = pJTXDB.JobManager; IJTXJobSet pJobs = pJobManager.GetJobsByQuery(pQF); pJobs.Reset(); for (int a = 0; a < pJobs.Count; a++) { IJTXJob pJob = pJobs.Next(); Console.WriteLine(pJob.Name); // Send it! JTXUtilities.SendNotification(sNotificationTypeName, pJTXDB, pJob, null); } } catch (Exception except) { Console.WriteLine("An error occurred: " + except.Message); } prog.CheckinLicense(); Console.WriteLine("Completed."); } }