Exemplo n.º 1
0
 /// <summary>
 /// Clones this NotificationRecipient object to a new NotificationRecipient object
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="deepCopy">if set to <c>true</c> a deep copy is made. If false, only the basic entity properties are copied.</param>
 /// <returns></returns>
 public static NotificationRecipient Clone(this NotificationRecipient source, bool deepCopy)
 {
     if (deepCopy)
     {
         return(source.Clone() as NotificationRecipient);
     }
     else
     {
         var target = new NotificationRecipient();
         target.CopyPropertiesFrom(source);
         return(target);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Copies the properties from another NotificationRecipient object to this NotificationRecipient object
 /// </summary>
 /// <param name="target">The target.</param>
 /// <param name="source">The source.</param>
 public static void CopyPropertiesFrom(this NotificationRecipient target, NotificationRecipient source)
 {
     target.Id                      = source.Id;
     target.ForeignGuid             = source.ForeignGuid;
     target.ForeignKey              = source.ForeignKey;
     target.NotificationId          = source.NotificationId;
     target.PersonAliasId           = source.PersonAliasId;
     target.Read                    = source.Read;
     target.ReadDateTime            = source.ReadDateTime;
     target.CreatedDateTime         = source.CreatedDateTime;
     target.ModifiedDateTime        = source.ModifiedDateTime;
     target.CreatedByPersonAliasId  = source.CreatedByPersonAliasId;
     target.ModifiedByPersonAliasId = source.ModifiedByPersonAliasId;
     target.Guid                    = source.Guid;
     target.ForeignId               = source.ForeignId;
 }
Exemplo n.º 3
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.º 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 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();
            }
        }