示例#1
0
        protected void ProcessAccountArchivedStatuses(
            Guid accountId,
            AccountDbContext accountDbContext,
            User[] users,
            Dictionary <Guid, Component> components,
            Dictionary <Guid, Subscription[]> userToSubscriptions,
            ILogger logger,
            Guid?componentId = null)
        {
            // получим архивные статусы
            var archivedStatusRepository = accountDbContext.GetArchivedStatusRepository();

            var archivedStatuses = archivedStatusRepository
                                   .GetTop(1000)
                                   .Include(x => x.Event)
                                   .ToArray();

            if (componentId.HasValue)
            {
                archivedStatuses = archivedStatuses.Where(t => t.Event.OwnerId == componentId.Value).ToArray();
            }

            var now      = Now();
            var statuses = new List <StatusInfo>(archivedStatuses.Length);

            foreach (var archivedStatus in archivedStatuses)
            {
                DbProcessor.CancellationToken.ThrowIfCancellationRequested();

                var eventObj = archivedStatus.Event;
                components.TryGetValue(eventObj.OwnerId, out var component);

                if (component == null)
                {
                    continue;
                }

                // удалим, чтобы больше не обрабатывать
                archivedStatusRepository.Delete(archivedStatus);

                var status = StatusInfo.Create(eventObj, component, now);
                statuses.Add(status);
            }

            ProcessAccountInternal(
                accountId,
                users,
                userToSubscriptions,
                statuses,
                accountDbContext,
                logger);
        }
示例#2
0
        protected void ProcessAccountCurrentStatuses(
            Guid accountId,
            AccountDbContext accountDbContext,
            User[] users,
            Dictionary <Guid, Subscription[]> userToSubscriptions,
            ILogger logger,
            Guid?componentId = null)
        {
            // получим колбаски компонентов
            var statusDatas = accountDbContext.Bulbs
                              .Where(x => x.EventCategory == EventCategory.ComponentExternalStatus &&
                                     x.IsDeleted == false &&
                                     x.Component.IsDeleted == false)
                              .ToArray();

            if (componentId.HasValue)
            {
                statusDatas = statusDatas.Where(t => t.ComponentId == componentId.Value).ToArray();
            }

            var now      = Now();
            var statuses = new List <StatusInfo>(statusDatas.Length);

            foreach (var statusData in statusDatas)
            {
                DbProcessor.CancellationToken.ThrowIfCancellationRequested();

                var component = statusData.Component;
                if (component == null)
                {
                    continue;
                }
                var status = StatusInfo.Create(statusData, component, now);
                statuses.Add(status);
            }

            ProcessAccountInternal(
                accountId,
                users,
                userToSubscriptions,
                statuses,
                accountDbContext,
                logger);
        }