Example #1
0
        internal ODataEntriesEntityMaterializer CreateODataEntriesEntityMaterializer(
            List <ODataResource> resources,
            Type resourceType,
            TestMaterializerContext materializerContext = null)
        {
            var clientEdmModel = new ClientEdmModel(ODataProtocolVersion.V4);
            var context        = new DataServiceContext();

            var resourceSet = new ODataResourceSet();

            MaterializerFeed.CreateFeed(resourceSet, resources);
            resources.ForEach(r =>
            {
                if (r == null)
                {
                    MaterializerEntry.CreateEmpty();
                }
                else
                {
                    MaterializerEntry.CreateEntry(r, ODataFormat.Json, true, clientEdmModel);
                }
            });
            materializerContext = materializerContext ?? new TestMaterializerContext()
            {
                Model = clientEdmModel, Context = context
            };
            var             adapter    = new EntityTrackingAdapter(new TestEntityTracker(), MergeOption.OverwriteChanges, clientEdmModel, context);
            QueryComponents components = new QueryComponents(new Uri("http://foo.com/Service"), new Version(4, 0), resourceType, null, new Dictionary <Expression, Expression>());

            return(new ODataEntriesEntityMaterializer(resources, materializerContext, adapter, components, resourceType, null, ODataFormat.Json));
        }
Example #2
0
        /// <summary>
        /// Reads the remainder of an entry.
        /// </summary>
        /// <returns>An entry.</returns>
        private MaterializerEntry ReadEntryCore()
        {
            this.ExpectState(ODataReaderState.ResourceStart);

            ODataResource result = (ODataResource)this.reader.Item;

            MaterializerEntry entry;
            List <ODataNestedResourceInfo> navigationLinks = new List <ODataNestedResourceInfo>();

            if (result != null)
            {
                entry = MaterializerEntry.CreateEntry(
                    result,
                    this.readODataFormat,
                    this.mergeOption != MergeOption.NoTracking,
                    this.clientEdmModel);

                do
                {
                    this.AssertRead();

                    switch (this.reader.State)
                    {
                    case ODataReaderState.NestedResourceInfoStart:
                        // Cache the list of navigation links here but don't add them to the entry because all of the key properties may not be available yet.
                        navigationLinks.Add(this.ReadNestedResourceInfo());
                        break;

                    case ODataReaderState.ResourceEnd:
                        break;

                    default:
                        throw DSClient.Error.InternalError(InternalError.UnexpectedReadState);
                    }
                }while (this.reader.State != ODataReaderState.ResourceEnd);

                if (!entry.Entry.IsTransient)
                {
                    entry.UpdateEntityDescriptor();
                }
            }
            else
            {
                entry = MaterializerEntry.CreateEmpty();
                this.ReadAndExpectState(ODataReaderState.ResourceEnd);
            }

            // Add the navigation links here now that all of the property values have been read and are available to build the links.
            foreach (ODataNestedResourceInfo navigationLink in navigationLinks)
            {
                entry.AddNestedResourceInfo(navigationLink);
            }

            return(entry);
        }
Example #3
0
        private void ApplyInnerProperty(ODataResource innerResource, ComplexTypeWithChildComplexType parentInstance, TestMaterializerContext context = null)
        {
            context = context ?? new TestMaterializerContext();
            var resource = new ODataResource()
            {
                TypeName = "ComplexTypeWithChildComplexType", Properties = new ODataProperty[0]
            };

            var clientEdmModel    = new ClientEdmModel(ODataProtocolVersion.V4);
            var materializerEntry = MaterializerEntry.CreateEntry(resource, ODataFormat.Json, false, clientEdmModel);

            materializerEntry.ResolvedObject = parentInstance;
            ODataNestedResourceInfo innerComplexP = new ODataNestedResourceInfo()
            {
                Name = "InnerComplexProperty", IsCollection = false
            };

            MaterializerEntry innerMaterializerEntry;

            if (innerResource != null)
            {
                innerMaterializerEntry = MaterializerEntry.CreateEntry(innerResource, ODataFormat.Json, true, clientEdmModel);
            }
            else
            {
                innerMaterializerEntry = MaterializerEntry.CreateEmpty();
            }

            MaterializerNavigationLink.CreateLink(innerComplexP, innerMaterializerEntry);
            materializerEntry.AddNestedResourceInfo(innerComplexP);

            var policy = this.CreateEntryMaterializationPolicy(context);

            policy.EntityTrackingAdapter.TargetInstance = parentInstance;
            policy.Materialize(materializerEntry, typeof(ComplexTypeWithChildComplexType), true);
        }