Exemplo n.º 1
0
        private static DomData AddDomData(DomDocument domDocument)
        {
            Contract.Requires(domDocument != null);

            // Add data node.
            var domData = domDocument.CreateAndAddNode(() => DomData.Create());

            return(domData);
        }
Exemplo n.º 2
0
        private static DomDataCollection AddDomDataCollection(DomDocument domDocument)
        {
            Contract.Requires(domDocument != null);

            // Add data collection node.
            var domDataCollection = domDocument.CreateAndAddNode(() => DomDataCollection.Create());

            return(domDataCollection);
        }
Exemplo n.º 3
0
        private static void ParseDocumentType(DomDocument domDocument, Document apiDocument)
        {
            Contract.Requires(domDocument != null);
            Contract.Requires(apiDocument != null);

            var documentType = apiDocument.GetDocumentType();

            domDocument.SetSingleAttribute(DocumentTypeNodeAttributeName, documentType);
        }
Exemplo n.º 4
0
        private static void ParseErrors(DomDocument domDocument, Document apiDocument)
        {
            Contract.Requires(domDocument != null);
            Contract.Requires(apiDocument != null);

            var errors = apiDocument.GetErrors();

            domDocument.CreateAndAddNode(() => DomReadOnlyErrors.Create(errors));
        }
Exemplo n.º 5
0
        private static void ParseDocumentErrors(DomDocument domDocument, Document apiDocument)
        {
            Contract.Requires(domDocument != null);
            Contract.Requires(apiDocument != null);

            if (apiDocument.IsErrorsDocument())
            {
                ParseErrors(domDocument, apiDocument);
            }
        }
Exemplo n.º 6
0
        private static void ParseDocumentLinks(DomDocument domDocument, Document apiDocument)
        {
            Contract.Requires(domDocument != null);
            Contract.Requires(apiDocument != null);

            if (apiDocument.HasLinks() == false)
            {
                return;
            }

            domDocument.CreateAndAddNode(() => DomReadOnlyLinks.Create(apiDocument));
        }
Exemplo n.º 7
0
        private static void ParseDocumentJsonApi(DomDocument domDocument, Document apiDocument)
        {
            Contract.Requires(domDocument != null);
            Contract.Requires(apiDocument != null);

            if (apiDocument.HasJsonApi() == false)
            {
                return;
            }

            domDocument.CreateAndAddNode(() => DomReadOnlyJsonApiVersion.Create(apiDocument));
        }
Exemplo n.º 8
0
        private static void ParsePrimaryData(DomDocument domDocument, ResourceIdentifier apiResourceIdentifier)
        {
            Contract.Requires(domDocument != null);

            // Add data node.
            var domData = AddDomData(domDocument);

            // Add the primary document data if there is any.
            if (apiResourceIdentifier == null)
            {
                return;
            }

            AddDomReadOnlyResourceIdentifier(domDocument, domData, apiResourceIdentifier);
        }
Exemplo n.º 9
0
        private static void ParsePrimaryData(DomDocument domDocument, IEnumerable <ResourceIdentifier> apiResourceIdentifierCollection)
        {
            Contract.Requires(domDocument != null);

            // Add data collection node.
            var domDataCollection = AddDomDataCollection(domDocument);

            // Parse the primary document data if there is any.
            if (apiResourceIdentifierCollection == null)
            {
                return;
            }

            foreach (var apiResourceIdentifier in apiResourceIdentifierCollection)
            {
                AddDomReadOnlyResourceIdentifier(domDocument, domDataCollection, apiResourceIdentifier);
            }
        }
Exemplo n.º 10
0
        private static void ParseDocumentIncluded(DomDocument domDocument, Document apiDocument)
        {
            Contract.Requires(domDocument != null);
            Contract.Requires(apiDocument != null);

            if (apiDocument.IsIncludedNullOrEmpty())
            {
                return;
            }

            // Add included node.
            var domIncluded = domDocument.CreateAndAddNode(() => DomIncluded.Create());

            var includedResources = apiDocument.GetIncludedResources();

            foreach (var includedResource in includedResources)
            {
                var apiResource = includedResource;
                AddDomReadOnlyResource(domDocument, domIncluded, apiResource);
            }
        }
Exemplo n.º 11
0
        private static DomReadOnlyResourceIdentifier AddDomReadOnlyResourceIdentifier(DomDocument domDocument, IContainerNode <DomNodeType> domParentNode, ResourceIdentifier apiResourceIdentifier)
        {
            Contract.Requires(domDocument != null);
            Contract.Requires(domParentNode != null);
            Contract.Requires(apiResourceIdentifier != null);

            // Find metadata based on the JsonApi resource.
            var apiResourceType = apiResourceIdentifier.Type;
            var resourceType    = domDocument.ServiceModel.GetResourceType(apiResourceType);
            var clrResourceType = resourceType.ClrType;

            // Create/Add DOM read-only resource identifier node to the parent node.
            var domReadOnlyResourceIdentifier = domParentNode.CreateAndAddNode(() => DomReadOnlyResourceIdentifier.Create(apiResourceIdentifier, clrResourceType));

            return(domReadOnlyResourceIdentifier);
        }
Exemplo n.º 12
0
        private static void ParseDocumentData(DomDocument domDocument, Document apiDocument)
        {
            Contract.Requires(domDocument != null);
            Contract.Requires(apiDocument != null);

            var documentType = apiDocument.GetDocumentType();

            switch (documentType)
            {
            case DocumentType.Document:
            case DocumentType.ErrorsDocument:
            {
                // NOOP
            }
            break;

            case DocumentType.EmptyDocument:
            {
                AddDomDataCollection(domDocument);
            }
            break;

            case DocumentType.NullDocument:
            {
                AddDomData(domDocument);
            }
            break;

            case DocumentType.ResourceDocument:
            {
                var apiResource = apiDocument.GetResource();
                ParsePrimaryData(domDocument, apiResource);
            }
            break;

            case DocumentType.ResourceCollectionDocument:
            {
                var apiResourceCollection = apiDocument.GetResourceCollection();
                ParsePrimaryData(domDocument, apiResourceCollection);
            }
            break;

            case DocumentType.ResourceIdentifierDocument:
            {
                var apiResourceIdentifier = apiDocument.GetResourceIdentifier();
                ParsePrimaryData(domDocument, apiResourceIdentifier);
            }
            break;

            case DocumentType.ResourceIdentifierCollectionDocument:
            {
                var apiResourceIdentifierCollection = apiDocument.GetResourceIdentifierCollection();
                ParsePrimaryData(domDocument, apiResourceIdentifierCollection);
            }
            break;

            default:
            {
                var detail = InfrastructureErrorStrings.InternalErrorExceptionDetailUnknownEnumerationValue
                             .FormatWith(typeof(DocumentType).Name, documentType);
                throw new InternalErrorException(detail);
            }
            }
        }