Ejemplo n.º 1
0
    /// <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);
    }
Ejemplo n.º 2
0
    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;
            }
        }
    }
    /// <summary>
    /// Parses the notification template site and name and returns proper Info object.
    /// </summary>
    private NotificationTemplateInfo GetTemplateInfo(string templateName)
    {
        if (!string.IsNullOrEmpty(templateName))
        {
            // Get current site name
            string siteName = CurrentSiteName;

            // If SiteName is not "#current#" or "-" get site name from property
            if (!(SiteName.EqualsCSafe("#current#", true) || (SiteName == "-")))
            {
                siteName = SiteName;
            }

            if (templateName.StartsWithCSafe(siteName + ".", true))
            {
                // Remove site name from template name
                templateName = templateName.Remove(0, siteName.Length + 1);

                // Site template
                SiteInfo tempSite = SiteInfoProvider.GetSiteInfo(siteName);
                if (tempSite != null)
                {
                    return(NotificationTemplateInfoProvider.GetNotificationTemplateInfo(templateName, tempSite.SiteID));
                }
            }
            else
            {
                // Global template
                return(NotificationTemplateInfoProvider.GetNotificationTemplateInfo(templateName));
            }
        }

        return(null);
    }
Ejemplo n.º 4
0
    /// <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);
    }
Ejemplo n.º 5
0
    /// <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);
    }
Ejemplo n.º 6
0
    /// <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);
    }
Ejemplo n.º 7
0
    /// <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);
    }
Ejemplo n.º 8
0
    /// <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);
    }
Ejemplo n.º 9
0
    /// <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);
    }
Ejemplo n.º 10
0
    /// <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);
    }
Ejemplo n.º 11
0
    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());
    }
Ejemplo n.º 12
0
    private void gridTemplates_OnAction(string actionName, object actionArgument)
    {
        // Get template id
        int templateId = ValidationHelper.GetInteger(actionArgument, 0);

        switch (actionName.ToLowerCSafe())
        {
        case "edit":
            URLHelper.Redirect("Template_Edit.aspx?templateid=" + templateId.ToString() + "&siteid=" + siteSelector.Value.ToString());
            break;

        case "delete":
            NotificationTemplateInfoProvider.DeleteNotificationTemplateInfo(templateId);
            break;
        }
    }
Ejemplo n.º 13
0
    /// <summary>
    /// Initializes the breadcrumb header element of the master page.
    /// </summary>
    private void InitializeBreadcrumb()
    {
        string[,] breadcrumbs = new string[2, 3];
        breadcrumbs[0, 0]     = GetString("notifications.header.templates");
        breadcrumbs[0, 1]     = "~/CMSModules/Notifications/Development/Templates/Template_List.aspx" + ((siteId > 0) ? "?siteid=" + siteId : "");
        breadcrumbs[1, 0]     = GetString("notifications.template_edit.new");
        breadcrumbs[0, 2]     = "_parent";
        if (templateId > 0)
        {
            breadcrumbs[1, 0] = NotificationTemplateInfoProvider.GetNotificationTemplateInfo(templateId).TemplateDisplayName;
            breadcrumbs[0, 1] = "~/CMSModules/Notifications/Development/Templates/Template_List.aspx?templateid=" + templateId + ((siteId > 0) ? "&siteid=" + siteId : "");
        }

        breadcrumbs[1, 1] = "";

        this.CurrentMaster.Title.Breadcrumbs = breadcrumbs;
    }
Ejemplo n.º 14
0
    /// <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);
    }
Ejemplo n.º 15
0
    /// <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);
    }
Ejemplo n.º 16
0
    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);
    }
Ejemplo n.º 17
0
    /// <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);
    }
Ejemplo n.º 18
0
    /// <summary>
    /// Parses the notification template site and name and returns proper Info object.
    /// </summary>
    private NotificationTemplateInfo GetTemplateInfo(string templateName)
    {
        if (templateName != null)
        {
            string[] temp = templateName.Split(new char[] { '.' });
            if (temp.Length == 2)
            {
                // Site template
                SiteInfo tempSite = SiteInfoProvider.GetSiteInfo(temp[0]);
                if (tempSite != null)
                {
                    return(NotificationTemplateInfoProvider.GetNotificationTemplateInfo(temp[1], tempSite.SiteID));
                }
            }
            else
            {
                // Global template
                return(NotificationTemplateInfoProvider.GetNotificationTemplateInfo(templateName));
            }
        }

        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 = 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"));
        }
    }
Ejemplo n.º 20
0
    /// <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"));
        }
    }