public MultistepActionStepResult Step(int step) { var context = (RecreateDynamicImagesContext)HttpContext.Current.Session[HttpContextSession.RecreateDynamicImagesServiceProcessingContext]; IEnumerable <Tuple <int, string> > dataForStep = context.ArticleData.Skip(step * ItemsPerStep).Take(ItemsPerStep).ToArray(); var flds = GetFields(context.FieldId); var dimg = flds.Item1.DynamicImage; var baseImagePathInfo = flds.Item2.PathInfo; if (dataForStep.Any()) { var ids = dataForStep.Select(d => d.Item1).ToArray(); var notificationRepository = new NotificationPushRepository { IgnoreInternal = true }; notificationRepository.PrepareNotifications(context.ContentId, ids, NotificationCode.Update); foreach (var dfs in dataForStep) { using (var transaction = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted })) { var newValue = dimg.GetValue(dimg.GetDesiredFileName(dfs.Item2)); RecreateDynamicImagesRepository.UpdateDynamicFieldValue(dimg.Field.Id, dfs.Item1, newValue); if (!context.ProcessedImages.Contains(dfs.Item2)) { dimg.CreateDynamicImage(baseImagePathInfo.GetPath(dfs.Item2), dfs.Item2); context.ProcessedImages.Add(dfs.Item2); } transaction.Complete(); } } notificationRepository.SendNotifications(); } return(new MultistepActionStepResult { ProcessedItemsCount = dataForStep.Count() }); }
public MultistepActionSettings SetupAction(int contentId, int fieldId) { if (HasAlreadyRun()) { throw new ApplicationException(MultistepActionStrings.ActionHasAlreadyRun); } var flds = GetFields(fieldId); if (flds.Item1.BaseImageId != null) { var articleData = RecreateDynamicImagesRepository.GetDataToProcess(flds.Item1.BaseImageId.Value); var dataRows = articleData as DataRow[] ?? articleData.ToArray(); var context = new RecreateDynamicImagesContext { FieldId = fieldId, ContentId = contentId, ArticleData = dataRows.Select(r => Tuple.Create(Converter.ToInt32(r.Field <decimal>("ID")), r.Field <string>("DATA"))).ToArray(), ProcessedImages = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase) }; HttpContext.Current.Session[HttpContextSession.RecreateDynamicImagesServiceProcessingContext] = context; var itemCount = dataRows.Length; var stepCount = MultistepActionHelper.GetStepCount(itemCount, ItemsPerStep); return(new MultistepActionSettings { Stages = new[] { new MultistepStageSettings { Name = FieldStrings.RecreateDynamicImagesStageName, StepCount = stepCount, ItemCount = itemCount } } }); } return(null); }