示例#1
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);
    }
示例#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);
    }
示例#3
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);
    }
 /// <summary>
 /// Inserts a notification subscription.
 /// </summary>
 public async Task InsertSubscriptionAsync(NotificationSubscriptionInfo subscription)
 {
     if (!await IsSubscribedAsync(subscription.UserId, subscription.NotificationName, subscription.EntityTypeName, subscription.EntityId))
     {
         var notificationSubscription = new NotificationSubscription(subscription);
         await _notificationSubscriptionRepository.InsertAsync(notificationSubscription);
     }
 }
 public virtual async Task InsertSubscriptionAsync(NotificationSubscriptionInfo subscription)
 {
     using (_unitOfWorkManager.Current.SetTenantId(subscription.TenantId))
     {
         await _notificationSubscriptionRepository.InsertAsync(subscription);
         await _unitOfWorkManager.Current.SaveChangesAsync();
     }
 }
        public virtual async Task InsertSubscriptionAsync(NotificationSubscriptionInfo subscription)
        {
            using (_unitOfWorkManager.Current.SetTenantId(subscription.TenantId))
            {
                await _notificationSubscriptionRepository.InsertAsync(subscription);

                await _unitOfWorkManager.Current.SaveChangesAsync();
            }
        }
 public NotificationSubscription(NotificationSubscriptionInfo subscription)
     : this(subscription.UserId,
            subscription.NotificationName,
            subscription.EntityTypeName,
            subscription.EntityId,
            subscription.CreationTime,
            subscription.TenantId)
 {
 }
        public async Task UnsubscribeAsync(NotificationSubscriptionOptions options)
        {
            var subscriptionInfo = new NotificationSubscriptionInfo
            {
                NotificationName = options.NotificationName,
                UserId = options.UserId,
                EntityTypeName = options.EntityType.FullName,
                EntityId = options.EntityId.ToString(), //TODO: ToString() can be problem for some types, use JSON serialization instead, based on entity's primary key type
            };

            await _store.DeleteSubscriptionAsync(subscriptionInfo);
        }
        /// <summary>
        /// 添加所有用户订阅通知(NotificationName)
        /// (激活状态,未删除的用户)
        /// </summary>
        /// <param name="notificationInfo"></param>
        /// <returns></returns>
        public async Task AddAllUserSubscriptionAsync(SysNotificationInfo notificationInfo)
        {
            var userList = _userInfoRepository.GetAllList(p => p.IsActive == true);

            foreach (var item in userList)
            {
                NotificationSubscriptionInfo subscription = new NotificationSubscriptionInfo()
                {
                    TenantId         = 1,
                    UserId           = item.Id,
                    NotificationName = notificationInfo.NotificationName
                };
                await _notificationStore.InsertSubscriptionAsync(subscription);
            }
        }
    /// <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;
            }
        }
    }
    /// <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"));
        }
    }
示例#12
0
 public virtual async Task InsertSubscriptionAsync(NotificationSubscriptionInfo subscription)
 {
     await _notificationSubscriptionsRepository.InsertAsync(subscription);
 }
示例#13
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>
 /// 插入订阅-异步
 /// </summary>
 /// <param name="subscription">通知订阅的信息</param>
 /// <returns></returns>
 public Task InsertSubscriptionAsync(NotificationSubscriptionInfo subscription)
 {
     return Task.FromResult(0);
 }
    /// <summary>
    /// Gets and updates notification subscription. Called when the "Get and update subscription" button is pressed.
    /// Expects the CreateNotificationSubscription method to be run first.
    /// </summary>
    private bool GetAndUpdateNotificationSubscription()
    {
        // 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))
            {
                // Create object from DataRow
                NotificationSubscriptionInfo updateSubscription = new NotificationSubscriptionInfo(subscriptions.Tables[0].Rows[0]);

                // Update the property
                updateSubscription.SubscriptionEventDisplayName = updateSubscription.SubscriptionEventDisplayName.ToLowerCSafe();

                // Update the notification subscription
                NotificationSubscriptionInfoProvider.SetNotificationSubscriptionInfo(updateSubscription);

                return true;
            }
        }

        return false;
    }
    /// <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>
    /// 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;
    }
示例#18
0
 public void InsertSubscription(NotificationSubscriptionInfo subscription)
 {
     _notificationSubscriptionsRepository.Insert(subscription);
 }
示例#19
0
 public virtual Task InsertSubscriptionAsync(NotificationSubscriptionInfo subscription)
 {
     return _notificationSubscriptionRepository.InsertAsync(subscription);
 }
    /// <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 (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;
            }
        }
    }
示例#22
0
    /// <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;
            }
        }
    }
    /// <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 (CMSContext.CurrentUser != null)
            {
                userId = CMSContext.CurrentUser.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++)
        {
            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 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 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 (NotificationGateways.Count > 1)
            {
                // Reset the state of the gateways
                for (int i = 0; i < 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");
        }
    }