示例#1
0
        protected override async Task SendQueryNotificationsAsync(ChangeType changeType, IRepositoryQuery query, ICommandOptions options)
        {
            if (!NotificationsEnabled || !options.ShouldNotify())
            {
                return;
            }

            var delay         = TimeSpan.FromSeconds(1.5);
            var organizations = query.GetOrganizations();
            var projects      = query.GetProjects();
            var stacks        = query.GetStacks();
            var ids           = query.GetIds();

            if (ids.Count > 0)
            {
                foreach (string id in ids)
                {
                    await PublishMessageAsync(new ExtendedEntityChanged {
                        ChangeType     = changeType,
                        Id             = id,
                        OrganizationId = organizations.Count == 1 ? organizations.Single() : null,
                        ProjectId      = projects.Count == 1 ? projects.Single() : null,
                        StackId        = stacks.Count == 1 ? stacks.Single() : null,
                        Type           = EntityTypeName
                    }, delay).AnyContext();
                }

                return;
            }

            if (stacks.Count > 0)
            {
                foreach (string stackId in stacks)
                {
                    await PublishMessageAsync(new ExtendedEntityChanged {
                        ChangeType     = changeType,
                        OrganizationId = organizations.Count == 1 ? organizations.Single() : null,
                        ProjectId      = projects.Count == 1 ? projects.Single() : null,
                        StackId        = stackId,
                        Type           = EntityTypeName
                    }, delay).AnyContext();
                }

                return;
            }

            if (projects.Count > 0)
            {
                foreach (string projectId in projects)
                {
                    await PublishMessageAsync(new ExtendedEntityChanged {
                        ChangeType     = changeType,
                        OrganizationId = organizations.Count == 1 ? organizations.Single() : null,
                        ProjectId      = projectId,
                        Type           = EntityTypeName
                    }, delay).AnyContext();
                }

                return;
            }

            if (organizations.Count > 0)
            {
                foreach (string organizationId in organizations)
                {
                    await PublishMessageAsync(new ExtendedEntityChanged {
                        ChangeType     = changeType,
                        OrganizationId = organizationId,
                        Type           = EntityTypeName
                    }, delay).AnyContext();
                }

                return;
            }

            await PublishMessageAsync(new EntityChanged {
                ChangeType = changeType,
                Type       = EntityTypeName
            }, delay).AnyContext();
        }
示例#2
0
        protected override Task SendQueryNotificationsAsync(ChangeType changeType, IRepositoryQuery query, ICommandOptions options)
        {
            if (!NotificationsEnabled || !options.ShouldNotify())
            {
                return(Task.CompletedTask);
            }

            var delay         = TimeSpan.FromSeconds(1.5);
            var organizations = query.GetOrganizations();
            var projects      = query.GetProjects();
            var stacks        = query.GetStacks();
            var ids           = query.GetIds();
            var tasks         = new List <Task>();

            string organizationId = organizations.Count == 1 ? organizations.Single() : null;

            if (ids.Count > 0)
            {
                string projectId = projects.Count == 1 ? projects.Single() : null;
                string stackId   = stacks.Count == 1 ? stacks.Single() : null;

                foreach (string id in ids)
                {
                    tasks.Add(PublishMessageAsync(CreateEntityChanged(changeType, organizationId, projectId, stackId, id), delay));
                }

                return(Task.WhenAll(tasks));
            }

            if (stacks.Count > 0)
            {
                string projectId = projects.Count == 1 ? projects.Single() : null;
                foreach (string stackId in stacks)
                {
                    tasks.Add(PublishMessageAsync(CreateEntityChanged(changeType, organizationId, projectId, stackId), delay));
                }

                return(Task.WhenAll(tasks));
            }

            if (projects.Count > 0)
            {
                foreach (string projectId in projects)
                {
                    tasks.Add(PublishMessageAsync(CreateEntityChanged(changeType, organizationId, projectId), delay));
                }

                return(Task.WhenAll(tasks));
            }

            if (organizations.Count > 0)
            {
                foreach (string organization in organizations)
                {
                    tasks.Add(PublishMessageAsync(CreateEntityChanged(changeType, organization), delay));
                }

                return(Task.WhenAll(tasks));
            }

            return(PublishMessageAsync(new EntityChanged {
                ChangeType = changeType,
                Type = EntityTypeName
            }, delay));
        }
示例#3
0
        private static string GetQueryHash(IRepositoryQuery query)
        {
            // org ids, project ids, date ranges, filter expression

            var appFilter  = query.GetAppFilter();
            var projectIds = query.GetProjects();

            if (projectIds.Count == 0 && appFilter?.Projects != null)
            {
                projectIds.AddRange(appFilter.Projects.Select(p => p.Id));
            }
            var organizationIds = query.GetOrganizations();

            if (organizationIds.Count == 0 && appFilter?.Organizations != null)
            {
                organizationIds.AddRange(appFilter.Organizations.Select(o => o.Id));
            }

            var hashCode = new HashCode();

            if (projectIds.Count > 0)
            {
                foreach (string projectId in projectIds)
                {
                    hashCode.Add(projectId);
                }
            }
            else if (organizationIds.Count > 0)
            {
                foreach (string organizationId in organizationIds)
                {
                    hashCode.Add(organizationId);
                }
            }

            var dateRanges = query.GetDateRanges();
            var minDate    = dateRanges.Min(r => r.StartDate) ?? DateTime.MinValue;
            var maxDate    = dateRanges.Max(r => r.EndDate) ?? DateTime.MaxValue;

            hashCode.Add(minDate);
            hashCode.Add(maxDate);

            hashCode.Add(query.GetFilterExpression());

            string cacheScope = "";

            if (organizationIds.Count == 1 && projectIds.Count == 1)
            {
                cacheScope = String.Concat(organizationIds.Single(), ":", projectIds.Single(), ":");
            }
            else if (organizationIds.Count == 1)
            {
                cacheScope = String.Concat(organizationIds.Single(), ":");
            }
            else if (projectIds.Count == 1)
            {
                cacheScope = String.Concat("project:", projectIds.Single(), ":");
            }

            return(String.Concat(cacheScope, hashCode.ToHashCode().ToString()));
        }