예제 #1
0
 internal abstract MI_Result NativeMoveNext(
     MI_Operation operationHandle,
     out T currentItem,
     out bool moreResults,
     out MI_Result operationResult,
     out string errorMessage,
     out MI_Instance errorDetailsHandle);
예제 #2
0
        internal override MI_Result NativeMoveNext(MI_Operation operationHandle, out CimClass currentItem,
                                                   out bool moreResults, out MI_Result operationResult,
                                                   out string errorMessage, out MI_Instance errorDetailsHandle)
        {
            Debug.Assert(operationHandle != null, "Caller should verify operationHandle != null");

            currentItem = null;

            MI_Class  classHandle;
            MI_Result functionResult = operationHandle.GetClass(
                out classHandle,
                out moreResults,
                out operationResult,
                out errorMessage,
                out errorDetailsHandle);

            if ((classHandle != null) && !classHandle.IsNull)
            {
                if (!this.ShortenLifetimeOfResults)
                {
                    classHandle = classHandle.Clone();
                }
                currentItem = new CimClass(classHandle);
            }

            return(functionResult);
        }
예제 #3
0
        internal override MI_Result NativeMoveNext(MI_Operation operationHandle, out CimSubscriptionResult currentItem,
                                                   out bool moreResults, out MI_Result operationResult,
                                                   out string errorMessage, out MI_Instance errorDetailsHandle)
        {
            Debug.Assert(operationHandle != null, "Caller should verify operationHandle != null");

            currentItem = null;

            MI_Instance instanceHandle;
            string      bookmark;
            string      machineID;
            MI_Result   functionResult = operationHandle.GetIndication(
                out instanceHandle,
                out bookmark,
                out machineID,
                out moreResults,
                out operationResult,
                out errorMessage,
                out errorDetailsHandle);

            if ((instanceHandle != null) && !instanceHandle.IsNull)
            {
                if (!this.ShortenLifetimeOfResults)
                {
                    instanceHandle = instanceHandle.Clone();
                }
                currentItem = new CimSubscriptionResult(instanceHandle, bookmark, machineID);
            }

            return(functionResult);
        }
예제 #4
0
 internal CimSubscriptionResult(MI_Instance handle, string bookmark, string machineId)
 {
     Debug.Assert(handle != null, "Caller should verify backingInstance != null");
     this._resultInstance = new CimInstance(handle);
     this._bookmark       = bookmark;
     this._machineId      = machineId;
 }
예제 #5
0
 internal void WriteErrorCallbackInternal(
     CimOperationCallbackProcessingContext callbackProcessingContext,
     MI_Operation operationHandle,
     MI_Instance instanceHandle,
     out MI_OperationCallback_ResponseType response)
 {
     response = MI_OperationCallback_ResponseType.Yes;
     if (_writeErrorCallback != null)
     {
         Debug.Assert(instanceHandle != null, "Caller should verify instance != null");
         CimInstance cimInstance = null;
         try
         {
             if (!instanceHandle.IsNull)
             {
                 cimInstance = new CimInstance(instanceHandle.Clone());
                 var             callbacksReceiverBase = (CimAsyncCallbacksReceiverBase)callbackProcessingContext.ManagedOperationContext;
                 CimResponseType userResponse          = CimResponseType.None;
                 callbacksReceiverBase.CallIntoUserCallback(
                     callbackProcessingContext,
                     delegate { userResponse = _writeErrorCallback(cimInstance); });
                 response = (MI_OperationCallback_ResponseType)userResponse;
             }
         }
         finally
         {
             if (cimInstance != null)
             {
                 cimInstance.Dispose();
             }
         }
     }
 }
예제 #6
0
        internal void ClassCallback(
            CimOperationCallbackProcessingContext callbackProcessingContext,
            MI_Operation operationHandle,
            MI_Class ClassHandle,
            bool moreResults,
            MI_Result operationResult,
            String errorMessage,
            MI_Instance errorDetailsHandle)
        {
            CimClass currentItem = null;

            if ((ClassHandle != null) && (!ClassHandle.IsNull))
            {
                if (!_shortenLifetimeOfResults)
                {
                    ClassHandle = ClassHandle.Clone();
                }
                currentItem = new CimClass(ClassHandle);
            }

            try
            {
                this.ProcessNativeCallback(callbackProcessingContext, currentItem, moreResults, operationResult, errorMessage, errorDetailsHandle);
            }
            finally
            {
                if (_shortenLifetimeOfResults)
                {
                    if (currentItem != null)
                    {
                        currentItem.Dispose();
                    }
                }
            }
        }
예제 #7
0
        /// <summary>
        /// Instantiates an empty <see cref="CimInstance"/>.
        /// </summary>
        /// <remarks>
        /// This constructor provides a way to create CIM instances, without communicating with a CIM server.
        /// This constructor is typically used when the client knows all the key properties (<see cref="CimFlags.Key"/>)
        /// of the instance and wants to pass the instance as an argument of a CimSession method
        /// (for example as a "sourceInstance" parameter of <see cref="CimSession.EnumerateAssociatedInstances(string, CimInstance, string, string, string, string)"/>).
        /// <see cref="CimSession.EnumerateInstances(string,string)"/> or <see cref="CimSession.GetInstance(string, CimInstance)"/>.
        /// </remarks>
        /// <param name="className"></param>
        /// <exception cref="ArgumentException">Thrown when <paramref name="className"/> is null or when it doesn't follow the format specified by DSP0004</exception>
        public CimInstance(string className, string namespaceName)
        {
            if (className == null)
            {
                throw new ArgumentNullException("className");
            }

            MI_Instance tmpHandle;
            MI_Result   result = CimApplication.Handle.NewInstance(className, null, out tmpHandle);

            if (result == MI_Result.MI_RESULT_INVALID_PARAMETER)
            {
                throw new ArgumentOutOfRangeException("className");
            }

            CimException.ThrowIfMiResultFailure(result);

            if (namespaceName != null)
            {
                result = tmpHandle.SetNameSpace(namespaceName);
                CimException.ThrowIfMiResultFailure(result);
            }

            this.nativeInstance = tmpHandle;
        }
예제 #8
0
 public void InstanceIsNullable()
 {
     this.value.Instance = MI_Instance.NewDirectPtr();
     Assert.NotNull(this.value.Instance);
     this.value.Instance = null;
     Assert.Null(this.value.Instance);
 }
예제 #9
0
파일: MIAssert.cs 프로젝트: madewokherd/MMI
        internal static void InstancesEqual(MI_Instance expected, MI_Instance actual, string propertyName)
        {
            uint expectedElementCount;

            expected.GetElementCount(out expectedElementCount);
            uint actualElementCount;

            actual.GetElementCount(out actualElementCount);
            Assert.Equal(expectedElementCount, actualElementCount);
            for (uint i = 0; i < expectedElementCount; i++)
            {
                MI_Flags expectedElementFlags;
                MI_Type  expectedElementType;
                string   expectedElementName  = null;
                MI_Value expectedElementValue = null;
                expected.GetElementAt(i, out expectedElementName, out expectedElementValue, out expectedElementType, out expectedElementFlags);

                MI_Flags actualElementFlags;
                MI_Value actualElementValue = null;
                MI_Type  actualElementType;
                string   actualElementName = null;
                actual.GetElementAt(i, out actualElementName, out actualElementValue, out actualElementType, out actualElementFlags);

                Assert.Equal(expectedElementName, actualElementName, "Expect the element names to be the same within the instances");
                MIAssert.MIPropertiesEqual(new TestMIProperty(expectedElementValue, expectedElementType, expectedElementFlags),
                                           new TestMIProperty(actualElementValue, actualElementType, actualElementFlags), propertyName);
            }
        }
        public static MI_Instance[] CloneMIArray(this MI_Instance[] arrayToClone)
        {
            if (arrayToClone == null)
            {
                throw new ArgumentNullException();
            }

            MI_Instance[] result = new MI_Instance[arrayToClone.Length];
            try
            {
                for (int i = 0; i < arrayToClone.Length; i++)
                {
                    MI_Instance origInstance = arrayToClone[i];
                    result[i] = origInstance == null ? null : origInstance.Clone();
                }
            }
            catch
            {
                // If we encounter an exception halfway through we need to rollback
                for (int i = 0; i < arrayToClone.Length; i++)
                {
                    if (arrayToClone[i] == null)
                    {
                        break;
                    }

                    arrayToClone[i].Delete();
                }

                throw;
            }

            return(result);
        }
예제 #11
0
            public void BadHost()
            {
                MI_Session  badSession;
                MI_Instance extendedError = null;
                MI_Result   res           = StaticFixtures.Application.NewSession(null,
                                                                                  "badhost",
                                                                                  MI_DestinationOptions.Null,
                                                                                  MI_SessionCreationCallbacks.Null,
                                                                                  out extendedError,
                                                                                  out badSession);

                MIAssert.Succeeded(res, "Expect simple NewSession to succeed");

                MI_Operation operation = null;

                badSession.TestConnection(0, null, out operation);

                bool        moreResults;
                MI_Result   result;
                string      errorMessage = null;
                MI_Instance instance     = null;
                MI_Instance errorDetails = null;

                res = operation.GetInstance(out instance, out moreResults, out result, out errorMessage, out errorDetails);
                MIAssert.Succeeded(res, "Expect the GetInstance operation to succeed");
                MIAssert.Failed(result, "Expect the actual retrieval to fail");
                Assert.True(!String.IsNullOrEmpty(errorMessage), "Expect error message to be available");

                res = operation.Close();
                MIAssert.Succeeded(res, "Expect to be able to close operation now");

                res = badSession.Close(IntPtr.Zero, null);
                MIAssert.Succeeded(res, "Expect to be able to close the bad session");
            }
예제 #12
0
        public void SimpleEnumerateInstance()
        {
            MI_Operation operation = null;

            this.Session.EnumerateInstances(MI_OperationFlags.MI_OPERATIONFLAGS_DEFAULT_RTTI,
                                            MI_OperationOptions.Null,
                                            TestEnumerateInstanceNamespace,
                                            TestEnumerateInstanceClassName,
                                            false,
                                            null,
                                            out operation);

            bool        moreResults    = true;
            MI_Instance clonedInstance = null;

            MI_Result   secondaryResult;
            string      errorMessage = null;
            MI_Instance instanceOut  = null;
            MI_Instance errorDetails = null;
            var         res          = operation.GetInstance(out instanceOut, out moreResults, out secondaryResult, out errorMessage, out errorDetails);

            MIAssert.Succeeded(res, "Expect the first GetInstance call to succeed");
            MIAssert.Succeeded(secondaryResult, "Expect the logical result of the GetInstance call to succeed");

            if (!instanceOut.IsNull)
            {
                res = instanceOut.Clone(out clonedInstance);
                MIAssert.Succeeded(res, "Expect the clone to succeed");
            }

            while (moreResults)
            {
                res = operation.GetInstance(out instanceOut, out moreResults, out secondaryResult, out errorMessage, out errorDetails);
                MIAssert.Succeeded(res, "Expect GetInstance to succeed even if we don't want the result");
                MIAssert.Succeeded(secondaryResult, "Expect the logical result of the GetInstance call to succeed even if we don't want the result");
            }

            res = operation.Close();
            MIAssert.Succeeded(res, "Expect operation to close successfully");

            string className = null;

            res = clonedInstance.GetClassName(out className);
            MIAssert.Succeeded(res, "Expect GetClassName to succeed");
            Assert.Equal(TestEnumerateInstanceClassName, className, "Expect the class name to be the one we queried");

            MI_Value elementValue = null;
            MI_Type  elementType;
            MI_Flags elementFlags;
            UInt32   elementIndex;

            res = clonedInstance.GetElement(TestEnumerateInstanceStringPropertyName, out elementValue, out elementType, out elementFlags, out elementIndex);
            MIAssert.Succeeded(res, "Expect GetElement to succeed");

            Assert.Equal(MI_Type.MI_STRING, elementType, "Expect that the property is registered as a string");
            Assert.Equal(TestEnumerateInstanceStringPropertyFlags,
                         elementFlags, "Expect the element flags to also be properly available from the query");
            Assert.Equal(TestEnumerateInstanceStringPropertyValue, elementValue.String, "Expect the machine name to have survived the whole journey");
        }
예제 #13
0
        public ApplicationFixture()
        {
            MI_Instance    extendedError = null;
            MI_Application newApplication;
            MI_Result      res = MI_Application.Initialize(ApplicationName, out extendedError, out newApplication);

            MIAssert.Succeeded(res, "Expect basic application initialization to succeed");
            this.Application = newApplication;
        }
예제 #14
0
        internal CimInstance(MI_Instance handle)
        {
            if (handle == null || handle.IsNull)
            {
                throw new ArgumentNullException();
            }

            this.nativeInstance = handle;
        }
예제 #15
0
        internal CimException(MI_Result errorCode, string errorMessage, MI_Instance errorDetailsHandle, string exceptionMessage)
            : base(exceptionMessage ?? CimException.GetExceptionMessage(errorCode, errorMessage, errorDetailsHandle))
        {
            this.NativeErrorCode = errorCode.ToNativeErrorCode();

            if (errorDetailsHandle != null)
            {
                this._errorData = new CimInstance(errorDetailsHandle.Clone());
            }
        }
예제 #16
0
        /// <summary>
        /// Instantiates a deep copy of <paramref name="cimInstanceToClone"/>
        /// </summary>
        /// <param name="cimInstanceToClone">Instance to clone</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="cimInstanceToClone"/> is <c>null</c></exception>
        public CimInstance(CimInstance cimInstanceToClone)
        {
            if (cimInstanceToClone == null)
            {
                throw new ArgumentNullException("cimInstanceToClone");
            }

            MI_Instance clonedHandle = cimInstanceToClone.InstanceHandle.Clone();

            this.nativeInstance = clonedHandle;
        }
예제 #17
0
        internal byte[] GetSerializationFromInstanceThunk(Func <MI_Instance> instanceGetter)
        {
            MI_Instance toSerialize = instanceGetter();

            byte[] serializedInstance;
            var    res = this.Serializer.SerializeInstance(MI_SerializerFlags.None, toSerialize, out serializedInstance);

            MIAssert.Succeeded(res);
            toSerialize.Delete();
            return(serializedInstance);
        }
예제 #18
0
        internal void ProcessNativeCallback(
            CimOperationCallbackProcessingContext callbackProcessingContext,
            T currentItem,
            bool moreResults,
            MI_Result operationResult,
            string errorMessage,
            MI_Instance errorDetailsHandle)
        {
            Debug.Assert(callbackProcessingContext != null, "We should never get called with a null callbackProcessingContext");

            if (!moreResults)
            {
                this.DisposeOperationWhenPossible();
            }

            if ((currentItem == null) && (operationResult == MI_Result.MI_RESULT_OK))
            {
                // process the ACK message if and only if operationResult == OK
                if (this._reportOperationStarted)
                {
                    this.OnNextInternal(callbackProcessingContext, currentItem);
                }
            }
            else if (currentItem != null)
            {
                Debug.Assert(operationResult == MI_Result.MI_RESULT_OK, "Assumming that instances are reported back only on success");
                this.OnNextInternal(callbackProcessingContext, currentItem);
            }

            CimException exception = CimException.GetExceptionIfMiResultFailure(operationResult, errorMessage, errorDetailsHandle);

            if (exception != null)
            {
                Debug.Assert(operationResult != MI_Result.MI_RESULT_OK, "Assumming that exceptions are reported back only on failure");
                Debug.Assert(!moreResults, "Assumming that an error means end of results");

                // this throw-catch is needed to fill-out 1) WER data and 2) exception's stack trace
                try
                {
                    throw exception;
                }
                catch (CimException filledOutException)
                {
                    exception = filledOutException;
                }
            }

            if (!moreResults)
            {
                this.InvokeWhenOperationIsSet(
                    cimOperation => this.ProcessEndOfResultsWorker(callbackProcessingContext, cimOperation, exception));
            }
        }
        public static MI_Instance Clone(this MI_Instance handleToClone)
        {
            if (handleToClone == null || handleToClone.IsNull)
            {
                throw new ArgumentNullException();
            }

            MI_Instance clonedHandle;
            MI_Result   result = handleToClone.Clone(out clonedHandle);

            CimException.ThrowIfMiResultFailure(result);
            return(clonedHandle);
        }
예제 #20
0
        static private string GetExceptionMessage(MI_Instance errorDetailsHandle)
        {
            if (errorDetailsHandle != null)
            {
                var    temporaryErrorData = new CimInstance(errorDetailsHandle);
                string cimErrorMessage;
                if (TryGetErrorDataProperty(temporaryErrorData, "Message", out cimErrorMessage))
                {
                    return(cimErrorMessage);
                }
            }

            return(null);
        }
예제 #21
0
        internal static MI_Value ConvertToNativeLayer(object value, CimType cimType)
        {
            var cimInstance = value as CimInstance;

            if (cimInstance != null)
            {
                MI_Value retval = new MI_Value();
                retval.Instance = cimInstance.InstanceHandle;
                return(retval);
            }

            var arrayOfCimInstances = value as CimInstance[];

            if (arrayOfCimInstances != null)
            {
                MI_Instance[] arrayOfInstanceHandles = new MI_Instance[arrayOfCimInstances.Length];
                for (int i = 0; i < arrayOfCimInstances.Length; i++)
                {
                    CimInstance inst = arrayOfCimInstances[i];
                    if (inst == null)
                    {
                        arrayOfInstanceHandles[i] = null;
                    }
                    else
                    {
                        arrayOfInstanceHandles[i] = inst.InstanceHandle;
                    }
                }

                MI_Value retval = new MI_Value();
                retval.InstanceA = arrayOfInstanceHandles;
                return(retval);
            }

            // TODO: What to do with Unknown types? Ignore? Uncomment and remove return line immediately below.
            return(CimProperty.ConvertToNativeLayer(value, cimType));

            /*
             * if (cimType != CimType.Unknown)
             * {
             * return CimProperty.ConvertToNativeLayer(value, cimType);
             * }
             * else
             * {
             * return value;
             * }
             */
        }
예제 #22
0
        public SessionFixture()
        {
            var application = StaticFixtures.Application;

            MI_Session  newSession;
            MI_Instance extendedError = null;
            MI_Result   res           = application.NewSession(null,
                                                               null,
                                                               MI_DestinationOptions.Null,
                                                               MI_SessionCreationCallbacks.Null,
                                                               out extendedError,
                                                               out newSession);

            MIAssert.Succeeded(res, "Expect simple NewSession to succeed");
            this.Session = newSession;
        }
예제 #23
0
        public void ReferenceTypesCanBeUsed()
        {
            MI_Instance InnerInstance = null;
            var         res           = this.Application.NewInstance("TestClass", MI_ClassDecl.Null, out InnerInstance);

            MIAssert.Succeeded(res);

            MI_Instance InnerInstance2 = null;

            res = this.Application.NewInstance("TestClass", MI_ClassDecl.Null, out InnerInstance2);
            MIAssert.Succeeded(res);

            try
            {
                MI_Value innerValue1 = new MI_Value();
                innerValue1.String = "This is a property";
                res = InnerInstance.AddElement("InnerInstanceProperty1", innerValue1, innerValue1.Type.Value, MI_Flags.MI_FLAG_BORROW);
                MIAssert.Succeeded(res);

                MI_Value innerValue2 = new MI_Value();
                innerValue2.String = "This is another property";
                res = InnerInstance.AddElement("InnerInstanceProperty2", innerValue2, innerValue2.Type.Value, MI_Flags.MI_FLAG_BORROW);
                MIAssert.Succeeded(res);

                MI_Value innerValue3 = new MI_Value();
                innerValue3.String = "Still another property";
                res = InnerInstance2.AddElement("InnerInstance2Property1", innerValue3, innerValue3.Type.Value, MI_Flags.MI_FLAG_BORROW);
                MIAssert.Succeeded(res);

                MI_Value innerValue4 = new MI_Value();
                innerValue4.String = "Okay, bored now";
                res = InnerInstance2.AddElement("InnerInstance2Property2", innerValue4, innerValue4.Type.Value, MI_Flags.MI_FLAG_BORROW);
                MIAssert.Succeeded(res);

                this.value.Reference = InnerInstance;
                this.TestValueRoundtrip();

                this.value.ReferenceA = new MI_Instance[] { InnerInstance, InnerInstance2 };
                this.TestValueRoundtrip();
            }
            finally
            {
                InnerInstance.Delete();
                InnerInstance2.Delete();
            }
        }
예제 #24
0
        public void TestSessionPositive()
        {
            MI_Operation operation = null;

            this.Session.TestConnection(MI_OperationFlags.Default, null, out operation);

            bool        moreResults;
            MI_Result   result;
            string      errorMessage = null;
            MI_Instance instance     = null;
            MI_Instance errorDetails = null;
            var         res          = operation.GetInstance(out instance, out moreResults, out result, out errorMessage, out errorDetails);

            MIAssert.Succeeded(res, "Expect GetInstance result to succeed");
            MIAssert.Succeeded(result, "Expect actual operation result to be success");

            res = operation.Close();
            MIAssert.Succeeded(res, "Expect to be able to close completed operation");
        }
예제 #25
0
        private CimInstance(SerializationInfo info, StreamingContext context)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }
            string serializedString = info.GetString(serializationId_MiXml);

            byte[] serializedBytes = Encoding.Unicode.GetBytes(serializedString);
            using (CimDeserializer cimDeserializer = CimDeserializer.Create())
            {
                uint        offset = 0;
                MI_Instance deserializedInstanceHandle = cimDeserializer.DeserializeInstanceHandle(
                    serializedBytes,
                    ref offset,
                    cimClasses: null);
                this.nativeInstance = deserializedInstanceHandle;
            }
            this.SetCimSessionComputerName(info.GetString(serializationId_CimSessionComputerName));
        }
예제 #26
0
        internal MI_Instance DeserializeInstanceHandle(byte[] serializedData, ref uint offset, IEnumerable <CimClass> cimClasses)
        {
            if (serializedData == null)
            {
                throw new ArgumentNullException("serializedData");
            }
            if (offset >= serializedData.Length)
            {
                throw new ArgumentOutOfRangeException("offset");
            }
            this.AssertNotDisposed();

            MI_Class[] nativeClassHandles = null;
            if (cimClasses != null)
            {
                nativeClassHandles = cimClasses.Select(cimClass => cimClass.ClassHandle).ToArray();
            }

            // TODO: Implement this next function

            /*
             *  UInt32 inputBufferUsed;
             *  MI_Instance deserializedInstance;
             *  MI_Instance cimError;
             *  MI_Result result = this._myHandle.DeserializeInstance(
             *      0,
             *      serializedData,
             *      offset,
             *      nativeClassHandles,
             *      out deserializedInstance,
             *      out inputBufferUsed,
             *      out cimError);
             *  CimException.ThrowIfMiResultFailure(result, cimError);
             *  offset += inputBufferUsed;
             *
             *  return deserializedInstance;
             */

            // TODO: remove this next line once above is fixed
            return(MI_Instance.NewIndirectPtr());
        }
        internal void InstanceResultCallback(
            CimOperationCallbackProcessingContext callbackProcessingContext,
            MI_Operation operationHandle,
            MI_Instance instanceHandle,
            bool moreResults,
            MI_Result operationResult,
            String errorMessage,
            MI_Instance errorDetailsHandle)
        {
            CimMethodResult currentItem = null;

            if ((instanceHandle != null) && (!instanceHandle.IsNull))
            {
                if (!_shortenLifetimeOfResults)
                {
                    instanceHandle = instanceHandle.Clone();
                }
                var backingInstance = new CimInstance(instanceHandle);
                backingInstance.SetCimSessionComputerName(this._CimSessionComputerName);
                backingInstance.SetCimSessionInstanceId(this._CimSessionInstanceID);
                currentItem = new CimMethodResult(backingInstance);
            }

            try
            {
                this.ProcessNativeCallback(callbackProcessingContext, currentItem, moreResults, operationResult, errorMessage, errorDetailsHandle);
            }
            finally
            {
                if (_shortenLifetimeOfResults)
                {
                    if (currentItem != null)
                    {
                        currentItem.Dispose();
                    }
                }
            }
        }
예제 #28
0
        /// <summary>
        /// Instantiates an empty <see cref="CimInstance"/>.
        /// </summary>
        /// <param name="cimClass"></param>
        /// <exception cref="ArgumentException">Thrown when <paramref name="cimClass"/> is null or when it doesn't follow the format specified by DSP0004</exception>
        public CimInstance(CimClass cimClass)
        {
            if (cimClass == null)
            {
                throw new ArgumentNullException("cimClass");
            }

            MI_Instance tmpHandle;
            MI_Result   result = CimApplication.Handle.NewInstanceFromClass(cimClass.CimSystemProperties.ClassName, cimClass.ClassHandle, out tmpHandle);

            if (result == MI_Result.MI_RESULT_INVALID_PARAMETER)
            {
                throw new ArgumentOutOfRangeException("cimClass");
            }
            CimException.ThrowIfMiResultFailure(result);

            result = tmpHandle.SetNameSpace(cimClass.CimSystemProperties.Namespace);
            CimException.ThrowIfMiResultFailure(result);
            result = tmpHandle.SetServerName(cimClass.CimSystemProperties.ServerName);
            CimException.ThrowIfMiResultFailure(result);

            this.nativeInstance = tmpHandle;
        }
        internal void IndicationResultCallback(
            CimOperationCallbackProcessingContext callbackProcessingContext,
            MI_Operation operationHandle,
            MI_Instance instanceHandle,
            String bookMark,
            String machineID,
            bool moreResults,
            MI_Result operationResult,
            String errorMessage,
            MI_Instance errorDetailsHandle)
        {
            CimSubscriptionResult currentItem = null;

            if ((instanceHandle != null) && (!instanceHandle.IsNull))
            {
                if (!_shortenLifetimeOfResults)
                {
                    instanceHandle = instanceHandle.Clone();
                }
                currentItem = new CimSubscriptionResult(instanceHandle, bookMark, machineID);
            }

            try
            {
                this.ProcessNativeCallback(callbackProcessingContext, currentItem, moreResults, operationResult, errorMessage, errorDetailsHandle);
            }
            finally
            {
                if (_shortenLifetimeOfResults)
                {
                    if (currentItem != null)
                    {
                        currentItem.Dispose();
                    }
                }
            }
        }
예제 #30
0
        internal override MI_Result NativeMoveNext(MI_Operation operationHandle, out CimInstance currentItem, out bool moreResults, out MI_Result operationResult, out string errorMessage, out MI_Instance errorDetailsHandle)
        {
            Debug.Assert(operationHandle != null, "Caller should verify operationHandle != null");

            currentItem = null;

            MI_Instance instanceHandle;
            MI_Result   functionResult = operationHandle.GetInstance(
                out instanceHandle,
                out moreResults,
                out operationResult,
                out errorMessage,
                out errorDetailsHandle);

            if ((instanceHandle != null) && !instanceHandle.IsNull)
            {
                if (!this.ShortenLifetimeOfResults)
                {
                    instanceHandle = instanceHandle.Clone();
                }
                currentItem = new CimInstance(instanceHandle);
                currentItem.SetCimSessionComputerName(this._CimSessionComputerName);
                currentItem.SetCimSessionInstanceId(this._CimSessionInstanceID);
            }

            return(functionResult);
        }