Ejemplo n.º 1
0
        public static NativeDestinationOptions GetDestinationOptions(SessionHandle handle)
        {
            NativeCimSession         session = MarshalledObject.FromPointer <NativeCimSession> (handle.DangerousGetHandle());
            NativeDestinationOptions options = new NativeDestinationOptions();

            if (session.DestinationOptions == IntPtr.Zero)
            {
                /* Setup Default Destination Options */
                options.ServerName      = session.ServerName;
                options.DestinationPort = 5985;
            }
            else
            {
                options = MarshalledObject.FromPointer <NativeDestinationOptions> (session.DestinationOptions);
                if (string.IsNullOrEmpty(options.ServerName))
                {
                    options.ServerName = session.ServerName;
                }
                if (options.DestinationPort == 0)
                {
                    options.DestinationPort = 5985;
                }
            }
            return(options);
        }
Ejemplo n.º 2
0
		internal unsafe MiResult ReleaseHandleAsynchronously(SessionHandle.OnSessionHandleReleasedDelegate completionCallback)
		{
			/*
			_MI_Result _MIResult;
			base.SetHandleAsInvalid();
			_MI_Session* _MISessionPointer = (_MI_Session*)((void*)this.handle);
			this.handle = IntPtr.Zero;
			SessionHandle_ReleaseHandle_CallbackWrapper* sessionHandleReleaseHandleCallbackWrapperPointer = (SessionHandle_ReleaseHandle_CallbackWrapper*)<Module>.Microsoft.Management.Infrastructure.Native.MI_CLI_malloc_core((long)24);
			<Module>.Microsoft.Management.Infrastructure.Native.SessionHandle_ReleaseHandle_CallbackWrapper_Initialize(sessionHandleReleaseHandleCallbackWrapperPointer, _MISessionPointer, completionCallback);
			WindowsImpersonationContext windowsImpersonationContext = WindowsIdentity.Impersonate(this.handleToSecurityTokenUsedForCreation);
			_MI_Result _MIResult1 = (_MI_Result)<Module>.?A0xf16864c4.MI_Session_Close(_MISessionPointer, sessionHandleReleaseHandleCallbackWrapperPointer, <Module>.__unep@?SessionHandle_OnReleaseHandleCompleted@Native@Infrastructure@Management@Microsoft@@$$FYAXPEAX@Z);
			if (<Module>.CloseHandle((void*)this.handleToSecurityTokenUsedForCreation) == null)
			{
				if (_MIResult1 == 0)
				{
					_MIResult = 1;
				}
				else
				{
					_MIResult = _MIResult1;
				}
				_MIResult1 = _MIResult;
			}
			else
			{
				this.handleToSecurityTokenUsedForCreation = IntPtr.Zero;
			}
			windowsImpersonationContext.Undo();
			return (MiResult)_MIResult1;
			*/
			return MiResult.OK;
		}
Ejemplo n.º 3
0
		private CimSession(SessionHandle handle, string computerName)
		{
			this._disposeThreadSafetyLock = new object();
			this._handle = handle;
			this.ComputerName = computerName;
			this.InstanceId = Guid.NewGuid();
			CimApplication.AddTracking(this);
		}
Ejemplo n.º 4
0
		internal static MiResult NewSession (ApplicationHandle handle, string protocol, string str1, DestinationOptionsHandle destinationOptionsHandle, out InstanceHandle instanceHandle, out SessionHandle sessionHandle)
		{
			string p1 = string.IsNullOrEmpty (str1) ? "localhost" : str1; //.Substring(1, str1.Length - 2);
			NewInstance (handle, p1, null, out instanceHandle);
			NativeCimSession session = new NativeCimSession();
			session.Protocol = protocol;
			session.ServerName = p1;
			session.DestinationOptions = destinationOptionsHandle == null ? IntPtr.Zero : destinationOptionsHandle.DangerousGetHandle ();
			IntPtr sessionPtr = (IntPtr)CimNativeApi.MarshalledObject.Create<NativeCimSession>(session);
			sessionHandle = new SessionHandle(sessionPtr);
			return MiResult.OK;
		}
Ejemplo n.º 5
0
        internal static MiResult NewSession(ApplicationHandle handle, string protocol, string str1, DestinationOptionsHandle destinationOptionsHandle, out InstanceHandle instanceHandle, out SessionHandle sessionHandle)
        {
            string p1 = string.IsNullOrEmpty(str1) ? "localhost" : str1;              //.Substring(1, str1.Length - 2);

            NewInstance(handle, p1, null, out instanceHandle);
            NativeCimSession session = new NativeCimSession();

            session.Protocol           = protocol;
            session.ServerName         = p1;
            session.DestinationOptions = destinationOptionsHandle == null ? IntPtr.Zero : destinationOptionsHandle.DangerousGetHandle();
            IntPtr sessionPtr = (IntPtr)CimNativeApi.MarshalledObject.Create <NativeCimSession>(session);

            sessionHandle = new SessionHandle(sessionPtr);
            return(MiResult.OK);
        }
Ejemplo n.º 6
0
		internal static unsafe void Subscribe(SessionHandle sessionHandle, MiOperationFlags operationFlags, OperationOptionsHandle operationOptionsHandle, string namespaceName, string queryDialect, string queryExpression, SubscriptionDeliveryOptionsHandle subscriptionDeliveryOptionsHandle, OperationCallbacks operationCallbacks, out OperationHandle operationHandle)
		{
			operationHandle = null;
			/*
			_MI_OperationCallbacks _MIOperationCallback;
			_MI_OperationCallbacks* _MIOperationCallbacksPointer;
			DangerousHandleAccessor dangerousHandleAccessor = null;
			DangerousHandleAccessor dangerousHandleAccessor1 = null;
			DangerousHandleAccessor dangerousHandleAccessor2 = null;
			operationHandle = null;
			DangerousHandleAccessor dangerousHandleAccessor = new DangerousHandleAccessor(sessionHandle);
			try
			{
				dangerousHandleAccessor = dangerousHandleAccessor;
				DangerousHandleAccessor dangerousHandleAccessor1 = new DangerousHandleAccessor(operationOptionsHandle);
				try
				{
					dangerousHandleAccessor1 = dangerousHandleAccessor1;
					_MI_OperationOptions* _MIOperationOptionsPointer = (_MI_OperationOptions*)((void*)dangerousHandleAccessor1.DangerousGetHandle());
					DangerousHandleAccessor dangerousHandleAccessor2 = new DangerousHandleAccessor(subscriptionDeliveryOptionsHandle);
					try
					{
						dangerousHandleAccessor2 = dangerousHandleAccessor2;
						_MI_SubscriptionDeliveryOptions* _MISubscriptionDeliveryOptionsPointer = (_MI_SubscriptionDeliveryOptions*)((void*)dangerousHandleAccessor2.DangerousGetHandle());
						&_MIOperationCallback;
						0;
						bool flag = operationCallbacks.SetMiOperationCallbacks(ref _MIOperationCallback);
						IntPtr hGlobalUni = Marshal.StringToHGlobalUni(namespaceName);
						IntPtr intPtr = hGlobalUni;
						try
						{
							IntPtr hGlobalUni1 = Marshal.StringToHGlobalUni(queryDialect);
							IntPtr intPtr1 = hGlobalUni1;
							try
							{
								IntPtr hGlobalUni2 = Marshal.StringToHGlobalUni(queryExpression);
								IntPtr intPtr2 = hGlobalUni2;
								try
								{
									_MI_Operation* _MIOperationPointer = (_MI_Operation*)<Module>.Microsoft.Management.Infrastructure.Native.MI_CLI_malloc_core((long)24);
									void* voidPointer = (void*)dangerousHandleAccessor.DangerousGetHandle();
									if (flag)
									{
										_MIOperationCallbacksPointer = &_MIOperationCallback;
									}
									else
									{
										_MIOperationCallbacksPointer = (_MI_OperationCallbacks*)((long)0);
									}
									_MI_OperationCallbacks* _MIOperationCallbacksPointer1 = _MIOperationCallbacksPointer;
									<Module>.?A0xf16864c4.MI_Session_Subscribe((_MI_Session*)voidPointer, operationFlags, _MIOperationOptionsPointer, (void*)hGlobalUni, (void*)hGlobalUni1, (void*)hGlobalUni2, _MISubscriptionDeliveryOptionsPointer, _MIOperationCallbacksPointer1, _MIOperationPointer);
									OperationHandle operationHandle = new OperationHandle((IntPtr)_MIOperationPointer, true);
									operationHandle = operationHandle;
									operationHandle.SetOperationCallback((long)_MIOperationCallback);
								}
								finally
								{
									if (intPtr2 != IntPtr.Zero)
									{
										Marshal.FreeHGlobal(intPtr2);
									}
								}
							}
							finally
							{
								if (intPtr1 != IntPtr.Zero)
								{
									Marshal.FreeHGlobal(intPtr1);
								}
							}
						}
						finally
						{
							if (intPtr != IntPtr.Zero)
							{
								Marshal.FreeHGlobal(intPtr);
							}
						}
					}
					dangerousHandleAccessor2.Dispose();
				}
				dangerousHandleAccessor1.Dispose();
			}
			dangerousHandleAccessor.Dispose();
			*/
		}
Ejemplo n.º 7
0
		internal static unsafe void QueryInstances (SessionHandle sessionHandle, MiOperationFlags operationFlags, OperationOptionsHandle operationOptionsHandle, string namespaceName, string queryDialect, string queryExpression, bool keysOnly, OperationCallbacks operationCallbacks, out OperationHandle operationHandle)
		{
			IntPtr sessionPtr = sessionHandle.DangerousGetHandle ();
			NativeDestinationOptions options = CimNativeApi.GetDestinationOptions (sessionHandle);
			operationHandle = new OperationHandle (IntPtr.Zero, true);
			operationHandle.SetOperationCallback (IntPtr.Zero.ToPointer ());
			int i = 0;
			var instances = CimNativeApi.QueryInstances (options, namespaceName, queryDialect, queryExpression, keysOnly);
			var currentContext = new OperationCallbackProcessingContext (operationCallbacks.ManagedOperationContext);
			int count = instances.Count ();
			if (count > 0) {
				foreach (var obj in instances) {
					obj.ClassName = null;
					obj.SessionHandle = sessionPtr;
					IntPtr instancePtr = (IntPtr)CimNativeApi.MarshalledObject.Create<NativeCimInstance> (obj);
					InstanceHandle resultHandle = new InstanceHandle (instancePtr, true);
					operationCallbacks.InstanceResultCallback.Invoke (currentContext, operationHandle, resultHandle, i < count - 1, MiResult.OK, null, null);
					i++;
				}
			} else {
				InstanceHandle resultHandle = new InstanceHandle (IntPtr.Zero, true);
				operationCallbacks.InstanceResultCallback.Invoke (currentContext, operationHandle, resultHandle, false, MiResult.NOT_FOUND, null, null);

			}
			/*
			_MI_OperationCallbacks _MIOperationCallback;
			_MI_OperationCallbacks* _MIOperationCallbacksPointer;
			DangerousHandleAccessor dangerousHandleAccessor = null;
			DangerousHandleAccessor dangerousHandleAccessor1 = null;
			operationHandle = null;
			DangerousHandleAccessor dangerousHandleAccessor = new DangerousHandleAccessor(sessionHandle);
			try
			{
				dangerousHandleAccessor = dangerousHandleAccessor;
				DangerousHandleAccessor dangerousHandleAccessor1 = new DangerousHandleAccessor(operationOptionsHandle);
				try
				{
					dangerousHandleAccessor1 = dangerousHandleAccessor1;
					_MI_OperationOptions* _MIOperationOptionsPointer = (_MI_OperationOptions*)((void*)dangerousHandleAccessor1.DangerousGetHandle());
					&_MIOperationCallback;
					0;
					bool flag = operationCallbacks.SetMiOperationCallbacks(ref _MIOperationCallback);
					IntPtr hGlobalUni = Marshal.StringToHGlobalUni(namespaceName);
					IntPtr intPtr = hGlobalUni;
					try
					{
						IntPtr hGlobalUni1 = Marshal.StringToHGlobalUni(queryDialect);
						IntPtr intPtr1 = hGlobalUni1;
						try
						{
							IntPtr hGlobalUni2 = Marshal.StringToHGlobalUni(queryExpression);
							IntPtr intPtr2 = hGlobalUni2;
							try
							{
								_MI_Operation* _MIOperationPointer = (_MI_Operation*)<Module>.Microsoft.Management.Infrastructure.Native.MI_CLI_malloc_core((long)24);
								void* voidPointer = (void*)dangerousHandleAccessor.DangerousGetHandle();
								if (flag)
								{
									_MIOperationCallbacksPointer = &_MIOperationCallback;
								}
								else
								{
									_MIOperationCallbacksPointer = (_MI_OperationCallbacks*)((long)0);
								}
								_MI_OperationCallbacks* _MIOperationCallbacksPointer1 = _MIOperationCallbacksPointer;
								<Module>.?A0xf16864c4.MI_Session_QueryInstances((_MI_Session*)voidPointer, operationFlags, _MIOperationOptionsPointer, (void*)hGlobalUni, (void*)hGlobalUni1, (void*)hGlobalUni2, _MIOperationCallbacksPointer1, _MIOperationPointer);
								OperationHandle operationHandle = new OperationHandle((IntPtr)_MIOperationPointer, true);
								operationHandle = operationHandle;
								operationHandle.SetOperationCallback((long)_MIOperationCallback);
							}
							finally
							{
								if (intPtr2 != IntPtr.Zero)
								{
									Marshal.FreeHGlobal(intPtr2);
								}
							}
						}
						finally
						{
							if (intPtr1 != IntPtr.Zero)
							{
								Marshal.FreeHGlobal(intPtr1);
							}
						}
					}
					finally
					{
						if (intPtr != IntPtr.Zero)
						{
							Marshal.FreeHGlobal(intPtr);
						}
					}
				}
				dangerousHandleAccessor1.Dispose();
			}
			dangerousHandleAccessor.Dispose();
			*/
		}
Ejemplo n.º 8
0
		internal static unsafe void ReferenceInstances(SessionHandle sessionHandle, MiOperationFlags operationFlags, OperationOptionsHandle operationOptionsHandle, string namespaceName, InstanceHandle sourceInstance, string associationClassName, string sourceRole, bool keysOnly, OperationCallbacks operationCallbacks, out OperationHandle operationHandle)
		{
			operationHandle = null;
			/*
			_MI_OperationCallbacks _MIOperationCallback;
			_MI_OperationCallbacks* _MIOperationCallbacksPointer;
			DangerousHandleAccessor dangerousHandleAccessor = null;
			DangerousHandleAccessor dangerousHandleAccessor1 = null;
			DangerousHandleAccessor dangerousHandleAccessor2 = null;
			operationHandle = null;
			DangerousHandleAccessor dangerousHandleAccessor = new DangerousHandleAccessor(sessionHandle);
			try
			{
				dangerousHandleAccessor = dangerousHandleAccessor;
				DangerousHandleAccessor dangerousHandleAccessor1 = new DangerousHandleAccessor(sourceInstance);
				try
				{
					dangerousHandleAccessor1 = dangerousHandleAccessor1;
					DangerousHandleAccessor dangerousHandleAccessor2 = new DangerousHandleAccessor(operationOptionsHandle);
					try
					{
						dangerousHandleAccessor2 = dangerousHandleAccessor2;
						_MI_OperationOptions* _MIOperationOptionsPointer = (_MI_OperationOptions*)((void*)dangerousHandleAccessor2.DangerousGetHandle());
						&_MIOperationCallback;
						0;
						bool flag = operationCallbacks.SetMiOperationCallbacks(ref _MIOperationCallback);
						IntPtr hGlobalUni = Marshal.StringToHGlobalUni(namespaceName);
						IntPtr intPtr = hGlobalUni;
						try
						{
							IntPtr hGlobalUni1 = Marshal.StringToHGlobalUni(associationClassName);
							IntPtr intPtr1 = hGlobalUni1;
							try
							{
								IntPtr hGlobalUni2 = Marshal.StringToHGlobalUni(sourceRole);
								IntPtr intPtr2 = hGlobalUni2;
								try
								{
									_MI_Operation* _MIOperationPointer = (_MI_Operation*)<Module>.Microsoft.Management.Infrastructure.Native.MI_CLI_malloc_core((long)24);
									void* voidPointer = (void*)dangerousHandleAccessor.DangerousGetHandle();
									if (flag)
									{
										_MIOperationCallbacksPointer = &_MIOperationCallback;
									}
									else
									{
										_MIOperationCallbacksPointer = (_MI_OperationCallbacks*)((long)0);
									}
									_MI_OperationCallbacks* _MIOperationCallbacksPointer1 = _MIOperationCallbacksPointer;
									IntPtr intPtr3 = dangerousHandleAccessor1.DangerousGetHandle();
									<Module>.?A0xf16864c4.MI_Session_ReferenceInstances((_MI_Session*)voidPointer, operationFlags, _MIOperationOptionsPointer, (void*)hGlobalUni, (void*)intPtr3, (void*)hGlobalUni1, (void*)hGlobalUni2, keysOnly, _MIOperationCallbacksPointer1, _MIOperationPointer);
									OperationHandle operationHandle = new OperationHandle((IntPtr)_MIOperationPointer, true);
									operationHandle = operationHandle;
									operationHandle.SetOperationCallback((long)_MIOperationCallback);
								}
								finally
								{
									if (intPtr2 != IntPtr.Zero)
									{
										Marshal.FreeHGlobal(intPtr2);
									}
								}
							}
							finally
							{
								if (intPtr1 != IntPtr.Zero)
								{
									Marshal.FreeHGlobal(intPtr1);
								}
							}
						}
						finally
						{
							if (intPtr != IntPtr.Zero)
							{
								Marshal.FreeHGlobal(intPtr);
							}
						}
					}
					dangerousHandleAccessor2.Dispose();
				}
				dangerousHandleAccessor1.Dispose();
			}
			dangerousHandleAccessor.Dispose();
			*/
		}
Ejemplo n.º 9
0
		internal static unsafe void Invoke(SessionHandle sessionHandle, MiOperationFlags operationFlags, OperationOptionsHandle operationOptionsHandle, string namespaceName, string className, string methodName, InstanceHandle instanceHandleForTargetOfInvocation, InstanceHandle instanceHandleForMethodParameters, OperationCallbacks operationCallbacks, out OperationHandle operationHandle)
		{
			NativeDestinationOptions options = CimNativeApi.GetDestinationOptions (sessionHandle);
			operationHandle = new OperationHandle(IntPtr.Zero, true);
			operationHandle.SetOperationCallback(IntPtr.Zero.ToPointer ());
			NativeCimInstance instance = instanceHandleForTargetOfInvocation == null ? new NativeCimInstance() : CimNativeApi.MarshalledObject.FromPointer<NativeCimInstance>(instanceHandleForTargetOfInvocation.DangerousGetHandle ());
			NativeCimInstance inSignature = instanceHandleForMethodParameters == null ? new NativeCimInstance() :  CimNativeApi.MarshalledObject.FromPointer<NativeCimInstance>(instanceHandleForMethodParameters.DangerousGetHandle ());
			NativeCimInstance result = CimNativeApi.InvokeMethod(options, namespaceName, className, methodName, instance, inSignature);
			IntPtr instancePtr = (IntPtr)CimNativeApi.MarshalledObject.Create<NativeCimInstance>(result);
			InstanceHandle resultHandle = new InstanceHandle(instancePtr, true);


			operationCallbacks.InstanceResultCallback.Invoke (new OperationCallbackProcessingContext(operationCallbacks.ManagedOperationContext), operationHandle, resultHandle, false, MiResult.OK, null, null);


			/*
			_MI_OperationCallbacks _MIOperationCallback;
			_MI_OperationCallbacks* _MIOperationCallbacksPointer;
			DangerousHandleAccessor dangerousHandleAccessor = null;
			DangerousHandleAccessor dangerousHandleAccessor1 = null;
			DangerousHandleAccessor dangerousHandleAccessor2 = null;
			DangerousHandleAccessor dangerousHandleAccessor3 = null;
			operationHandle = null;
			DangerousHandleAccessor dangerousHandleAccessor = new DangerousHandleAccessor(sessionHandle);
			try
			{
				dangerousHandleAccessor = dangerousHandleAccessor;
				DangerousHandleAccessor dangerousHandleAccessor1 = new DangerousHandleAccessor(operationOptionsHandle);
				try
				{
					dangerousHandleAccessor1 = dangerousHandleAccessor1;
					_MI_OperationOptions* _MIOperationOptionsPointer = (_MI_OperationOptions*)((void*)dangerousHandleAccessor1.DangerousGetHandle());
					&_MIOperationCallback;
					0;
					bool flag = operationCallbacks.SetMiOperationCallbacks(ref _MIOperationCallback);
					IntPtr hGlobalUni = Marshal.StringToHGlobalUni(namespaceName);
					IntPtr intPtr = hGlobalUni;
					try
					{
						IntPtr hGlobalUni1 = Marshal.StringToHGlobalUni(className);
						IntPtr intPtr1 = hGlobalUni1;
						try
						{
							IntPtr hGlobalUni2 = Marshal.StringToHGlobalUni(methodName);
							IntPtr intPtr2 = hGlobalUni2;
							try
							{
								_MI_Operation* _MIOperationPointer = (_MI_Operation*)<Module>.Microsoft.Management.Infrastructure.Native.MI_CLI_malloc_core((long)24);
								DangerousHandleAccessor dangerousHandleAccessor2 = new DangerousHandleAccessor(instanceHandleForTargetOfInvocation);
								try
								{
									dangerousHandleAccessor2 = dangerousHandleAccessor2;
									_MI_Instance* _MIInstancePointer = (_MI_Instance*)((void*)dangerousHandleAccessor2.DangerousGetHandle());
									DangerousHandleAccessor dangerousHandleAccessor3 = new DangerousHandleAccessor(instanceHandleForMethodParameters);
									try
									{
										dangerousHandleAccessor3 = dangerousHandleAccessor3;
										_MI_Instance* _MIInstancePointer1 = (_MI_Instance*)((void*)dangerousHandleAccessor3.DangerousGetHandle());
										void* voidPointer = (void*)dangerousHandleAccessor.DangerousGetHandle();
										if (flag)
										{
											_MIOperationCallbacksPointer = &_MIOperationCallback;
										}
										else
										{
											_MIOperationCallbacksPointer = (_MI_OperationCallbacks*)((long)0);
										}
										_MI_OperationCallbacks* _MIOperationCallbacksPointer1 = _MIOperationCallbacksPointer;
										<Module>.?A0xf16864c4.MI_Session_Invoke((_MI_Session*)voidPointer, operationFlags, _MIOperationOptionsPointer, (void*)hGlobalUni, (void*)hGlobalUni1, (void*)hGlobalUni2, _MIInstancePointer, _MIInstancePointer1, _MIOperationCallbacksPointer1, _MIOperationPointer);
										OperationHandle operationHandle = new OperationHandle((IntPtr)_MIOperationPointer, true);
										operationHandle = operationHandle;
										operationHandle.SetOperationCallback((long)_MIOperationCallback);
									}
									dangerousHandleAccessor3.Dispose();
								}
								dangerousHandleAccessor2.Dispose();
							}
							finally
							{
								if (intPtr2 != IntPtr.Zero)
								{
									Marshal.FreeHGlobal(intPtr2);
								}
							}
						}
						finally
						{
							if (intPtr1 != IntPtr.Zero)
							{
								Marshal.FreeHGlobal(intPtr1);
							}
						}
					}
					finally
					{
						if (intPtr != IntPtr.Zero)
						{
							Marshal.FreeHGlobal(intPtr);
						}
					}
				}
				dangerousHandleAccessor1.Dispose();
			}
			dangerousHandleAccessor.Dispose();
			*/
		}
Ejemplo n.º 10
0
		internal static unsafe void GetInstance(SessionHandle sessionHandle, MiOperationFlags operationFlags, OperationOptionsHandle operationOptionsHandle, string namespaceName, InstanceHandle instanceHandle, OperationCallbacks operationCallbacks, out OperationHandle operationHandle)
		{
			IntPtr sessionPtr = sessionHandle.DangerousGetHandle ();
			NativeDestinationOptions options = CimNativeApi.GetDestinationOptions (sessionHandle);
			operationHandle = new OperationHandle(IntPtr.Zero, true);
			operationHandle.SetOperationCallback(IntPtr.Zero.ToPointer ());
			NativeCimInstance obj = new NativeCimInstance();
			obj.Namespace = namespaceName;
			obj.ServerName = "localhost";
			obj.SessionHandle = sessionPtr;
			var properties = new NativeCimProperties();
			//properties.Keys = new string[] { "PSShowComputerName", "Name", "Status", "PSComputerName" };
			//properties.Values = new object[] { true, "test1", "Started", "localhost" };
			obj.Properties = NativeCimPropertiesHelper.Serialize (properties);
			IntPtr instancePtr = (IntPtr)CimNativeApi.MarshalledObject.Create<NativeCimInstance>(obj);
			InstanceHandle resultHandle = new InstanceHandle(instancePtr, true);
			operationCallbacks.InstanceResultCallback.Invoke (new OperationCallbackProcessingContext(operationCallbacks.ManagedOperationContext), operationHandle, resultHandle, false, MiResult.OK, null, null);

			/*
			_MI_OperationCallbacks _MIOperationCallback;
			_MI_OperationCallbacks* _MIOperationCallbacksPointer;
			DangerousHandleAccessor dangerousHandleAccessor = null;
			DangerousHandleAccessor dangerousHandleAccessor1 = null;
			DangerousHandleAccessor dangerousHandleAccessor2 = null;
			operationHandle = null;
			DangerousHandleAccessor dangerousHandleAccessor = new DangerousHandleAccessor(sessionHandle);
			try
			{
				dangerousHandleAccessor = dangerousHandleAccessor;
				DangerousHandleAccessor dangerousHandleAccessor1 = new DangerousHandleAccessor(instanceHandle);
				try
				{
					dangerousHandleAccessor1 = dangerousHandleAccessor1;
					DangerousHandleAccessor dangerousHandleAccessor2 = new DangerousHandleAccessor(operationOptionsHandle);
					try
					{
						dangerousHandleAccessor2 = dangerousHandleAccessor2;
						_MI_OperationOptions* _MIOperationOptionsPointer = (_MI_OperationOptions*)((void*)dangerousHandleAccessor2.DangerousGetHandle());
						&_MIOperationCallback;
						0;
						bool flag = operationCallbacks.SetMiOperationCallbacks(ref _MIOperationCallback);
						IntPtr hGlobalUni = Marshal.StringToHGlobalUni(namespaceName);
						IntPtr intPtr = hGlobalUni;
						try
						{
							_MI_Operation* _MIOperationPointer = (_MI_Operation*)<Module>.Microsoft.Management.Infrastructure.Native.MI_CLI_malloc_core((long)24);
							void* voidPointer = (void*)dangerousHandleAccessor.DangerousGetHandle();
							if (flag)
							{
								_MIOperationCallbacksPointer = &_MIOperationCallback;
							}
							else
							{
								_MIOperationCallbacksPointer = (_MI_OperationCallbacks*)((long)0);
							}
							_MI_OperationCallbacks* _MIOperationCallbacksPointer1 = _MIOperationCallbacksPointer;
							IntPtr intPtr1 = dangerousHandleAccessor1.DangerousGetHandle();
							<Module>.?A0xf16864c4.MI_Session_GetInstance((_MI_Session*)voidPointer, operationFlags, _MIOperationOptionsPointer, (void*)hGlobalUni, (void*)intPtr1, _MIOperationCallbacksPointer1, _MIOperationPointer);
							OperationHandle operationHandle = new OperationHandle((IntPtr)_MIOperationPointer, true);
							operationHandle = operationHandle;
							operationHandle.SetOperationCallback((long)_MIOperationCallback);
						}
						finally
						{
							if (intPtr != IntPtr.Zero)
							{
								Marshal.FreeHGlobal(intPtr);
							}
						}
					}
					dangerousHandleAccessor2.Dispose();
				}
				dangerousHandleAccessor1.Dispose();
			}
			dangerousHandleAccessor.Dispose();
			*/
		}
Ejemplo n.º 11
0
		internal static unsafe void EnumerateClasses (SessionHandle sessionHandle, MiOperationFlags operationFlags, OperationOptionsHandle operationOptionsHandle, string namespaceName, string className, bool classNamesOnly, OperationCallbacks operationCallbacks, out OperationHandle operationHandle)
		{
			/* TODO: Use ClassName if classNamesOnly */
			IntPtr sessionPtr = sessionHandle.DangerousGetHandle ();
			NativeDestinationOptions options = CimNativeApi.GetDestinationOptions (sessionHandle);
			operationHandle = new OperationHandle (IntPtr.Zero, true);
			operationHandle.SetOperationCallback (IntPtr.Zero.ToPointer ());
			var currentContext = new OperationCallbackProcessingContext (operationCallbacks.ManagedOperationContext);
			int i = 0;
			var instances = CimNativeApi.QueryClasses (options, namespaceName, CimNativeApi.WQLNamespace, "SELECT * FROM Meta_Class" + (string.IsNullOrEmpty (className) ? "" : " WHERE ClassName LIKE '" + className.Replace ("*", "%") + "'"));
			int count = instances.Count ();
			if (count >= 0) {
				foreach (var obj in instances) {
					obj.SessionHandle = sessionPtr;
					IntPtr instancePtr = (IntPtr)CimNativeApi.MarshalledObject.Create<NativeCimClass> (obj);
					ClassHandle resultHandle = new ClassHandle (instancePtr, true);
					operationCallbacks.ClassCallback.Invoke (currentContext, operationHandle, resultHandle, i < count - 1, MiResult.OK, null, null);
					i++;
				}
			} else {
				ClassHandle resultHandle = new ClassHandle (IntPtr.Zero, true);
				operationCallbacks.ClassCallback.Invoke (currentContext, operationHandle, resultHandle, false, MiResult.OK, null, null);

			}
			/*
			_MI_OperationCallbacks _MIOperationCallback;
			_MI_OperationCallbacks* _MIOperationCallbacksPointer;
			DangerousHandleAccessor dangerousHandleAccessor = null;
			DangerousHandleAccessor dangerousHandleAccessor1 = null;
			operationHandle = null;
			DangerousHandleAccessor dangerousHandleAccessor = new DangerousHandleAccessor(sessionHandle);
			try
			{
				dangerousHandleAccessor = dangerousHandleAccessor;
				DangerousHandleAccessor dangerousHandleAccessor1 = new DangerousHandleAccessor(operationOptionsHandle);
				try
				{
					dangerousHandleAccessor1 = dangerousHandleAccessor1;
					_MI_OperationOptions* _MIOperationOptionsPointer = (_MI_OperationOptions*)((void*)dangerousHandleAccessor1.DangerousGetHandle());
					&_MIOperationCallback;
					0;
					bool flag = operationCallbacks.SetMiOperationCallbacks(ref _MIOperationCallback);
					IntPtr hGlobalUni = Marshal.StringToHGlobalUni(namespaceName);
					IntPtr intPtr = hGlobalUni;
					try
					{
						IntPtr hGlobalUni1 = Marshal.StringToHGlobalUni(className);
						IntPtr intPtr1 = hGlobalUni1;
						try
						{
							_MI_Operation* _MIOperationPointer = (_MI_Operation*)<Module>.Microsoft.Management.Infrastructure.Native.MI_CLI_malloc_core((long)24);
							void* voidPointer = (void*)dangerousHandleAccessor.DangerousGetHandle();
							if (flag)
							{
								_MIOperationCallbacksPointer = &_MIOperationCallback;
							}
							else
							{
								_MIOperationCallbacksPointer = (_MI_OperationCallbacks*)((long)0);
							}
							_MI_OperationCallbacks* _MIOperationCallbacksPointer1 = _MIOperationCallbacksPointer;
							<Module>.?A0xf16864c4.MI_Session_EnumerateClasses((_MI_Session*)voidPointer, operationFlags, _MIOperationOptionsPointer, (void*)hGlobalUni, (void*)hGlobalUni1, classNamesOnly, _MIOperationCallbacksPointer1, _MIOperationPointer);
							IntPtr intPtr2 = (IntPtr)_MIOperationPointer;
							operationHandle = new OperationHandle(intPtr2, true);
						}
						finally
						{
							if (intPtr1 != IntPtr.Zero)
							{
								Marshal.FreeHGlobal(intPtr1);
							}
						}
					}
					finally
					{
						if (intPtr != IntPtr.Zero)
						{
							Marshal.FreeHGlobal(intPtr);
						}
					}
				}
				dangerousHandleAccessor1.Dispose();
			}
			dangerousHandleAccessor.Dispose();
			*/
		}
Ejemplo n.º 12
0
		internal static unsafe void CreateInstance(SessionHandle sessionHandle, MiOperationFlags operationFlags, OperationOptionsHandle operationOptionsHandle, string namespaceName, InstanceHandle instanceHandle, OperationCallbacks operationCallbacks, out OperationHandle operationHandle)
		{
			IntPtr sessionPtr = sessionHandle.DangerousGetHandle ();
			NativeDestinationOptions options = CimNativeApi.GetDestinationOptions (sessionHandle);
			operationHandle = new OperationHandle (IntPtr.Zero, true);
			operationHandle.SetOperationCallback (IntPtr.Zero.ToPointer ());
			var currentContext = new OperationCallbackProcessingContext (operationCallbacks.ManagedOperationContext);

			/*
			_MI_OperationCallbacks _MIOperationCallback;
			_MI_OperationCallbacks* _MIOperationCallbacksPointer;
			DangerousHandleAccessor dangerousHandleAccessor = null;
			DangerousHandleAccessor dangerousHandleAccessor1 = null;
			DangerousHandleAccessor dangerousHandleAccessor2 = null;
			operationHandle = null;
			DangerousHandleAccessor dangerousHandleAccessor = new DangerousHandleAccessor(sessionHandle);
			try
			{
				dangerousHandleAccessor = dangerousHandleAccessor;
				DangerousHandleAccessor dangerousHandleAccessor1 = new DangerousHandleAccessor(instanceHandle);
				try
				{
					dangerousHandleAccessor1 = dangerousHandleAccessor1;
					DangerousHandleAccessor dangerousHandleAccessor2 = new DangerousHandleAccessor(operationOptionsHandle);
					try
					{
						dangerousHandleAccessor2 = dangerousHandleAccessor2;
						_MI_OperationOptions* _MIOperationOptionsPointer = (_MI_OperationOptions*)((void*)dangerousHandleAccessor2.DangerousGetHandle());
						&_MIOperationCallback;
						0;
						bool flag = operationCallbacks.SetMiOperationCallbacks(ref _MIOperationCallback);
						IntPtr hGlobalUni = Marshal.StringToHGlobalUni(namespaceName);
						IntPtr intPtr = hGlobalUni;
						try
						{
							_MI_Operation* _MIOperationPointer = (_MI_Operation*)<Module>.Microsoft.Management.Infrastructure.Native.MI_CLI_malloc_core((long)24);
							void* voidPointer = (void*)dangerousHandleAccessor.DangerousGetHandle();
							if (flag)
							{
								_MIOperationCallbacksPointer = &_MIOperationCallback;
							}
							else
							{
								_MIOperationCallbacksPointer = (_MI_OperationCallbacks*)((long)0);
							}
							_MI_OperationCallbacks* _MIOperationCallbacksPointer1 = _MIOperationCallbacksPointer;
							IntPtr intPtr1 = dangerousHandleAccessor1.DangerousGetHandle();
							<Module>.?A0xf16864c4.MI_Session_CreateInstance((_MI_Session*)voidPointer, operationFlags, _MIOperationOptionsPointer, (void*)hGlobalUni, (void*)intPtr1, _MIOperationCallbacksPointer1, _MIOperationPointer);
							OperationHandle operationHandle = new OperationHandle((IntPtr)_MIOperationPointer, true);
							operationHandle = operationHandle;
							operationHandle.SetOperationCallback((long)_MIOperationCallback);
						}
						finally
						{
							if (intPtr != IntPtr.Zero)
							{
								Marshal.FreeHGlobal(intPtr);
							}
						}
					}
					dangerousHandleAccessor2.Dispose();
				}
				dangerousHandleAccessor1.Dispose();
			}
			dangerousHandleAccessor.Dispose();
			*/
		}
Ejemplo n.º 13
0
		internal static unsafe void TestConnection(SessionHandle sessionHandle, MiOperationFlags operationFlags, OperationCallbacks operationCallbacks, out OperationHandle operationHandle)
		{
			operationHandle = new OperationHandle(IntPtr.Zero, true);
			operationHandle.SetOperationCallback(IntPtr.Zero.ToPointer ());
			NativeCimSession session = CimNativeApi.MarshalledObject.FromPointer<NativeCimSession>(sessionHandle.DangerousGetHandle ());
			IntPtr instancePtr = (IntPtr)CimNativeApi.MarshalledObject.Create<NativeCimSession>(session);
			InstanceHandle testInstance = new InstanceHandle(instancePtr, false);
			var context = new OperationCallbackProcessingContext(operationCallbacks.ManagedOperationContext);
			operationCallbacks.InstanceResultCallback.Invoke (context, operationHandle, testInstance, false, MiResult.OK, null, null);

			/*
			_MI_OperationCallbacks _MIOperationCallback;
			_MI_OperationCallbacks* _MIOperationCallbacksPointer;
			DangerousHandleAccessor dangerousHandleAccessor = null;
			DangerousHandleAccessor dangerousHandleAccessor1 = null;
			operationHandle = null;
			DangerousHandleAccessor dangerousHandleAccessor = new DangerousHandleAccessor(sessionHandle);
			try
			{
				dangerousHandleAccessor = dangerousHandleAccessor;
				&_MIOperationCallback;
				0;
				bool flag = operationCallbacks.SetMiOperationCallbacks(ref _MIOperationCallback);
				_MI_Operation* _MIOperationPointer = (_MI_Operation*)<Module>.Microsoft.Management.Infrastructure.Native.MI_CLI_malloc_core((long)24);
				void* voidPointer = (void*)dangerousHandleAccessor.DangerousGetHandle();
				if (flag)
				{
					_MIOperationCallbacksPointer = &_MIOperationCallback;
				}
				else
				{
					_MIOperationCallbacksPointer = (_MI_OperationCallbacks*)((long)0);
				}
				_MI_OperationCallbacks* _MIOperationCallbacksPointer1 = _MIOperationCallbacksPointer;
				<Module>.?A0xf16864c4.MI_Session_TestConnection((_MI_Session*)voidPointer, operationFlags, _MIOperationCallbacksPointer1, _MIOperationPointer);
				OperationHandle operationHandle = new OperationHandle((IntPtr)_MIOperationPointer, true);
				operationHandle = operationHandle;
				DangerousHandleAccessor dangerousHandleAccessor1 = new DangerousHandleAccessor(operationHandle);
				try
				{
					dangerousHandleAccessor1 = dangerousHandleAccessor1;
				}
				dangerousHandleAccessor1.Dispose();
			}
			dangerousHandleAccessor.Dispose();
			*/
		}