/// <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);
                }
            }
        }
예제 #2
0
		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");
			}
		}
        /// <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);
                }
            }
        }