Exemplo n.º 1
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (!Page.IsPostBack)
            {
                if (CurrentPersonAliasId != null)
                {
                    var rockContext = new RockContext();
                    var notificationRecipientService = new NotificationRecipientService(rockContext);
                    var notificationItems            = notificationRecipientService
                                                       .Queryable()
                                                       .AsNoTracking()
                                                       .Where(n => n.PersonAliasId == CurrentPersonAliasId && n.Read == false)
                                                       .OrderByDescending(n => n.Notification.SentDateTime)
                                                       .ToList();

                    ViewState["NotificationCount"] = notificationItems.Count;

                    if (notificationItems.Count == 0)
                    {
                        HidePanel();
                    }

                    rptNotifications.DataSource = notificationItems;
                    rptNotifications.DataBind();
                }
            }
        }
        public static async Task Run([EventHubTrigger("dtoclassrecipient", Connection = "evhBLTutorialConn")] EventData[] events,
                                     ILogger log)
        {
            var exceptions = new List <Exception>();

            foreach (EventData eventData in events)
            {
                try
                {
                    string messageBody = Encoding.UTF8.GetString(eventData.Body.Array, eventData.Body.Offset, eventData.Body.Count);

                    var service = new NotificationRecipientService();
                    service.CreateNewNotification(messageBody);
                }
                catch (Exception e)
                {
                    // We need to keep processing the rest of the batch - capture this exception and continue.
                    // Also, consider capturing details of the message that failed processing so it can be processed again later.
                    exceptions.Add(e);
                }
            }

            // Once processing of the batch is complete, if any messages in the batch failed processing throw an exception so that there is a record of the failure.

            if (exceptions.Count > 1)
            {
                throw new AggregateException(exceptions);
            }

            if (exceptions.Count == 1)
            {
                throw exceptions.Single();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Handles the ItemCommand event of the control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RepeaterCommandEventArgs"/> instance containing the event data.</param>
        protected void rptProjects_ItemCommand(object Sender, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Close")
            {
                var notificationRecipientGuid = e.CommandArgument.ToString().AsGuidOrNull();
                if (notificationRecipientGuid.HasValue)
                {
                    var rockContext = new RockContext();
                    var notificationRecipientService = new NotificationRecipientService(rockContext);
                    var notificationItem             = notificationRecipientService.Get(notificationRecipientGuid.Value);
                    if (notificationItem != null)
                    {
                        notificationItem.Read         = true;
                        notificationItem.ReadDateTime = RockDateTime.Now;
                    }

                    var toHide = e.Item.FindControl("rptNotificationAlert");
                    if (toHide != null)
                    {
                        toHide.Visible = false;
                    }

                    rockContext.SaveChanges();

                    NotificationCount--;
                    if (NotificationCount == 0)
                    {
                        HidePanel();
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public virtual void Execute(IJobExecutionContext context)
        {
            JobDataMap dataMap   = context.JobDetail.JobDataMap;
            var        groupGuid = dataMap.Get("NotificationGroup").ToString().AsGuid();

            var rockContext = new RockContext();
            var group       = new GroupService(rockContext).Get(groupGuid);

            if (group != null)
            {
                var notifications = Utility.SparkLinkHelper.SendToSpark(rockContext);
                if (notifications.Count == 0)
                {
                    return;
                }

                var notificationService = new NotificationService(rockContext);
                foreach (var notification in notifications.ToList())
                {
                    if (notificationService.Get(notification.Guid) == null)
                    {
                        notificationService.Add(notification);
                    }
                    else
                    {
                        notifications.Remove(notification);
                    }
                }
                rockContext.SaveChanges();

                var notificationRecipientService = new NotificationRecipientService(rockContext);
                foreach (var notification in notifications)
                {
                    foreach (var member in group.Members)
                    {
                        if (member.Person.PrimaryAliasId.HasValue)
                        {
                            var recipientNotification = new NotificationRecipient();
                            recipientNotification.NotificationId = notification.Id;
                            recipientNotification.PersonAliasId  = member.Person.PrimaryAliasId.Value;
                            notificationRecipientService.Add(recipientNotification);
                        }
                    }
                }
                rockContext.SaveChanges();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public virtual void Execute( IJobExecutionContext context )
        {
            JobDataMap dataMap = context.JobDetail.JobDataMap;
            var groupGuid = dataMap.Get( "NotificationGroup" ).ToString().AsGuid();

            var rockContext = new RockContext();
            var group = new GroupService( rockContext ).Get( groupGuid );

            if ( group != null )
            {
                var installedPackages = InstalledPackageService.GetInstalledPackages();

                var sparkLinkRequest = new SparkLinkRequest();
                sparkLinkRequest.RockInstanceId = Rock.Web.SystemSettings.GetRockInstanceId();
                sparkLinkRequest.OrganizationName = GlobalAttributesCache.Value( "OrganizationName" );
                sparkLinkRequest.VersionIds = installedPackages.Select( i => i.VersionId ).ToList();
                sparkLinkRequest.RockVersion = VersionInfo.VersionInfo.GetRockSemanticVersionNumber();

                var notifications = new List<Notification>();

                var sparkLinkRequestJson = JsonConvert.SerializeObject( sparkLinkRequest );

                var client = new RestClient( "https://www.rockrms.com/api/SparkLink/update" );
                //var client = new RestClient( "http://localhost:57822/api/SparkLink/update" );
                var request = new RestRequest( Method.POST );
                request.AddParameter( "application/json", sparkLinkRequestJson, ParameterType.RequestBody );
                IRestResponse response = client.Execute( request );
                if ( response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Accepted )
                {
                    foreach ( var notification in JsonConvert.DeserializeObject<List<Notification>>( response.Content ) )
                    {
                        notifications.Add( notification );
                    }
                }

                if ( sparkLinkRequest.VersionIds.Any() )
                {
                    client = new RestClient( "https://www.rockrms.com/api/Packages/VersionNotifications" );
                    //client = new RestClient( "http://localhost:57822/api/Packages/VersionNotifications" );
                    request = new RestRequest( Method.GET );
                    request.AddParameter( "VersionIds", sparkLinkRequest.VersionIds.AsDelimited( "," ) );
                    response = client.Execute( request );
                    if ( response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Accepted )
                    {
                        foreach ( var notification in JsonConvert.DeserializeObject<List<Notification>>( response.Content ) )
                        {
                            notifications.Add( notification );
                        }
                    }
                }

                if ( notifications.Count == 0 )
                {
                    return;
                }

                var notificationService = new NotificationService( rockContext);
                foreach ( var notification in notifications.ToList() )
                {
                    if (notificationService.Get(notification.Guid) == null )
                    {
                        notificationService.Add( notification );
                    }
                    else
                    {
                        notifications.Remove( notification );
                    }
                }
                rockContext.SaveChanges();

                var notificationRecipientService = new NotificationRecipientService( rockContext );
                foreach (var notification in notifications )
                {
                    foreach ( var member in group.Members )
                    {
                        if ( member.Person.PrimaryAliasId.HasValue )
                        {
                            var recipientNotification = new Rock.Model.NotificationRecipient();
                            recipientNotification.NotificationId = notification.Id;
                            recipientNotification.PersonAliasId = member.Person.PrimaryAliasId.Value;
                            notificationRecipientService.Add( recipientNotification );
                        }
                    }
                }
                rockContext.SaveChanges();

            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad( EventArgs e )
        {
            base.OnLoad( e );

            if ( !Page.IsPostBack )
            {
                if ( CurrentPersonAliasId != null )
                {
                    var rockContext = new RockContext();
                    var notificationRecipientService = new NotificationRecipientService( rockContext );
                    var notificationItems = notificationRecipientService
                        .Queryable()
                        .AsNoTracking()
                        .Where( n => n.PersonAliasId == CurrentPersonAliasId && n.Read == false )
                        .OrderByDescending( n => n.Notification.SentDateTime )
                        .ToList();

                    ViewState["NotificationCount"] = notificationItems.Count;

                    if ( notificationItems.Count == 0 )
                    {
                        HidePanel();
                    }

                    rptNotifications.DataSource = notificationItems;
                    rptNotifications.DataBind();
                }
            }
        }
Exemplo n.º 7
0
        protected void rptProjects_ItemCommand( object Sender, RepeaterCommandEventArgs e )
        {
            if ( e.CommandName == "Close" )
            {
                var notificationRecipientGuid = e.CommandArgument.ToString().AsGuidOrNull();
                if ( notificationRecipientGuid.HasValue )
                {
                    var rockContext = new RockContext();
                    var notificationRecipientService = new NotificationRecipientService( rockContext );
                    var notificationItem = notificationRecipientService.Get( notificationRecipientGuid.Value );
                    if ( notificationItem != null )
                    {
                        notificationRecipientService.Delete( notificationItem );
                    }

                    var toHide = e.Item.FindControl( "rptNotificationAlert" );
                    if ( toHide != null )
                    {
                        toHide.Visible = false;
                    }

                    rockContext.SaveChanges();

                    NotificationCount--;
                    if (NotificationCount == 0 )
                    {
                        HidePanel();
                    }
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Handles the Click event of the lbSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void lbSave_Click(object sender, EventArgs e)
        {
            List <int> personAliasIds = null;

            if (rblSource.SelectedValue == "Manual Selection")
            {
                personAliasIds = PersonList.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries)
                                 .Select(p => p.Split('^')[0].AsInteger())
                                 .ToList();
            }
            else if (rblSource.SelectedValue == "Group")
            {
                int?groupId = gpGroup.SelectedValueAsId();

                var group = new GroupService(new RockContext()).Get(groupId ?? 0);
                if (groupId.HasValue)
                {
                    personAliasIds = new GroupMemberService(new RockContext()).Queryable()
                                     .Where(m => m.GroupId == groupId.Value && m.GroupMemberStatus == GroupMemberStatus.Active)
                                     .Select(m => m.Person)
                                     .ToList()
                                     .Select(p => p.PrimaryAliasId.Value)
                                     .ToList();
                }
            }
            else if (rblSource.SelectedValue == "Data View")
            {
                int?dataviewId = dvDataView.SelectedValueAsId();

                if (dataviewId.HasValue)
                {
                    using (var rockContext = new RockContext())
                    {
                        var           personService       = new PersonService(rockContext);
                        var           parameterExpression = personService.ParameterExpression;
                        var           dv = new DataViewService(rockContext).Get(dataviewId.Value);
                        List <string> errorMessages;
                        var           whereExpression = dv.GetExpression(personService, parameterExpression, out errorMessages);

                        personAliasIds = new PersonService(rockContext)
                                         .Get(parameterExpression, whereExpression)
                                         .ToList()
                                         .Select(p => p.PrimaryAliasId.Value)
                                         .ToList();
                    }
                }
            }

            using (var rockContext = new RockContext())
            {
                var notificationService          = new NotificationService(rockContext);
                var notificationRecipientService = new NotificationRecipientService(rockContext);

                var notification = new Notification();

                notification.Title          = tbTitle.Text;
                notification.Message        = ceMessage.Text;
                notification.SentDateTime   = RockDateTime.Now;
                notification.IconCssClass   = tbIconCssClass.Text;
                notification.Classification = ddlClassification.SelectedValueAsEnum <NotificationClassification>();
                notificationService.Add(notification);

                foreach (var aliasId in personAliasIds)
                {
                    notification.Recipients.Add(new NotificationRecipient {
                        PersonAliasId = aliasId
                    });
                }

                rockContext.SaveChanges();
            }

            pnlPost.Visible    = false;
            pnlResults.Visible = true;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public virtual void Execute(IJobExecutionContext context)
        {
            JobDataMap dataMap   = context.JobDetail.JobDataMap;
            var        groupGuid = dataMap.Get("NotificationGroup").ToString().AsGuid();

            var rockContext = new RockContext();
            var group       = new GroupService(rockContext).Get(groupGuid);

            if (group != null)
            {
                var installedPackages = InstalledPackageService.GetInstalledPackages();

                var sparkLinkRequest = new SparkLinkRequest();
                sparkLinkRequest.RockInstanceId   = Rock.Web.SystemSettings.GetRockInstanceId();
                sparkLinkRequest.OrganizationName = GlobalAttributesCache.Value("OrganizationName");
                sparkLinkRequest.VersionIds       = installedPackages.Select(i => i.VersionId).ToList();
                sparkLinkRequest.RockVersion      = VersionInfo.VersionInfo.GetRockSemanticVersionNumber();

                var notifications = new List <Notification>();

                var sparkLinkRequestJson = JsonConvert.SerializeObject(sparkLinkRequest);

                var client = new RestClient("https://www.rockrms.com/api/SparkLink/update");
                //var client = new RestClient( "http://localhost:57822/api/SparkLink/update" );
                var request = new RestRequest(Method.POST);
                request.AddParameter("application/json", sparkLinkRequestJson, ParameterType.RequestBody);
                IRestResponse response = client.Execute(request);
                if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Accepted)
                {
                    foreach (var notification in JsonConvert.DeserializeObject <List <Notification> >(response.Content))
                    {
                        notifications.Add(notification);
                    }
                }

                if (sparkLinkRequest.VersionIds.Any())
                {
                    client = new RestClient("https://www.rockrms.com/api/Packages/VersionNotifications");
                    //client = new RestClient( "http://localhost:57822/api/Packages/VersionNotifications" );
                    request = new RestRequest(Method.GET);
                    request.AddParameter("VersionIds", sparkLinkRequest.VersionIds.AsDelimited(","));
                    response = client.Execute(request);
                    if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Accepted)
                    {
                        foreach (var notification in JsonConvert.DeserializeObject <List <Notification> >(response.Content))
                        {
                            notifications.Add(notification);
                        }
                    }
                }

                if (notifications.Count == 0)
                {
                    return;
                }

                var notificationService = new NotificationService(rockContext);
                foreach (var notification in notifications.ToList())
                {
                    if (notificationService.Get(notification.Guid) == null)
                    {
                        notificationService.Add(notification);
                    }
                    else
                    {
                        notifications.Remove(notification);
                    }
                }
                rockContext.SaveChanges();

                var notificationRecipientService = new NotificationRecipientService(rockContext);
                foreach (var notification in notifications)
                {
                    foreach (var member in group.Members)
                    {
                        if (member.Person.PrimaryAliasId.HasValue)
                        {
                            var recipientNotification = new Rock.Model.NotificationRecipient();
                            recipientNotification.NotificationId = notification.Id;
                            recipientNotification.PersonAliasId  = member.Person.PrimaryAliasId.Value;
                            notificationRecipientService.Add(recipientNotification);
                        }
                    }
                }
                rockContext.SaveChanges();
            }
        }