コード例 #1
0
ファイル: PSCommandManager.cs プロジェクト: nickchal/pash
		public IReferenceSetCommand GetReferenceSetCommand(CommandType commandType, UserContext userContext, ResourceProperty property, EntityMetadata entityMetadata, string membershipId, ResourceType resourceType)
		{
			Envelope<PSRunspace, UserContext> envelope = this.runspaceStore.Borrow(userContext, membershipId);
			PSReferenceSetCmdletInfo item = null;
			try
			{
				item = ((PSEntityMetadata)entityMetadata).CmdletsForReferenceSets[property.Name].Cmdlets[commandType];
			}
			catch (KeyNotFoundException keyNotFoundException)
			{
				Tracer tracer = new Tracer();
				tracer.DebugMessage(string.Concat("GetCommand cannot find commandType: ", commandType.ToString()));
				object[] fullName = new object[3];
				fullName[0] = property.ResourceType.FullName;
				fullName[1] = property.Name;
				fullName[2] = commandType.ToString();
				string str = string.Format(CultureInfo.CurrentCulture, Resources.PropertyDoesNotHaveCommand, fullName);
				throw new InvalidOperationException(str);
			}
			return new PSReferenceCommand(envelope, resourceType, item);
		}
コード例 #2
0
        public static void CreateDataServiceController(DSConfiguration settings, CustomAuthorizationHandler.ICustomContextStore customContextStore, ISchemaBuilder testSchemaBuilder)
        {
            string filePath;

            lock (DataServiceController.syncObject)
            {
                Configuration configuration = null;
                if (settings == null)
                {
                    try
                    {
                        settings = DSConfiguration.GetSection(configuration);
                    }
                    catch (Exception exception1)
                    {
                        Exception exception = exception1;
                        Microsoft.Management.Odata.Tracing.Tracer current = TraceHelper.Current;
                        string str = "config file is ";
                        if (configuration == null)
                        {
                            filePath = "(not available)";
                        }
                        else
                        {
                            filePath = configuration.FilePath;
                        }
                        current.DebugMessage(string.Concat(str, filePath));
                        if (TraceHelper.IsEnabled(5))
                        {
                            TraceHelper.Current.DebugMessage(exception.ToTraceMessage("DataServiceController failed to create"));
                        }
                        TraceHelper.Current.DataServiceControllerCreationFailedOperational(exception.Message);
                        throw;
                    }
                }
                DataServiceController.current = new DataServiceController(settings, customContextStore, testSchemaBuilder);
            }
        }
コード例 #3
0
ファイル: EntityTypeSerializer.cs プロジェクト: nickchal/pash
		public override object Serialize(object clrObject, int depth)
		{
			object value;
			object[] name = new object[1];
			name[0] = base.ResourceType.Name;
			clrObject.ThrowIfNull("clrObject", new ParameterExtensions.MessageLoader(SerializerBase.GetNullPassedForSerializingEntityMessage), name);
			ResourceType resourceType = base.ResourceType;
			if (clrObject as PSObject == null)
			{
				resourceType = base.ResourceType.FindResourceType(clrObject.GetType());
			}
			else
			{
				PSObject pSObject = clrObject as PSObject;
				if (pSObject != null && pSObject.BaseObject != null)
				{
					resourceType = base.ResourceType.FindResourceType(pSObject.BaseObject.GetType());
				}
			}
			DSResource dSResource = new DSResource(resourceType, this.serializeKeyOnly);
			foreach (ResourceProperty property in resourceType.Properties)
			{
				if (this.serializeKeyOnly && (property.Kind & ResourcePropertyKind.Key) != ResourcePropertyKind.Key)
				{
					continue;
				}
				if ((property.Kind & ResourcePropertyKind.ResourceSetReference) == ResourcePropertyKind.ResourceSetReference)
				{
					PSEntityMetadata testHookEntityMetadata = this.TestHookEntityMetadata;
					if (testHookEntityMetadata == null)
					{
						DataContext currentContext = DataServiceController.Current.GetCurrentContext();
						if (currentContext != null)
						{
							testHookEntityMetadata = currentContext.UserSchema.GetEntityMetadata(base.ResourceType) as PSEntityMetadata;
						}
					}
					if (testHookEntityMetadata != null)
					{
						PSEntityMetadata.ReferenceSetCmdlets referenceSetCmdlet = null;
						if (testHookEntityMetadata.CmdletsForReferenceSets.TryGetValue(property.Name, out referenceSetCmdlet) && referenceSetCmdlet.Cmdlets.ContainsKey(CommandType.GetReference))
						{
							if (referenceSetCmdlet.GetRefHidden)
							{
								dSResource.SetValue(property.Name, null);
								continue;
							}
							else
							{
								PSReferencedResourceSet pSReferencedResourceSet = new PSReferencedResourceSet(property, base.ResourceType);
								dSResource.SetValue(property.Name, pSReferencedResourceSet);
								continue;
							}
						}
					}
				}
				if (clrObject != null)
				{
					value = SerializerBase.GetValue(property, clrObject);
				}
				else
				{
					value = null;
				}
				object obj = value;
				if (obj == null)
				{
					if (!property.ResourceType.IsPrimitive() || property.ResourceType.IsNullable())
					{
						if ((property.Kind & (ResourcePropertyKind.Primitive | ResourcePropertyKind.ResourceReference)) != 0)
						{
							Tracer tracer = new Tracer();
							tracer.DebugMessage(string.Concat(property.Name, " is null; skipping"));
							continue;
						}
					}
					else
					{
						object[] objArray = new object[1];
						objArray[0] = property.Name;
						throw new PSObjectSerializationFailedException(string.Format(CultureInfo.CurrentCulture, Resources.PropertyNotFoundInPSObject, objArray));
					}
				}
				dSResource.SetValue(property.Name, SerializerBase.SerializeResourceProperty(obj, base.ResourceType, property, depth));
			}
			return dSResource;
		}
コード例 #4
0
ファイル: PSCommand.cs プロジェクト: nickchal/pash
		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);
		}
コード例 #5
0
ファイル: PSCommand.cs プロジェクト: nickchal/pash
		private static Exception GetStreamException(string cmdletName, PSDataStreams streams)
		{
			string str;
			string empty;
			if (streams.Error.Count <= 0)
			{
				return null;
			}
			else
			{
				PSDataCollection<ErrorRecord> error = streams.Error;
				string str1 = error[0].ToString();
				if (error.Count >= 2)
				{
					str = error[1].ToString();
				}
				else
				{
					str = string.Empty;
				}
				string str2 = str;
				if (error.Count >= 3)
				{
					empty = error[2].ToString();
				}
				else
				{
					empty = string.Empty;
				}
				string str3 = empty;
				Tracer tracer = new Tracer();
				tracer.CommandInvocationError(cmdletName, (uint)error.Count, str1, str2, str3);
				return error[0].Exception;
			}
		}
コード例 #6
0
ファイル: ServiceHostFactory.cs プロジェクト: nickchal/pash
		public ServiceHostFactory()
		{
			Tracer tracer = new Tracer();
			tracer.MethodCall0("ServiceHostFactory", "ServiceHostFactory");
		}
コード例 #7
0
ファイル: ServiceHostFactory.cs プロジェクト: nickchal/pash
		protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
		{
			Tracer tracer = new Tracer();
			tracer.MethodCall1("ServiceHostFactory", "CreateServiceHost", serviceType.ToString());
			return base.CreateServiceHost(serviceType, baseAddresses);
		}