Esempio n. 1
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);
    }
Esempio n. 2
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);
    }
Esempio n. 3
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);
    }
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that threw event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void gridElem_OnAction(string actionName, object actionArgument)
    {
        if (actionName == "delete")
        {
            try
            {
                if (!RaiseOnCheckPermissions(PERMISSION_MODIFY, this))
                {
                    var cui = MembershipContext.AuthenticatedUser;
                    if ((cui == null) || ((UserId != cui.UserID) && !cui.IsAuthorizedPerResource("CMS.Users", PERMISSION_MODIFY)))
                    {
                        RedirectToAccessDenied("CMS.Users", PERMISSION_MODIFY);
                    }
                }

                NotificationSubscriptionInfoProvider.DeleteNotificationSubscriptionInfo(Convert.ToInt32(actionArgument));
            }
            catch (Exception ex)
            {
                // Show error message
                ShowError(ex.Message);
            }
        }
    }
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that threw event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void gridElem_OnAction(string actionName, object actionArgument)
    {
        if (actionName == "delete")
        {
            try
            {
                if (!RaiseOnCheckPermissions(CMSAdminControl.PERMISSION_MODIFY, this))
                {
                    CurrentUserInfo cui = CMSContext.CurrentUser;
                    if ((cui == null) || ((this.UserId != cui.UserID) && !cui.IsAuthorizedPerResource("CMS.Users", CMSAdminControl.PERMISSION_MODIFY)))
                    {
                        RedirectToAccessDenied("CMS.Users", CMSAdminControl.PERMISSION_MODIFY);
                    }
                }

                NotificationSubscriptionInfoProvider.DeleteNotificationSubscriptionInfo(Convert.ToInt32(actionArgument));
            }
            catch (Exception ex)
            {
                lblError.Visible = true;
                lblError.Text    = ex.Message;
            }
        }
    }
Esempio n. 6
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"));
        }
    }
    /// <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"));
        }
    }