Beispiel #1
0
 /// <summary>
 /// Releases resources associated with this object
 /// </summary>
 protected virtual void Dispose(bool disposing)
 {
     if (Interlocked.CompareExchange(ref this._disposed, 1, 0) == 0)
     {
         if (disposing)
         {
             MI_OperationOptions tmpHandle = this.OperationOptionsHandle;
             if (tmpHandle != null)
             {
                 tmpHandle.Delete();
             }
         }
     }
 }
Beispiel #2
0
        internal MI_Class[] DeserializeClassHandle(
            byte[] serializedData,
            ref uint offset,
            IEnumerable <CimClass> cimClasses,
            string computerName,
            string namespaceName,
            OnClassNeeded onClassNeededCallback,
            GetIncludedFileContent getIncludedFileCallback)
        {
            if (serializedData == null)
            {
                throw new ArgumentNullException("serializedData");
            }
            else if (offset >= serializedData.Length)
            {
                throw new ArgumentOutOfRangeException("offset");
            }
            else if (getIncludedFileCallback != null)
            {
                // Need the definition for the callbacks
                throw new NotImplementedException();
            }
            else if (offset != 0)
            {
                // Need to internally handle the offset as the native calls
                // have no knowledge of this right now
                throw new NotImplementedException();
            }

            this.AssertNotDisposed();

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

            UInt32              inputBufferUsed;
            MI_Instance         cimError;
            MI_ExtendedArray    classArray;
            MI_OperationOptions nativeOption = GetOperationOptions().OperationOptionsHandle;

            //MI_DeserializerCallbacks callbacks = new MI_DeserializerCallbacks();
            //if (onClassNeededCallback != null) callbacks.ClassObjectNeededCallback = CreateClassObjectNeededCallbackDelegate(onClassNeededCallback);
            //if (getIncludedFileCallback != null) callbacks.GetIncludedFileBufferCallback = CreateGetIncludedFileBufferCallback(getIncludedFileCallback);
            MI_DeserializerCallbacks callbacks = new MI_DeserializerCallbacks();

            if (onClassNeededCallback != null)
            {
                callbacks.classObjectNeeded = CreateClassObjectNeededCallbackDelegate(onClassNeededCallback);
            }

            MI_Result result = this._myHandle.DeserializeClassArray(
                MI_SerializerFlags.None,
                nativeOption,
                callbacks,
                serializedData,
                nativeClassHandles,
                computerName,
                namespaceName,
                out inputBufferUsed,
                out classArray,
                out cimError);

            CimException.ThrowIfMiResultFailure(result, cimError);

            MI_Class[] deserializedClasses = classArray.ReadAsManagedPointerArray(MI_Class.NewFromDirectPtr);
            MI_Class[] resultClasses       = deserializedClasses.CloneMIArray();
            classArray.Delete();

            offset += inputBufferUsed;
            return(resultClasses);
        }
Beispiel #3
0
        internal MI_Instance[] DeserializeInstanceHandle(
            byte[] serializedData,
            ref uint offset,
            IEnumerable <CimClass> cimClasses,
            OnClassNeeded onClassNeededCallback,
            GetIncludedFileContent getIncludedFileCallback)
        {
            if (serializedData == null)
            {
                throw new ArgumentNullException("serializedData");
            }
            else if (offset >= serializedData.Length)
            {
                throw new ArgumentOutOfRangeException("offset");
            }
            else if (offset != 0)
            {
                // Need to implement this in our layer as it is not
                // handled by the underlying API
                throw new NotImplementedException();
            }
            else if (getIncludedFileCallback != null)
            {
                // Still need to add the native definitions of these callbacks
                throw new NotImplementedException();
            }
            this.AssertNotDisposed();

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

            UInt32              inputBufferUsed;
            MI_Instance         cimError;
            MI_ExtendedArray    instanceArray;
            MI_OperationOptions nativeOption = GetOperationOptions().OperationOptionsHandle;

            // TODO: Add definitions for these callbacks
            //if (getIncludedFileCallback != null) callbacks.GetIncludedFileBufferCallback = CreateGetIncludedFileBufferCallback(getIncludedFileCallback);
            MI_DeserializerCallbacks callbacks = new MI_DeserializerCallbacks();

            if (onClassNeededCallback != null)
            {
                callbacks.classObjectNeeded = CreateClassObjectNeededCallbackDelegate(onClassNeededCallback);
            }

            MI_Result result = this._myHandle.DeserializeInstanceArray(
                MI_SerializerFlags.None,
                nativeOption,
                callbacks,
                serializedData,
                nativeClassHandles,
                out inputBufferUsed,
                out instanceArray,
                out cimError);

            CimException.ThrowIfMiResultFailure(result, cimError);

            MI_Instance[] deserializedInstances = instanceArray.ReadAsManagedPointerArray(MI_Instance.NewFromDirectPtr);
            MI_Instance[] resultInstances       = deserializedInstances.CloneMIArray();
            instanceArray.Delete();

            offset += inputBufferUsed;
            return(resultInstances);
        }