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(); }
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)); }
protected virtual Task InvalidateCacheByQueryAsync(IRepositoryQuery <T> query) { return(InvalidateCacheAsync(query.GetIds())); }