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); }
/// <summary> /// /// </summary> /// <param name="rootContent"></param> /// <param name="notFoundInDef"></param> /// <param name="entityIds">int c id поля для невиртуальных полей и string с именем поля для виртуальных</param> /// <returns></returns> private object GetObjectFromDef(Content rootContent, out bool notFoundInDef, IEnumerable <object> entityIds) { object[] entityIdsToSearch = entityIds .Skip(1) //корень ровно один поэтому первый компонент пути нам не нужен .ToArray(); object currentPositionObj = rootContent; notFoundInDef = false; foreach (object entityId in entityIdsToSearch) { if (currentPositionObj is Content) { var currContent = (Content)currentPositionObj; if (entityId is int) { currentPositionObj = currContent.Fields.SingleOrDefault(x => x.FieldId == (int)entityId); } else { currentPositionObj = currContent.Fields.SingleOrDefault(x => x.FieldName == (string)entityId && x is BaseVirtualField); } if (currentPositionObj == null) { //дурацкая система что Dictionaries это поле с id=0 if (entityId is int && (int)entityId == 0) { notFoundInDef = true; return(new Dictionaries()); } if (entityId is int) { int enitityIdInt = (int)entityId; var qpField = _fieldService.Read(enitityIdInt); if (qpField == null) { notFoundInDef = true; return(null); } if (qpField.RelationType == RelationType.None && !qpField.IsClassifier) { currentPositionObj = new PlainField { FieldId = enitityIdInt, FieldName = qpField.Name }; notFoundInDef = !currContent.LoadAllPlainFields; } else { using (_fieldService.CreateQpConnectionScope()) { if (qpField.ContentId == currContent.ContentId) { if (!qpField.IsClassifier) { currentPositionObj = new EntityField { FieldId = enitityIdInt, FieldName = qpField.Name, CloningMode = CloningMode.UseExisting, Content = new Content { ContentId = qpField.RelateToContentId.Value, ContentName = qpField.RelatedToContent.Name } } } } ; else { currentPositionObj = new ExtensionField { FieldId = qpField.Id, FieldName = qpField.Name, CloningMode = CloningMode.UseExisting }; var classifierContents = _fieldService.ListRelated(qpField.ContentId) .Where(x => x.Aggregated) .Select(x => x.Content); foreach (var classifierContent in classifierContents) { ((ExtensionField)currentPositionObj).ContentMapping.Add( classifierContent.Id, new Content { ContentId = classifierContent.Id, ContentName = classifierContent.Name }); } } else { currentPositionObj = new BackwardRelationField { FieldId = qpField.Id, FieldName = qpField.Name, Content = new Content { ContentId = qpField.ContentId, ContentName = qpField.Content.Name }, CloningMode = CloningMode.UseExisting }; } } notFoundInDef = !qpField.IsClassifier || !currContent.LoadAllPlainFields; } }