/// <summary> /// Creates native objects from SP list items. /// </summary> /// <typeparam name="T">Type of native object.</typeparam> /// <param name="spItems">SP list items to instantiate and map.</param> /// <param name="contentType">Content type model.</param> /// <param name="fields">Viewable fields.</param> /// <returns>Collection of native object.</returns> protected IEnumerable <T> Materialize <T>(IEnumerable <TSPListItem> spItems, MetaContentType contentType, IReadOnlyCollection <MemberRefModel> fields = null) { var mapper = contentType.GetMapper <TSPListItem>(); return(mapper.CreateAndMap <T>(spItems, fields)); }
/// <summary> /// Creates native object from SP list item. /// </summary> /// <typeparam name="T">Type of native object.</typeparam> /// <param name="spItem">SP list item to instantiate and map.</param> /// <param name="contentType">Content type model.</param> /// <param name="fields">Viewable fields.</param> /// <returns>Native object.</returns> protected T Materialize <T>(TSPListItem spItem, MetaContentType contentType, IReadOnlyCollection <MemberRefModel> fields = null) { var mapper = contentType.GetMapper <TSPListItem>(); return((T)mapper.CreateAndMap(spItem, fields)); }
/// <summary> /// Initializes a new instance of the <see cref="TypeMapper{TSPItem}"/> for the specified SP ContentType. /// </summary> /// <param name="contentType">ContentType to map.</param> /// <exception cref="ArgumentNullException"><paramref name="contentType"/> is null.</exception> protected TypeMapper([NotNull] MetaContentType contentType) { Guard.CheckNotNull(nameof(contentType), contentType); ContentType = contentType; TypeCreator = InstanceCreationUtility.GetCreator <object>(contentType.EntityType); }
private static string GetMessage(MetaContentType contentType) { Guard.CheckNotNull(nameof(contentType), contentType); return ($"Unable to find or load content type ${contentType.Id} in list ${contentType.List.Url} that located at SP site ${contentType.List.Context.Url}."); }
public MetaField GetMetaField(MetaContentType parent) => new MetaField(parent, _member, string.IsNullOrEmpty(_fieldAttribute.Name) ? _member.Name : _fieldAttribute.Name) { CustomConverterType = _fieldAttribute.CustomConverterType, TypeAsString = _fieldAttribute.FieldType };
MetaField IMetaFieldProvider.GetMetaField(MetaContentType parent) { var internalName = string.IsNullOrEmpty(_internalName) ? _member.Name : _internalName; return(new MetaField(parent, _member, internalName) { TypeAsString = _typeAsString, CustomConverterType = _customConverterType }); }
/// <summary> /// Visit <see cref="MetaContentType"/> /// </summary> /// <param name="contentType">ContentType to visit.</param> public virtual void VisitContentType(MetaContentType contentType) { if (contentType == null) { return; } foreach (var model in (IEnumerable <MetaField>)contentType.Fields) { VisitField(model); } }
/// <summary> /// Updates view fields in query if they were't specified. /// </summary> /// <param name="query">Query to update view fields.</param> /// <param name="contentType">Content type that provides list of fields to load.</param> protected void UpdateViewFields([NotNull] QueryModel query, [NotNull] MetaContentType contentType) { if (!query.SelectableFields.IsNullOrEmpty()) { return; } var viewFields = ((IEnumerable <MetaField>)contentType.Fields) .Select(n => new MemberRefModel(n.Member)) .ToList(); query.MergeSelectableFields(viewFields); }
/// <summary> /// Converts query model to CAML-string in next format <![CDATA[<View><Query></Query></View>]]>. /// </summary> /// <param name="queryModel">Query model to convert.</param> /// <param name="contentType">Content type to use as a fields source.</param> /// <returns>CAML-string in next format <![CDATA[<View><Query></Query></View>]]></returns> protected string ConvertToCamlString([NotNull] QueryModel queryModel, [NotNull] MetaContentType contentType) { if (FilterByContentType && !List.IsExternal) { queryModel.MergeWheres(new ComparisonModel(ComparisonOperator.Eq, new ContentTypeIdRefModel(), contentType.Id) { IsValueConverted = true }); } return(new CamlQueryTranslator(contentType).Process(queryModel)); }
protected override ListItem GetInternal(int id, MetaContentType contentType) { var spItem = _spList.GetItemById(id); _clientContext.Load(spItem, n => n, n => n.ContentType.StringId); _clientContext.ExecuteQuery(); if (FilterByContentType && spItem.ContentType.StringId != contentType.Id) { throw new InvalidOperationException("ContentType mismatch"); } return(spItem); }
public override void VisitContentType(MetaContentType contentType) { var spContentType = SpList.ContentTypes .Where(n => n.StringId.StartsWith(contentType.Id ?? "0x01")) .OrderBy(n => n.StringId.Length) .FirstOrDefault(); if (spContentType == null) { throw new ContentTypeNotFoundException(contentType); } contentType.Id = spContentType.Id.ToString(); contentType.Name = spContentType.Name; base.VisitContentType(contentType); }
public ClientTypeMapper(MetaContentType contentType) : base(contentType) { }
/// <summary> /// Fetchs SP list item by specified ID. /// </summary> /// <param name="id">Item ID to load.</param> /// <param name="contentType">Expected item content type info.</param> /// <returns>Loaded SP list item.</returns> protected abstract TSPListItem GetInternal(int id, MetaContentType contentType);
public override void VisitContentType(MetaContentType contentType) { contentType.SetMapper(new ClientTypeMapper(contentType)); base.VisitContentType(contentType); }
/// <summary> /// Initializes a new instance of the <see cref="ContentTypeNotFoundException"/> class with the specified <see cref="MetaContentType"/>. /// </summary> /// <param name="contentType">Meta content type that wasn't found or loaded.</param> public ContentTypeNotFoundException(MetaContentType contentType) : base(GetMessage(contentType)) { }
/// <summary> /// Initializes a new instance of the <see cref="ContentTypeNotFoundException"/> class with the specified <see cref="MetaContentType"/> /// and a reference to the inner exception that is the cause of this exception. /// </summary> /// <param name="contentType">Meta content type that wasn't found or loaded.</param> /// <param name="innerException">The exception that is the casue of this exception.</param> public ContentTypeNotFoundException(MetaContentType contentType, Exception innerException) : base(GetMessage(contentType), innerException) { }
public CamlQueryTranslator([NotNull] MetaContentType contentType) { Guard.CheckNotNull(nameof(contentType), contentType); ContentType = contentType; }