示例#1
0
        private ArticleField DeserializeField(Field fieldInDef, Quantumart.QP8.BLL.Field qpField, IProductDataSource productDataSource, DBConnector connector, Context context)
        {
            ArticleField field;

            if (fieldInDef is BackwardRelationField)
            {
                field = DeserializeBackwardField((BackwardRelationField)fieldInDef, productDataSource, connector, context);
            }
            else if (fieldInDef is EntityField)
            {
                field = DeserializeEntityField((EntityField)fieldInDef, qpField, productDataSource, connector, context);
            }
            else if (fieldInDef is ExtensionField)
            {
                field = DeserializeExtensionField((ExtensionField)fieldInDef, qpField, productDataSource, connector, context);
            }
            else if (fieldInDef is PlainField)
            {
                field = DeserializePlainField(qpField, productDataSource, connector);
            }
            else
            {
                throw new Exception("Неподдерживаемый тип поля: " + fieldInDef.GetType().Name);
            }

            field.ContentId = qpField.ContentId;

            field.FieldId = qpField.Id;

            field.FieldName = string.IsNullOrEmpty(fieldInDef.FieldName) ? qpField.Name : fieldInDef.FieldName;

            field.FieldDisplayName = qpField.DisplayName;

            return(field);
        }
示例#2
0
        public DefinitionTreeNode(Field fieldFromDef, string parentPath, string ownPath, bool missingInQp, bool notInDefinition)
        {
            Id = ownPath ?? parentPath + Separator + (fieldFromDef is BaseVirtualField ? VirtualFieldPrefix + fieldFromDef.FieldName : fieldFromDef.FieldId.ToString());

            text = fieldFromDef.FieldName;

            if (fieldFromDef is BackwardRelationField backwardField)
            {
                if (backwardField.Content != null)
                {
                    text += " из " + (backwardField.Content.ContentName ?? "контента " + backwardField.Content.ContentId);
                }
            }

            expanded = false;

            hasChildren = !(fieldFromDef is PlainField) && !notInDefinition && !(fieldFromDef is VirtualField);

            if (fieldFromDef is Association)
            {
                imageUrl = "images/icons/relation.gif";
                IconName = "link";
            }
            else if (fieldFromDef is BaseVirtualField)
            {
                imageUrl = "images/icons/virtualField.gif";
                IconName = "cube";
            }

            MissingInQp = missingInQp;

            NotInDefinition = notInDefinition;

            IsDictionaries = fieldFromDef is Dictionaries;
        }
示例#3
0
        /// <exception cref="NotSupportedException" />
        /// <exception cref="InvalidOperationException" />
        private JSchema GetVirtualFieldSchema(
            BaseVirtualField baseVirtualField, Content definition, SchemaContext context)
        {
            if (baseVirtualField is VirtualMultiEntityField virtualMultiEntityField)
            {
                var boundFieldKey = Tuple.Create(definition, virtualMultiEntityField.Path);

                Field boundField = context.VirtualFields[boundFieldKey];

                var contentForArrayFields = ((EntityField)boundField).Content;

                var itemSchema = new JSchema { Type = JSchemaType.Object };

                foreach (BaseVirtualField childField in virtualMultiEntityField.Fields)
                {
                    JSchema childfieldSchema = GetVirtualFieldSchema(childField, contentForArrayFields, context);

                    itemSchema.Properties[childField.FieldName] = childfieldSchema;
                }

                return new JSchema { Type = JSchemaType.Array, Items = { itemSchema } };
            }
            else if (baseVirtualField is VirtualEntityField virtualEntityField)
            {
                BaseVirtualField[] fields = virtualEntityField.Fields;

                var virtualEntityFieldSchema = new JSchema { Type = JSchemaType.Object };

                foreach (BaseVirtualField childField in fields)
                {
                    JSchema childfieldSchema = GetVirtualFieldSchema(childField, definition, context);

                    virtualEntityFieldSchema.Properties[childField.FieldName] = childfieldSchema;
                }

                return virtualEntityFieldSchema;
            }
            else if (baseVirtualField is VirtualField virtualField)
            {
                if (virtualField.Converter != null)
                {
                    return new JSchema { Type = ConvertTypeToJsType(virtualField.Converter.OutputType) };
                }
                else
                {
                    var virtualFieldKey = Tuple.Create(definition, virtualField.Path);

                    return GetFieldSchema(context.VirtualFields[virtualFieldKey], null, context, false);
                }
            }
            else
            {
                throw new NotSupportedException($"Field type {baseVirtualField.GetType()} is not supported");
            }
        }
示例#4
0
        /// <param name="qpField">Can be null</param>
        /// <exception cref="NotSupportedException" />
        /// <exception cref="InvalidOperationException" />
        private JSchema GetFieldSchema(
            Field field, Quantumart.QP8.BLL.Field qpField, SchemaContext context, bool forList)
        {
            if (qpField == null && !(field is BaseVirtualField))
            {
                qpField = _fieldService.Read(field.FieldId);
            }

            if (field is PlainField)
            {
                return GetPlainFieldSchema(qpField);
            }
            else if (field is BackwardRelationField backwardRelationalField)
            {
                JSchema backwardItemSchema = GetSchemaRecursive(backwardRelationalField.Content, context, forList);

                return AttachFieldData(qpField, new JSchema
                {
                    Type = JSchemaType.Array, Items = { backwardItemSchema }
                });
            }
            else if (field is EntityField entityField)
            {
                Content fieldContent = entityField.Content;

                if (qpField.RelationType == Quantumart.QP8.BLL.RelationType.OneToMany)
                {
                    return AttachFieldData(qpField, GetSchemaRecursive(fieldContent, context, forList));
                }
                else
                {
                    JSchema arrayItemSchema = GetSchemaRecursive(fieldContent, context, forList);

                    return AttachFieldData(qpField, new JSchema
                    {
                        Type = JSchemaType.Array, Items = { arrayItemSchema }
                    });
                }
            }
            else
            {
                throw new NotSupportedException($"Field type {field.GetType()} is not supported");
            }
        }
        public Field GetFieldByPath(string path, Content definition, out bool hasFilter, out Content parent)
        {
            var articleData = DPathProcessor.VerifyAndParseExpression(path).ToList();

            hasFilter = articleData.Any(ad => ad.FiltersData.Any());
            parent    = definition;

            Field currentField = null;

            foreach (var fieldName in articleData.Select(ad => ad.FieldName))
            {
                if (currentField != null)
                {
                    var currentEntityField = currentField as EntityField;
                    if (currentEntityField == null)
                    {
                        throw new Exception("Schema generator requires virtual field to relate to EntityField type or its descendant");
                    }

                    parent = currentEntityField.Content;
                }

                var nonVirtualFields = parent.Fields.Where(x => !(x is BaseVirtualField)).ToArray();
                if (nonVirtualFields.All(x => x.FieldName != fieldName) && parent.LoadAllPlainFields)
                {
                    var allPlainFields = _fieldService.List(parent.ContentId).Where(x => x.RelationType == RelationType.None);
                    currentField = new PlainField
                    {
                        FieldId   = allPlainFields.Single(x => x.Name == fieldName).Id,
                        FieldName = fieldName
                    };
                }
                else
                {
                    currentField = nonVirtualFields.Single(x => x.FieldName == fieldName);
                }
            }

            return(currentField);
        }
示例#6
0
        public ActionResult SaveField(DefinitionFieldInfo defInfo)
        {
            var rootContent = (Content)XamlConfigurationParser.CreateFrom(defInfo.Xml);

            var savedField = _definitionEditorService.UpdateOrDeleteField(rootContent, defInfo.GetField(), defInfo.Path, !defInfo.InDefinition);

            string resultXml = XamlConfigurationParser.Save(rootContent);

            ModelState.Clear();

            Field fieldForEditView = savedField ?? (Field)_definitionEditorService.GetObjectFromPath(rootContent, defInfo.Path, out _);

            return(new ContentResult()
            {
                ContentType = "application/json",
                Content = JsonConvert.SerializeObject(new DefinitionFieldInfo(fieldForEditView)
                {
                    InDefinition = defInfo.InDefinition,
                    Path = defInfo.Path,
                    Xml = resultXml
                })
            });
        }
示例#7
0
        private int[] GetParentArticleIds(int childContentId, int[] childArticleIds, Field parentField, out int parentsContentId)
        {
            if (childArticleIds == null || childArticleIds.Length == 0)
            {
                parentsContentId = 0;

                return(new int[0]);
            }

            if (parentField is BackwardRelationField)
            {
                var childArticleField = _fieldService.Read(parentField.FieldId);

                if (!childArticleField.RelateToContentId.HasValue)
                {
                    throw new Exception("Некорректный BackwardRelationField: RelateToContentId у fieldId=" + childArticleField.Id + " null");
                }

                parentsContentId = childArticleField.RelateToContentId.Value;

                if (childArticleField.RelationType == RelationType.ManyToMany)
                {
                    return(GetManyToManyLinkedItems(childArticleField.LinkId, childArticleIds));
                }
                else if (childArticleField.RelationType == RelationType.OneToMany)
                {
                    return(_articleService.GetFieldValues(childArticleIds, childContentId, childArticleField.Name)
                           .Where(x => !string.IsNullOrEmpty(x))
                           .Select(int.Parse)
                           .Distinct()
                           .ToArray());
                }
                else
                {
                    throw new Exception("Некорректный BackwardRelationField с ID=" + parentField.FieldId);
                }
            }
            else if (parentField is ExtensionField)
            {
                var parentArticleField = _fieldService.Read(parentField.FieldId);

                parentsContentId = parentArticleField.ContentId;

                var childField = _fieldService.List(childContentId).Single(x => x.ClassifierId == parentField.FieldId);

                return(_articleService.GetFieldValues(childArticleIds, childContentId, childField.Name)
                       .Where(x => !string.IsNullOrEmpty(x))
                       .Select(int.Parse)
                       .ToArray());
            }
            else if (parentField is EntityField)
            {
                var parentArticleField = _fieldService.Read(parentField.FieldId);

                parentsContentId = parentArticleField.ContentId;

                switch (parentArticleField.RelationType)
                {
                case RelationType.OneToMany:

                    return(_articleService.GetRelatedItemsMultiple(parentField.FieldId, childArticleIds, true)
                           .SelectMany(x => Converter.ToIdArray(x.Value))
                           .Distinct()
                           .ToArray());

                case RelationType.ManyToMany:

                    return(GetManyToManyLinkedItems(parentArticleField.LinkId, childArticleIds));

                case RelationType.ManyToOne:

                    if (!parentArticleField.BackRelationId.HasValue)
                    {
                        throw new Exception("Связь ManyToMany некорректно настроена у fieldId=" + parentField.FieldId + ": BackRelationId null");
                    }

                    return(_articleService.GetFieldValues(childArticleIds, childContentId, parentArticleField.BackRelationId.Value)
                           .Where(x => !string.IsNullOrEmpty(x))
                           .Distinct()
                           .Select(int.Parse)
                           .ToArray());

                default:
                    throw new Exception("Связь типа " + parentArticleField.RelationType + " не поддерживается");
                }
            }
            else
            {
                throw new Exception("Тип поля " + parentField.GetType().Name + " не поддерживается");
            }
        }