Exemplo n.º 1
0
        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;
                    }
                }
            }
        }
Exemplo n.º 2
0
        public IEnumerator <DSResource> InvokeAsync(Expression expression, bool noStreamingResponse)
        {
            object                   obj = null;
            PipelineInvocation       pipelineInvocation = null;
            object                   obj1 = null;
            PipelineInvocation       pipelineInvocation1 = null;
            IEnumerator <DSResource> enumerator;

            object[]    name;
            CommandType commandType = this.commandType;

            if (commandType == CommandType.Create)
            {
                UserDataCache.UserDataEnvelope userDataEnvelope = DataServiceController.Current.UserDataCache.Get(this.userContext);
                using (userDataEnvelope)
                {
                    Envelope <PSRunspace, UserContext> envelope = this.runspaceStore.Borrow(this.userContext, this.membershipId);
                    PipelineInvocation pipelineInvocation2      = new PipelineInvocation(envelope, this.entityType);
                    foreach (KeyValuePair <string, object> parameter in this.parameters)
                    {
                        pipelineInvocation2.AddFieldParameter(parameter.Key, parameter.Value);
                    }
                    PipelineInvocation pipelineInvocation3 = null;
                    userDataEnvelope.Data.CommandInvocations.AddOrLockKey(pipelineInvocation2.ID, pipelineInvocation2, out pipelineInvocation3);
                    try
                    {
                        List <DSResource> dSResources = new List <DSResource>();
                        pipelineInvocation3.InvokeAsync(dSResources.AsQueryable <DSResource>().Expression, true);
                        dSResources.Add(pipelineInvocation3.MakeDsResource());
                        enumerator = dSResources.GetEnumerator();
                    }
                    finally
                    {
                        userDataEnvelope.Data.CommandInvocations.TryUnlockKey(pipelineInvocation3.ID);
                    }
                }
            }
            else if (commandType == CommandType.Read)
            {
                UserDataCache.UserDataEnvelope userDataEnvelope1 = DataServiceController.Current.UserDataCache.Get(this.userContext);
                using (userDataEnvelope1)
                {
                    List <DSResource> dSResources1 = new List <DSResource>();
                    if (!this.parameters.TryGetValue("ID", out obj))
                    {
                        foreach (KeyValuePair <Guid, PipelineInvocation> list in userDataEnvelope1.Data.CommandInvocations.ToList())
                        {
                            dSResources1.Add(list.Value.MakeDsResource());
                        }
                    }
                    else
                    {
                        Guid guid = (Guid)obj;
                        if (userDataEnvelope1.Data.CommandInvocations.TryGetValue(guid, out pipelineInvocation))
                        {
                            dSResources1.Add(pipelineInvocation.MakeDsResource());
                        }
                    }
                    enumerator = dSResources1.GetEnumerator();
                }
            }
            else if (commandType == CommandType.Update)
            {
                name    = new object[2];
                name[0] = this.entityType.Name;
                name[1] = (object)this.commandType.ToString();
                throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.EntityDoesNotHaveCommand, name));
            }
            else if (commandType == CommandType.Delete)
            {
                UserDataCache.UserDataEnvelope userDataEnvelope2 = DataServiceController.Current.UserDataCache.Get(this.userContext);
                using (userDataEnvelope2)
                {
                    if (!this.parameters.TryGetValue("ID", out obj1))
                    {
                        throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.KeysMissingInQuery, new object[0]));
                    }
                    else
                    {
                        if (userDataEnvelope2.Data.CommandInvocations.TryGetValue((Guid)obj1, out pipelineInvocation1))
                        {
                            bool flag = pipelineInvocation1.Interrupt();
                            userDataEnvelope2.Data.CommandInvocations.TryRemove((Guid)obj1);
                            if (flag)
                            {
                                pipelineInvocation1.Dispose();
                            }
                        }
                        enumerator = (new List <DSResource>()).GetEnumerator();
                    }
                }
            }
            else
            {
                name    = new object[2];
                name[0] = this.entityType.Name;
                name[1] = (object)this.commandType.ToString();
                throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.EntityDoesNotHaveCommand, name));
            }
            return(enumerator);

            name    = new object[2];
            name[0] = this.entityType.Name;
            name[1] = this.commandType.ToString();
            throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.EntityDoesNotHaveCommand, name));
        }
Exemplo n.º 3
0
        public bool AddFieldParameter(string parameter, object value)
        {
            Func <ResourceProperty, bool> func = null;

            if (!string.Equals(parameter, "Command", StringComparison.Ordinal))
            {
                if (!string.Equals(parameter, "OutputFormat", StringComparison.Ordinal))
                {
                    if (!string.Equals(parameter, "WaitMsec", StringComparison.Ordinal))
                    {
                        ReadOnlyCollection <ResourceProperty> properties = this.entityType.Properties;
                        if (func == null)
                        {
                            func = (ResourceProperty it) => string.Equals(it.Name, parameter, StringComparison.Ordinal);
                        }
                        if (properties.FirstOrDefault <ResourceProperty>(func) == null)
                        {
                            object[] name = new object[2];
                            name[0] = this.entityType.Name;
                            name[1] = parameter;
                            throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.ReadOnlyProperty, name));
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        this.WaitMsec = (new BoundedPositiveInteger((int)value, 0x7530, true)).Value;
                        return(true);
                    }
                }
                else
                {
                    string str = value as string;
                    if (str != null)
                    {
                        if (PipelineInvocation.ValidateOutputFormat(str))
                        {
                            this.OutputFormat = str;
                            return(true);
                        }
                        else
                        {
                            object[] objArray = new object[2];
                            objArray[0] = parameter;
                            objArray[1] = value;
                            throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.InvalidParameterValue, objArray));
                        }
                    }
                    else
                    {
                        object[] objArray1 = new object[2];
                        objArray1[0] = parameter;
                        objArray1[1] = value;
                        throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.InvalidParameterValue, objArray1));
                    }
                }
            }
            else
            {
                if (value == null || value as string == null)
                {
                    object[] objArray2 = new object[2];
                    objArray2[0] = parameter;
                    objArray2[1] = value;
                    throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.InvalidParameterValue, objArray2));
                }
                else
                {
                    this.ValidateAndBuildPipeline(value as string);
                    this.Command = value as string;
                    return(true);
                }
            }
        }
Exemplo n.º 4
0
		public IEnumerator<DSResource> InvokeAsync(Expression expression, bool noStreamingResponse)
		{
			object obj = null;
			PipelineInvocation pipelineInvocation = null;
			object obj1 = null;
			PipelineInvocation pipelineInvocation1 = null;
			IEnumerator<DSResource> enumerator;
			object[] name;
			CommandType commandType = this.commandType;
			if (commandType == CommandType.Create)
			{
				UserDataCache.UserDataEnvelope userDataEnvelope = DataServiceController.Current.UserDataCache.Get(this.userContext);
				using (userDataEnvelope)
				{
					Envelope<PSRunspace, UserContext> envelope = this.runspaceStore.Borrow(this.userContext, this.membershipId);
					PipelineInvocation pipelineInvocation2 = new PipelineInvocation(envelope, this.entityType);
					foreach (KeyValuePair<string, object> parameter in this.parameters)
					{
						pipelineInvocation2.AddFieldParameter(parameter.Key, parameter.Value);
					}
					PipelineInvocation pipelineInvocation3 = null;
					userDataEnvelope.Data.CommandInvocations.AddOrLockKey(pipelineInvocation2.ID, pipelineInvocation2, out pipelineInvocation3);
					try
					{
						List<DSResource> dSResources = new List<DSResource>();
						pipelineInvocation3.InvokeAsync(dSResources.AsQueryable<DSResource>().Expression, true);
						dSResources.Add(pipelineInvocation3.MakeDsResource());
						enumerator = dSResources.GetEnumerator();
					}
					finally
					{
						userDataEnvelope.Data.CommandInvocations.TryUnlockKey(pipelineInvocation3.ID);
					}
				}
			}
			else if (commandType == CommandType.Read)
			{
				UserDataCache.UserDataEnvelope userDataEnvelope1 = DataServiceController.Current.UserDataCache.Get(this.userContext);
				using (userDataEnvelope1)
				{
					List<DSResource> dSResources1 = new List<DSResource>();
					if (!this.parameters.TryGetValue("ID", out obj))
					{
						foreach (KeyValuePair<Guid, PipelineInvocation> list in userDataEnvelope1.Data.CommandInvocations.ToList())
						{
							dSResources1.Add(list.Value.MakeDsResource());
						}
					}
					else
					{
						Guid guid = (Guid)obj;
						if (userDataEnvelope1.Data.CommandInvocations.TryGetValue(guid, out pipelineInvocation))
						{
							dSResources1.Add(pipelineInvocation.MakeDsResource());
						}
					}
					enumerator = dSResources1.GetEnumerator();
				}
			}
			else if (commandType == CommandType.Update)
			{
				name = new object[2];
				name[0] = this.entityType.Name;
				name[1] = (object)this.commandType.ToString();
				throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.EntityDoesNotHaveCommand, name));
			}
			else if (commandType == CommandType.Delete)
			{
				UserDataCache.UserDataEnvelope userDataEnvelope2 = DataServiceController.Current.UserDataCache.Get(this.userContext);
				using (userDataEnvelope2)
				{
					if (!this.parameters.TryGetValue("ID", out obj1))
					{
						throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.KeysMissingInQuery, new object[0]));
					}
					else
					{
						if (userDataEnvelope2.Data.CommandInvocations.TryGetValue((Guid)obj1, out pipelineInvocation1))
						{
							bool flag = pipelineInvocation1.Interrupt();
							userDataEnvelope2.Data.CommandInvocations.TryRemove((Guid)obj1);
							if (flag)
							{
								pipelineInvocation1.Dispose();
							}
						}
						enumerator = (new List<DSResource>()).GetEnumerator();
					}
				}
			}
			else
			{
				name = new object[2];
				name[0] = this.entityType.Name;
				name[1] = (object)this.commandType.ToString();
				throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.EntityDoesNotHaveCommand, name));
			}
			return enumerator;
			name = new object[2];
			name[0] = this.entityType.Name;
			name[1] = this.commandType.ToString();
			throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.EntityDoesNotHaveCommand, name));
		}