예제 #1
0
        internal EntityDescriptor(String identity, Uri selfLink, Uri editLink, object entity, EntityDescriptor parentEntity, string parentProperty, string entitySetName, string etag, EntityStates state)
            : base(state)
        {
            Debug.Assert(entity != null, "entity is null");
            Debug.Assert((parentEntity == null && parentProperty == null) || (parentEntity != null && parentProperty != null), "When parentEntity is specified, must also specify parentProperyName");

#if DEBUG
            if (state == EntityStates.Added)
            {
                Debug.Assert(identity == null && selfLink == null && editLink == null && etag == null, "For objects in added state, identity, self-link, edit-link and etag must be null");
                Debug.Assert((!String.IsNullOrEmpty(entitySetName) && parentEntity == null && String.IsNullOrEmpty(parentProperty)) ||
                             (String.IsNullOrEmpty(entitySetName) && parentEntity != null && !String.IsNullOrEmpty(parentProperty)),
                             "For entities in added state, entity set name or the insert path must be specified");
            }
            else
            {
                Debug.Assert(identity != null, "For objects in non-added state, identity must never be null");
                Debug.Assert(String.IsNullOrEmpty(entitySetName) && String.IsNullOrEmpty(parentProperty) && parentEntity == null, "For non-added entities, the entity set name and the insert path must be null");
            }
#endif

            this.identity = identity;
            this.selfLink = selfLink;
            this.editLink = editLink;

            this.parentDescriptor = parentEntity;
            this.parentProperty = parentProperty;
            this.entity = entity;
            this.etag = etag;
            this.entitySetName = entitySetName;
        }
예제 #2
0
 private MaterializerEntry(ODataEntry entry, DataServiceProtocolVersion maxProtocolVersion)
 {
     this.entry = entry;
     this.entityDescriptor = new System.Data.Services.Client.EntityDescriptor(maxProtocolVersion);
     SerializationTypeNameAnnotation annotation = entry.GetAnnotation<SerializationTypeNameAnnotation>();
     this.entityDescriptor.ServerTypeName = (annotation != null) ? annotation.TypeName : (this.entityDescriptor.ServerTypeName = this.Entry.TypeName);
 }
예제 #3
0
        private MaterializerEntry(ODataEntry entry, DataServiceProtocolVersion maxProtocolVersion)
        {
            this.entry            = entry;
            this.entityDescriptor = new System.Data.Services.Client.EntityDescriptor(maxProtocolVersion);
            SerializationTypeNameAnnotation annotation = entry.GetAnnotation <SerializationTypeNameAnnotation>();

            this.entityDescriptor.ServerTypeName = (annotation != null) ? annotation.TypeName : (this.entityDescriptor.ServerTypeName = this.Entry.TypeName);
        }
예제 #4
0
 internal void AddEntityDescriptor(EntityDescriptor descriptor)
 {
     try
     {
         this.entityDescriptors.Add(descriptor.Entity, descriptor);
     }
     catch (ArgumentException)
     {
         throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Context_EntityAlreadyContained);
     }
 }
예제 #5
0
 internal EntityDescriptor(string identity, Uri selfLink, Uri editLink, Uri addToUri, object entity, EntityDescriptor parentEntity, string parentProperty, string etag, EntityStates state, DataServiceProtocolVersion maxProtocolVersion) : base(state)
 {
     this.identity = identity;
     this.selfLink = selfLink;
     this.editLink = editLink;
     this.addToUri = addToUri;
     this.parentDescriptor = parentEntity;
     this.parentProperty = parentProperty;
     this.MaxProtocolVersion = maxProtocolVersion;
     this.Entity = entity;
     this.etag = etag;
 }
예제 #6
0
 internal string GetServerTypeName(EntityDescriptor descriptor)
 {
     if (this.HasResolveName)
     {
         Type type = descriptor.Entity.GetType();
         if (this.IsUserSuppliedResolver)
         {
             return (this.ResolveNameFromType(type) ?? descriptor.GetLatestServerTypeName());
         }
         return (descriptor.GetLatestServerTypeName() ?? this.ResolveNameFromType(type));
     }
     return descriptor.GetLatestServerTypeName();
 }
예제 #7
0
 internal void AttachIdentity(EntityDescriptor entityDescriptorFromMaterializer, MergeOption metadataMergeOption)
 {
     this.EnsureIdentityToResource();
     EntityDescriptor descriptor = this.entityDescriptors[entityDescriptorFromMaterializer.Entity];
     this.ValidateDuplicateIdentity(entityDescriptorFromMaterializer.Identity, descriptor);
     this.DetachResourceIdentity(descriptor);
     if (descriptor.IsDeepInsert)
     {
         LinkDescriptor descriptor2 = this.bindings[descriptor.GetRelatedEnd(this.maxProtocolVersion)];
         descriptor2.State = EntityStates.Unchanged;
     }
     descriptor.Identity = entityDescriptorFromMaterializer.Identity;
     AtomMaterializerLog.MergeEntityDescriptorInfo(descriptor, entityDescriptorFromMaterializer, true, metadataMergeOption);
     descriptor.State = EntityStates.Unchanged;
     this.identityToDescriptor[entityDescriptorFromMaterializer.Identity] = descriptor;
 }
예제 #8
0
        /// <summary>
        /// Applies the media entry information (if any) to the specified 
        /// <paramref name="descriptor"/>.
        /// </summary>
        /// <param name="entry">Entry with (potential) media entry information to apply.</param>
        /// <param name="descriptor">Descriptor to update.</param>
        private void ApplyMediaEntryInformation(AtomEntry entry, EntityDescriptor descriptor)
        {
            Debug.Assert(entry != null, "entry != null");
            Debug.Assert(descriptor != null, "descriptor != null");

            if (entry.MediaEditUri != null || entry.MediaContentUri != null)
            {
                // 

                if (entry.MediaEditUri != null)
                {
                    descriptor.EditStreamUri = new Uri(this.context.BaseUriWithSlash, entry.MediaEditUri);
                }

                if (entry.MediaContentUri != null)
                {
                    descriptor.ReadStreamUri = new Uri(this.context.BaseUriWithSlash, entry.MediaContentUri);
                }

                descriptor.StreamETag = entry.StreamETagText;
            }
        }
예제 #9
0
 protected abstract MaterializeAtom GetMaterializer(EntityDescriptor entityDescriptor, ResponseInfo responseInfo);
예제 #10
0
파일: Serializer.cs 프로젝트: nickchal/pash
 internal void WriteNavigationLink(EntityDescriptor entityDescriptor, IEnumerable<LinkDescriptor> relatedLinks, ODataWriter odataWriter)
 {
     ClientTypeAnnotation clientTypeAnnotation = null;
     foreach (LinkDescriptor descriptor in relatedLinks)
     {
         descriptor.ContentGeneratedForSave = true;
         if (clientTypeAnnotation == null)
         {
             ClientEdmModel model = ClientEdmModel.GetModel(this.requestInfo.MaxProtocolVersion);
             clientTypeAnnotation = model.GetClientTypeAnnotation(model.GetOrCreateEdmType(entityDescriptor.Entity.GetType()));
         }
         ODataNavigationLink navigationLink = new ODataNavigationLink {
             Url = this.requestInfo.EntityTracker.GetEntityDescriptor(descriptor.Target).GetLatestEditLink(),
             IsCollection = new bool?(clientTypeAnnotation.GetProperty(descriptor.SourceProperty, false).IsEntityCollection),
             Name = descriptor.SourceProperty
         };
         odataWriter.WriteStart(navigationLink);
         ODataEntityReferenceLink entityReferenceLink = new ODataEntityReferenceLink {
             Url = navigationLink.Url
         };
         odataWriter.WriteEntityReferenceLink(entityReferenceLink);
         odataWriter.WriteEnd();
     }
 }
예제 #11
0
파일: Serializer.cs 프로젝트: nickchal/pash
 internal void WriteEntry(EntityDescriptor entityDescriptor, IEnumerable<LinkDescriptor> relatedLinks, ODataRequestMessageWrapper requestMessage)
 {
     ClientEdmModel model = ClientEdmModel.GetModel(this.requestInfo.MaxProtocolVersion);
     ClientTypeAnnotation clientTypeAnnotation = model.GetClientTypeAnnotation(model.GetOrCreateEdmType(entityDescriptor.Entity.GetType()));
     using (ODataMessageWriter writer = CreateMessageWriter(requestMessage, this.requestInfo))
     {
         ODataWriter odataWriter = writer.CreateODataEntryWriter();
         ODataEntry entry = new ODataEntry();
         if (this.requestInfo.HasWritingEventHandlers)
         {
             entry.SetAnnotation<WritingEntityInfo>(new WritingEntityInfo(entityDescriptor.Entity, this.requestInfo));
         }
         string serverTypeName = this.requestInfo.GetServerTypeName(entityDescriptor);
         if (clientTypeAnnotation.ElementTypeName != serverTypeName)
         {
             SerializationTypeNameAnnotation annotation = new SerializationTypeNameAnnotation {
                 TypeName = serverTypeName
             };
             entry.SetAnnotation<SerializationTypeNameAnnotation>(annotation);
         }
         entry.TypeName = clientTypeAnnotation.ElementTypeName;
         if (EntityStates.Modified == entityDescriptor.State)
         {
             entry.Id = entityDescriptor.GetLatestIdentity();
         }
         if (entityDescriptor.IsMediaLinkEntry || clientTypeAnnotation.IsMediaLinkEntry)
         {
             entry.MediaResource = new ODataStreamReferenceValue();
         }
         odataWriter.WriteStart(entry);
         if (EntityStates.Added == entityDescriptor.State)
         {
             this.WriteNavigationLink(entityDescriptor, relatedLinks, odataWriter);
         }
         entry.Properties = this.PopulateProperties(clientTypeAnnotation, entityDescriptor.Entity, null);
         odataWriter.WriteEnd();
     }
 }
예제 #12
0
 protected override MaterializeAtom GetMaterializer(EntityDescriptor entityDescriptor, ResponseInfo responseInfo)
 {
     return new MaterializeAtom(responseInfo, new QueryComponents(null, Util.DataServiceVersionEmpty, entityDescriptor.Entity.GetType(), null, null), null, this.currentOperationResponse.CreateResponseMessage(), ODataPayloadKind.Entry);
 }
예제 #13
0
 protected ResponseInfo CreateResponseInfo(EntityDescriptor entityDescriptor)
 {
     MergeOption overwriteChanges = MergeOption.OverwriteChanges;
     if (entityDescriptor.StreamState == EntityStates.Added)
     {
         overwriteChanges = MergeOption.PreserveChanges;
     }
     return this.RequestInfo.GetDeserializationInfo(new MergeOption?(overwriteChanges));
 }
예제 #14
0
        internal static EntityDescriptor RestoreState(EntityDescriptorState state)
        {
            SaveStreamState saveStreamState = state.SaveStream;
            DataServiceContext.DataServiceSaveStream saveStream = (saveStreamState != null)
                ? DataServiceContext.DataServiceSaveStream.RestoreState(saveStreamState)
                : null;

            var entityDescriptor = new EntityDescriptor(
                state.Identity,
                state.SelfLink,
                state.EditLink,
                state.Entity,
                null,
                null,
                state.EntitySetName,
                state.Etag,
                state.State)
            {
                editMediaLink = state.EditMediaLink,
                readStreamLink = state.ReadStreamLink,
                saveStream = saveStream,
                selfLink = state.SelfLink,
                serverTypeName = state.ServerTypeName,
                streamETag = state.StreamETag,
                streamState = state.StreamState,
            };

            entityDescriptor.RestoreState((DescriptorState)state);

            return entityDescriptor;
        }
예제 #15
0
 private void HandleResponsePost(EntityDescriptor entityDescriptor, string etag)
 {
     try
     {
         if ((EntityStates.Added != entityDescriptor.State) && (EntityStates.Added != entityDescriptor.StreamState))
         {
             System.Data.Services.Client.Error.ThrowBatchUnexpectedContent(InternalError.EntityNotAddedState);
         }
         if (this.ProcessResponsePayload)
         {
             this.MaterializeResponse(entityDescriptor, this.CreateResponseInfo(entityDescriptor), etag);
         }
         else
         {
             entityDescriptor.ETag = etag;
             entityDescriptor.State = EntityStates.Unchanged;
         }
         if (entityDescriptor.StreamState != EntityStates.Added)
         {
             foreach (LinkDescriptor descriptor in this.RelatedLinks(entityDescriptor))
             {
                 if (Util.IncludeLinkState(descriptor.SaveResultWasProcessed) || (descriptor.SaveResultWasProcessed == EntityStates.Added))
                 {
                     HandleResponsePost(descriptor);
                 }
             }
         }
     }
     finally
     {
         if (entityDescriptor.StreamState == EntityStates.Added)
         {
             entityDescriptor.State = EntityStates.Modified;
             entityDescriptor.StreamState = EntityStates.Unchanged;
         }
     }
 }
예제 #16
0
 internal void DetachResourceIdentity(EntityDescriptor resource)
 {
     EntityDescriptor descriptor = null;
     if (((resource.Identity != null) && this.identityToDescriptor.TryGetValue(resource.Identity, out descriptor)) && object.ReferenceEquals(descriptor, resource))
     {
         this.identityToDescriptor.Remove(resource.Identity);
     }
 }
예제 #17
0
 private void MaterializeResponse(EntityDescriptor entityDescriptor, ResponseInfo responseInfo, string etag)
 {
     using (MaterializeAtom atom = this.GetMaterializer(entityDescriptor, responseInfo))
     {
         atom.SetInsertingObject(entityDescriptor.Entity);
         object obj2 = null;
         foreach (object obj3 in atom)
         {
             if (obj2 != null)
             {
                 System.Data.Services.Client.Error.ThrowInternalError(InternalError.MaterializerReturningMoreThanOneEntity);
             }
             obj2 = obj3;
         }
         if (entityDescriptor.GetLatestETag() == null)
         {
             entityDescriptor.ETag = etag;
         }
     }
 }
예제 #18
0
 internal override void ClearChanges()
 {
     this.transientEntityDescriptor = null;
     this.CloseSaveStream();
 }
예제 #19
0
 protected IEnumerable<LinkDescriptor> RelatedLinks(EntityDescriptor entityDescriptor)
 {
     foreach (LinkDescriptor iteratorVariable0 in this.RequestInfo.EntityTracker.Links)
     {
         if ((iteratorVariable0.Source == entityDescriptor.Entity) && (iteratorVariable0.Target != null))
         {
             EntityDescriptor iteratorVariable1 = this.RequestInfo.EntityTracker.GetEntityDescriptor(iteratorVariable0.Target);
             if ((Util.IncludeLinkState(iteratorVariable1.SaveResultWasProcessed) || ((iteratorVariable1.SaveResultWasProcessed == 0) && Util.IncludeLinkState(iteratorVariable1.State))) || (((iteratorVariable1.Identity != null) && (iteratorVariable1.ChangeOrder < entityDescriptor.ChangeOrder)) && (((iteratorVariable1.SaveResultWasProcessed == 0) && (EntityStates.Added == iteratorVariable1.State)) || (EntityStates.Added == iteratorVariable1.SaveResultWasProcessed))))
             {
                 yield return iteratorVariable0;
             }
         }
     }
 }
예제 #20
0
 internal void RestoreParentState(EntityDescriptor parentDescriptor, string parentProperty)
 {
     this.parentDescriptor = parentDescriptor;
     this.parentProperty = parentProperty;
 }
예제 #21
0
        /// <summary>Applies all accumulated changes to the associated data context.</summary>
        /// <remarks>The log should be cleared after this method successfully executed.</remarks>
        internal void ApplyToContext()
        {
            Debug.Assert(
                this.mergeOption != MergeOption.OverwriteChanges || this.foundEntriesWithMedia.Count == 0,
                "mergeOption != MergeOption.OverwriteChanges || foundEntriesWithMedia.Count == 0 - we only use the 'entries-with-media' lookaside when we're not in overwrite mode, otherwise we track everything through identity stack");

            if (!this.Tracking)
            {
                return;
            }

            foreach (KeyValuePair<String, AtomEntry> entity in this.identityStack)
            {
                AtomEntry entry = entity.Value;
                if (entry.CreatedByMaterializer ||
                    entry.ResolvedObject == this.insertRefreshObject ||
                    entry.ShouldUpdateFromPayload)
                {
                    // Create a new descriptor and try to attach, if one already exists, get the existing reference instead.
                    EntityDescriptor descriptor = new EntityDescriptor(entity.Key, entry.QueryLink, entry.EditLink, entry.ResolvedObject, null, null, null, entry.ETagText, EntityStates.Unchanged);
                    descriptor = this.context.InternalAttachEntityDescriptor(descriptor, false);

                    // we should always reset descriptor's state to Unchanged (old v1 behaviour)
                    descriptor.State = EntityStates.Unchanged;

                    this.ApplyMediaEntryInformation(entry, descriptor);
                    descriptor.ServerTypeName = entry.TypeName;
                }
                else
                {
                    // Refresh the entity state indirectly by calling TryGetEntity.
                    EntityStates state;
                    this.context.TryGetEntity(entity.Key, entry.ETagText, this.mergeOption, out state);
                }
            }

            // Regardless of the merge mode, media link information should
            // always be applied to the context.
            foreach (AtomEntry entry in this.foundEntriesWithMedia.Values)
            {
                Debug.Assert(entry.ResolvedObject != null, "entry.ResolvedObject != null -- otherwise it wasn't found");
                EntityDescriptor descriptor = this.context.GetEntityDescriptor(entry.ResolvedObject);
                this.ApplyMediaEntryInformation(entry, descriptor);
            }

            foreach (LinkDescriptor link in this.links)
            {
                if (EntityStates.Added == link.State)
                {
                    // Added implies collection
                    if ((EntityStates.Deleted == this.context.GetEntityDescriptor(link.Target).State) ||
                        (EntityStates.Deleted == this.context.GetEntityDescriptor(link.Source).State))
                    {
                        this.context.DeleteLink(link.Source, link.SourceProperty, link.Target);
                    }
                    else
                    {
                        this.context.AttachLink(link.Source, link.SourceProperty, link.Target, this.mergeOption);
                    }
                }
                else if (EntityStates.Modified == link.State)
                {
                    // Modified implies reference
                    object target = link.Target;
                    if (MergeOption.PreserveChanges == this.mergeOption)
                    {
                        LinkDescriptor end = this.context.GetLinks(link.Source, link.SourceProperty).FirstOrDefault();
                        if (null != end && null == end.Target)
                        {
                            // leave the SetLink(link.Source, link.SourceProperty, null)
                            continue;
                        }

                        if ((null != target) && (EntityStates.Deleted == this.context.GetEntityDescriptor(target).State) ||
                            (EntityStates.Deleted == this.context.GetEntityDescriptor(link.Source).State))
                        {
                            target = null;
                        }
                    }

                    this.context.AttachLink(link.Source, link.SourceProperty, target, this.mergeOption);
                }
                else
                {
                    // detach link
                    Debug.Assert(EntityStates.Detached == link.State, "not detached link");
                    this.context.DetachLink(link.Source, link.SourceProperty, link.Target);
                }
            }
        }
예제 #22
0
 internal static void MergeEntityDescriptorInfo(EntityDescriptor trackedEntityDescriptor, EntityDescriptor entityDescriptorFromMaterializer, bool mergeInfo, MergeOption mergeOption)
 {
     if (!object.ReferenceEquals(trackedEntityDescriptor, entityDescriptorFromMaterializer))
     {
         if ((entityDescriptorFromMaterializer.ETag != null) && (mergeOption != MergeOption.AppendOnly))
         {
             trackedEntityDescriptor.ETag = entityDescriptorFromMaterializer.ETag;
         }
         if (mergeInfo)
         {
             if (entityDescriptorFromMaterializer.SelfLink != null)
             {
                 trackedEntityDescriptor.SelfLink = entityDescriptorFromMaterializer.SelfLink;
             }
             if (entityDescriptorFromMaterializer.EditLink != null)
             {
                 trackedEntityDescriptor.EditLink = entityDescriptorFromMaterializer.EditLink;
             }
             foreach (LinkInfo info in entityDescriptorFromMaterializer.LinkInfos)
             {
                 trackedEntityDescriptor.MergeLinkInfo(info);
             }
             foreach (StreamDescriptor descriptor in entityDescriptorFromMaterializer.StreamDescriptors)
             {
                 trackedEntityDescriptor.MergeStreamDescriptor(descriptor);
             }
             trackedEntityDescriptor.ServerTypeName = entityDescriptorFromMaterializer.ServerTypeName;
         }
         if (entityDescriptorFromMaterializer.ReadStreamUri != null)
         {
             trackedEntityDescriptor.ReadStreamUri = entityDescriptorFromMaterializer.ReadStreamUri;
         }
         if (entityDescriptorFromMaterializer.EditStreamUri != null)
         {
             trackedEntityDescriptor.EditStreamUri = entityDescriptorFromMaterializer.EditStreamUri;
         }
         if ((entityDescriptorFromMaterializer.ReadStreamUri != null) || (entityDescriptorFromMaterializer.EditStreamUri != null))
         {
             trackedEntityDescriptor.StreamETag = entityDescriptorFromMaterializer.StreamETag;
         }
     }
 }
예제 #23
0
        internal void ApplyToContext()
        {
            Debug.Assert(
                this.mergeOption != MergeOption.OverwriteChanges || this.foundEntriesWithMedia.Count == 0,
                "mergeOption != MergeOption.OverwriteChanges || foundEntriesWithMedia.Count == 0 - we only use the 'entries-with-media' lookaside when we're not in overwrite mode, otherwise we track everything through identity stack");

            if (!this.Tracking)
            {
                return;
            }

            foreach (KeyValuePair<String, AtomEntry> entity in this.identityStack)
            {
                AtomEntry entry = entity.Value;
                if (entry.CreatedByMaterializer ||
                    entry.ResolvedObject == this.insertRefreshObject ||
                    entry.ShouldUpdateFromPayload)
                {
                    EntityDescriptor descriptor = new EntityDescriptor(entity.Key, entry.QueryLink, entry.EditLink, entry.ResolvedObject, null, null, null, entry.ETagText, EntityStates.Unchanged);
                    descriptor = this.context.InternalAttachEntityDescriptor(descriptor, false);

                    descriptor.State = EntityStates.Unchanged;

                    this.ApplyMediaEntryInformation(entry, descriptor);
                    descriptor.ServerTypeName = entry.TypeName;
                }
                else
                {
                    EntityStates state;
                    this.context.TryGetEntity(entity.Key, entry.ETagText, this.mergeOption, out state);
                }
            }

            foreach (AtomEntry entry in this.foundEntriesWithMedia.Values)
            {
                Debug.Assert(entry.ResolvedObject != null, "entry.ResolvedObject != null -- otherwise it wasn't found");
                EntityDescriptor descriptor = this.context.GetEntityDescriptor(entry.ResolvedObject);
                this.ApplyMediaEntryInformation(entry, descriptor);
            }

            foreach (LinkDescriptor link in this.links)
            {
                if (EntityStates.Added == link.State)
                {
                    if ((EntityStates.Deleted == this.context.GetEntityDescriptor(link.Target).State) ||
                        (EntityStates.Deleted == this.context.GetEntityDescriptor(link.Source).State))
                    {
                        this.context.DeleteLink(link.Source, link.SourceProperty, link.Target);
                    }
                    else
                    {
                        this.context.AttachLink(link.Source, link.SourceProperty, link.Target, this.mergeOption);
                    }
                }
                else if (EntityStates.Modified == link.State)
                {
                    object target = link.Target;
                    if (MergeOption.PreserveChanges == this.mergeOption)
                    {
                        LinkDescriptor end = this.context.GetLinks(link.Source, link.SourceProperty).FirstOrDefault();
                        if (null != end && null == end.Target)
                        {
                            continue;
                        }

                        if ((null != target) && (EntityStates.Deleted == this.context.GetEntityDescriptor(target).State) ||
                            (EntityStates.Deleted == this.context.GetEntityDescriptor(link.Source).State))
                        {
                            target = null;
                        }
                    }

                    this.context.AttachLink(link.Source, link.SourceProperty, target, this.mergeOption);
                }
                else
                {
                    Debug.Assert(EntityStates.Detached == link.State, "not detached link");
                    this.context.DetachLink(link.Source, link.SourceProperty, link.Target);
                }
            }
        }
예제 #24
0
 internal bool DetachResource(EntityDescriptor resource)
 {
     foreach (LinkDescriptor descriptor in this.bindings.Values.Where<LinkDescriptor>(new Func<LinkDescriptor, bool>(resource.IsRelatedEntity)).ToList<LinkDescriptor>())
     {
         this.DetachExistingLink(descriptor, (descriptor.Target == resource.Entity) && (resource.State == EntityStates.Added));
     }
     resource.ChangeOrder = uint.MaxValue;
     resource.State = EntityStates.Detached;
     this.entityDescriptors.Remove(resource.Entity);
     this.DetachResourceIdentity(resource);
     return true;
 }
예제 #25
0
파일: SaveResult.cs 프로젝트: nickchal/pash
 private ODataRequestMessageWrapper CheckAndProcessMediaEntryPost(EntityDescriptor entityDescriptor)
 {
     ClientEdmModel model = ClientEdmModel.GetModel(base.RequestInfo.MaxProtocolVersion);
     ClientTypeAnnotation clientTypeAnnotation = model.GetClientTypeAnnotation(model.GetOrCreateEdmType(entityDescriptor.Entity.GetType()));
     if (!clientTypeAnnotation.IsMediaLinkEntry && !entityDescriptor.IsMediaLinkEntry)
     {
         return null;
     }
     if ((clientTypeAnnotation.MediaDataMember == null) && (entityDescriptor.SaveStream == null))
     {
         throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Context_MLEWithoutSaveStream(clientTypeAnnotation.ElementTypeName));
     }
     ODataRequestMessageWrapper mediaResourceRequest = null;
     if (clientTypeAnnotation.MediaDataMember != null)
     {
         string contentType = null;
         int length = 0;
         if (clientTypeAnnotation.MediaDataMember.MimeTypeProperty == null)
         {
             contentType = "application/octet-stream";
         }
         else
         {
             object obj2 = clientTypeAnnotation.MediaDataMember.MimeTypeProperty.GetValue(entityDescriptor.Entity);
             string str2 = (obj2 != null) ? obj2.ToString() : null;
             if (string.IsNullOrEmpty(str2))
             {
                 throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Context_NoContentTypeForMediaLink(clientTypeAnnotation.ElementTypeName, clientTypeAnnotation.MediaDataMember.MimeTypeProperty.PropertyName));
             }
             contentType = str2;
         }
         object propertyValue = clientTypeAnnotation.MediaDataMember.GetValue(entityDescriptor.Entity);
         if (propertyValue == null)
         {
             base.mediaResourceRequestStream = null;
         }
         else
         {
             byte[] bytes = propertyValue as byte[];
             if (bytes == null)
             {
                 string str3;
                 Encoding encoding;
                 HttpProcessUtility.ReadContentType(contentType, out str3, out encoding);
                 if (encoding == null)
                 {
                     encoding = Encoding.UTF8;
                     contentType = contentType + ";charset=UTF-8";
                 }
                 bytes = encoding.GetBytes(ClientConvert.ToString(propertyValue));
             }
             length = bytes.Length;
             base.mediaResourceRequestStream = new MemoryStream(bytes, 0, bytes.Length, false, true);
         }
         mediaResourceRequest = this.CreateMediaResourceRequest(entityDescriptor.GetResourceUri(base.RequestInfo.BaseUriResolver, false), "POST", Util.DataServiceVersion1, clientTypeAnnotation.MediaDataMember == null, true);
         mediaResourceRequest.SetHeader("Content-Length", length.ToString(CultureInfo.InvariantCulture));
         mediaResourceRequest.SetHeader("Content-Type", contentType);
         mediaResourceRequest.AddHeadersToReset("Content-Length");
         mediaResourceRequest.AddHeadersToReset("Content-Type");
     }
     else
     {
         mediaResourceRequest = this.CreateMediaResourceRequest(entityDescriptor.GetResourceUri(base.RequestInfo.BaseUriResolver, false), "POST", Util.DataServiceVersion1, clientTypeAnnotation.MediaDataMember == null, true);
         this.SetupMediaResourceRequest(mediaResourceRequest, entityDescriptor.SaveStream, null);
     }
     entityDescriptor.State = EntityStates.Modified;
     return mediaResourceRequest;
 }
예제 #26
0
 internal EntityDescriptor InternalAttachEntityDescriptor(EntityDescriptor entityDescriptorFromMaterializer, bool failIfDuplicated)
 {
     EntityDescriptor descriptor;
     EntityDescriptor descriptor2;
     this.EnsureIdentityToResource();
     this.entityDescriptors.TryGetValue(entityDescriptorFromMaterializer.Entity, out descriptor);
     this.identityToDescriptor.TryGetValue(entityDescriptorFromMaterializer.Identity, out descriptor2);
     if (failIfDuplicated && (descriptor != null))
     {
         throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Context_EntityAlreadyContained);
     }
     if (descriptor != descriptor2)
     {
         throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Context_DifferentEntityAlreadyContained);
     }
     if (descriptor == null)
     {
         descriptor = entityDescriptorFromMaterializer;
         this.IncrementChange(entityDescriptorFromMaterializer);
         this.entityDescriptors.Add(entityDescriptorFromMaterializer.Entity, entityDescriptorFromMaterializer);
         this.identityToDescriptor.Add(entityDescriptorFromMaterializer.Identity, entityDescriptorFromMaterializer);
     }
     return descriptor;
 }
예제 #27
0
파일: SaveResult.cs 프로젝트: nickchal/pash
 private ODataRequestMessageWrapper CheckAndProcessMediaEntryPut(EntityDescriptor entityDescriptor)
 {
     if (entityDescriptor.SaveStream == null)
     {
         return null;
     }
     Uri latestEditStreamUri = entityDescriptor.GetLatestEditStreamUri();
     if (latestEditStreamUri == null)
     {
         throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Context_SetSaveStreamWithoutEditMediaLink);
     }
     ODataRequestMessageWrapper mediaResourceRequest = this.CreateMediaResourceRequest(latestEditStreamUri, "PUT", Util.DataServiceVersion1, true, false);
     this.SetupMediaResourceRequest(mediaResourceRequest, entityDescriptor.SaveStream, entityDescriptor.GetLatestStreamETag());
     return mediaResourceRequest;
 }
예제 #28
0
 private void ValidateDuplicateIdentity(string identity, EntityDescriptor descriptor)
 {
     EntityDescriptor descriptor2;
     if ((this.identityToDescriptor.TryGetValue(identity, out descriptor2) && (descriptor != descriptor2)) && ((descriptor2.State != EntityStates.Deleted) && (descriptor2.State != EntityStates.Detached)))
     {
         throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Context_DifferentEntityAlreadyContained);
     }
 }
예제 #29
0
파일: SaveResult.cs 프로젝트: nickchal/pash
 protected override MaterializeAtom GetMaterializer(EntityDescriptor entityDescriptor, ResponseInfo responseInfo)
 {
     return new MaterializeAtom(responseInfo, new ODataEntry[] { this.cachedResponse.Entry }, entityDescriptor.Entity.GetType());
 }
예제 #30
0
 private MaterializeAtom ReadPropertyFromAtom(EntityDescriptor box, ClientPropertyAnnotation property)
 {
     MaterializeAtom atom2;
     DataServiceContext source = (DataServiceContext) base.Source;
     bool applyingChanges = source.ApplyingChanges;
     try
     {
         source.ApplyingChanges = true;
         bool flag2 = EntityStates.Deleted == box.State;
         bool instanceCreated = false;
         object instance = null;
         if (property.IsEntityCollection)
         {
             instance = this.GetCollectionInstance(property, out instanceCreated);
         }
         Type type = property.IsEntityCollection ? property.EntityCollectionItemType : property.NullablePropertyType;
         IList results = (IList) Activator.CreateInstance(typeof(List<>).MakeGenericType(new Type[] { type }));
         DataServiceQueryContinuation continuation = null;
         using (MaterializeAtom atom = base.GetMaterializer(this.plan))
         {
             bool flag4 = property.EdmProperty.PropertyKind == EdmPropertyKind.Navigation;
             int num = 0;
             foreach (object obj3 in atom)
             {
                 if (property.IsEntityCollection)
                 {
                     property.SetValue(instance, obj3, this.propertyName, true);
                     results.Add(obj3);
                 }
                 else if (property.IsPrimitiveOrComplexCollection)
                 {
                     object obj4 = property.GetValue(this.entity);
                     if (obj4 == null)
                     {
                         obj4 = Activator.CreateInstance(obj3.GetType());
                         property.SetValue(this.entity, obj4, this.propertyName, false);
                     }
                     else
                     {
                         property.ClearBackingICollectionInstance(obj4);
                     }
                     foreach (object obj5 in (IEnumerable) obj3)
                     {
                         property.AddValueToBackingICollectionInstance(obj4, obj5);
                     }
                     results.Add(obj4);
                 }
                 else
                 {
                     property.SetValue(this.entity, obj3, this.propertyName, false);
                     results.Add(obj3);
                 }
                 num++;
                 if (((obj3 != null) && (MergeOption.NoTracking != atom.MergeOptionValue)) && flag4)
                 {
                     if (flag2)
                     {
                         source.DeleteLink(this.entity, this.propertyName, obj3);
                     }
                     else
                     {
                         source.AttachLink(this.entity, this.propertyName, obj3, atom.MergeOptionValue);
                     }
                 }
             }
             continuation = atom.GetContinuation(null);
             Util.SetNextLinkForCollection(property.IsEntityCollection ? instance : this.entity, continuation);
         }
         if (instanceCreated)
         {
             property.SetValue(this.entity, instance, this.propertyName, false);
         }
         atom2 = MaterializeAtom.CreateWrapper(source, results, continuation);
     }
     finally
     {
         source.ApplyingChanges = applyingChanges;
     }
     return atom2;
 }
예제 #31
0
 protected Uri CreateRequestUri(EntityDescriptor sourceResource, LinkDescriptor binding)
 {
     Uri uri;
     LinkInfo linkInfo = null;
     if (sourceResource.TryGetLinkInfo(binding.SourceProperty, out linkInfo) && ((uri = linkInfo.AssociationLink) != null))
     {
         if (binding.IsSourcePropertyCollection && (EntityStates.Deleted == binding.State))
         {
             EntityDescriptor entityDescriptor = this.RequestInfo.EntityTracker.GetEntityDescriptor(binding.Target);
             uri = DataServiceContext.AppendKeysToUri(uri.AbsoluteUri, entityDescriptor.Entity, UriKind.Absolute, this.RequestInfo.MaxProtocolVersion);
         }
         return uri;
     }
     return Util.CreateUri(sourceResource.GetResourceUri(this.RequestInfo.BaseUriResolver, false), this.CreateRequestRelativeUri(binding));
 }