Пример #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();
                }
            }
        }
Пример #2
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();

            }
        }
Пример #3
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();
                    }
                }
            }
        }