public void CanDeserializeInstanceWithInternalMOFMethod() { var cimClass = this.GetClassDefinition(); var serializedInstance = this.GetSerializedSingleton(); MI_ExtendedArray deserializedArray; MI_Instance[] instances; uint bufferRead; MI_Instance cimErrorDetails; MI_DeserializerCallbacks callbacks = new MI_DeserializerCallbacks(); var res = this.Deserializer.DeserializeInstanceArray(MI_SerializerFlags.None, MI_OperationOptions.Null, callbacks, serializedInstance, new MI_Class[] { cimClass }, out bufferRead, out deserializedArray, out cimErrorDetails); MIAssert.Succeeded(res, "Expect to be able to deserialize instance"); instances = deserializedArray.ReadAsManagedPointerArray(MI_Instance.NewFromDirectPtr); var expectedInstance = this.GetSerializableInstance(); Assert.Equal(1, instances.Length, "Expect only the instance we serialized"); MIAssert.InstancesEqual(expectedInstance, instances[0], "SerializedInstance"); cimClass.Delete(); expectedInstance.Delete(); deserializedArray.Delete(); }
public void CanDeserializeClassWithInternalMOFMethod() { var serializedClass = this.GetSerializedClass(); MI_ExtendedArray deserializedArray; MI_Class[] classes; uint bufferRead; MI_Instance cimErrorDetails; MI_DeserializerCallbacks callbacks = new MI_DeserializerCallbacks(); var res = this.Deserializer.DeserializeClassArray(MI_SerializerFlags.None, MI_OperationOptions.Null, callbacks, serializedClass, new MI_Class[] {}, null, null, out bufferRead, out deserializedArray, out cimErrorDetails); MIAssert.Succeeded(res, "Expect to be able to deserialize instance"); classes = deserializedArray.ReadAsManagedPointerArray(MI_Class.NewFromDirectPtr); var expectedInstance = this.GetSerializableInstance(); Assert.Equal(1, classes.Length, "Expect only the class we serialized"); MI_Value elementValue; UInt32 elementIndex; MI_Type elementType; MI_Flags elementFlags; bool valueExists; string referenceClass; MI_QualifierSet qualifierSet; res = classes[0].GetElement(SerializationTestData.SerializableClassStringProperty, out elementValue, out valueExists, out elementType, out referenceClass, out qualifierSet, out elementFlags, out elementIndex); MIAssert.Succeeded(res, "Expect to be able to get property from deserialized class"); Assert.Equal(MI_Type.MI_STRING, elementType, "Expect the type to be correct"); expectedInstance.Delete(); deserializedArray.Delete(); }
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); }
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); }