/// <summary> /// Annotates the resource collection with out-of-line app:categories values. /// </summary> /// <param name="resourceCollection">The resource collection to annotate.</param> /// <param name="uri">The value of the app:categories href property.</param> /// <returns>The resource collection with the annotation applied.</returns> public static ResourceCollectionInstance AppOutOfLineCategories(this ResourceCollectionInstance resourceCollection, string uri) { ExceptionUtilities.CheckArgumentNotNull(resourceCollection, "resourceCollection"); resourceCollection.AddAnnotation(CreateAppElement("categories", null, XmlTreeAnnotation.AtomAttribute(TestAtomConstants.AtomHRefAttributeName, uri))); return(resourceCollection); }
/// <summary> /// Annotates the resource collection with app:accept values. /// </summary> /// <param name="resourceCollection">The resource collection to annotate.</param> /// <param name="value">The value of the app:accept element.</param> /// <returns>The resource collection with the annotation applied.</returns> public static ResourceCollectionInstance AppAccept(this ResourceCollectionInstance resourceCollection, string value) { ExceptionUtilities.CheckArgumentNotNull(resourceCollection, "resourceCollection"); resourceCollection.AddAnnotation(CreateAppElement(TestAtomConstants.AtomPublishingAcceptAttributeName, value)); return(resourceCollection); }
/// <summary> /// Visits a payload element whose root is a WorkspaceInstance. /// </summary> /// <param name="payloadElement">The root node of payload element being visited.</param> /// <returns>The original element or a copy to replace it with</returns> public virtual ODataPayloadElement Visit(WorkspaceInstance payloadElement) { ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement"); IList <ResourceCollectionInstance> replacedCollections = null; if (payloadElement.ResourceCollections != null) { replacedCollections = new List <ResourceCollectionInstance>(); foreach (ResourceCollectionInstance collection in payloadElement.ResourceCollections) { ExceptionUtilities.CheckObjectNotNull(collection, "Resource collection is null"); ResourceCollectionInstance replacedCollection = this.Visit(collection) as ResourceCollectionInstance; ExceptionUtilities.CheckObjectNotNull(replacedCollection, "Replaced resource collection was null or wrong type"); replacedCollections.Add(replacedCollection); } } if (!this.ShouldReplace(payloadElement.ResourceCollections, replacedCollections)) { return(payloadElement); } WorkspaceInstance replacedWorkspace = new WorkspaceInstance(replacedCollections.ToArray()); replacedWorkspace.Title = payloadElement.Title; return(payloadElement.ReplaceWith(replacedWorkspace)); }
/// <summary> /// Visits a payload element whose root is a ResourceCollectionInstance. /// </summary> /// <param name="payloadElement">The root node of payload element being visited.</param> public void Visit(ResourceCollectionInstance payloadElement) { ExceptionUtilities.Assert(!this.isRootElement, "Json serialization does not allow a root element of type: {0}", payloadElement.ElementType.ToString()); // NOTE: Following the ODataLib approach here where the Href is used as the entity set name in JSON. // The Title is only available in ATOM through ATOM metadata. this.writer.WriteString(payloadElement.Href); }
/// <summary> /// Normalizes resoure collection specific atom metadata. /// </summary> /// <param name="payloadElement">The payload element to normalize.</param> public override void Visit(ResourceCollectionInstance payloadElement) { NormalizeTitleValue( payloadElement, payloadElement.Title, (value) => payloadElement.Title = value); base.Visit(payloadElement); }
/// <summary> /// Annotates the resource collection with inline app:categories values. /// </summary> /// <param name="resourceCollection">The resource collection to annotate.</param> /// <param name="fixedValue">The value of the app:categories fixed property.</param> /// <param name="scheme">The value of the app:categories scheme property.</param> /// <param name="categories">The atom:category children of the app:categories.</param> /// <returns>The resource collection with the annotation applied.</returns> public static ResourceCollectionInstance AppInlineCategories(this ResourceCollectionInstance resourceCollection, string fixedValue, string scheme, params XmlTreeAnnotation[] categories) { ExceptionUtilities.CheckArgumentNotNull(resourceCollection, "resourceCollection"); XmlTreeAnnotation[] categoriesAttributes = CreateAtomAttributes( new KeyValuePair <string, string>(TestAtomConstants.AtomPublishingFixedAttributeName, fixedValue), new KeyValuePair <string, string>(TestAtomConstants.AtomCategorySchemeAttributeName, scheme)); resourceCollection.AddAnnotation(CreateAppElement("categories", null, categoriesAttributes.Union(categories).ToArray())); return(resourceCollection); }
/// <summary> /// Visits a resource collection. /// </summary> /// <param name="entitySetInfo">The resource collection to visit.</param> protected override ODataPayloadElement VisitResourceCollection(ODataEntitySetInfo entitySetInfo) { ExceptionUtilities.CheckArgumentNotNull(entitySetInfo, "entitySetInfo"); ResourceCollectionInstance collectionInstance = new ResourceCollectionInstance(); collectionInstance.Href = entitySetInfo.Url.OriginalString; collectionInstance.Name = entitySetInfo.Name; return(collectionInstance); }
/// <summary> /// Visits a payload element whose root is a ResourceCollectionInstance. /// </summary> /// <param name="payloadElement">The root node of payload element being visited.</param> /// <returns>The original element or a copy to replace it with</returns> public virtual ODataPayloadElement Visit(ResourceCollectionInstance payloadElement) { ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement"); if (this.alwaysReplace) { return(payloadElement.ReplaceWith(new ResourceCollectionInstance { Title = payloadElement.Title, Href = payloadElement.Href, Name = payloadElement.Name })); } return(payloadElement); }
/// <summary> /// Visits a payload element whose root is a ResourceCollectionInstance. /// </summary> /// <param name="expected">The root node of payload element being visited.</param> public void Visit(ResourceCollectionInstance expected) { ExceptionUtilities.CheckArgumentNotNull(expected, "expected"); var observed = this.GetNextObservedElement <ResourceCollectionInstance>(); using (this.Assert.WithMessage("Resource collection instance did not match expectation")) { this.CompareAnnotations(expected.Annotations, observed.Annotations); this.Assert.AreEqual(expected.Title, observed.Title, "Title did not match expectation"); this.Assert.AreEqual(expected.Href, observed.Href, "Href did not match expectation"); this.Assert.AreEqual(expected.Name, observed.Name, "Name did not match expectation"); } }
/// <summary> /// Visits the payload element /// </summary> /// <param name="payloadElement">The payload element to visit</param> public override void Visit(ResourceCollectionInstance payloadElement) { ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement"); ExceptionUtilities.CheckObjectNotNull(this.currentXElement, "Current XElement is not defined"); XElement collectionElement = CreateAtomPubElement(this.currentXElement, "collection"); if (payloadElement.Href != null) { collectionElement.SetAttributeValue("href", payloadElement.Href); } if (payloadElement.Title != null) { XElement title = CreateAtomElement(collectionElement, "title"); title.Value = payloadElement.Title; } PostProcessXElement(payloadElement, collectionElement); }
/// <summary> /// Visits a serviceDocument. /// </summary> /// <param name="serviceDocument">The serviceDocument to visit.</param> protected override ODataPayloadElement VisitWorkspace(ODataServiceDocument serviceDocument) { ExceptionUtilities.CheckArgumentNotNull(serviceDocument, "serviceDocument"); WorkspaceInstance workspaceInstance = new WorkspaceInstance(); IEnumerable <ODataEntitySetInfo> collections = serviceDocument.EntitySets; if (collections != null) { foreach (ODataEntitySetInfo collection in collections) { ResourceCollectionInstance collectionInstance = (ResourceCollectionInstance)this.Visit(collection); workspaceInstance.ResourceCollections.Add(collectionInstance); } } // Since ODataLib only supports a single serviceDocument and does not have an OM representation of the service // document, wrap the single serviceDocument in a service document instance here. return(new ServiceDocumentInstance(workspaceInstance)); }
/// <summary> /// Visits a resource collection. /// </summary> /// <param name="entitySetInfo">The resource collection to visit.</param> protected override ODataPayloadElement VisitResourceCollection(ODataEntitySetInfo entitySetInfo) { ExceptionUtilities.CheckArgumentNotNull(entitySetInfo, "entitySetInfo"); ResourceCollectionInstance collectionInstance = (ResourceCollectionInstance)base.VisitResourceCollection(entitySetInfo); AtomResourceCollectionMetadata atomMetadata = entitySetInfo.GetAnnotation <AtomResourceCollectionMetadata>(); if (atomMetadata != null) { if (atomMetadata.Title != null) { collectionInstance.Title = atomMetadata.Title.Text; collectionInstance.AtomTitle(atomMetadata.Title.Text, ToString(atomMetadata.Title.Kind)); } if (atomMetadata.Accept != null) { collectionInstance.AppAccept(atomMetadata.Accept); } if (atomMetadata.Categories != null) { if (atomMetadata.Categories.Href != null) { collectionInstance.AppOutOfLineCategories(atomMetadata.Categories.Href.OriginalString); } else { collectionInstance.AppInlineCategories( atomMetadata.Categories.Fixed == null ? null : (atomMetadata.Categories.Fixed.Value ? TestAtomConstants.AtomPublishingFixedYesValue : TestAtomConstants.AtomPublishingFixedNoValue), atomMetadata.Categories.Scheme, atomMetadata.Categories.Categories == null ? new XmlTreeAnnotation[0] : atomMetadata.Categories.Categories.Select(category => AtomMetadataBuilder.AtomCategory(category.Term, category.Scheme, category.Label)).ToArray()); } } } return(collectionInstance); }
/// <summary> /// Visits the payload element /// </summary> /// <param name="payloadElement">The payload element to visit</param> public virtual void Visit(ResourceCollectionInstance payloadElement) { ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement"); }
/// <summary> /// Visits a payload element whose root is a ResourceCollectionInstance. /// </summary> /// <param name="payloadElement">The root node of payload element being visited.</param> public void Visit(ResourceCollectionInstance payloadElement) { throw new TaupoNotSupportedException("Not implemented."); }
/// <summary> /// Removes the title property and ATOM metadata annotations from a <see cref="ResourceCollectionInstance"/>. /// </summary> /// <param name="payloadElement">The resource collection instance to visit</param> public override void Visit(ResourceCollectionInstance payloadElement) { payloadElement.Title = null; base.Visit(payloadElement); }