Пример #1
0
        internal void UpdateCompleteObject(DataServiceQueryProvider.ResultSetCollection resultSets)
        {
            DataServiceQueryProvider.ResultSet resultSet = null;
            Tracer tracer = new Tracer();

            if (resultSets == null || !resultSets.TryGetValue(this.ResourceType.Name, out resultSet))
            {
                tracer.DebugMessage(string.Concat("UpdateCompleteObject: result set ", this.ResourceType.Name, " not found"));
                throw new PowerShellWebServiceException(string.Concat("no result set named ", this.ResourceType.Name));
            }
            else
            {
                this.completeObject = resultSet.FirstOrDefault <DSResource>((DSResource item) => this.MatchKeyProperties(item));
                if (this.completeObject != null)
                {
                    tracer.DebugMessage("UpdateCompleteObject: found complete object");
                    return;
                }
                else
                {
                    tracer.DebugMessage("UpdateCompleteObject: no match for key properties of this object");
                    throw new PowerShellWebServiceException(string.Concat("no matching instance in result set named", this.ResourceType.Name));
                }
            }
        }
Пример #2
0
        public void VerifyConcurrencyValues(IEnumerable <KeyValuePair <string, object> > values)
        {
            DSResource originalResource = this.GetOriginalResource();

            if (originalResource != null)
            {
                foreach (KeyValuePair <string, object> value in values)
                {
                    object obj = originalResource.GetValue(value.Key, null);
                    if (obj.Equals(value.Value))
                    {
                        continue;
                    }
                    object[] key = new object[2];
                    key[0] = value.Key;
                    key[1] = value.Value;
                    throw new DataServiceException(0x19c, ExceptionHelpers.GetDataServiceExceptionMessage(HttpStatusCode.PreconditionFailed, Resources.PropertyKey, key));
                }
                return;
            }
            else
            {
                throw new OptimisticConcurrencyException(ExceptionHelpers.GetExceptionMessage(Resources.GetCmdletNotReturningAnObject, new object[0]));
            }
        }
Пример #3
0
 public bool Extract(Expression tree, IQueryable <DSResource> resourceRoot, ResourceType resourceType, EntityMetadata entityMetadata)
 {
     this.resourceRoot        = resourceRoot;
     this.entityMetadata      = entityMetadata;
     this.navigationProperty  = null;
     this.referredEntityKeys  = new Dictionary <string, object>();
     this.referringEntityKeys = new Dictionary <string, object>();
     this.currentState        = ReferredResourceExtractor.ExtractionState.ExtractingReferredEntityInfo;
     this.Visit(tree);
     if (this.currentState == ReferredResourceExtractor.ExtractionState.ExtractingReferringEntityInfo)
     {
         DSResource dSResource = ResourceTypeExtensions.CreateKeyOnlyResource(resourceType, this.referringEntityKeys);
         if (dSResource != null)
         {
             this.ReferredResource = ResourceTypeExtensions.CreateKeyOnlyResource(this.navigationProperty.ResourceType, this.referredEntityKeys);
             if (this.ReferredResource != null)
             {
                 this.currentState = ReferredResourceExtractor.ExtractionState.ExtractionDone;
             }
         }
     }
     if (this.currentState != ReferredResourceExtractor.ExtractionState.ExtractionDone)
     {
         this.currentState = ReferredResourceExtractor.ExtractionState.ExtractionFailed;
     }
     return(this.currentState == ReferredResourceExtractor.ExtractionState.ExtractionDone);
 }
Пример #4
0
 public ReferredEntityInstance(DSResource resource, UserContext userContext, ResourceType type, EntityMetadata metadata, string membershipId)
 {
     this.userContext  = userContext;
     this.resourceType = type;
     this.metadata     = metadata;
     this.membershipId = membershipId;
     this.resource     = resource;
 }
Пример #5
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);
        }
Пример #6
0
        public IEnumerator <DSResource> InvokeAsync(Expression expression, bool noStreamingResponse)
        {
            List <DSResource> dSResources = new List <DSResource>();
            DSResource        dSResource  = ResourceTypeExtensions.CreateResourceWithKeyAndReferenceSetCmdlets(this.resourceType, this.properties, this.entityMetadata);

            if (dSResource != null)
            {
                dSResources.Add(dSResource);
            }
            return(dSResources.GetEnumerator());
        }
Пример #7
0
 public EntityUpdate(UserContext userContext, ResourceType type, EntityMetadata metadata, string membershipId)
 {
     this.userContext     = userContext;
     this.resourceType    = type;
     this.metadata        = metadata;
     this.commandType     = CommandType.Create;
     this.query           = null;
     this.membershipId    = membershipId;
     this.propertyUpdates = new SortedDictionary <string, object>();
     this.updatedResource = null;
     this.resolveResource = null;
 }
Пример #8
0
 public void InvokeCommand()
 {
     if (PSCommandManager.IsReferenceCmdlet(this.commandType))
     {
         IReferenceSetCommand referenceSetCommand = DataServiceController.Current.GetReferenceSetCommand(this.commandType, this.userContext, this.referringProperty, this.metadata, this.membershipId, null);
         using (referenceSetCommand)
         {
             UriParametersHelper.AddParametersToCommand(referenceSetCommand, DataServiceController.Current.GetCurrentResourceUri());
             this.AddPropertyUpdates(referenceSetCommand);
             referenceSetCommand.AddReferredObject(this.referredInstance.GetKeyValues());
             referenceSetCommand.AddReferringObject(this.GetKeyValues());
             List <DSResource> dSResources = new List <DSResource>();
             DataServiceController.Current.QuotaSystem.CheckCmdletExecutionQuota(this.userContext);
             IEnumerator <DSResource> enumerator = referenceSetCommand.InvokeAsync(dSResources.AsQueryable <DSResource>().Expression, true);
             while (enumerator.MoveNext())
             {
             }
         }
     }
     else
     {
         ICommand command = DataServiceController.Current.GetCommand(this.commandType, this.userContext, this.resourceType, this.metadata, this.membershipId);
         using (command)
         {
             UriParametersHelper.AddParametersToCommand(command, DataServiceController.Current.GetCurrentResourceUri());
             this.AddPropertyUpdates(command);
             List <DSResource>        dSResources1 = new List <DSResource>();
             IEnumerator <DSResource> enumerator1  = command.InvokeAsync(dSResources1.AsQueryable <DSResource>().Expression, true);
             while (enumerator1.MoveNext())
             {
                 dSResources1.Add(enumerator1.Current);
             }
             if (this.commandType == CommandType.Delete || dSResources1.Count < 1)
             {
                 if (this.commandType != CommandType.Create || dSResources1.Count > 0)
                 {
                     this.updatedResource = null;
                 }
                 else
                 {
                     throw new DataServiceException(string.Format(Resources.CreateCommandNotReturnedInstance, this.resourceType.Name));
                 }
             }
             else
             {
                 this.updatedResource = dSResources1.First <DSResource>();
             }
         }
     }
 }
Пример #9
0
        private IEnumerable <DSResource> GetUniqueKeys(IQueryable <DSResource> source, ResourceProperty property)
        {
            DSResource.KeyEqualityComparer keyEqualityComparer = new DSResource.KeyEqualityComparer();
            List <DSResource> dSResources = new List <DSResource>();

            foreach (DSResource dSResource in source)
            {
                if (property.Kind != ResourcePropertyKind.ResourceReference)
                {
                    if (property.Kind != ResourcePropertyKind.ResourceSetReference)
                    {
                        throw new ArgumentException("the property is not a reference property", property.Name);
                    }
                    else
                    {
                        object value = dSResource.GetValue(property.Name, this.resultSets);
                        IEnumerable <DSResource> dSResources1 = value as IEnumerable <DSResource>;
                        if (dSResources1 == null)
                        {
                            object[] name = new object[1];
                            name[0] = property.Name;
                            throw new UnauthorizedAccessException(ExceptionHelpers.GetExceptionMessage(Resources.NoAccessToNavProperty, name));
                        }
                        else
                        {
                            dSResources.AddRange(dSResources1);
                        }
                    }
                }
                else
                {
                    DSResource value1 = dSResource.GetValue(property.Name, this.resultSets) as DSResource;
                    if (value1 == null)
                    {
                        continue;
                    }
                    dSResources.Add(value1);
                }
            }
            return(dSResources.Distinct <DSResource>(keyEqualityComparer));
        }
Пример #10
0
        private bool MatchKeyProperties(DSResource other)
        {
            bool flag;
            IEnumerator <ResourceProperty> enumerator = this.ResourceType.KeyProperties.GetEnumerator();

            using (enumerator)
            {
                while (enumerator.MoveNext())
                {
                    ResourceProperty current = enumerator.Current;
                    current.GetType();
                    if (this.properties[current.Name].Equals(other.properties[current.Name]))
                    {
                        continue;
                    }
                    flag = false;
                    return(flag);
                }
                return(true);
            }
            return(flag);
        }
Пример #11
0
 public object Resolve()
 {
     if (this.commandType != CommandType.Delete)
     {
         if (this.updatedResource == null)
         {
             if (this.resolveResource == null)
             {
                 this.resolveResource = new DSResource(this.resourceType, true);
             }
             return(this.resolveResource);
         }
         else
         {
             return(this.updatedResource);
         }
     }
     else
     {
         throw new NotImplementedException(ExceptionHelpers.GetExceptionMessage(Resources.ResolveResourceAfterDelete, new object[0]));
     }
 }
Пример #12
0
        public object GetPropertyValue(object resourceObject, ResourceProperty resourceProperty)
        {
            object value;

            object[] objArray = new object[2];
            objArray[0] = "resourceObject";
            objArray[1] = "DataServiceQueryProvider.GetPropertyValue";
            resourceObject.ThrowIfNull("resourceObject", new ParameterExtensions.MessageLoader(DataServiceQueryProvider.GetInputVariableToODataMethodNullMessage), objArray);
            object[] objArray1 = new object[2];
            objArray1[0] = "resourceProperty";
            objArray1[1] = "DataServiceQueryProvider.GetPropertyValue";
            resourceProperty.ThrowIfNull("resourceProperty", new ParameterExtensions.MessageLoader(DataServiceQueryProvider.GetInputVariableToODataMethodNullMessage), objArray1);
            DSResource dSResource = resourceObject as DSResource;

            if (dSResource != null)
            {
                try
                {
                    value = dSResource.GetValue(resourceProperty.Name, this.resultSets);
                }
                catch (PowerShellWebServiceException powerShellWebServiceException1)
                {
                    PowerShellWebServiceException powerShellWebServiceException = powerShellWebServiceException1;
                    powerShellWebServiceException.Trace(null);
                    value = null;
                }
                return(value);
            }
            else
            {
                object[] assemblyQualifiedName = new object[3];
                assemblyQualifiedName[0] = "resourceObject";
                assemblyQualifiedName[1] = resourceObject.GetType().AssemblyQualifiedName;
                assemblyQualifiedName[2] = typeof(DSResource).AssemblyQualifiedName;
                string exceptionMessage = ExceptionHelpers.GetExceptionMessage(Resources.InvalidArgClrType, assemblyQualifiedName);
                throw new ArgumentException(exceptionMessage, "resourceObject");
            }
        }
Пример #13
0
        public ResourceType GetResourceType(object resourceObject)
        {
            TraceHelper.Current.MethodCall0("DataServiceQueryProvider", "GetResourceType");
            object[] objArray = new object[2];
            objArray[0] = "resourceObject";
            objArray[1] = "DataServiceQueryProvider.GetResourceType";
            resourceObject.ThrowIfNull("resourceObject", new ParameterExtensions.MessageLoader(DataServiceQueryProvider.GetInputVariableToODataMethodNullMessage), objArray);
            DSResource dSResource = resourceObject as DSResource;

            if (dSResource != null)
            {
                return(dSResource.ResourceType);
            }
            else
            {
                object[] assemblyQualifiedName = new object[3];
                assemblyQualifiedName[0] = "resourceObject";
                assemblyQualifiedName[1] = resourceObject.GetType().AssemblyQualifiedName;
                assemblyQualifiedName[2] = typeof(DSResource).AssemblyQualifiedName;
                string exceptionMessage = ExceptionHelpers.GetExceptionMessage(Resources.InvalidArgClrType, assemblyQualifiedName);
                throw new ArgumentException(exceptionMessage, "resourceObject");
            }
        }
Пример #14
0
        public EntityUpdate(CommandType commandType, UserContext userContext, ResourceType type, EntityMetadata metadata, IQueryable query, string membershipId)
        {
            ExceptionHelpers.ThrowArgumentExceptionIf("commandType", commandType != CommandType.Update, Resources.InternalErrorOccurred, new object[0]);
            this.query           = query;
            this.userContext     = userContext;
            this.membershipId    = membershipId;
            this.resourceType    = type;
            this.metadata        = metadata;
            this.commandType     = commandType;
            this.propertyUpdates = new SortedDictionary <string, object>();
            this.updatedResource = null;
            this.resolveResource = null;
            CommandArgumentVisitor commandArgumentVisitor = new CommandArgumentVisitor(this);

            commandArgumentVisitor.Visit(query.Expression);
            if (this.AreAllKeyFieldsSpecified())
            {
                return;
            }
            else
            {
                throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.KeysMissingInQuery, new object[0]));
            }
        }