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); }
private DSResource GetOriginalResource() { DSResource dSResource; ICommand command = DataServiceController.Current.GetCommand(CommandType.Read, this.userContext, this.resourceType, this.metadata, this.membershipId); using (command) { UriParametersHelper.AddParametersToCommand(command, DataServiceController.Current.GetCurrentResourceUri()); CommandArgumentVisitor commandArgumentVisitor = new CommandArgumentVisitor(command); commandArgumentVisitor.Visit(this.query.Expression); List <DSResource> dSResources = new List <DSResource>(); DataServiceController.Current.QuotaSystem.CheckCmdletExecutionQuota(this.userContext); IEnumerator <DSResource> enumerator = command.InvokeAsync(dSResources.AsQueryable <DSResource>().Expression, true); while (enumerator.MoveNext()) { dSResources.Add(enumerator.Current); } if (dSResources.Count != 0) { dSResource = dSResources.First <DSResource>(); } else { throw new DataServiceException(0x194, ExceptionHelpers.GetDataServiceExceptionMessage(HttpStatusCode.NotFound, Resources.ResourceInstanceNotFound, new object[0])); } } return(dSResource); }
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>(); } } } }
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); }
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); }