public Schema Create(UserContext id, string membershipId) { Schema schema; try { using (OperationTracer operationTracer = new OperationTracer(new Action <string>(TraceHelper.Current.UserSchemaCreationStart), new Action <string>(TraceHelper.Current.UserSchemaCreationEnd), id.Name)) { Schema schema1 = new Schema(this.logicalSchema.ContainerName, this.logicalSchema.ContainerNamespace); foreach (ISchemaBuilder schemaBuilder in this.schemaBuilders) { schemaBuilder.Build(this.logicalSchema, schema1, id, membershipId); } TraceHelper.Current.UserSchemaCreationSucceeded(id.Name); schema1.Trace(string.Concat("New user schema for user ", id.Name)); schema = schema1; } } catch (Exception exception1) { Exception exception = exception1; TraceHelper.Current.UserSchemaCreationFailed(id.Name, exception.Message); TraceHelper.Current.DebugMessage(exception.ToTraceMessage("User Schema creation failed", new StringBuilder()).ToString()); throw; } return(schema); }
public IEnumerator <DSResource> InvokeAsync(Expression expression, bool noStreamingResponse) { IEnumerator <DSResource> enumerator; using (OperationTracer operationTracer = new OperationTracer("Entering Pipeline.InvokeAsync")) { MonitorLock monitorLock = new MonitorLock(this); MonitorLock monitorLock1 = monitorLock; using (monitorLock) { if (this.Command == null || this.OutputFormat == null) { throw new DataServiceException(ExceptionHelpers.GetExceptionMessage(Resources.InvalidInvocationData, new object[0])); } else { this.ExpirationTime = DateTimeHelper.UtcNow; DateTime expirationTime = this.ExpirationTime; this.ExpirationTime = expirationTime.AddMilliseconds((double)this.WaitMsec); DateTime dateTime = this.ExpirationTime; this.ExpirationTime = dateTime.AddSeconds((double)DataServiceController.Current.Configuration.Invocation.Lifetime); WindowsImpersonationContext windowsImpersonationContext = this.executionToken.Instance.Impersonate(); using (windowsImpersonationContext) { using (OperationTracer operationTracer1 = new OperationTracer("PowerShell.Create")) { ScriptBlockAst scriptBlockAst = this.ValidateAndBuildPipeline(string.Concat(this.Command, "| ConvertTo-", this.OutputFormat)); Runspace.DefaultRunspace = this.runspace.Item.Runspace; this.powerShell = scriptBlockAst.GetScriptBlock().GetPowerShell(new object[0]); this.powerShell.Runspace = this.runspace.Item.Runspace; Runspace.DefaultRunspace = null; } TraceHelper.Current.BeginOperation0("RunspaceContext.Create"); DefaultRunspaceContext defaultRunspaceContext = DefaultRunspaceContext.Create(this.runspace.Item.Runspace); using (defaultRunspaceContext) { TraceHelper.Current.EndOperation("RunspaceContext.Create"); TraceHelper.Current.PipelineStart(this.ID, this.Command, this.OutputFormat); this.outputObjects.DataAdded += new EventHandler <DataAddedEventArgs>(this.DataAddedEventHandler); this.powerShell.BeginInvoke <PSObject, PSObject>(null, this.outputObjects, Utils.GetPSInvocationSettings(), this.TestHookCompletionCallback, null); monitorLock1.Exit(); this.finished.WaitOne(this.WaitMsec); this.timer.Start(); monitorLock1.Enter(); List <DSResource> dSResources = new List <DSResource>(); dSResources.Add(this.MakeDsResource()); TraceHelper.Current.DebugMessage("Exiting Pipeline.InvokeAsync"); enumerator = dSResources.AsEnumerable <DSResource>().GetEnumerator(); } } } } } return(enumerator); }
internal void DataAddedEventHandler(object obj, DataAddedEventArgs eventArgs) { int length; using (OperationTracer operationTracer = new OperationTracer("Invoke.OutputAddedCallback")) { lock (this) { if (obj == this.outputObjects) { PSObject item = this.outputObjects[eventArgs.Index]; string str = PipelineInvocation.TranslatePSObjectToString(item, this.OutputFormat); int maxResponseChars = DataServiceController.Current.Configuration.Invocation.MaxResponseChars; if (this.Output != null) { length = this.Output.Length; } else { length = 0; } int num = maxResponseChars - length; if (num < str.Length) { if (!this.outputQuotaExceeded) { this.outputQuotaExceeded = true; if (num > 0) { PipelineInvocation pipelineInvocation = this; pipelineInvocation.Output = string.Concat(pipelineInvocation.Output, str.Substring(0, num)); } object[] objArray = new object[1]; objArray[0] = DataServiceController.Current.Configuration.Invocation.MaxResponseChars; string str1 = string.Format(CultureInfo.CurrentCulture, Resources.InvocationOutputQuotaExceeded, objArray); ErrorRecord errorRecord = new ErrorRecord(new DataServiceException(0x193, str1), null, ErrorCategory.PermissionDenied, null); errorRecord.ErrorDetails = new ErrorDetails(str1); this.Errors.Add(errorRecord); } this.outputObjects.Clear(); } else { PipelineInvocation pipelineInvocation1 = this; pipelineInvocation1.Output = string.Concat(pipelineInvocation1.Output, str); } } else { return; } } } }
internal IEnumerator <DSResource> InvokeCmdletAsync(System.Management.Automation.PowerShell powerShell, Expression expression, EventHandler <DataAddedEventArgs> dataAddedEventHandler, AsyncCallback executionCompletionCallback, bool noStreamingResponse) { Tracer tracer = new Tracer(); this.dataStore = new AsyncDataStore <DSResource>(expression, noStreamingResponse); this.output = new PSDataCollection <PSObject>(); tracer.CommandInvocationStart(this.cmdletInfo.CmdletName); powerShell.Runspace = this.runspace.Item.Runspace; powerShell.AddCommand(this.cmdletInfo.CmdletName); foreach (string key in this.parameters.Keys) { if (!this.cmdletInfo.IsSwitch(key)) { powerShell.AddParameter(key, this.parameters[key]); } else { powerShell.AddParameter(key); } } this.isExecutionCompleted = false; using (OperationTracer operationTracer = new OperationTracer(new Action <string>(TraceHelper.Current.CmdletExecutionStart), new Action <string>(TraceHelper.Current.CmdletExecutionEnd), powerShell.Commands.ToTraceMessage())) { try { this.timer.Start(); powerShell.Invoke <PSObject>(null, this.output, Utils.GetPSInvocationSettings()); } catch (CommandNotFoundException commandNotFoundException1) { CommandNotFoundException commandNotFoundException = commandNotFoundException1; throw new CommandInvocationFailedException(powerShell.Commands.Commands[0].CommandText, commandNotFoundException); } catch (ParameterBindingException parameterBindingException1) { ParameterBindingException parameterBindingException = parameterBindingException1; throw new CommandInvocationFailedException(powerShell.Commands.Commands[0].CommandText, parameterBindingException); } catch (CmdletInvocationException cmdletInvocationException1) { CmdletInvocationException cmdletInvocationException = cmdletInvocationException1; throw new CommandInvocationFailedException(powerShell.Commands.Commands[0].CommandText, cmdletInvocationException); } } return(new BlockingEnumerator <DSResource>(this.dataStore)); }
public PSRunspace Create(UserContext userContext, string membershipId) { PSRunspace pSRunspace; TraceHelper.Current.BeginOperation0("borrow InitialSessionState"); Envelope <InitialSessionState, UserContext> envelope = this.initialSessionStateStore.Borrow(userContext, membershipId); using (envelope) { TraceHelper.Current.EndOperation("borrow InitialSessionState"); using (OperationTracer operationTracer = new OperationTracer(new Action <string>(TraceHelper.Current.PowerShellRunspaceCreationStart), new Action <string>(TraceHelper.Current.PowerShellRunspaceCreationEnd), userContext.Name)) { pSRunspace = new PSRunspace(envelope.Item, this.executeCmdletInSameThread); } } return(pSRunspace); }
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); }
public IQueryable CreateQuery(Expression expression) { IQueryable queryables; using (OperationTracer operationTracer = new OperationTracer("CreateQuery")) { Type enumerableElementType = TypeSystem.GetIEnumerableElementType(expression.Type); Type[] typeArray = new Type[1]; typeArray[0] = enumerableElementType; Type type = typeof(DSLinqQuery <>).MakeGenericType(typeArray); object[] objArray = new object[2]; objArray[0] = this; objArray[1] = expression; object[] objArray1 = objArray; Type[] typeArray1 = new Type[2]; typeArray1[0] = typeof(DSLinqQueryProvider); typeArray1[1] = typeof(Expression); ConstructorInfo constructor = type.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, typeArray1, null); queryables = (IQueryable)constructor.Invoke(objArray1); } return(queryables); }
public IQueryable GetQueryRootForResourceSet(ResourceSet resourceSet) { IQueryable queryables; string name; Tracer current = TraceHelper.Current; string str = "DataServiceQueryProvider"; string str1 = "GetQueryRootForResourceSet"; if (resourceSet == null) { name = "<null>"; } else { name = resourceSet.Name; } current.MethodCall1(str, str1, name); object[] objArray = new object[2]; objArray[0] = "resourceProperty"; objArray[1] = "DataServiceQueryProvider.GetQueryRootForResourceSet"; resourceSet.ThrowIfNull("resourceSet", new ParameterExtensions.MessageLoader(DataServiceQueryProvider.GetInputVariableToODataMethodNullMessage), objArray); try { using (OperationTracer operationTracer = new OperationTracer("GetQueryRoot")) { queryables = DSLinqQueryProvider.CreateQuery(this.dataContext.UserSchema, resourceSet.ResourceType, this.dataContext.UserContext, this.dataContext.MembershipId, this.resultSets); } } catch (Exception exception1) { Exception exception = exception1; exception.Trace(null); TraceHelper.Current.QueryGetQueryRootForResourceFailed(this.dataContext.UserContext.Name, resourceSet.Name); throw; } return(queryables); }
public SchemaFactory(string mofFileName, string dispatchFileName, List <ISchemaBuilder> schemaBuilders, DSConfiguration settings) { bool enabled; SchemaLoader schemaLoader = new SchemaLoader(); using (OperationTracer operationTracer = new OperationTracer(new Action <string>(TraceHelper.Current.SchemaLoadingStart), new Action <string>(TraceHelper.Current.SchemaLoadingEnd), mofFileName)) { if (settings == null) { enabled = true; } else { enabled = settings.Invocation.Enabled; } bool flag = enabled; this.logicalSchema = schemaLoader.LoadSchemaFiles(mofFileName, dispatchFileName, flag); if (settings != null) { this.logicalSchema.ValidateResourceLimits(settings); } } this.schemaBuilders = schemaBuilders; }
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); }