/// <summary> /// Gets and bulk updates notification templates. Called when the "Get and bulk update templates" button is pressed. /// Expects the CreateNotificationTemplate method to be run first. /// </summary> private bool GetAndBulkUpdateNotificationTemplates() { // Prepare the parameters string where = "TemplateName LIKE N'MyNewTemplate%'"; where = SqlHelperClass.AddWhereCondition(where, "TemplateSiteID = " + CMSContext.CurrentSiteID, "AND"); // Get the data DataSet templates = NotificationTemplateInfoProvider.GetTemplates(where, null); if (!DataHelper.DataSourceIsEmpty(templates)) { // Loop through the individual items foreach (DataRow templateDr in templates.Tables[0].Rows) { // Create object from DataRow NotificationTemplateInfo modifyTemplate = new NotificationTemplateInfo(templateDr); // Update the property modifyTemplate.TemplateDisplayName = modifyTemplate.TemplateDisplayName.ToUpper(); // Update the notification template NotificationTemplateInfoProvider.SetNotificationTemplateInfo(modifyTemplate); } return(true); } return(false); }
protected void Page_Load(object sender, EventArgs e) { // Show info message inf changes were saved if (QueryHelper.GetInteger("saved", 0) == 1) { lblInfo.Visible = true; lblInfo.Text = GetString("general.changessaved"); // Reload header if changes were saved ScriptHelper.RefreshTabHeader(Page, null); } // Get resource strings lblDisplayName.ResourceString = "general.displayname"; lblCodeName.ResourceString = "general.codename"; valCodeName.Text = GetString("general.requirescodename"); valDisplayName.Text = GetString("general.requiresdisplayname"); btnOk.ResourceString = "general.ok"; // Load values if (!RequestHelper.IsPostBack() && (this.TemplateID != 0)) { NotificationTemplateInfo nti = NotificationTemplateInfoProvider.GetNotificationTemplateInfo(this.TemplateID); if (nti != null) { txtCodeName.Text = nti.TemplateName; txtDisplayName.Text = nti.TemplateDisplayName; } } }
public async Task UpdateTemplateAsync_BadRequest_TemplateAndLocal_Exist() { var templateService = new Mock <ITemplateService>(); var controller = new NotificationTemplateController(templateService.Object); var info = new NotificationTemplateInfo("temp", new List <Localization> { Localization.From("en") }); templateService.Setup(e => e.GetTemplateInfoAsync(It.IsAny <string>())) .Returns(Task.FromResult(info)); var ex = await Record.ExceptionAsync(() => controller.UpdateTemplateAsync(new NewTemplateRequest { TemplateName = "temp", TemplateBody = "hello", LocalizationCode = "en-us" })); Assert.NotNull(ex); Assert.IsType <ValidationApiException>(ex); Assert.Equal(HttpStatusCode.BadRequest, ((ValidationApiException)ex).StatusCode); controller.Dispose(); }
/// <summary> /// Creates notification template text. Called when the "Create text" button is pressed. /// </summary> private bool CreateNotificationTemplateText() { // Get the template NotificationTemplateInfo template = NotificationTemplateInfoProvider.GetNotificationTemplateInfo("MyNewTemplate", CMSContext.CurrentSiteID); // Get the gateway NotificationGatewayInfo gateway = NotificationGatewayInfoProvider.GetNotificationGatewayInfo("MyNewGateway"); if ((template != null) && (gateway != null)) { // Create new notification template text object NotificationTemplateTextInfo newText = new NotificationTemplateTextInfo(); // Set the properties newText.TemplateSubject = "My new text"; newText.TemplateID = template.TemplateID; newText.GatewayID = gateway.GatewayID; newText.TemplateHTMLText = ""; newText.TemplatePlainText = ""; newText.TempalateTextLastModified = DateTime.Now; // Create the notification template text NotificationTemplateTextInfoProvider.SetNotificationTemplateTextInfo(newText); return(true); } return(false); }
/// <summary> /// Gets and updates notification template text. Called when the "Get and update text" button is pressed. /// Expects the CreateNotificationTemplateText method to be run first. /// </summary> private bool GetAndUpdateNotificationTemplateText() { // Get the template NotificationTemplateInfo template = NotificationTemplateInfoProvider.GetNotificationTemplateInfo("MyNewTemplate", CMSContext.CurrentSiteID); //Get the gateway NotificationGatewayInfo gateway = NotificationGatewayInfoProvider.GetNotificationGatewayInfo("MyNewGateway"); if ((template != null) && (gateway != null)) { // Get the notification template text NotificationTemplateTextInfo updateText = NotificationTemplateTextInfoProvider.GetNotificationTemplateTextInfo(gateway.GatewayID, template.TemplateID); if (updateText != null) { // Update the property updateText.TemplateSubject = updateText.TemplateSubject.ToLower(); // Update the notification template text NotificationTemplateTextInfoProvider.SetNotificationTemplateTextInfo(updateText); return(true); } } return(false); }
/// <summary> /// Creates notification subscription. Called when the "Create subscription" button is pressed. /// </summary> private bool CreateNotificationSubscription() { // Get the gateway NotificationGatewayInfo gateway = NotificationGatewayInfoProvider.GetNotificationGatewayInfo("MyNewGateway"); // Get the tamplate NotificationTemplateInfo template = NotificationTemplateInfoProvider.GetNotificationTemplateInfo("MyNewTemplate", CMSContext.CurrentSiteID); if ((gateway != null) && (template != null)) { // Create new notification subscription object NotificationSubscriptionInfo newSubscription = new NotificationSubscriptionInfo(); // Set the properties newSubscription.SubscriptionEventDisplayName = "My new subscription"; newSubscription.SubscriptionGatewayID = gateway.GatewayID; newSubscription.SubscriptionTemplateID = template.TemplateID; newSubscription.SubscriptionTime = DateTime.Now; newSubscription.SubscriptionUserID = CMSContext.CurrentUser.UserID; newSubscription.SubscriptionTarget = ""; newSubscription.SubscriptionLastModified = DateTime.Now; newSubscription.SubscriptionSiteID = CMSContext.CurrentSiteID; // Create the notification subscription NotificationSubscriptionInfoProvider.SetNotificationSubscriptionInfo(newSubscription); return(true); } return(false); }
/// <summary> /// Gets and bulk updates notification subscriptions. Called when the "Get and bulk update subscriptions" button is pressed. /// Expects the CreateNotificationSubscription method to be run first. /// </summary> private bool GetAndBulkUpdateNotificationSubscriptions() { // Get the gateway NotificationGatewayInfo gateway = NotificationGatewayInfoProvider.GetNotificationGatewayInfo("MyNewGateway"); // Get the tamplate NotificationTemplateInfo template = NotificationTemplateInfoProvider.GetNotificationTemplateInfo("MyNewTemplate", CMSContext.CurrentSiteID); if ((gateway != null) && (template != null)) { // Prepare the parameters string where = "SubscriptionGatewayID = " + gateway.GatewayID + " AND SubscriptionTemplateID = " + template.TemplateID; // Get the notification subscription DataSet subscriptions = NotificationSubscriptionInfoProvider.GetSubscriptions(where, null); if (!DataHelper.DataSourceIsEmpty(subscriptions)) { foreach (DataRow subscriptionDr in subscriptions.Tables[0].Rows) { // Create object from DataRow NotificationSubscriptionInfo updateSubscription = new NotificationSubscriptionInfo(subscriptions.Tables[0].Rows[0]); // Update the property updateSubscription.SubscriptionEventDisplayName = updateSubscription.SubscriptionEventDisplayName.ToUpper(); // Update the notification subscription NotificationSubscriptionInfoProvider.SetNotificationSubscriptionInfo(updateSubscription); return(true); } } } return(false); }
public async Task InsertOrUpdateAsync(NotificationTemplateInfo templateInfo) { using (var context = _msSqlContextFactory.CreateDataContext()) { var entity = await context.Templates.FirstOrDefaultAsync(x => x.Name == templateInfo.Name); if (entity == null) { entity = new TemplateEntity { Name = templateInfo.Name, ListOfLocalization = ConvertListLocalizationToString(templateInfo.AvailableLocalizations) }; await context.AddAsync(entity); } else { entity.ListOfLocalization = ConvertListLocalizationToString(templateInfo.AvailableLocalizations); context.Update(entity); } await context.SaveChangesAsync(); } }
/// <summary> /// Deletes notification subscription. Called when the "Delete subscription" button is pressed. /// Expects the CreateNotificationSubscription method to be run first. /// </summary> private bool DeleteNotificationSubscription() { // Get the gateway NotificationGatewayInfo gateway = NotificationGatewayInfoProvider.GetNotificationGatewayInfo("MyNewGateway"); // Get the template NotificationTemplateInfo template = NotificationTemplateInfoProvider.GetNotificationTemplateInfo("MyNewTemplate", CMSContext.CurrentSiteID); if ((gateway != null) && (template != null)) { // Prepare the parameters string where = "SubscriptionGatewayID = " + gateway.GatewayID + " AND SubscriptionTemplateID = " + template.TemplateID; // Get the notification subscription DataSet subscriptions = NotificationSubscriptionInfoProvider.GetSubscriptions(where, null); if (!DataHelper.DataSourceIsEmpty(subscriptions)) { // Create object from DataRow NotificationSubscriptionInfo deleteSubscription = new NotificationSubscriptionInfo(subscriptions.Tables[0].Rows[0]); // Delete the notification subscription NotificationSubscriptionInfoProvider.DeleteNotificationSubscriptionInfo(deleteSubscription); return(deleteSubscription != null); } } return(false); }
/// <summary> /// Deletes notification template. Called when the "Delete template" button is pressed. /// Expects the CreateNotificationTemplate method to be run first. /// </summary> private bool DeleteNotificationTemplate() { // Get the notification template NotificationTemplateInfo deleteTemplate = NotificationTemplateInfoProvider.GetNotificationTemplateInfo("MyNewTemplate", CMSContext.CurrentSiteID); // Delete the notification template NotificationTemplateInfoProvider.DeleteNotificationTemplateInfo(deleteTemplate); return(deleteTemplate != null); }
/// <summary> /// Creates notification template. Called when the "Create template" button is pressed. /// </summary> private bool CreateNotificationTemplate() { // Create new notification template object NotificationTemplateInfo newTemplate = new NotificationTemplateInfo(); // Set the properties newTemplate.TemplateDisplayName = "My new template"; newTemplate.TemplateName = "MyNewTemplate"; newTemplate.TemplateSiteID = CMSContext.CurrentSiteID; // Create the notification template NotificationTemplateInfoProvider.SetNotificationTemplateInfo(newTemplate); return(true); }
protected void btnOK_Click(object sender, EventArgs e) { // Load or create new NotificationTemplateInfo NotificationTemplateInfo nti = null; string target = ""; if (TemplateID > 0) { nti = NotificationTemplateInfoProvider.GetNotificationTemplateInfo(TemplateID); if (nti == null) { throw new Exception("Template with given ID not found!"); } target = "Template_Edit_General.aspx"; } else { nti = new NotificationTemplateInfo(); nti.TemplateGUID = Guid.NewGuid(); target = "Template_Edit.aspx"; } // Validate codename string error = ValidateForm(nti); if ((error != null) && (error != "")) { // Show error message ShowError(GetString(error)); return; } // Setup object nti.TemplateName = txtCodeName.Text.Trim(); nti.TemplateDisplayName = txtDisplayName.Text.Trim(); nti.TemplateSiteID = SiteID; // Update db NotificationTemplateInfoProvider.SetNotificationTemplateInfo(nti); TemplateID = nti.TemplateID; //Redirect to edit page URLHelper.Redirect(target + "?saved=1&templateid=" + TemplateID.ToString() + "&siteid=" + SiteID.ToString()); }
public async Task <NotificationTemplateInfo> GetTemplateInfoAsync(string templateName) { using (var context = _msSqlContextFactory.CreateDataContext()) { var entity = await context.Templates.FirstOrDefaultAsync(x => x.Name == templateName); if (entity == null) { return(null); } var info = new NotificationTemplateInfo( entity.Name, SplitLocalizations(entity)); return(info); } }
/// <summary> /// Gets and updates notification template. Called when the "Get and update template" button is pressed. /// Expects the CreateNotificationTemplate method to be run first. /// </summary> private bool GetAndUpdateNotificationTemplate() { // Get the notification template NotificationTemplateInfo updateTemplate = NotificationTemplateInfoProvider.GetNotificationTemplateInfo("MyNewTemplate", CMSContext.CurrentSiteID); if (updateTemplate != null) { // Update the property updateTemplate.TemplateDisplayName = updateTemplate.TemplateDisplayName.ToLower(); // Update the notification template NotificationTemplateInfoProvider.SetNotificationTemplateInfo(updateTemplate); return(true); } return(false); }
/// <summary> /// Deletes notification template text. Called when the "Delete text" button is pressed. /// Expects the CreateNotificationTemplateText method to be run first. /// </summary> private bool DeleteNotificationTemplateText() { // Get the template NotificationTemplateInfo template = NotificationTemplateInfoProvider.GetNotificationTemplateInfo("MyNewTemplate", CMSContext.CurrentSiteID); //Get the gateway NotificationGatewayInfo gateway = NotificationGatewayInfoProvider.GetNotificationGatewayInfo("MyNewGateway"); if ((template != null) && (gateway != null)) { // Get the notification template text NotificationTemplateTextInfo deleteText = NotificationTemplateTextInfoProvider.GetNotificationTemplateTextInfo(gateway.GatewayID, template.TemplateID); // Delete the notification template text NotificationTemplateTextInfoProvider.DeleteNotificationTemplateTextInfo(deleteText); return(deleteText != null); } return(false); }
public async Task CreateOrUpdateTemplateAsync(string templateName, string templateBody, Localization localization) { await _templateContentRepository.SaveContentAsync(templateName, localization, templateBody); var info = await _templateRepository.GetTemplateInfoAsync(templateName); if (info == null) { info = new NotificationTemplateInfo(templateName, new List <Localization> { localization }); await _templateRepository.InsertOrUpdateAsync(info); } else if (!info.HasLocalization(localization)) { info.AvailableLocalizations.Add(localization); await _templateRepository.InsertOrUpdateAsync(info); } _log.Info("Template updated", new { Name = templateName, Localization = localization.ToString() }); }
/// <summary> /// Gets and bulk updates notification template texts. Called when the "Get and bulk update texts" button is pressed. /// Expects the CreateNotificationTemplateText method to be run first. /// </summary> private bool GetAndBulkUpdateNotificationTemplateTexts() { // Get the template NotificationTemplateInfo template = NotificationTemplateInfoProvider.GetNotificationTemplateInfo("MyNewTemplate", CMSContext.CurrentSiteID); //Get the gateway NotificationGatewayInfo gateway = NotificationGatewayInfoProvider.GetNotificationGatewayInfo("MyNewGateway"); if ((template != null) && (gateway != null)) { // Prepare the parameters string where = ""; where = SqlHelperClass.AddWhereCondition(where, "TemplateID = " + template.TemplateID, "AND"); where = SqlHelperClass.AddWhereCondition(where, "GatewayID = " + gateway.GatewayID, "AND"); // Get the data DataSet texts = NotificationTemplateTextInfoProvider.GetNotificationTemplateTexts(where, null); if (!DataHelper.DataSourceIsEmpty(texts)) { // Loop through the individual items foreach (DataRow textDr in texts.Tables[0].Rows) { // Create object from DataRow NotificationTemplateTextInfo modifyText = new NotificationTemplateTextInfo(textDr); // Update the property modifyText.TemplateSubject = modifyText.TemplateSubject.ToUpper(); // Update the notification template text NotificationTemplateTextInfoProvider.SetNotificationTemplateTextInfo(modifyText); } return(true); } } return(false); }
private string ValidateForm(NotificationTemplateInfo nti) { string codename = txtCodeName.Text.Trim(); // Check if display name is not empty string result = new Validator().NotEmpty(txtDisplayName.Text.Trim(), "general.requiresdisplayname").Result; if (result != "") { return(result); } // Check if code name is not empty result = new Validator().NotEmpty(codename, "general.requiresdisplayname").Result; if (result != "") { return(result); } // Check if code name is valid result = new Validator().IsCodeName(codename, "general.invalidcodename").Result; if (result != "") { return(result); } // Check if codename is unique if ((nti.TemplateName != codename)) { NotificationTemplateInfo testNti = NotificationTemplateInfoProvider.GetNotificationTemplateInfo(codename, this.SiteID); if ((testNti != null) && (testNti.TemplateID != nti.TemplateID)) { return("general.uniquecodenameerror"); } } return(null); }
public async Task UpdateTemplateAsync_SuccessCreate() { var templateService = new Mock <ITemplateService>(); var controller = new NotificationTemplateController(templateService.Object); controller.ControllerContext.HttpContext = new DefaultHttpContext(); var info = new NotificationTemplateInfo("temp", new List <Localization> { Localization.From("en") }); templateService.Setup(e => e.GetTemplateInfoAsync(It.IsAny <string>())) .Returns(Task.FromResult(info)); await controller.UpdateTemplateAsync(new NewTemplateRequest { TemplateName = "temp", TemplateBody = "hello", LocalizationCode = "en" }); templateService.Verify(e => e.CreateOrUpdateTemplateAsync("temp", "hello", Localization.From("en")), Times.Once); Assert.Equal((int)HttpStatusCode.NoContent, controller.Response.StatusCode); controller.Dispose(); }
/// <summary> /// Creates notification template. Called when the "Create template" button is pressed. /// </summary> private bool CreateNotificationTemplate() { // Create new notification template object NotificationTemplateInfo newTemplate = new NotificationTemplateInfo(); // Set the properties newTemplate.TemplateDisplayName = "My new template"; newTemplate.TemplateName = "MyNewTemplate"; newTemplate.TemplateSiteID = CMSContext.CurrentSiteID; // Create the notification template NotificationTemplateInfoProvider.SetNotificationTemplateInfo(newTemplate); return true; }
/// <summary> /// Calls Validate() method, if validation fails returns error message, /// otherwise creates subscriptions and returns empty string. /// </summary> public override string Subscribe() { // Validate inputs string errorMessage = this.Validate(); if (!String.IsNullOrEmpty(errorMessage)) { return(errorMessage); } // Get correct user ID int userId = 0; if (this.EventUserID > 0) { userId = this.EventUserID; } else { if (CMSContext.CurrentUser != null) { userId = CMSContext.CurrentUser.UserID; } } // Parse the notification template site and name NotificationTemplateInfo nti = null; string templateName = this.NotificationTemplateName; if (this.NotificationTemplateName != null) { string[] temp = this.NotificationTemplateName.Split(new char[] { '.' }); if (temp.Length == 2) { SiteInfo tempSite = SiteInfoProvider.GetSiteInfo(temp[0]); if (tempSite != null) { templateName = temp[1]; nti = NotificationTemplateInfoProvider.GetNotificationTemplateInfo(templateName, tempSite.SiteID); } } else { nti = NotificationTemplateInfoProvider.GetNotificationTemplateInfo(templateName, 0); } } bool hasSubscription = false; // Inputs are valid now, create the subscriptions for (int i = 0; i < this.NotificationGateways.Count; i++) { CheckBox chk = controls[i, 0] as CheckBox; Panel pnl = controls[i, 1] as Panel; CMSNotificationGateway g = controls[i, 2] as CMSNotificationGateway; if ((pnl != null) && (chk != null) && (g != null) && (chk.Checked)) { // Register the subscriptions if (g.NotificationGatewayObj != null) { if (g.NotificationGatewayForm != null) { // Stores NotificationSubscriptionInfo objects List <NotificationSubscriptionInfo> infos = new List <NotificationSubscriptionInfo>(); bool uniquenessFailed = false; bool templateFailed = false; foreach (NotificationSubscriptionInfo nsiTemplate in this.Subscriptions) { // Create new subscription and initialize it with default values NotificationSubscriptionInfo nsi = new NotificationSubscriptionInfo(); nsi.SubscriptionEventDisplayName = this.EventDisplayName; nsi.SubscriptionTarget = Convert.ToString(g.NotificationGatewayForm.Value); nsi.SubscriptionEventCode = this.EventCode; nsi.SubscriptionEventObjectID = this.EventObjectID; nsi.SubscriptionEventSource = this.EventSource; nsi.SubscriptionGatewayID = g.NotificationGatewayObj.GatewayID; nsi.SubscriptionTime = DateTime.Now; nsi.SubscriptionUserID = userId; nsi.SubscriptionEventData1 = this.EventData1; nsi.SubscriptionEventData2 = this.EventData2; nsi.SubscriptionUseHTML = this.SubscriptionUseHTML; nsi.SubscriptionSiteID = this.SubscriptionSiteID; if (nti != null) { nsi.SubscriptionTemplateID = nti.TemplateID; } // Overwrite default values if these are specified in template subscription if (!String.IsNullOrEmpty(nsiTemplate.SubscriptionEventDisplayName)) { nsi.SubscriptionEventDisplayName = nsiTemplate.SubscriptionEventDisplayName; } if (!String.IsNullOrEmpty(nsiTemplate.SubscriptionEventCode)) { nsi.SubscriptionEventCode = nsiTemplate.SubscriptionEventCode; } if (!String.IsNullOrEmpty(nsiTemplate.SubscriptionEventSource)) { nsi.SubscriptionEventSource = nsiTemplate.SubscriptionEventSource; } if (!String.IsNullOrEmpty(nsiTemplate.SubscriptionEventData1)) { nsi.SubscriptionEventData1 = nsiTemplate.SubscriptionEventData1; } if (!String.IsNullOrEmpty(nsiTemplate.SubscriptionEventData2)) { nsi.SubscriptionEventData2 = nsiTemplate.SubscriptionEventData2; } if (nsiTemplate.SubscriptionEventObjectID > 0) { nsi.SubscriptionEventObjectID = nsiTemplate.SubscriptionEventObjectID; } if (nsiTemplate.SubscriptionUserID > 0) { nsi.SubscriptionEventObjectID = nsiTemplate.SubscriptionUserID; } if (nsiTemplate.SubscriptionSiteID > 0) { nsi.SubscriptionSiteID = nsiTemplate.SubscriptionSiteID; } if (nsiTemplate.SubscriptionTemplateID > 0) { nsi.SubscriptionTemplateID = nsiTemplate.SubscriptionTemplateID; } // Check uniqueness (create only unique subsciptions) string where = "SubscriptionEventSource = '" + SqlHelperClass.GetSafeQueryString(nsi.SubscriptionEventSource, false) + "' AND " + "SubscriptionEventCode = '" + SqlHelperClass.GetSafeQueryString(nsi.SubscriptionEventCode, false) + "' AND " + "SubscriptionTarget = '" + SqlHelperClass.GetSafeQueryString(nsi.SubscriptionTarget, false) + "' AND " + "SubscriptionEventObjectID = " + nsi.SubscriptionEventObjectID + " AND " + "SubscriptionGatewayID = " + nsi.SubscriptionGatewayID + " AND " + "SubscriptionEventData1 LIKE '" + SqlHelperClass.GetSafeQueryString(nsi.SubscriptionEventData1, false) + "' AND " + "SubscriptionEventData2 LIKE '" + SqlHelperClass.GetSafeQueryString(nsi.SubscriptionEventData2, false) + "' AND "; if (nsi.SubscriptionSiteID > 0) { where += "SubscriptionSiteID = " + nsi.SubscriptionSiteID; } else { where += "SubscriptionSiteID IS NULL"; } // Only if subscription is unique and if the template is set, put it into the list if (!DataHelper.DataSourceIsEmpty(NotificationSubscriptionInfoProvider.GetSubscriptions(where, null))) { uniquenessFailed = true; break; } else if (nsi.SubscriptionTemplateID <= 0) { templateFailed = true; break; } else { infos.Add(nsi); } } if (uniquenessFailed) { return(GetString("notifications.subscription.notunique")); } else if (templateFailed) { return(GetString("notifications.subscription.templatemissing")); } else { // Save vaild subscriptions into the DB foreach (NotificationSubscriptionInfo nsi in infos) { NotificationSubscriptionInfoProvider.SetNotificationSubscriptionInfo(nsi); } } // Clear the form after successful registration g.NotificationGatewayForm.ClearForm(); hasSubscription = true; } } } } if (hasSubscription) { if (this.NotificationGateways.Count > 1) { // Reset the state of the gateways for (int i = 0; i < this.NotificationGateways.Count; i++) { CheckBox chk = controls[i, 0] as CheckBox; Panel pnl = controls[i, 1] as Panel; if ((chk != null) && (pnl != null)) { chk.Checked = false; pnl.Attributes.Add("style", "display: none;"); } } } return(String.Empty); } else { return(GetString("notifications.subscription.selectgateway")); } }
/// <summary> /// Initializes the control properties. /// </summary> protected void SetupControl() { if (StopProcessing) { // Do nothing subscriptionElem.StopProcessing = true; } else { // Build the actions string string actionsString = (CreateEventEnabled ? "|CREATEDOC" : "") + (DeleteEventEnabled ? "|DELETEDOC" : "") + (UpdateEventEnabled ? "|UPDATEDOC" : ""); actionsString = actionsString.TrimStart('|'); // Get the actions string[] actions = actionsString.Split(new char[] { '|' }); if (actions.Length > 0) { // Inititalize subscriptionElem control subscriptionElem.GatewayNames = GatewayNames; subscriptionElem.EventSource = "Content"; subscriptionElem.EventDescription = EventDescription; subscriptionElem.EventObjectID = 0; subscriptionElem.EventData1 = (String.IsNullOrEmpty(Path) ? "/%" : MacroResolver.ResolveCurrentPath(Path)); subscriptionElem.EventData2 = DocumentTypes; subscriptionElem.SubscriptionUseHTML = SubscriptionUseHTML; // If "#current#" is set, then get current site ID if (SiteName == "#current#") { subscriptionElem.SubscriptionSiteID = SiteContext.CurrentSiteID; } // If "-" as global is not set, then try to find the site else if (SiteName != "-") { // Try to find given site SiteInfo si = SiteInfoProvider.GetSiteInfo(SiteName); if (si != null) { subscriptionElem.SubscriptionSiteID = si.SiteID; } } // Initialize SubscriptionInfo objects NotificationSubscriptionInfo[] subscriptions = new NotificationSubscriptionInfo[actions.Length]; for (int i = 0; i < actions.Length; i++) { NotificationSubscriptionInfo nsi = new NotificationSubscriptionInfo(); nsi.SubscriptionEventCode = actions[i]; // Get correct template name and event display name string currentDisplayName = string.Empty; string currentTemplateName = string.Empty; switch (actions[i].ToLowerCSafe()) { case "createdoc": currentDisplayName = CreateEventDisplayName; currentTemplateName = CreateEventTemplateName; break; case "deletedoc": currentDisplayName = DeleteEventDisplayName; currentTemplateName = DeleteEventTemplateName; break; case "updatedoc": currentDisplayName = UpdateEventDisplayName; currentTemplateName = UpdateEventTemplateName; break; } // Get correct template NotificationTemplateInfo nti = GetTemplateInfo(currentTemplateName); if (nti != null) { nsi.SubscriptionTemplateID = nti.TemplateID; } if (String.IsNullOrEmpty(currentDisplayName)) { nsi.SubscriptionEventDisplayName = TextHelper.LimitLength(String.Format(GetString("notifications.contentsubscription.name"), (String.IsNullOrEmpty(Path) ? "/%" : Path), (String.IsNullOrEmpty(DocumentTypes) ? GetString("notifications.contentsubscription.alldoctypes") : DocumentTypes), actions[i]), 250, wholeWords: true, cutLocation: CutTextEnum.Middle); } else { nsi.SubscriptionEventDisplayName = currentDisplayName; } subscriptions[i] = nsi; } subscriptionElem.Subscriptions = subscriptions; } } }
/// <summary> /// Initializes the control properties. /// </summary> protected void SetupControl() { if (this.StopProcessing) { // Do nothing this.subscriptionElem.StopProcessing = true; } else { // Build the actions string string actionsString = (CreateEventEnabled ? "|CREATEDOC" : "") + (DeleteEventEnabled ? "|DELETEDOC" : "") + (UpdateEventEnabled ? "|UPDATEDOC" : ""); actionsString = actionsString.TrimStart('|'); // Get the actions string[] actions = actionsString.Split(new char[] { '|' }); if (actions.Length > 0) { // Inititalize subscriptionElem control this.subscriptionElem.GatewayNames = this.GatewayNames; this.subscriptionElem.EventSource = "Content"; this.subscriptionElem.EventDescription = this.EventDescription; this.subscriptionElem.EventObjectID = 0; this.subscriptionElem.EventData1 = (String.IsNullOrEmpty(this.Path) ? "/%" : this.Path); this.subscriptionElem.EventData2 = this.DocumentTypes; this.subscriptionElem.SubscriptionUseHTML = this.SubscriptionUseHTML; // If "#current#" is set, then get current site ID if (this.SiteName == "#current#") { this.subscriptionElem.SubscriptionSiteID = CMSContext.CurrentSiteID; } // If "-" as global is not set, then try to find the site else if (this.SiteName != "-") { // Try to find given site SiteInfo si = SiteInfoProvider.GetSiteInfo(this.SiteName); if (si != null) { this.subscriptionElem.SubscriptionSiteID = si.SiteID; } } // Initialize SubscriptionInfo objects NotificationSubscriptionInfo[] subscriptions = new NotificationSubscriptionInfo[actions.Length]; for (int i = 0; i < actions.Length; i++) { NotificationSubscriptionInfo nsi = new NotificationSubscriptionInfo(); nsi.SubscriptionEventCode = actions[i]; // Get correct template name and event display name string currentDisplayName = ""; string currentTemplateName = ""; switch (actions[i].ToLower()) { case "createdoc": currentDisplayName = this.CreateEventDisplayName; currentTemplateName = this.CreateEventTemplateName; break; case "deletedoc": currentDisplayName = this.DeleteEventDisplayName; currentTemplateName = this.DeleteEventTemplateName; break; case "updatedoc": currentDisplayName = this.UpdateEventDisplayName; currentTemplateName = this.UpdateEventTemplateName; break; } // Get correct template NotificationTemplateInfo nti = GetTemplateInfo(currentTemplateName); if (nti != null) { nsi.SubscriptionTemplateID = nti.TemplateID; } if (String.IsNullOrEmpty(currentDisplayName)) { nsi.SubscriptionEventDisplayName = String.Format(GetString("notifications.contentsubscription.name"), (String.IsNullOrEmpty(this.Path) ? "/%" : this.Path), (String.IsNullOrEmpty(this.DocumentTypes) ? GetString("notifications.contentsubscription.alldoctypes") : this.DocumentTypes), actions[i]); } else { nsi.SubscriptionEventDisplayName = currentDisplayName; } subscriptions[i] = nsi; } this.subscriptionElem.Subscriptions = subscriptions; } } }
private string ValidateForm(NotificationTemplateInfo nti) { string codename = txtCodeName.Text.Trim(); // Check if display name is not empty string result = new Validator().NotEmpty(txtDisplayName.Text.Trim(), "general.requiresdisplayname").Result; if (result != "") { return result; } // Check if code name is not empty result = new Validator().NotEmpty(codename, "general.requiresdisplayname").Result; if (result != "") { return result; } // Check if code name is valid result = new Validator().IsCodeName(codename, "general.invalidcodename").Result; if (result != "") { return result; } // Check if codename is unique if ((nti.TemplateName != codename)) { NotificationTemplateInfo testNti = NotificationTemplateInfoProvider.GetNotificationTemplateInfo(codename, this.SiteID); if ((testNti != null) && (testNti.TemplateID != nti.TemplateID)) { return "general.uniquecodenameerror"; } } return null; }
/// <summary> /// Calls Validate() method, if validation fails returns error message, /// otherwise creates subscriptions and returns empty string. /// </summary> public override string Subscribe() { // Validate inputs string errorMessage = Validate(); if (!String.IsNullOrEmpty(errorMessage)) { return(errorMessage); } // Get correct user ID int userId = 0; if (EventUserID > 0) { userId = EventUserID; } else { if (MembershipContext.AuthenticatedUser != null) { userId = MembershipContext.AuthenticatedUser.UserID; } } // Parse the notification template site and name NotificationTemplateInfo nti = null; string templateName = NotificationTemplateName; if (NotificationTemplateName != null) { string[] temp = NotificationTemplateName.Split(new char[] { '.' }); if (temp.Length == 2) { SiteInfo tempSite = SiteInfoProvider.GetSiteInfo(temp[0]); if (tempSite != null) { templateName = temp[1]; nti = NotificationTemplateInfoProvider.GetNotificationTemplateInfo(templateName, tempSite.SiteID); } } else { nti = NotificationTemplateInfoProvider.GetNotificationTemplateInfo(templateName, 0); } } bool hasSubscription = false; // Inputs are valid now, create the subscriptions for (int i = 0; i < NotificationGateways.Count; i++) { CMSCheckBox chk = controls[i, 0] as CMSCheckBox; Panel pnl = controls[i, 1] as Panel; CMSNotificationGateway g = controls[i, 2] as CMSNotificationGateway; if ((pnl != null) && (chk != null) && (g != null) && (chk.Checked)) { // Register the subscriptions if (g.NotificationGatewayObj != null && g.NotificationGatewayForm != null) { // Stores NotificationSubscriptionInfo objects List <NotificationSubscriptionInfo> infos = new List <NotificationSubscriptionInfo>(); bool uniquenessFailed = false; bool templateFailed = false; foreach (NotificationSubscriptionInfo nsiTemplate in Subscriptions) { // Create new subscription and initialize it with default values NotificationSubscriptionInfo nsi = new NotificationSubscriptionInfo(); nsi.SubscriptionEventDisplayName = EventDisplayName; nsi.SubscriptionTarget = Convert.ToString(g.NotificationGatewayForm.Value); nsi.SubscriptionEventCode = EventCode; nsi.SubscriptionEventObjectID = EventObjectID; nsi.SubscriptionEventSource = EventSource; nsi.SubscriptionGatewayID = g.NotificationGatewayObj.GatewayID; nsi.SubscriptionTime = DateTime.Now; nsi.SubscriptionUserID = userId; nsi.SubscriptionEventData1 = EventData1; nsi.SubscriptionEventData2 = EventData2; nsi.SubscriptionUseHTML = SubscriptionUseHTML; nsi.SubscriptionSiteID = SubscriptionSiteID; if (nti != null) { nsi.SubscriptionTemplateID = nti.TemplateID; } // Overwrite default values if these are specified in template subscription if (!String.IsNullOrEmpty(nsiTemplate.SubscriptionEventDisplayName)) { nsi.SubscriptionEventDisplayName = nsiTemplate.SubscriptionEventDisplayName; } if (!String.IsNullOrEmpty(nsiTemplate.SubscriptionEventCode)) { nsi.SubscriptionEventCode = nsiTemplate.SubscriptionEventCode; } if (!String.IsNullOrEmpty(nsiTemplate.SubscriptionEventSource)) { nsi.SubscriptionEventSource = nsiTemplate.SubscriptionEventSource; } if (!String.IsNullOrEmpty(nsiTemplate.SubscriptionEventData1)) { nsi.SubscriptionEventData1 = nsiTemplate.SubscriptionEventData1; } if (!String.IsNullOrEmpty(nsiTemplate.SubscriptionEventData2)) { nsi.SubscriptionEventData2 = nsiTemplate.SubscriptionEventData2; } if (nsiTemplate.SubscriptionEventObjectID > 0) { nsi.SubscriptionEventObjectID = nsiTemplate.SubscriptionEventObjectID; } if (nsiTemplate.SubscriptionUserID > 0) { nsi.SubscriptionEventObjectID = nsiTemplate.SubscriptionUserID; } if (nsiTemplate.SubscriptionSiteID > 0) { nsi.SubscriptionSiteID = nsiTemplate.SubscriptionSiteID; } if (nsiTemplate.SubscriptionTemplateID > 0) { nsi.SubscriptionTemplateID = nsiTemplate.SubscriptionTemplateID; } // Check whether template is set if (nsi.SubscriptionTemplateID <= 0) { templateFailed = true; break; } // Check uniqueness (create only unique subscriptions) var additionalWhere = new WhereCondition() .WhereEquals("SubscriptionTarget", nsi.SubscriptionTarget) .WhereEquals("SubscriptionGatewayID", nsi.SubscriptionGatewayID); var whereConditionObj = NotificationSubscriptionInfoProvider.GetWhereConditionObject(nsi.SubscriptionEventSource, nsi.SubscriptionEventCode, nsi.SubscriptionEventObjectID, nsi.SubscriptionEventData1, nsi.SubscriptionEventData2, nsi.SubscriptionSiteID, additionalWhere); bool subscriptionExists = NotificationSubscriptionInfoProvider.GetNotificationSubscriptions() .Where(whereConditionObj) .TopN(1) .HasResults(); // Only if subscription is unique put it into the list if (subscriptionExists) { uniquenessFailed = true; break; } else { infos.Add(nsi); } } if (uniquenessFailed) { return(GetString("notifications.subscription.notunique")); } else if (templateFailed) { return(GetString("notifications.subscription.templatemissing")); } else { // Save valid subscriptions into the DB foreach (NotificationSubscriptionInfo nsi in infos) { NotificationSubscriptionInfoProvider.SetNotificationSubscriptionInfo(nsi); } } // Clear the form after successful registration g.NotificationGatewayForm.ClearForm(); hasSubscription = true; } } } if (hasSubscription) { if (NotificationGateways.Count > 1) { // Reset the state of the gateways for (int i = 0; i < NotificationGateways.Count; i++) { CMSCheckBox chk = controls[i, 0] as CMSCheckBox; Panel pnl = controls[i, 1] as Panel; if ((chk != null) && (pnl != null)) { chk.Checked = false; pnl.Attributes.Add("style", "display: none;"); } } } return(String.Empty); } else { return(GetString("notifications.subscription.selectgateway")); } }
/// <summary> /// Gets and bulk updates notification templates. Called when the "Get and bulk update templates" button is pressed. /// Expects the CreateNotificationTemplate method to be run first. /// </summary> private bool GetAndBulkUpdateNotificationTemplates() { // Prepare the parameters string where = "TemplateName LIKE N'MyNewTemplate%'"; where = SqlHelperClass.AddWhereCondition(where, "TemplateSiteID = " + CMSContext.CurrentSiteID, "AND"); // Get the data DataSet templates = NotificationTemplateInfoProvider.GetTemplates(where, null); if (!DataHelper.DataSourceIsEmpty(templates)) { // Loop through the individual items foreach (DataRow templateDr in templates.Tables[0].Rows) { // Create object from DataRow NotificationTemplateInfo modifyTemplate = new NotificationTemplateInfo(templateDr); // Update the property modifyTemplate.TemplateDisplayName = modifyTemplate.TemplateDisplayName.ToUpper(); // Update the notification template NotificationTemplateInfoProvider.SetNotificationTemplateInfo(modifyTemplate); } return true; } return false; }