Esempio n. 1
0
        public static Content Save(Content content)
        {
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }
            if (content.VirtualType == VirtualType.None)
            {
                throw new ApplicationException("Content virtual type is undefined.");
            }

            // Сохранить контент
            var helper     = new VirtualContentHelper(content.ForceVirtualFieldIds?.ToList());
            var newContent = VirtualContentRepository.Save(content);

            if (content.VirtualType == VirtualType.Join)
            {
                newContent = helper.SaveJoinContent(content, newContent);
            }
            else if (content.VirtualType == VirtualType.Union)
            {
                newContent = helper.SaveUnionContent(content, newContent);
            }
            else if (content.VirtualType == VirtualType.UserQuery)
            {
                newContent = helper.SaveUserQueryContent(content, newContent);
            }

            newContent.NewVirtualFieldIds = helper.NewFieldIds;

            return(newContent);
        }
Esempio n. 2
0
        public override MultistepActionSettings Setup(int siteId, int contentId, bool?boundToExternal)
        {
            var content = ContentRepository.GetById(contentId);

            if (content == null)
            {
                throw new ApplicationException(string.Format(SiteStrings.SiteNotFound, siteId));
            }

            List <Content.TreeItem> rebuildedViewSubContents;
            var helper = new VirtualContentHelper();

            using (VirtualFieldRepository.LoadVirtualFieldsRelationsToMemory(contentId))
            {
                rebuildedViewSubContents = helper.TraverseForUpdateVirtualSubContents(content);
            }

            _rebuildViewsCommand = new RebuildVirtualContentViewsCommand(contentId, content.Name, rebuildedViewSubContents);
            _rebuildViewsCommand.Setup();

            _rebuildUserQueryCommand = new RebuildUserQueryCommand(contentId, content.Name, rebuildedViewSubContents);
            _rebuildUserQueryCommand.Setup();

            return(base.Setup(siteId, contentId, boundToExternal));
        }
Esempio n. 3
0
        public static string UpdateVirtualContents(int oldSiteId, int newSiteId, IEnumerable <DataRow> rows)
        {
            var contentsWithErrors = new StringBuilder();

            if (rows == null)
            {
                return(string.Empty);
            }

            foreach (var row in rows)
            {
                var virtualTypeId = int.Parse(row["virtual_type"].ToString());
                var newContentId  = int.Parse(row["content_id_new"].ToString());
                var helper        = new VirtualContentHelper();
                var newContent    = ContentRepository.GetById(newContentId);
                if (virtualTypeId == VirtualType.UserQuery)
                {
                    var contentsRelations = ContentRepository.GetRelationsBetweenContents(oldSiteId, newSiteId, string.Empty).ToList();
                    var newSqlQuery       = ReplaceOldContentIdsFromQuery(contentsRelations, row["sqlquery"].ToString());
                    ContentRepository.UpdateVirtualContent(newSqlQuery, newContentId);
                    newContent.UserQuery = newSqlQuery;
                }
                try
                {
                    helper.CreateContentViews(newContent);
                }
                catch (Exception)
                {
                    contentsWithErrors.Append($"{newContent.Name}, ");
                }
            }

            return(contentsWithErrors.ToString());
        }
Esempio n. 4
0
        public static Field Update(Field item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            if (!FieldRepository.Exists(item.Id))
            {
                throw new ApplicationException(string.Format(FieldStrings.FieldNotFound, item.Id));
            }

            if (item.Content.VirtualType == VirtualType.None)
            {
                throw new ApplicationException($"Content {item.Content.Id} of field {item.Id} is not virtual.");
            }

            using (VirtualFieldRepository.LoadVirtualFieldsRelationsToMemory(item.ContentId))
            {
                var newField = ((IFieldRepository) new FieldRepository()).Update(item);
                var helper   = new VirtualContentHelper();

                helper.DropContentViews(newField.Content);
                helper.CreateContentViews(newField.Content);

                // Обновить дочерние виртуальные контенты
                helper.UpdateVirtualFields(newField);
                return(newField);
            }
        }
        public void NotRootLevelFieldName_CorrectResult_ReplacePersistentFieldNameTest()
        {
            const string expected = "m1.m2.m3.m4.Header";
            var          helper   = new VirtualContentHelper();
            var          actual   = helper.ReplacePersistentFieldName("m1.m2.m3.m4.Title", "Header");

            Assert.AreEqual(expected, actual);
        }
        public void NotRootLevelFieldName_ReturnLastPointSplitedName_GetPersistentFieldNameTest()
        {
            const string expected = "Title";
            var          helper   = new VirtualContentHelper();
            var          actual   = helper.GetPersistentFieldName("m1.m2.m3.m4.Title");

            Assert.AreEqual(expected, actual);
        }
        public void RootLevelFieldName_ReturnSameName_GetPersistentFieldNameTest()
        {
            const string expected = "Title";
            var          helper   = new VirtualContentHelper();
            var          actual   = helper.GetPersistentFieldName("Title");

            Assert.AreEqual(expected, actual);
        }
Esempio n. 8
0
        /// <summary>
        /// Проверяем только те поля, у которых пользователь изменил имя. Сравниваем только с теми полями Join-контена, у которых было изменено имя (отличается от сгенерированного)
        /// </summary>
        /// <param name="parentContent"></param>
        /// <param name="subContent"></param>
        /// <param name="checkedFields"></param>
        /// <param name="ruleViolation"></param>
        /// <param name="fieldNameComparer"></param>
        /// <param name="newRuleViolation"></param>
        private void CheckForJoin(Content parentContent, Content subContent, IEnumerable <Field> checkedFields, List <RuleViolation> ruleViolation, IEqualityComparer <Field> fieldNameComparer, Func <Field, RuleViolation> newRuleViolation)
        {
            var helper = new VirtualContentHelper();
            var virtualFieldsWithChangedName = helper.GetJoinVirtualFieldsWithChangedName(parentContent, subContent);

            // А теперь сравнить имена полей
            ruleViolation.AddRange(
                virtualFieldsWithChangedName
                .Intersect(checkedFields.Where(f => !f.IsNew && f.IsNameChanged), fieldNameComparer)
                .Select(newRuleViolation)
                );
        }
Esempio n. 9
0
        public static IEnumerable <EntityTreeItem> GetChildFieldList(ChildFieldListQuery query)
        {
            var helper = new VirtualContentHelper();

            // Дочерние поля выбранного поля
            if (!string.IsNullOrWhiteSpace(query.EntityId))
            {
                return(helper.GetChildFieldList(query.EntityId, query.ParentAlias, (f, eid, alias) => Enumerable.Empty <EntityTreeItem>()));
            }

            // рутовые поля
            if (query.VirtualContentId > 0 || query.JoinedContentId.HasValue)
            {
                return(helper.GetRootFieldList(query));
            }

            return(null);
        }
Esempio n. 10
0
        public static IEnumerable <EntityTreeItem> GetChildFieldList(int virtualContentId, int?joinedContentId, string entityId, string selectItemIDs, string parentAlias)
        {
            var helper = new VirtualContentHelper();

            // Дочерние поля выбранного поля
            if (!string.IsNullOrWhiteSpace(entityId))
            {
                return(helper.GetChildFieldList(entityId, parentAlias, (f, eid, alias) => Enumerable.Empty <EntityTreeItem>()));
            }

            // рутовые поля
            if (virtualContentId > 0 || joinedContentId.HasValue)
            {
                return(helper.GetRootFieldList(virtualContentId, joinedContentId, selectItemIDs));
            }

            return(null);
        }
Esempio n. 11
0
        public void GenerateCreateUnionViewDdlTest()
        {
            const int            contentId             = 10;
            IEnumerable <int>    unionSourceContentIDs = new[] { 1, 2 };
            IEnumerable <string> contentFieldNames     = new[] { "f1", "f2", "f3", "f4" };
            var fieldNameInSourceContents = new Dictionary <string, HashSet <int> >(StringComparer.InvariantCultureIgnoreCase)
            {
                { "f1", new HashSet <int>(new[] { 1 }) },
                { "f2", new HashSet <int>(new[] { 1 }) },
                { "f3", new HashSet <int>(new[] { 2 }) },
                { "f4", new HashSet <int>(new[] { 2 }) }
            };

            var expected = "CREATE VIEW [dbo].[content_10] AS SELECT 1 content_id,content_item_id,created,modified,last_modified_by,status_type_id,visible,archive,[f1] [f1],[f2] [f2],NULL [f3],NULL [f4] FROM dbo.content_1 UNION ALL SELECT 2 content_id,content_item_id,created,modified,last_modified_by,status_type_id,visible,archive,NULL [f1],NULL [f2],[f3] [f3],[f4] [f4] FROM dbo.content_2".ToLower();
            var helper   = new VirtualContentHelper();
            var actual   = helper.GenerateCreateUnionViewDdl(contentId, unionSourceContentIDs, contentFieldNames, fieldNameInSourceContents).ToLower();

            Assert.AreEqual(expected, actual);
        }
        public MultistepActionStepResult Step(int step)
        {
            var context = HttpContext.Current.Session[HttpContextSession.RebuildVirtualContentProcessingContext] as RebuildVirtualContentViewsCommandContext;
            var ids     = context.ContentIdsToRebuild
                          .Skip(step * ItemsPerStep)
                          .Take(ItemsPerStep)
                          .ToArray();

            var helper   = new VirtualContentHelper();
            var contents = ContentRepository.GetList(ids).ToDictionary(n => n.Id);

            foreach (var content in ids.Select(n => contents[n]))
            {
                helper.RebuildSubContentView(content);
            }

            return(new MultistepActionStepResult {
                ProcessedItemsCount = ItemsPerStep
            });
        }
Esempio n. 13
0
        /// <summary>
        /// Обновляет виртуальный контент
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        public static Content Update(Content content)
        {
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }

            var helper = new VirtualContentHelper(content.ForceVirtualFieldIds?.ToList());

            using (VirtualFieldRepository.LoadVirtualFieldsRelationsToMemory(content.Id))
            {
                // Если тип контента изменился
                // то удалить связанную с контентом информацию
                if (content.StoredVirtualType != content.VirtualType)
                {
                    helper.RemoveContentData(content);
                }

                // Обновить контент
                var dbContent = VirtualContentRepository.Update(content);

                // Спициальное обновления для конкретного типа контента
                if (content.VirtualType == VirtualType.Join)
                {
                    dbContent = helper.UpdateJoinContent(content, dbContent);
                }
                else if (content.VirtualType == VirtualType.Union)
                {
                    dbContent = helper.UpdateUnionContent(content, dbContent);
                }
                else if (content.VirtualType == VirtualType.UserQuery)
                {
                    dbContent = helper.UpdateUserQueryContent(content, dbContent);
                }

                dbContent.NewVirtualFieldIds = helper.NewFieldIds;
                return(dbContent);
            }
        }
Esempio n. 14
0
        public MultistepActionStepResult Step(int step)
        {
            var context = HttpContext.Current.Session[HttpContextSession.RebuildUserQueryCommandProcessingContext] as RebuildUserQueryCommandContext;
            var ids     = context.ContentIdsToRebuild
                          .Skip(step * ItemsPerStep)
                          .Take(ItemsPerStep)
                          .ToArray();

            var helper   = new VirtualContentHelper();
            var contents = ContentRepository.GetList(ids).ToDictionary(n => n.Id);

            using (VirtualFieldRepository.LoadVirtualFieldsRelationsToMemory(ContentId))
            {
                foreach (var content in ids.Select(n => contents[n]).Where(n => n.VirtualType == VirtualType.UserQuery))
                {
                    helper.UpdateUserQueryAsSubContent(content);
                }
            }

            return(new MultistepActionStepResult {
                ProcessedItemsCount = ItemsPerStep
            });
        }
Esempio n. 15
0
        public void ThereIsVirtualFileds_ReturnJoinVirtualContentAsyncViewDLLStatment_GenerateCreateJoinAsyncViewDDLTest()
        {
            var virtualFieldsData = new[]
            {
                new VirtualFieldData {
                    Id = 1180, Name = "Title", Type = 1, PersistentContentId = 295, PersistentId = 1152, PersistentName = "Title", RelateToPersistentContentId = null, JoinId = null
                },
                new VirtualFieldData {
                    Id = 1189, Name = "fff", Type = 1, PersistentContentId = 295, PersistentId = 1159, PersistentName = "fff", RelateToPersistentContentId = null, JoinId = null
                },

                new VirtualFieldData {
                    Id = 1181, Name = "m2m", Type = 11, PersistentContentId = 295, PersistentId = 1158, PersistentName = "m2m", RelateToPersistentContentId = 295, JoinId = null
                },
                new VirtualFieldData {
                    Id = 1182, Name = "m2m.Title", Type = 1, PersistentContentId = 295, PersistentId = 1152, PersistentName = "Title", RelateToPersistentContentId = null, JoinId = 1181
                },
                new VirtualFieldData {
                    Id = 1188, Name = "m2m.fff", Type = 1, PersistentContentId = 295, PersistentId = 1159, PersistentName = "fff", RelateToPersistentContentId = null, JoinId = 1181
                },

                new VirtualFieldData {
                    Id = 1183, Name = "m2m.m2m", Type = 11, PersistentContentId = 295, PersistentId = 1158, PersistentName = "m2m", RelateToPersistentContentId = 295, JoinId = 1181
                },
                new VirtualFieldData {
                    Id = 1184, Name = "m2m.m2m.Title", Type = 1, PersistentContentId = 295, PersistentId = 1152, PersistentName = "Title", RelateToPersistentContentId = null, JoinId = 1183
                },
                new VirtualFieldData {
                    Id = 1187, Name = "m2m.m2m.fff", Type = 1, PersistentContentId = 295, PersistentId = 1159, PersistentName = "fff", RelateToPersistentContentId = null, JoinId = 1183
                },

                new VirtualFieldData {
                    Id = 1185, Name = "kdsfjkdsfjk.m2m", Type = 11, PersistentContentId = 295, PersistentId = 1158, PersistentName = "m2m", RelateToPersistentContentId = 295, JoinId = 1183
                },
                new VirtualFieldData {
                    Id = 1186, Name = "m2m.m2m.m2m.Title", Type = 1, PersistentContentId = 295, PersistentId = 1152, PersistentName = "Title", RelateToPersistentContentId = null, JoinId = 1185
                },

                new VirtualFieldData {
                    Id = 1190, Name = "o2o", Type = 11, PersistentContentId = 295, PersistentId = 1158, PersistentName = "o2o", RelateToPersistentContentId = 300, JoinId = null
                },
                new VirtualFieldData {
                    Id = 1191, Name = "o2o.Title", Type = 1, PersistentContentId = 295, PersistentId = 1152, PersistentName = "Title", RelateToPersistentContentId = null, JoinId = 1190
                }
            };

            const int joinRootContentId = 295;
            const int virtualContentId  = 500;

            const string expected = "CREATE VIEW [dbo].[content_500_async] AS " +
                                    "SELECT c_0.CONTENT_ITEM_ID,c_0.STATUS_TYPE_ID,c_0.VISIBLE,c_0.ARCHIVE,c_0.CREATED,c_0.MODIFIED,c_0.LAST_MODIFIED_BY,c_0.[Title] as [Title],c_0.[fff] as [fff],c_0.[m2m] as [m2m]," +
                                    "c_0_0.[Title] as [m2m.Title],c_0_0.[fff] as [m2m.fff],c_0_0.[m2m] as [m2m.m2m]," +
                                    "c_0_0_0.[Title] as [m2m.m2m.Title],c_0_0_0.[fff] as [m2m.m2m.fff],c_0_0_0.[m2m] as [kdsfjkdsfjk.m2m]," +
                                    "c_0_0_0_0.[Title] as [m2m.m2m.m2m.Title]," +
                                    "c_0.[o2o] as [o2o],c_0_1.[Title] as [o2o.Title] " +
                                    "FROM dbo.CONTENT_295_async AS c_0 " +
                                    "LEFT OUTER JOIN dbo.CONTENT_295_united AS c_0_0 WITH (nolock) ON c_0_0.CONTENT_ITEM_ID = c_0.[m2m] " +
                                    "LEFT OUTER JOIN dbo.CONTENT_295_united AS c_0_0_0 WITH (nolock) ON c_0_0_0.CONTENT_ITEM_ID = c_0_0.[m2m] " +
                                    "LEFT OUTER JOIN dbo.CONTENT_295_united AS c_0_0_0_0 WITH (nolock) ON c_0_0_0_0.CONTENT_ITEM_ID = c_0_0_0.[m2m] " +
                                    "LEFT OUTER JOIN dbo.CONTENT_300_united AS c_0_1 WITH (nolock) ON c_0_1.CONTENT_ITEM_ID = c_0.[o2o] ";

            var helper = new VirtualContentHelper();
            var actual = helper.GenerateCreateJoinAsyncViewDdl(virtualContentId, joinRootContentId, virtualFieldsData);

            Assert.IsTrue(actual.Equals(expected, StringComparison.InvariantCultureIgnoreCase));
        }