Exemple #1
0
        public object GetResource(IQueryable query, string fullTypeName)
        {
            object obj;

            TraceHelper.Current.MethodCall2("DataServiceUpdateProvider", "GetResource", query.ToString(), fullTypeName);
            try
            {
                DSLinqQueryProvider provider = query.Provider as DSLinqQueryProvider;
                ExceptionHelpers.ThrowArgumentExceptionIf("query", provider == null, Resources.QueryDoesNotIncludePswsProvider, new object[0]);
                if (!provider.IsFilterOverResourceRoot(query.Expression))
                {
                    ReferredResourceExtractor referredResourceExtractor = new ReferredResourceExtractor();
                    DSResource current = null;
                    if (!referredResourceExtractor.Extract(query.Expression, provider.GetInitialQueryable(), provider.GetInitialResourceType(), provider.GetEntityMetadata(provider.GetInitialResourceType())))
                    {
                        IEnumerator <DSResource> enumerator = (query.GetEnumerator() as IEnumerable <DSResource>).GetEnumerator();
                        if (enumerator.MoveNext())
                        {
                            current = enumerator.Current;
                            if (enumerator.MoveNext())
                            {
                                throw new ArgumentException("multiple instances");
                            }
                        }
                        else
                        {
                            throw new ArgumentException("no instances");
                        }
                    }
                    else
                    {
                        current = referredResourceExtractor.ReferredResource;
                    }
                    ResourceType    resourceType           = current.ResourceType;
                    EntityMetadata  entityMetadata         = provider.GetEntityMetadata(resourceType);
                    IUpdateInstance referredEntityInstance = new ReferredEntityInstance(current, this.dataContext.UserContext, resourceType, entityMetadata, this.dataContext.MembershipId);
                    this.instances.Add(referredEntityInstance);
                    obj = referredEntityInstance;
                }
                else
                {
                    ResourceType   initialResourceType = provider.GetInitialResourceType();
                    EntityMetadata entityMetadatum     = provider.GetEntityMetadata(initialResourceType);
                    this.entityInstance = new EntityUpdate(CommandType.Update, this.dataContext.UserContext, initialResourceType, entityMetadatum, query, this.dataContext.MembershipId);
                    this.instances.Add(this.entityInstance);
                    obj = this.entityInstance;
                }
            }
            catch (ArgumentException argumentException1)
            {
                ArgumentException argumentException = argumentException1;
                TraceHelper.Current.InvalidUpdateQuery(fullTypeName, query.ToString(), argumentException.GetType().ToString(), argumentException.Message);
                obj = null;
            }
            return(obj);
        }
		public object GetResource(IQueryable query, string fullTypeName)
		{
			object obj;
			TraceHelper.Current.MethodCall2("DataServiceUpdateProvider", "GetResource", query.ToString(), fullTypeName);
			try
			{
				DSLinqQueryProvider provider = query.Provider as DSLinqQueryProvider;
				ExceptionHelpers.ThrowArgumentExceptionIf("query", provider == null, Resources.QueryDoesNotIncludePswsProvider, new object[0]);
				if (!provider.IsFilterOverResourceRoot(query.Expression))
				{
					ReferredResourceExtractor referredResourceExtractor = new ReferredResourceExtractor();
					DSResource current = null;
					if (!referredResourceExtractor.Extract(query.Expression, provider.GetInitialQueryable(), provider.GetInitialResourceType(), provider.GetEntityMetadata(provider.GetInitialResourceType())))
					{
						IEnumerator<DSResource> enumerator = (query.GetEnumerator() as IEnumerable<DSResource>).GetEnumerator();
						if (enumerator.MoveNext())
						{
							current = enumerator.Current;
							if (enumerator.MoveNext())
							{
								throw new ArgumentException("multiple instances");
							}
						}
						else
						{
							throw new ArgumentException("no instances");
						}
					}
					else
					{
						current = referredResourceExtractor.ReferredResource;
					}
					ResourceType resourceType = current.ResourceType;
					EntityMetadata entityMetadata = provider.GetEntityMetadata(resourceType);
					IUpdateInstance referredEntityInstance = new ReferredEntityInstance(current, this.dataContext.UserContext, resourceType, entityMetadata, this.dataContext.MembershipId);
					this.instances.Add(referredEntityInstance);
					obj = referredEntityInstance;
				}
				else
				{
					ResourceType initialResourceType = provider.GetInitialResourceType();
					EntityMetadata entityMetadatum = provider.GetEntityMetadata(initialResourceType);
					this.entityInstance = new EntityUpdate(CommandType.Update, this.dataContext.UserContext, initialResourceType, entityMetadatum, query, this.dataContext.MembershipId);
					this.instances.Add(this.entityInstance);
					obj = this.entityInstance;
				}
			}
			catch (ArgumentException argumentException1)
			{
				ArgumentException argumentException = argumentException1;
				TraceHelper.Current.InvalidUpdateQuery(fullTypeName, query.ToString(), argumentException.GetType().ToString(), argumentException.Message);
				obj = null;
			}
			return obj;
		}