Beispiel #1
0
        public void Process(IEnumerable <CsvDbUpdateModel> data, bool updateExisting)
        {
            using (var ts = QPConfiguration.CreateTransactionScope(IsolationLevel.ReadCommitted))
                using (new QPConnectionScope())
                {
                    var articlesData = new List <ArticleData>();
                    foreach (var csvFileData in data)
                    {
                        foreach (var csvRowFields in csvFileData.Fields.Values)
                        {
                            var dbFields  = GetFieldsByNames(csvFileData.ContentId, csvRowFields);
                            var dataToAdd = CreateArticleDatas(csvFileData.ContentId, csvRowFields, dbFields, updateExisting);
                            dataToAdd = InsertFields(csvFileData.ContentId, dataToAdd, dbFields, csvRowFields);
                            foreach (var extensionContentId in dataToAdd.Where(ad => ad.ContentId != csvFileData.ContentId).Select(ad => ad.ContentId))
                            {
                                var contentNamePrefix = $"{_contentRepository.GetById(extensionContentId).Name}.";
                                var extensionDbFields = GetFieldsByNames(extensionContentId, csvRowFields, contentNamePrefix);
                                dataToAdd = InsertFields(extensionContentId, dataToAdd, extensionDbFields, csvRowFields, contentNamePrefix);
                            }

                            articlesData.AddRange(dataToAdd);
                        }
                    }

                    articlesData = FilterNotExistedReferences(articlesData);
                    _articleService.BatchUpdate(articlesData);
                    ts.Complete();
                }
        }
Beispiel #2
0
        public MultistepActionStepResult Step(int step)
        {
            var settings = HttpContext.Session.GetValue <ImportSettings>(HttpContextSession.ImportSettingsSessionKey);

            Ensure.NotNull(settings);

            var reader = new CsvReader(SiteId, ContentId, settings);
            var result = new MultistepActionStepResult();

            using (var ts = QPConfiguration.CreateTransactionScope(IsolationLevel.ReadCommitted))
            {
                using (new QPConnectionScope())
                {
                    try
                    {
                        reader.Process(step, ItemsPerStep, out var processedItemsCount);
                        var lastStep = step * ItemsPerStep >= reader.ArticleCount - ItemsPerStep;
                        if (lastStep)
                        {
                            ContentRepository.UpdateContentModification(ContentId);
                            reader.PostUpdateM2MRelationAndO2MRelationFields();
                        }

                        settings = HttpContext.Session.GetValue <ImportSettings>(HttpContextSession.ImportSettingsSessionKey);

                        var logData = new ImportArticlesLogData()
                        {
                            Id = settings.Id,
                            InsertedArticleIds = settings.InsertedArticleIds.ToArray(),
                            UpdatedArticleIds  = settings.UpdatedArticleIds.ToArray(),
                            ImportAction       = (CsvImportMode)settings.ImportAction
                        };

                        ImportLogger.Trace()
                        .Message("Import articles step: {step}.", step)
                        .Property("result", logData)
                        .Property("customerCode", QPContext.CurrentCustomerCode)
                        .Write();

                        result.ProcessedItemsCount = processedItemsCount;
                        result.TraceResult         = reader.GetTraceResult();
                        result.AdditionalInfo      = $"{MultistepActionStrings.InsertedArticles}: {settings.InsertedArticleIds.Count}; {MultistepActionStrings.UpdatedArticles}: {settings.UpdatedArticleIds.Count}.";
                    }
                    catch (Exception ex)
                    {
                        throw new ImportException(string.Format(ImportStrings.ImportInterrupted, ex.Message, reader.LastProcessed), ex, settings);
                    }
                }

                ts.Complete();
            }

            return(result);
        }
Beispiel #3
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var qpController = filterContext.Controller as QPController;

            if (qpController == null || !filterContext.HttpContext.IsXmlDbUpdateReplayAction())
            {
                if (Mode == ConnectionScopeMode.TransactionOn)
                {
                    var transactionScope = QPConfiguration.CreateTransactionScope();
                    SetTransactionScope(filterContext.HttpContext, transactionScope);
                }

                SetConnectionScope(filterContext.HttpContext, new QPConnectionScope());
            }

            base.OnActionExecuting(filterContext);
        }
        public MultistepActionStepResult Step(int step)
        {
            var context = HttpContext.Session.GetValue <RecreateDynamicImagesContext>(HttpContextSession.RecreateDynamicImagesServiceProcessingContext);
            var currentProcessedImages = new HashSet <string>(context.ProcessedImages);
            var 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 = QPConfiguration.CreateTransactionScope(IsolationLevel.ReadCommitted))
                    {
                        var newValue = dimg.GetValue(dimg.GetDesiredFileName(dfs.Item2));
                        RecreateDynamicImagesRepository.UpdateDynamicFieldValue(dimg.Field.Id, dfs.Item1, newValue);

                        if (!currentProcessedImages.Contains(dfs.Item2))
                        {
                            dimg.CreateDynamicImage(baseImagePathInfo.GetPath(dfs.Item2), dfs.Item2);
                            currentProcessedImages.Add(dfs.Item2);
                            context.ProcessedImages.Add(dfs.Item2);
                        }
                        transaction.Complete();
                    }
                }

                notificationRepository.SendNotifications();
            }

            return(new MultistepActionStepResult {
                ProcessedItemsCount = dataForStep.Count()
            });
        }
Beispiel #5
0
        public virtual void Process(string xmlString, IList <string> filePathes = null)
        {
            Ensure.Argument.NotNullOrWhiteSpace(xmlString, nameof(xmlString));

            var filteredXmlDocument = FilterFromSubRootNodeDuplicates(xmlString);
            var currentDbVersion    = String.Empty;

            using (new QPConnectionScope(ConnectionInfo, _identityInsertOptions))
            {
                currentDbVersion = _appInfoRepository.GetCurrentDbVersion();
                ValidateReplayInput(filteredXmlDocument, currentDbVersion);
            }

            var filteredXmlString = filteredXmlDocument.ToNormalizedString(SaveOptions.DisableFormatting);
            var dbLogEntry        = new XmlDbUpdateLogModel
            {
                UserId   = _userId,
                Body     = filteredXmlString,
                FileName = filePathes == null ? null : string.Join(",", filePathes),
                Applied  = DateTime.Now,
                Hash     = HashHelpers.CalculateMd5Hash(filteredXmlString)
            };

            using (new ThreadStorageScopeContext())
                using (var ts = QPConfiguration.CreateTransactionScope(IsolationLevel.ReadCommitted))
                    using (new QPConnectionScope(ConnectionInfo, _identityInsertOptions))
                    {
                        if (_dbLogService.IsFileAlreadyReplayed(dbLogEntry.Hash))
                        {
                            var throwEx = new XmlDbUpdateLoggingException("XmlDbUpdate conflict: current xml document(s) already applied and exist at database.");
                            throwEx.Data.Add("LogEntry", dbLogEntry.ToJsonLog());
                            throw throwEx;
                        }

                        var updateId = _dbLogService.InsertFileLogEntry(dbLogEntry);
                        ReplayActionsFromXml(filteredXmlDocument.Root?.Elements(), currentDbVersion, filteredXmlDocument.Root?.Attribute(XmlDbUpdateXDocumentConstants.RootBackendUrlAttribute)?.Value, updateId);
                        ts.Complete();
                    }
        }