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)); } } }
internal Expression ProcessNestedWhereOfResourceRoot(Expression rootExpression, MethodCallExpression whereExpression, bool insideNavPropertyWithGetReferenceCmdlet = false) { ICommand referenceInstanceBuilderCommand; ResourceType initialResourceType = this.GetInitialResourceType(); EntityMetadata item = this.schema.EntityMetadataDictionary[initialResourceType.FullName]; DataServiceQueryProvider.ResultSet resultSet = new DataServiceQueryProvider.ResultSet(initialResourceType); Expression expression = null; if (insideNavPropertyWithGetReferenceCmdlet) { referenceInstanceBuilderCommand = new ReferenceInstanceBuilderCommand(initialResourceType, item); } else { referenceInstanceBuilderCommand = DataServiceController.Current.GetCommand(CommandType.Read, this.userContext, initialResourceType, item, this.membershipId); } using (referenceInstanceBuilderCommand) { UriParametersHelper.AddParametersToCommand(referenceInstanceBuilderCommand, DataServiceController.Current.GetCurrentResourceUri()); this.TryAddingAllExpressions(rootExpression, whereExpression, referenceInstanceBuilderCommand, resultSet, out expression); this.InvokeCommandWithQuota(referenceInstanceBuilderCommand, resultSet); } IQueryable <DSResource> dSResources = resultSet.AsQueryable <DSResource>(); ExpressionNodeReplacer expressionNodeReplacer = new ExpressionNodeReplacer(expression, Expression.Constant(dSResources)); Expression expression1 = expressionNodeReplacer.Visit(rootExpression); return(expression1); }
internal Expression ProcessSelectExpansion(Expression rootExpression, MethodCallExpression selectExpression) { LambdaExpression operand = (LambdaExpression)((UnaryExpression)selectExpression.Arguments[1]).Operand; operand = (LambdaExpression)PartialEvaluator.Eval(operand); List <ResourceProperty> refPropertiesUsed = GetRefPropertiesUsed(operand); IQueryable <DSResource> source = this.EvaluateByLinqToObjects(selectExpression.Arguments[0]) as IQueryable <DSResource>; foreach (ResourceProperty property in refPropertiesUsed) { ResourceType resourceType = property.ResourceType; DataServiceQueryProvider.ResultSet associatedInstances = this.GetAssociatedInstances(source, property); DataServiceQueryProvider.ResultSet set2 = null; if (this.resultSets.TryGetValue(resourceType.Name, out set2)) { set2.Concat <DSResource>(associatedInstances); } else { this.resultSets[resourceType.Name] = associatedInstances; } } MethodCallExpression expression = new DSMethodTranslatingVisitor(this.resultSets).VisitAndConvert <MethodCallExpression>(selectExpression, "ProcessSelectExpansion"); object obj2 = source.Provider.CreateQuery(expression); var ___Site4 = CallSite <Func <CallSite, Type, MethodCallExpression, object, ExpressionNodeReplacer> > .Create(Microsoft.CSharp.RuntimeBinder.Binder.InvokeConstructor(CSharpBinderFlags.None, typeof(DSLinqQueryProvider), new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.IsStaticType | CSharpArgumentInfoFlags.UseCompileTimeType, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) })); return(___Site4.Target(___Site4, typeof(ExpressionNodeReplacer), selectExpression, Expression.Constant((dynamic)obj2)).Visit(rootExpression)); }
internal Expression ProcessWhereWithResourceRoot(Expression rootExpression, MethodCallExpression whereExpression, bool insideNavPropertyWithGetReferenceCmdlet = false) { ICommand command; LambdaExpression operand = (LambdaExpression)((UnaryExpression)whereExpression.Arguments[1]).Operand; operand = (LambdaExpression)PartialEvaluator.Eval(operand); ResourceType initialResourceType = this.GetInitialResourceType(); EntityMetadata entityMetadatum = this.schema.EntityMetadataDictionary[initialResourceType.FullName]; if (!insideNavPropertyWithGetReferenceCmdlet) { command = DataServiceController.Current.GetCommand(CommandType.Read, this.userContext, initialResourceType, entityMetadatum, this.membershipId); } else { command = new ReferenceInstanceBuilderCommand(initialResourceType, entityMetadatum); } DataServiceQueryProvider.ResultSet resultSet = null; using (command) { operand = this.InvokeFilteredGet(command, initialResourceType, operand, out resultSet); } DSMethodTranslatingVisitor dSMethodTranslatingVisitor = new DSMethodTranslatingVisitor(this.resultSets); operand = dSMethodTranslatingVisitor.VisitAndConvert <LambdaExpression>(operand, "ProcessWhereWithResourceRoot"); Func <DSResource, bool> func = (Func <DSResource, bool>)operand.Compile(); IQueryable <DSResource> dSResources = resultSet.Where <DSResource>((DSResource item) => func(item)).AsQueryable <DSResource>(); ExpressionNodeReplacer expressionNodeReplacer = new ExpressionNodeReplacer(whereExpression, Expression.Constant(dSResources)); Expression expression = expressionNodeReplacer.Visit(rootExpression); return(expression); }
private DSLinqQueryProvider(Microsoft.Management.Odata.Schema.Schema schema, ResourceType root, UserContext userContext, string membershipId, DataServiceQueryProvider.ResultSetCollection resultSets) { this.schema = schema; this.initialResourceRoot = new DataServiceQueryProvider.ResultSet(root); this.initialQueryable = this.initialResourceRoot.AsQueryable <DSResource>(); this.resultSets = resultSets; this.userContext = userContext; this.membershipId = membershipId; }
internal Expression ProcessResourceRoot(Expression rootExpression, ConstantExpression whereExpression) { ResourceType resourceType = this.initialResourceRoot.ResourceType; DataServiceQueryProvider.ResultSet resultSet = null; EntityMetadata item = this.schema.EntityMetadataDictionary[resourceType.FullName]; ICommand command = DataServiceController.Current.GetCommand(CommandType.Read, this.userContext, resourceType, item, this.membershipId); using (command) { this.InvokeFilteredGet(command, resourceType, null, out resultSet); } IQueryable <DSResource> dSResources = resultSet.AsQueryable <DSResource>(); ExpressionNodeReplacer expressionNodeReplacer = new ExpressionNodeReplacer(whereExpression, Expression.Constant(dSResources)); Expression expression = expressionNodeReplacer.Visit(rootExpression); return(expression); }
internal LambdaExpression InvokeFilteredGet(ICommand command, ResourceType originType, LambdaExpression filter, out DataServiceQueryProvider.ResultSet resultSet) { LambdaExpression lambdaExpression; using (OperationTracer operationTracer = new OperationTracer("ProcessExpression")) { LambdaExpression lambdaExpression1 = null; //this.schema.EntityMetadataDictionary[originType.FullName]; resultSet = new DataServiceQueryProvider.ResultSet(originType); UriParametersHelper.AddParametersToCommand(command, DataServiceController.Current.GetCurrentResourceUri()); if (filter != null) { CommandArgumentVisitor commandArgumentVisitor = new CommandArgumentVisitor(command); lambdaExpression1 = commandArgumentVisitor.VisitAndConvert <LambdaExpression>(filter, "InvokeFilteredGet"); } this.InvokeCommandWithQuota(command, resultSet); lambdaExpression = lambdaExpression1; } return(lambdaExpression); }
private void InvokeCommandWithQuota(ICommand command, DataServiceQueryProvider.ResultSet resultSet) { try { if (command.GetType() != typeof(ReferenceInstanceBuilderCommand)) { DataServiceController.Current.QuotaSystem.CheckCmdletExecutionQuota(this.userContext); } IEnumerator <DSResource> enumerator = command.InvokeAsync(new List <DSResource>().AsQueryable <DSResource>().Expression, true); while (enumerator.MoveNext()) { resultSet.Add(enumerator.Current); } } catch (Exception exception1) { Exception exception = exception1; Tracer tracer = new Tracer(); tracer.ExceptionMessage(exception.Message); throw; } }
internal bool TryAddingAllExpressions(Expression rootExpression, Expression baseExpression, ICommand command, DataServiceQueryProvider.ResultSet resultSet, out Expression nodeToReplace) { if (!ExpressionHelper.IsResourceRoot(baseExpression, this.initialQueryable)) { MethodCallExpression methodCallExpression = baseExpression as MethodCallExpression; bool flag = this.TryAddingAllExpressions(rootExpression, methodCallExpression.Arguments[0], command, resultSet, out nodeToReplace); if (!flag) { return(false); } else { LambdaExpression operand = (LambdaExpression)((UnaryExpression)methodCallExpression.Arguments[1]).Operand; operand = (LambdaExpression)PartialEvaluator.Eval(operand); CommandArgumentVisitor commandArgumentVisitor = new CommandArgumentVisitor(command); operand = commandArgumentVisitor.VisitAndConvert <LambdaExpression>(operand, "TryAddingAllExpressions"); if (!ExpressionHelper.IsConstantTrue(operand.Body)) { return(false); } else { nodeToReplace = methodCallExpression; return(true); } } } else { nodeToReplace = baseExpression; return(true); } }
internal DataServiceQueryProvider.ResultSet GetAssociatedInstances(IQueryable <DSResource> source, ResourceProperty property) { EntityMetadata entityMetadatum = null; DataServiceQueryProvider.ResultSet resultSet; using (OperationTracer operationTracer = new OperationTracer("ProcessExpression")) { if (this.schema.EntityMetadataDictionary.TryGetValue(property.ResourceType.FullName, out entityMetadatum)) { DataServiceQueryProvider.ResultSet resultSet1 = new DataServiceQueryProvider.ResultSet(property.ResourceType); IEnumerable <DSResource> uniqueKeys = this.GetUniqueKeys(source, property); foreach (DSResource uniqueKey in uniqueKeys) { if (!uniqueKey.ContainsNonKeyProperties) { ICommand command = DataServiceController.Current.GetCommand(CommandType.Read, this.userContext, property.ResourceType, entityMetadatum, this.membershipId); using (command) { UriParametersHelper.AddParametersToCommand(command, DataServiceController.Current.GetCurrentResourceUri()); foreach (ResourceProperty keyProperty in property.ResourceType.KeyProperties) { if (command.AddFieldParameter(keyProperty.Name, uniqueKey.GetValue(keyProperty.Name, null))) { continue; } object[] name = new object[2]; name[0] = property.ResourceType.Name; name[1] = keyProperty.Name; string str = string.Format(CultureInfo.CurrentCulture, Resources.KeyParameterFailed, name); throw new NotImplementedException(str); } try { DataServiceController.Current.QuotaSystem.CheckCmdletExecutionQuota(this.userContext); IEnumerator <DSResource> enumerator = command.InvokeAsync(new List <DSResource>().AsQueryable <DSResource>().Expression, true); while (enumerator.MoveNext()) { resultSet1.Add(enumerator.Current); } } catch (Exception exception1) { Exception exception = exception1; Tracer tracer = new Tracer(); tracer.ExceptionMessage(exception.Message); throw; } } } else { resultSet1.Add(uniqueKey); } } resultSet = resultSet1; } else { object[] objArray = new object[1]; objArray[0] = property.Name; throw new UnauthorizedAccessException(ExceptionHelpers.GetExceptionMessage(Resources.NoAccessToNavProperty, objArray)); } } return(resultSet); }