当前位置: 首页>>代码示例>>C#>>正文


C# ManagementOperationObserver.RemoveSink方法代码示例

本文整理汇总了C#中System.Management.ManagementOperationObserver.RemoveSink方法的典型用法代码示例。如果您正苦于以下问题:C# ManagementOperationObserver.RemoveSink方法的具体用法?C# ManagementOperationObserver.RemoveSink怎么用?C# ManagementOperationObserver.RemoveSink使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Management.ManagementOperationObserver的用法示例。


在下文中一共展示了ManagementOperationObserver.RemoveSink方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetRelationshipClasses

		/// <summary>
		///    <para>Retrieves relationship classes that relate the class according to the specified 
		///       options, asynchronously.</para>
		/// </summary>
		/// <param name='watcher'>The handler for progress and results of the asynchronous operation.</param>
		/// <param name='relationshipClass'><para>The class from which all resulting relationship classes must derive.</para></param>
		/// <param name=' relationshipQualifier'>The qualifier which the resulting relationship classes must have.</param>
		/// <param name=' thisRole'>The role which the source class must have in the resulting relationship classes.</param>
		/// <param name=' options'> The options for retrieving the results.</param>
		/// <returns>
		///    <para>A collection of association classes
		///       relating this class to others, according to the given options.</para>
		/// </returns>
		public void GetRelationshipClasses(
			ManagementOperationObserver watcher, 
			string relationshipClass,
			string relationshipQualifier,
			string thisRole,
			EnumerationOptions options)
		{
			if ((null == Path) || (null == Path.Path) || (0 == Path.Path.Length))
				throw new InvalidOperationException();
			if (null == watcher)
				throw new ArgumentNullException("watcher");
			else
			{
				Initialize ( true ) ;
			
				EnumerationOptions o = 
						(null != options) ? (EnumerationOptions)options.Clone() : new EnumerationOptions();

				//Ensure EnumerateDeep flag is turned off as it's invalid for queries
				o.EnumerateDeep = true;

				// Ensure we switch off ReturnImmediately as this is invalid for async calls
				o.ReturnImmediately = false;

				// If someone has registered for progress, make sure we flag it
				if (watcher.HaveListenersForProgress)
					o.SendStatus = true;
				
				WmiEventSink sink = watcher.GetNewSink(Scope, o.Context);

				RelationshipQuery q = new RelationshipQuery(true, Path.Path, relationshipClass,
						relationshipQualifier, thisRole);

				SecurityHandler securityHandler = null;
				int status						= (int)ManagementStatus.NoError;

				securityHandler = Scope.GetSecurityHandler();

                            status = scope.GetSecuredIWbemServicesHandler(Scope.GetIWbemServices()).ExecQueryAsync_(
						q.QueryLanguage, 
						q.QueryString, 
						o.Flags, 
						o.GetContext(), 
						sink.Stub);


				if (securityHandler != null)
					securityHandler.Reset();

				if (status < 0)
				{
					watcher.RemoveSink(sink);
					if ((status & 0xfffff000) == 0x80041000)
						ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
					else
						Marshal.ThrowExceptionForHR(status);
				}
			}
		}
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:72,代码来源:ManagementClass.cs

示例2: GetSubclasses

		/// <summary>
		///    <para>Retrieves all classes derived from this class, asynchronously, using the specified 
		///       options.</para>
		/// </summary>
		/// <param name='watcher'>The object to handle the asynchronous operation's progress. </param>
		/// <param name='options'>The specified additional options to use in the derived class retrieval.</param>
		public void GetSubclasses(ManagementOperationObserver watcher,
										EnumerationOptions options) 
		{ 				
			if (null == watcher)
				throw new ArgumentNullException("watcher");
			
			if (null == Path)
				throw new InvalidOperationException();

			Initialize ( false ) ;

			EnumerationOptions o = (null == options) ? new EnumerationOptions() : 
									  (EnumerationOptions)options.Clone();

			//Need to make sure that we're not passing invalid flags to enumeration APIs.
			//The only flags in EnumerationOptions not valid for enumerations are EnsureLocatable & PrototypeOnly.
			o.EnsureLocatable = false; o.PrototypeOnly = false;

			// Ensure we switch off ReturnImmediately as this is invalid for async calls
			o.ReturnImmediately = false;

			// If someone has registered for progress, make sure we flag it
			if (watcher.HaveListenersForProgress)
				o.SendStatus = true;

			WmiEventSink sink = watcher.GetNewSink(Scope, o.Context);

			SecurityHandler securityHandler = null;
			int status						= (int)ManagementStatus.NoError;

			securityHandler = Scope.GetSecurityHandler();

                    status = scope.GetSecuredIWbemServicesHandler(Scope.GetIWbemServices() ).CreateClassEnumAsync_(ClassName,
				o.Flags,
				o.GetContext(),
				sink.Stub);


			if (securityHandler != null)
				securityHandler.Reset();

			if (status < 0)
			{
				watcher.RemoveSink(sink);
				if ((status & 0xfffff000) == 0x80041000)
					ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
				else
					Marshal.ThrowExceptionForHR(status);
			}
		}
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:56,代码来源:ManagementClass.cs

示例3: GetRelated

		public void GetRelated(ManagementOperationObserver watcher, string relatedClass, string relationshipClass, string relationshipQualifier, string relatedQualifier, string relatedRole, string thisRole, bool classDefinitionsOnly, EnumerationOptions options)
		{
			EnumerationOptions enumerationOption;
			if (this.path == null || this.path.Path.Length == 0)
			{
				throw new InvalidOperationException();
			}
			else
			{
				this.Initialize(true);
				if (watcher != null)
				{
					if (options != null)
					{
						enumerationOption = (EnumerationOptions)options.Clone();
					}
					else
					{
						enumerationOption = new EnumerationOptions();
					}
					EnumerationOptions enumerationOption1 = enumerationOption;
					enumerationOption1.ReturnImmediately = false;
					if (watcher.HaveListenersForProgress)
					{
						enumerationOption1.SendStatus = true;
					}
					WmiEventSink newSink = watcher.GetNewSink(this.scope, enumerationOption1.Context);
					RelatedObjectQuery relatedObjectQuery = new RelatedObjectQuery(this.path.Path, relatedClass, relationshipClass, relationshipQualifier, relatedQualifier, relatedRole, thisRole, classDefinitionsOnly);
					enumerationOption1.EnumerateDeep = true;
					SecurityHandler securityHandler = this.scope.GetSecurityHandler();
					int num = this.scope.GetSecuredIWbemServicesHandler(this.scope.GetIWbemServices()).ExecQueryAsync_(relatedObjectQuery.QueryLanguage, relatedObjectQuery.QueryString, enumerationOption1.Flags, enumerationOption1.GetContext(), newSink.Stub);
					securityHandler.Reset();
					if (num < 0)
					{
						watcher.RemoveSink(newSink);
						if (((long)num & (long)-4096) != (long)-2147217408)
						{
							Marshal.ThrowExceptionForHR(num);
						}
						else
						{
							ManagementException.ThrowWithExtendedInfo((ManagementStatus)num);
							return;
						}
					}
					return;
				}
				else
				{
					throw new ArgumentNullException("watcher");
				}
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:53,代码来源:ManagementObject.cs

示例4: Get

		public void Get(ManagementOperationObserver watcher)
		{
			if (watcher != null)
			{
				this.Initialize();
				IWbemServices wbemServices = this.scope.GetIWbemServices();
				EnumerationOptions enumerationOption = (EnumerationOptions)this.options.Clone();
				enumerationOption.ReturnImmediately = false;
				if (watcher.HaveListenersForProgress)
				{
					enumerationOption.SendStatus = true;
				}
				WmiEventSink newSink = watcher.GetNewSink(this.scope, enumerationOption.Context);
				SecurityHandler securityHandler = this.scope.GetSecurityHandler();
				int num = 0;
				try
				{
					try
					{
						if (!(this.query.GetType() == typeof(SelectQuery)) || ((SelectQuery)this.query).Condition != null || ((SelectQuery)this.query).SelectedProperties != null || !this.options.EnumerateDeep)
						{
							enumerationOption.EnumerateDeep = true;
							num = this.scope.GetSecuredIWbemServicesHandler(wbemServices).ExecQueryAsync_(this.query.QueryLanguage, this.query.QueryString, enumerationOption.Flags, enumerationOption.GetContext(), newSink.Stub);
						}
						else
						{
							enumerationOption.EnsureLocatable = false;
							enumerationOption.PrototypeOnly = false;
							if (((SelectQuery)this.query).IsSchemaQuery)
							{
								num = this.scope.GetSecuredIWbemServicesHandler(wbemServices).CreateClassEnumAsync_(((SelectQuery)this.query).ClassName, enumerationOption.Flags, enumerationOption.GetContext(), newSink.Stub);
							}
							else
							{
								num = this.scope.GetSecuredIWbemServicesHandler(wbemServices).CreateInstanceEnumAsync_(((SelectQuery)this.query).ClassName, enumerationOption.Flags, enumerationOption.GetContext(), newSink.Stub);
							}
						}
					}
					catch (COMException cOMException1)
					{
						COMException cOMException = cOMException1;
						watcher.RemoveSink(newSink);
						ManagementException.ThrowWithExtendedInfo(cOMException);
					}
				}
				finally
				{
					securityHandler.Reset();
				}
				if (((long)num & (long)-4096) != (long)-2147217408)
				{
					if (((long)num & (long)-2147483648) != (long)0)
					{
						Marshal.ThrowExceptionForHR(num);
					}
					return;
				}
				else
				{
					ManagementException.ThrowWithExtendedInfo((ManagementStatus)num);
					return;
				}
			}
			else
			{
				throw new ArgumentNullException("watcher");
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:68,代码来源:ManagementObjectSearcher.cs

示例5: Delete

		public void Delete(ManagementOperationObserver watcher, DeleteOptions options)
		{
			int num;
			DeleteOptions deleteOption;
			if (this.path == null || this.path.Path.Length == 0)
			{
				throw new InvalidOperationException();
			}
			else
			{
				if (watcher != null)
				{
					this.Initialize(false);
					if (options != null)
					{
						deleteOption = (DeleteOptions)options.Clone();
					}
					else
					{
						deleteOption = new DeleteOptions();
					}
					DeleteOptions deleteOption1 = deleteOption;
					if (watcher.HaveListenersForProgress)
					{
						deleteOption1.SendStatus = true;
					}
					IWbemServices wbemServices = this.scope.GetIWbemServices();
					WmiEventSink newSink = watcher.GetNewSink(this.scope, deleteOption1.Context);
					SecurityHandler securityHandler = this.scope.GetSecurityHandler();
					if (!base.IsClass)
					{
						num = this.scope.GetSecuredIWbemServicesHandler(wbemServices).DeleteInstanceAsync_(this.path.RelativePath, deleteOption1.Flags, deleteOption1.GetContext(), newSink.Stub);
					}
					else
					{
						num = this.scope.GetSecuredIWbemServicesHandler(wbemServices).DeleteClassAsync_(this.path.RelativePath, deleteOption1.Flags, deleteOption1.GetContext(), newSink.Stub);
					}
					if (securityHandler != null)
					{
						securityHandler.Reset();
					}
					if (num < 0)
					{
						watcher.RemoveSink(newSink);
						if (((long)num & (long)-4096) != (long)-2147217408)
						{
							Marshal.ThrowExceptionForHR(num);
						}
						else
						{
							ManagementException.ThrowWithExtendedInfo((ManagementStatus)num);
							return;
						}
					}
					return;
				}
				else
				{
					throw new ArgumentNullException("watcher");
				}
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:62,代码来源:ManagementObject.cs

示例6: Get

		public void Get(ManagementOperationObserver watcher)
		{
			this.Initialize(false);
			if (this.path == null || this.path.Path.Length == 0)
			{
				throw new InvalidOperationException();
			}
			else
			{
				if (watcher != null)
				{
					IWbemServices wbemServices = this.scope.GetIWbemServices();
					ObjectGetOptions objectGetOption = ObjectGetOptions._Clone(this.options);
					WmiGetEventSink newGetSink = watcher.GetNewGetSink(this.scope, objectGetOption.Context, this);
					if (watcher.HaveListenersForProgress)
					{
						objectGetOption.SendStatus = true;
					}
					SecurityHandler securityHandler = this.scope.GetSecurityHandler();
					int objectAsync_ = this.scope.GetSecuredIWbemServicesHandler(wbemServices).GetObjectAsync_(this.path.RelativePath, objectGetOption.Flags, objectGetOption.GetContext(), newGetSink.Stub);
					if (securityHandler != null)
					{
						securityHandler.Reset();
					}
					if (objectAsync_ < 0)
					{
						watcher.RemoveSink(newGetSink);
						if (((long)objectAsync_ & (long)-4096) != (long)-2147217408)
						{
							Marshal.ThrowExceptionForHR(objectAsync_);
						}
						else
						{
							ManagementException.ThrowWithExtendedInfo((ManagementStatus)objectAsync_);
							return;
						}
					}
					return;
				}
				else
				{
					throw new ArgumentNullException("watcher");
				}
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:45,代码来源:ManagementObject.cs

示例7: InvokeMethod

		public void InvokeMethod(ManagementOperationObserver watcher, string methodName, ManagementBaseObject inParameters, InvokeMethodOptions options)
		{
			InvokeMethodOptions invokeMethodOption;
			if (this.path == null || this.path.Path.Length == 0)
			{
				throw new InvalidOperationException();
			}
			else
			{
				if (watcher != null)
				{
					if (methodName != null)
					{
						this.Initialize(false);
						if (options != null)
						{
							invokeMethodOption = (InvokeMethodOptions)options.Clone();
						}
						else
						{
							invokeMethodOption = new InvokeMethodOptions();
						}
						InvokeMethodOptions invokeMethodOption1 = invokeMethodOption;
						if (watcher.HaveListenersForProgress)
						{
							invokeMethodOption1.SendStatus = true;
						}
						WmiEventSink newSink = watcher.GetNewSink(this.scope, invokeMethodOption1.Context);
						SecurityHandler securityHandler = this.scope.GetSecurityHandler();
						IWbemClassObjectFreeThreaded wbemClassObjectFreeThreaded = null;
						if (inParameters != null)
						{
							wbemClassObjectFreeThreaded = inParameters.wbemObject;
						}
						int num = this.scope.GetSecuredIWbemServicesHandler(this.scope.GetIWbemServices()).ExecMethodAsync_(this.path.RelativePath, methodName, invokeMethodOption1.Flags, invokeMethodOption1.GetContext(), wbemClassObjectFreeThreaded, newSink.Stub);
						if (securityHandler != null)
						{
							securityHandler.Reset();
						}
						if (num < 0)
						{
							watcher.RemoveSink(newSink);
							if (((long)num & (long)-4096) != (long)-2147217408)
							{
								Marshal.ThrowExceptionForHR(num);
							}
							else
							{
								ManagementException.ThrowWithExtendedInfo((ManagementStatus)num);
								return;
							}
						}
						return;
					}
					else
					{
						throw new ArgumentNullException("methodName");
					}
				}
				else
				{
					throw new ArgumentNullException("watcher");
				}
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:65,代码来源:ManagementObject.cs

示例8: Put

        /// <summary>
        ///    <para>Commits the changes to the object asynchronously and
        ///       using the specified options.</para>
        /// </summary>
        /// <param name='watcher'>A <see cref='System.Management.ManagementOperationObserver'/> used to handle the progress and results of the asynchronous operation.</param>
        /// <param name=' options'>A <see cref='System.Management.PutOptions'/> used to specify additional options for the commit operation.</param>
        public void Put(ManagementOperationObserver watcher, PutOptions options)
        {
            if (null == watcher)
                throw new ArgumentNullException("watcher");
            else
            {
                Initialize ( false ) ;

                PutOptions o = (null == options) ?
                    new PutOptions() : (PutOptions)options.Clone();
                
                // If someone has registered for progress, make sure we flag it
                if (watcher.HaveListenersForProgress)
                    o.SendStatus = true;

                IWbemServices wbemServices = scope.GetIWbemServices();
                WmiEventSink sink = watcher.GetNewPutSink(scope, 
                    o.Context, scope.Path.GetNamespacePath((int)tag_WBEM_GET_TEXT_FLAGS.WBEMPATH_GET_SERVER_AND_NAMESPACE_ONLY), ClassName);

                // Add ourselves to the watcher so we can update our state
                sink.InternalObjectPut += 
                    new InternalObjectPutEventHandler(this.HandleObjectPut);

                SecurityHandler securityHandler    = null;
                // Assign to error initially to insure internal event handler cleanup
                // on non-management exception.
                int status                        = (int)ManagementStatus.Failed;

                securityHandler = scope.GetSecurityHandler();

                if (IsClass)
                {
                    status = scope.GetSecuredIWbemServicesHandler( wbemServices ).PutClassAsync_(
                        wbemObject, 
                        o.Flags, 
                        o.GetContext(),
                        sink.Stub);
                }
                else
                {
                    status = scope.GetSecuredIWbemServicesHandler( wbemServices ).PutInstanceAsync_(
                        wbemObject, 
                        o.Flags, 
                        o.GetContext(),
                        sink.Stub);
                }

                
                if (securityHandler != null)
                    securityHandler.Reset();

                if (status < 0)
                {
                    sink.InternalObjectPut -= new InternalObjectPutEventHandler(this.HandleObjectPut);
                    watcher.RemoveSink(sink);
                    if ((status & 0xfffff000) == 0x80041000)
                        ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
                    else
                        Marshal.ThrowExceptionForHR(status);
                }
            }
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:68,代码来源:ManagementObject.cs

示例9: GetRelationshipClasses

 public void GetRelationshipClasses(ManagementOperationObserver watcher, string relationshipClass, string relationshipQualifier, string thisRole, EnumerationOptions options)
 {
     if (((this.Path == null) || (this.Path.Path == null)) || (this.Path.Path.Length == 0))
     {
         throw new InvalidOperationException();
     }
     if (watcher == null)
     {
         throw new ArgumentNullException("watcher");
     }
     this.Initialize(true);
     EnumerationOptions options2 = (options != null) ? ((EnumerationOptions) options.Clone()) : new EnumerationOptions();
     options2.EnumerateDeep = true;
     options2.ReturnImmediately = false;
     if (watcher.HaveListenersForProgress)
     {
         options2.SendStatus = true;
     }
     WmiEventSink newSink = watcher.GetNewSink(base.Scope, options2.Context);
     RelationshipQuery query = new RelationshipQuery(true, this.Path.Path, relationshipClass, relationshipQualifier, thisRole);
     SecurityHandler securityHandler = null;
     int errorCode = 0;
     securityHandler = base.Scope.GetSecurityHandler();
     errorCode = base.scope.GetSecuredIWbemServicesHandler(base.Scope.GetIWbemServices()).ExecQueryAsync_(query.QueryLanguage, query.QueryString, options2.Flags, options2.GetContext(), newSink.Stub);
     if (securityHandler != null)
     {
         securityHandler.Reset();
     }
     if (errorCode < 0)
     {
         watcher.RemoveSink(newSink);
         if ((errorCode & 0xfffff000L) == 0x80041000L)
         {
             ManagementException.ThrowWithExtendedInfo((ManagementStatus) errorCode);
         }
         else
         {
             Marshal.ThrowExceptionForHR(errorCode);
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:41,代码来源:ManagementClass.cs

示例10: GetSubclasses

 public void GetSubclasses(ManagementOperationObserver watcher, EnumerationOptions options)
 {
     if (watcher == null)
     {
         throw new ArgumentNullException("watcher");
     }
     if (this.Path == null)
     {
         throw new InvalidOperationException();
     }
     this.Initialize(false);
     EnumerationOptions options2 = (options == null) ? new EnumerationOptions() : ((EnumerationOptions) options.Clone());
     options2.EnsureLocatable = false;
     options2.PrototypeOnly = false;
     options2.ReturnImmediately = false;
     if (watcher.HaveListenersForProgress)
     {
         options2.SendStatus = true;
     }
     WmiEventSink newSink = watcher.GetNewSink(base.Scope, options2.Context);
     SecurityHandler securityHandler = null;
     int errorCode = 0;
     securityHandler = base.Scope.GetSecurityHandler();
     errorCode = base.scope.GetSecuredIWbemServicesHandler(base.Scope.GetIWbemServices()).CreateClassEnumAsync_(base.ClassName, options2.Flags, options2.GetContext(), newSink.Stub);
     if (securityHandler != null)
     {
         securityHandler.Reset();
     }
     if (errorCode < 0)
     {
         watcher.RemoveSink(newSink);
         if ((errorCode & 0xfffff000L) == 0x80041000L)
         {
             ManagementException.ThrowWithExtendedInfo((ManagementStatus) errorCode);
         }
         else
         {
             Marshal.ThrowExceptionForHR(errorCode);
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:41,代码来源:ManagementClass.cs

示例11: Get


//.........这里部分代码省略.........
        /// //Here we can use the object
        /// Console.WriteLine(o["SomeProperty"]);
        /// 
        /// public class MyHandler
        /// {
        ///     private bool completed = false;
        /// 
        ///     public void Done(object sender, CompletedEventArgs e) {
        ///         Console.WriteLine("async Get completed !");
        ///         completed = true;
        ///     }
        ///     
        ///     public bool Completed { 
        ///         get {
        ///             return completed;
        ///         }
        ///     }
        /// }
        ///    </code>
        ///    <code lang='VB'>Dim o As New ManagementObject("MyClass.Name=""abc""")
        /// 
        /// 'Set up handlers for asynchronous get
        /// Dim h As New MyHandler()
        /// Dim ob As New ManagementOperationObserver()
        /// ob.Completed += New CompletedEventHandler(h.Done)
        /// 
        /// 'Get the object asynchronously
        /// o.Get(ob)
        /// 
        /// 'Wait until operation is completed
        /// While Not h.Completed
        ///     System.Threading.Thread.Sleep(1000)
        /// End While
        ///     
        /// 'Here we can use the object
        /// Console.WriteLine(o("SomeProperty"))
        /// 
        /// Public Class MyHandler
        ///     Private _completed As Boolean = false;
        /// 
        ///     Public Sub Done(sender As Object, e As EventArrivedEventArgs)
        ///         Console.WriteLine("async Get completed !")
        ///         _completed = True
        ///     End Sub    
        /// 
        ///     Public ReadOnly Property Completed() As Boolean
        ///        Get
        ///            Return _completed
        ///        End Get
        ///     End Property
        /// End Class
        ///    </code>
        /// </example>
        public void Get(ManagementOperationObserver watcher)
        {
            Initialize ( false ) ;

            if ((null == path) || (path.Path.Length==0))
                throw new InvalidOperationException();
            else if (null == watcher)
                throw new ArgumentNullException("watcher");
            else
            {
                IWbemServices wbemServices = scope.GetIWbemServices();

                ObjectGetOptions o = ObjectGetOptions._Clone(options);

                WmiGetEventSink sink = watcher.GetNewGetSink(
                    scope,
                    o.Context, 
                    this);

                // If someone has registered for progress, make sure we flag it
                if (watcher.HaveListenersForProgress)
                    o.SendStatus = true;

                SecurityHandler securityHandler = null;
                int status                        = (int)ManagementStatus.NoError;

                securityHandler = scope.GetSecurityHandler();

                status = scope.GetSecuredIWbemServicesHandler(wbemServices).GetObjectAsync_(path.RelativePath,
                                            o.Flags,
                                            o.GetContext(),
                                            sink.Stub);

                
                if (securityHandler != null)
                    securityHandler.Reset();

                if (status < 0)
                {
                    watcher.RemoveSink(sink);
                    if ((status & 0xfffff000) == 0x80041000)
                        ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
                    else
                        Marshal.ThrowExceptionForHR(status);
                }
            }
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:101,代码来源:ManagementObject.cs

示例12: InvokeMethod

        /// <summary>
        ///    <para>Invokes a method on the object, asynchronously.</para>
        /// </summary>
        /// <param name='watcher'>A <see cref='System.Management.ManagementOperationObserver'/> used to handle the asynchronous execution's progress and results.</param>
        /// <param name=' methodName'>The name of the method to be executed.</param>
        /// <param name=' inParameters'><para>A <see cref='System.Management.ManagementBaseObject'/> containing the input parameters for the method.</para></param>
        /// <param name=' options'>An <see cref='System.Management.InvokeMethodOptions'/> containing additional options used to execute the method.</param>
        /// <remarks>
        ///    <para>The method invokes the specified method execution and then 
        ///       returns. Progress and results are reported through events on the <see cref='System.Management.ManagementOperationObserver'/>.</para>
        /// </remarks>
        public void InvokeMethod(
            ManagementOperationObserver watcher, 
            string methodName, 
            ManagementBaseObject inParameters, 
            InvokeMethodOptions options)
        {
            if ((null == path) || (path.Path.Length==0))
                throw new InvalidOperationException();
            else if (null == watcher)
                throw new ArgumentNullException("watcher");
            else if (null == methodName)
                throw new ArgumentNullException("methodName");
            else
            {
                Initialize ( false ) ;
                InvokeMethodOptions o = (null != options) ? 
                    (InvokeMethodOptions) options.Clone() : new InvokeMethodOptions();

                // If someone has registered for progress, make sure we flag it
                if (watcher.HaveListenersForProgress)
                    o.SendStatus = true;
    
                WmiEventSink sink = watcher.GetNewSink(scope, o.Context);

                SecurityHandler securityHandler = null;
                int status                        = (int)ManagementStatus.NoError;

                securityHandler = scope.GetSecurityHandler();

                IWbemClassObjectFreeThreaded inParams = null;

                if (null != inParameters)
                    inParams = inParameters.wbemObject;

                status = scope.GetSecuredIWbemServicesHandler( scope.GetIWbemServices() ).ExecMethodAsync_(
                    path.RelativePath, 
                    methodName,
                    o.Flags, 
                    o.GetContext(),
                    inParams,
                    sink.Stub );

                if (securityHandler != null)
                    securityHandler.Reset();

                if (status < 0)
                {
                    watcher.RemoveSink(sink);
                    if ((status & 0xfffff000) == 0x80041000)
                        ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
                    else
                        Marshal.ThrowExceptionForHR(status);
                }
            }
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:66,代码来源:ManagementObject.cs

示例13: CopyTo

        /// <summary>
        ///    <para>Copies the object to a different location, asynchronously.</para>
        /// </summary>
        /// <param name='watcher'>The object that will receive the results of the operation.</param>
        /// <param name='path'>The path to which the object should be copied.</param>
        /// <param name='options'>The options for how the object should be put.</param>
        public void CopyTo(ManagementOperationObserver watcher, ManagementPath path, PutOptions options)
        {
            if (null == watcher)
                throw new ArgumentNullException("watcher");
            else
            {
                Initialize ( false ) ;
                ManagementScope destinationScope = null;

                destinationScope = new ManagementScope(path, scope);
                destinationScope.Initialize();

                PutOptions o = (null != options) ? (PutOptions) options.Clone() : new PutOptions();

                // If someone has registered for progress, make sure we flag it
                if (watcher.HaveListenersForProgress)
                    o.SendStatus = true;

                WmiEventSink sink = watcher.GetNewPutSink(destinationScope, o.Context, 
                    path.GetNamespacePath((int)tag_WBEM_GET_TEXT_FLAGS.WBEMPATH_GET_SERVER_AND_NAMESPACE_ONLY), ClassName);
                IWbemServices destWbemServices = destinationScope.GetIWbemServices();

                SecurityHandler securityHandler = null;
                int status                        = (int)ManagementStatus.NoError;

                securityHandler = destinationScope.GetSecurityHandler();

                if (IsClass)
                {
                    status = destinationScope.GetSecuredIWbemServicesHandler( destWbemServices ).PutClassAsync_(
                                                    wbemObject, 
                                                    o.Flags, 
                                                    o.GetContext(), 
                                                    sink.Stub);
                    
                }
                else
                {
                    status = destinationScope.GetSecuredIWbemServicesHandler( destWbemServices ).PutInstanceAsync_(
                                                    wbemObject, 
                                                    o.Flags, 
                                                    o.GetContext(), 
                                                    sink.Stub);
                }


                if (securityHandler != null)
                    securityHandler.Reset();

                if (status < 0)
                {
                    watcher.RemoveSink(sink);
                    if ((status & 0xfffff000) == 0x80041000)
                        ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
                    else
                        Marshal.ThrowExceptionForHR(status);
                }
            }
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:65,代码来源:ManagementObject.cs

示例14: Get

        }//Get()


        //********************************************
        //Get() asynchronous
        //********************************************
        /// <summary>
        ///    <para>Invokes the WMI query, asynchronously, and binds to a watcher to deliver the results.</para>
        /// </summary>
        /// <param name='watcher'>The watcher that raises events triggered by the operation. </param>
        public void Get(ManagementOperationObserver watcher)
        {
            if (null == watcher)
                throw new ArgumentNullException ("watcher");

            Initialize ();
            IWbemServices wbemServices = scope.GetIWbemServices ();
            
            EnumerationOptions enumOptions = (EnumerationOptions)options.Clone();
            // Ensure we switch off ReturnImmediately as this is invalid for async calls
            enumOptions.ReturnImmediately = false;
            // If someone has registered for progress, make sure we flag it
            if (watcher.HaveListenersForProgress)
                enumOptions.SendStatus = true;

            WmiEventSink sink = watcher.GetNewSink (scope, enumOptions.Context);
            SecurityHandler securityHandler = scope.GetSecurityHandler();

            int status = (int)ManagementStatus.NoError;

            try 
            {
                //If this is a simple SelectQuery (className only), and the enumerateDeep is set, we have
                //to find out whether this is a class enumeration or instance enumeration and call CreateInstanceEnum/
                //CreateClassEnum appropriately, because with ExecQuery we can't do a deep enumeration.
                if ((query.GetType() == typeof(SelectQuery)) && 
                    (((SelectQuery)query).Condition == null) && 
                    (((SelectQuery)query).SelectedProperties == null) &&
                    (options.EnumerateDeep == true))
                {
                    //Need to make sure that we're not passing invalid flags to enumeration APIs.
                    //The only flags not valid for enumerations are EnsureLocatable & PrototypeOnly.
                    enumOptions.EnsureLocatable = false; enumOptions.PrototypeOnly = false;
                    
                    if (((SelectQuery)query).IsSchemaQuery == false) //deep instance enumeration
                    {
                        status = scope.GetSecuredIWbemServicesHandler( wbemServices ).CreateInstanceEnumAsync_(((SelectQuery)query).ClassName, 
                            enumOptions.Flags, 
                            enumOptions.GetContext(), 
                            sink.Stub);
                    }
                    else    
                    {
                        status = scope.GetSecuredIWbemServicesHandler( wbemServices ).CreateClassEnumAsync_(((SelectQuery)query).ClassName, 
                            enumOptions.Flags, 
                            enumOptions.GetContext(), 
                            sink.Stub);
                    }
                }
                else //we can use ExecQuery
                {
                    //Make sure the EnumerateDeep flag bit is turned off because it's invalid for queries
                    enumOptions.EnumerateDeep = true;
                    status = scope.GetSecuredIWbemServicesHandler( wbemServices ).ExecQueryAsync_(
                        query.QueryLanguage, 
                        query.QueryString, 
                        enumOptions.Flags, 
                        enumOptions.GetContext(), 
                        sink.Stub);
                }

            } 
            catch (COMException e) 
            {
                // 
                watcher.RemoveSink (sink);
                ManagementException.ThrowWithExtendedInfo (e);
            } 
            finally 
            {
                securityHandler.Reset();
            }

            if ((status & 0xfffff000) == 0x80041000)
            {
                ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
            }
            else if ((status & 0x80000000) != 0)
            {
                Marshal.ThrowExceptionForHR(status);
            }
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:92,代码来源:ManagementObjectSearcher.cs

示例15: CopyTo

		public void CopyTo(ManagementOperationObserver watcher, ManagementPath path, PutOptions options)
		{
			int num;
			PutOptions putOption;
			if (watcher != null)
			{
				this.Initialize(false);
				ManagementScope managementScope = new ManagementScope(path, this.scope);
				managementScope.Initialize();
				if (options != null)
				{
					putOption = (PutOptions)options.Clone();
				}
				else
				{
					putOption = new PutOptions();
				}
				PutOptions putOption1 = putOption;
				if (watcher.HaveListenersForProgress)
				{
					putOption1.SendStatus = true;
				}
				WmiEventSink newPutSink = watcher.GetNewPutSink(managementScope, putOption1.Context, path.GetNamespacePath(8), base.ClassName);
				IWbemServices wbemServices = managementScope.GetIWbemServices();
				SecurityHandler securityHandler = managementScope.GetSecurityHandler();
				if (!base.IsClass)
				{
					num = managementScope.GetSecuredIWbemServicesHandler(wbemServices).PutInstanceAsync_(base.wbemObject, putOption1.Flags, putOption1.GetContext(), newPutSink.Stub);
				}
				else
				{
					num = managementScope.GetSecuredIWbemServicesHandler(wbemServices).PutClassAsync_(base.wbemObject, putOption1.Flags, putOption1.GetContext(), newPutSink.Stub);
				}
				if (securityHandler != null)
				{
					securityHandler.Reset();
				}
				if (num < 0)
				{
					watcher.RemoveSink(newPutSink);
					if (((long)num & (long)-4096) != (long)-2147217408)
					{
						Marshal.ThrowExceptionForHR(num);
					}
					else
					{
						ManagementException.ThrowWithExtendedInfo((ManagementStatus)num);
						return;
					}
				}
				return;
			}
			else
			{
				throw new ArgumentNullException("watcher");
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:57,代码来源:ManagementObject.cs


注:本文中的System.Management.ManagementOperationObserver.RemoveSink方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。