Example #1
0
        public Article Deserialize(IProductDataSource productDataSource, Models.Configuration.Content definition)
        {
            using (var cs = new QPConnectionScope(_customer.ConnectionString, (Quantumart.QP8.Constants.DatabaseType)_customer.DatabaseType))
            {
                _cacheItemWatcher.TrackChanges();

                _contentService.LoadStructureCache(_contextStorage);

                var connector = new DBConnector(cs.DbConnection);

                var context = new Context();
                var article = DeserializeArticle(productDataSource, definition, connector, context);
                context.UpdateExtensionArticles();
                return(article);
            }
        }
Example #2
0
        private Article DeserializeArticle(IProductDataSource productDataSource, Models.Configuration.Content definition, DBConnector connector, Context context)
        {
            if (productDataSource == null)
            {
                return(null);
            }

            int id = productDataSource.GetArticleId();

            context.TakeIntoAccount(id);

            var qpContent = _contentService.Read(definition.ContentId);

            Article article = new Article
            {
                Id                 = id,
                ContentName        = qpContent.NetName,
                Modified           = productDataSource.GetModified(),
                ContentId          = definition.ContentId,
                ContentDisplayName = qpContent.Name,
                PublishingMode     = definition.PublishingMode,
                IsReadOnly         = definition.IsReadOnly,
                Visible            = true
            };

            foreach (Field fieldInDef in definition.Fields.Where(x => !(x is BaseVirtualField) && !(x is Dictionaries)))
            {
                var field = DeserializeField(fieldInDef, _fieldService.Read(fieldInDef.FieldId), productDataSource, connector, context);

                article.Fields[field.FieldName] = field;
            }

            if (definition.LoadAllPlainFields)
            {
                var qpFields = _fieldService.List(definition.ContentId);

                foreach (var plainFieldFromQp in qpFields.Where(x => x.RelationType == RelationType.None && definition.Fields.All(y => y.FieldId != x.Id)))
                {
                    article.Fields[plainFieldFromQp.Name] = DeserializeField(new PlainField {
                        FieldId = plainFieldFromQp.Id
                    }, plainFieldFromQp, productDataSource, connector, context);
                }
            }

            return(article);
        }
Example #3
0
        private ArticleField DeserializeExtensionField(ExtensionField fieldInDef, Quantumart.QP8.BLL.Field qpField, IProductDataSource productDataSource, DBConnector connector, Context context)
        {
            var extensionArticleField = new ExtensionArticleField();

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

            string contentName = productDataSource.GetString(fieldName);

            if (!string.IsNullOrEmpty(contentName))
            {
                Models.Configuration.Content valueDef = fieldInDef.ContentMapping.Values.FirstOrDefault(x => _contentService.Read(x.ContentId).NetName == contentName);

                if (valueDef == null)
                {
                    throw new Exception(
                              $"'{contentName}' value is not found in an available extension content list, id = {fieldInDef.FieldId}");
                }

                extensionArticleField.Value        = valueDef.ContentId.ToString();
                extensionArticleField.SubContentId = valueDef.ContentId;

                IProductDataSource extensionDataSource = productDataSource.GetExtensionContainer(fieldName, contentName);

                extensionArticleField.Item = DeserializeArticle(extensionDataSource, valueDef, connector, context);

                if (extensionArticleField.Item.Id == productDataSource.GetArticleId())
                {
                    var id = GetExtensionId(connector, valueDef.ContentId, fieldInDef.FieldId, extensionArticleField.Item.Id);

                    if (id.HasValue)
                    {
                        extensionArticleField.Item.Id = id.Value;
                    }
                    else
                    {
                        context.AddExtensionArticle(extensionArticleField.Item.Id, extensionArticleField.Item);
                        extensionArticleField.Item.Id = default(int);
                    }
                }
            }

            return(extensionArticleField);
        }
Example #4
0
 public ProductManager(IProductDataSource productDataSource)
 {
     this._productDataSource = productDataSource;
 }
Example #5
0
 public ProductsController(IProductDataSource products)
 {
     _products = products;
 }
Example #6
0
        private ArticleField DeserializeEntityField(EntityField fieldInDef, Quantumart.QP8.BLL.Field qpField, IProductDataSource productDataSource, DBConnector connector, Context context)
        {
            string fieldName = fieldInDef.FieldName ?? qpField.Name;

            ArticleField articleField;

            if (qpField.RelationType == RelationType.OneToMany)
            {
                articleField = new SingleArticleField
                {
                    Item         = DeserializeArticle(productDataSource.GetContainer(fieldName), fieldInDef.Content, connector, context),
                    Aggregated   = qpField.Aggregated,
                    SubContentId = fieldInDef.Content.ContentId
                };
            }
            else if (qpField.RelationType == RelationType.ManyToMany || qpField.RelationType == RelationType.ManyToOne)
            {
                var multiArticleField = new MultiArticleField {
                    SubContentId = fieldInDef.Content.ContentId
                };

                var containersCollection = productDataSource.GetContainersCollection(fieldName);

                if (containersCollection != null)
                {
                    foreach (Article article in containersCollection.Select(x => DeserializeArticle(x, fieldInDef.Content, connector, context)))
                    {
                        multiArticleField.Items.Add(article.Id, article);
                    }
                }

                articleField = multiArticleField;
            }
            else
            {
                throw new Exception(string.Format("Field definition id={0} has EntityField type but its RelationType is not valid", fieldInDef.FieldId));
            }

            return(articleField);
        }
Example #7
0
        private ArticleField DeserializeBackwardField(BackwardRelationField fieldInDef, IProductDataSource productDataSource, DBConnector connector, Context context)
        {
            if (string.IsNullOrEmpty(fieldInDef.FieldName))
            {
                throw new Exception("BackwardArticleField definition should have non-empty FieldName");
            }

            IEnumerable <IProductDataSource> containersCollection = productDataSource.GetContainersCollection(fieldInDef.FieldName);

            var backwardArticleField = new BackwardArticleField
            {
                SubContentId = fieldInDef.Content.ContentId,
            };

            if (containersCollection != null)
            {
                foreach (Article article in containersCollection.Select(x => DeserializeArticle(x, fieldInDef.Content, connector, context)))
                {
                    backwardArticleField.Items.Add(article.Id, article);
                }
            }

            return(backwardArticleField);
        }
Example #8
0
        private ArticleField DeserializePlainField(Quantumart.QP8.BLL.Field plainFieldFromQP, IProductDataSource productDataSource, DBConnector connector)
        {
            var field = new PlainArticleField
            {
                PlainFieldType = (PlainFieldType)plainFieldFromQP.ExactType
            };

            switch (field.PlainFieldType)
            {
            case PlainFieldType.Date:
            case PlainFieldType.DateTime:

                DateTime?dt = productDataSource.GetDateTime(plainFieldFromQP.Name);

                if (dt.HasValue)
                {
                    field.Value = dt.ToString();

                    field.NativeValue = dt;
                }
                break;

            case PlainFieldType.Numeric:
            case PlainFieldType.O2MRelation:
            {
                object number;
                if (plainFieldFromQP.IsInteger ||
                    plainFieldFromQP.RelationType == RelationType.OneToMany)
                {
                    number = productDataSource.GetInt(plainFieldFromQP.Name);
                }
                else
                {
                    var dec = productDataSource.GetDecimal(plainFieldFromQP.Name);
                    number = !plainFieldFromQP.IsDecimal && dec.HasValue ? (object)Convert.ToDouble(dec) : dec;
                }

                if (number != null)
                {
                    field.Value = number.ToString();

                    field.NativeValue = number;
                }
            }
            break;

            case PlainFieldType.Image:
                string imageUrl = productDataSource.GetString(plainFieldFromQP.Name);

                if (imageUrl != null)
                {
                    string imageName = Common.GetFileNameByUrl(connector, plainFieldFromQP.Id, imageUrl);
                    field.NativeValue = field.Value = imageName;
                }
                break;

            case PlainFieldType.File:
                if (productDataSource is EditorJsonProductDataSource)
                {
                    string fileName = productDataSource.GetString(plainFieldFromQP.Name);
                    field.NativeValue = field.Value = fileName;
                }
                else
                {
                    IProductDataSource fileContainer = productDataSource.GetContainer(plainFieldFromQP.Name);

                    if (fileContainer != null)
                    {
                        string fileUrl  = fileContainer.GetString("AbsoluteUrl");
                        string fileName = Common.GetFileNameByUrl(connector, plainFieldFromQP.Id, fileUrl);
                        field.NativeValue = field.Value = fileName;
                    }
                }
                break;

            case PlainFieldType.Boolean:
            {
                decimal?number = productDataSource.GetDecimal(plainFieldFromQP.Name);

                if (number != null)
                {
                    field.Value = number.ToString();

                    field.NativeValue = number;
                }
            }
            break;

            default:
                field.NativeValue = field.Value = productDataSource.GetString(plainFieldFromQP.Name);
                break;
            }

            field.Value = field.Value ?? string.Empty;

            return(field);
        }
Example #9
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);
        }
Example #10
0
 public HealthController(IProductDataSource products)
 {
     _products = products;
 }
Example #11
0
 public ProductsCache(IProductDataSource productDataSource,
                      ProductsLocalRepo productsLocalRepo)
 {
     _remoteSrc = productDataSource;
     _localRepo = productsLocalRepo;
 }
Example #12
0
 public ProductService(IProductDataSource dataSource)
 {
     _dataSource = dataSource;
 }
Example #13
0
 public ProductsController(IProductDataSource productDataSource)
 {
     _productDataSource = productDataSource;
 }