Ejemplo n.º 1
0
        private static DomReadOnlyResource AddDomReadOnlyResource(DomDocument domDocument, IContainerNode <DomNodeType> domParentNode, Resource apiResource)
        {
            Contract.Requires(domDocument != null);
            Contract.Requires(domParentNode != null);
            Contract.Requires(apiResource != null);

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

            // Create/Add DOM read-only resource node to the parent node.
            var clrResource = resourceType.CreateClrObject();

            var domReadOnlyResource = domParentNode.CreateAndAddNode(() => DomReadOnlyResource.Create(apiResource, clrResource));

            // Map the incoming JsonApi resource to the created CLR resource.
            resourceType.MapApiMetaToClrResource(clrResource, apiResource);
            resourceType.MapApiIdToClrResource(clrResource, apiResource);
            resourceType.MapApiAttributesToClrResource(clrResource, apiResource, serviceModel);
            resourceType.MapApiRelationshipsToClrResource(clrResource, apiResource);
            resourceType.MapApiLinksToClrResource(clrResource, apiResource);

            return(domReadOnlyResource);
        }
        // PUBLIC METHODS ///////////////////////////////////////////////////
        #region Factory Methods
        public static DomReadOnlyResource Create(Resource apiResource, object clrResource)
        {
            Contract.Requires(apiResource != null);
            Contract.Requires(clrResource != null);

            var domReadOnlyResource = new DomReadOnlyResource(apiResource, clrResource);

            return(domReadOnlyResource);
        }
Ejemplo n.º 3
0
        public static DomData CreateFromResource(DomReadOnlyResource domReadOnlyResource)
        {
            var domData = new DomData(domReadOnlyResource);

            return(domData);
        }