Example #1
0
        public MultistepActionStepResult Step(int step)
        {
            var context    = (FieldDefaultValueContext)HttpContext.Current.Session[HttpContextSession.FieldDefaultValueServiceProcessingContext];
            var idsForStep = context.ProcessedContentItemIds
                             .Skip(step * ItemsPerStep)
                             .Take(ItemsPerStep)
                             .ToList();

            if (idsForStep.Any())
            {
                var notificationRepository = new NotificationPushRepository {
                    IgnoreInternal = true
                };
                notificationRepository.PrepareNotifications(context.ContentId, idsForStep.ToArray(), NotificationCode.Update);
                FieldDefaultValueRepository.SetDefaultValue(context.ContentId, context.FieldId, context.IsBlob, context.IsM2M, idsForStep, context.Symmetric);
                notificationRepository.SendNotifications();
            }

            return(new MultistepActionStepResult {
                ProcessedItemsCount = idsForStep.Count
            });
        }
Example #2
0
        public MultistepActionSettings SetupAction(int contentId, int fieldId)
        {
            var field = FieldRepository.GetById(fieldId);

            if (field == null)
            {
                throw new ApplicationException(string.Format(FieldStrings.FieldNotFound, fieldId));
            }

            var contentItemIdsToProcess = FieldDefaultValueRepository.GetItemIdsToProcess(contentId, fieldId, field.DefaultValue, field.IsBlob, field.ExactType == FieldExactTypes.M2MRelation);
            var itemIdsToProcess        = contentItemIdsToProcess as int[] ?? contentItemIdsToProcess.ToArray();
            var itemCount = itemIdsToProcess.Length;
            var stepCount = MultistepActionHelper.GetStepCount(itemCount, ItemsPerStep);
            var context   = new FieldDefaultValueContext
            {
                ProcessedContentItemIds = itemIdsToProcess.ToArray(),
                ContentId       = contentId,
                FieldId         = fieldId,
                IsBlob          = field.IsBlob,
                IsM2M           = field.ExactType == FieldExactTypes.M2MRelation,
                DefaultArticles = field.DefaultArticleIds.ToArray(),
                Symmetric       = field.ContentLink.Symmetric
            };

            HttpContext.Current.Session[HttpContextSession.FieldDefaultValueServiceProcessingContext] = context;
            return(new MultistepActionSettings
            {
                Stages = new[]
                {
                    new MultistepStageSettings
                    {
                        Name = FieldStrings.ApplyDefaultValueStageName,
                        StepCount = stepCount,
                        ItemCount = itemCount
                    }
                }
            });
        }