コード例 #1
0
        public void OnNext(T value)
        {
            CimInstance instance = value as CimInstance;

            if (instance != null)
            {
                SampleCimOperation.PrintCimInstance(instance);
                return;
            }

            CimMethodResult methodResult = value as CimMethodResult;

            if (methodResult != null)
            {
                SampleCimOperation.PrintCimMethodResult(methodResult);
                return;
            }

            CimMethodStreamedResult methodStreamResult = value as CimMethodStreamedResult;

            if (methodStreamResult != null)
            {
                SampleCimOperation.PrintCimMethodStreamResult(methodStreamResult);
            }

            CimSubscriptionResult subscriptionResult = value as CimSubscriptionResult;

            if (subscriptionResult != null)
            {
                SampleCimOperation.PrintCimInstance(subscriptionResult.Instance);
                return;
            }
        }
コード例 #2
0
        public static CimResponseType WriteError(CimInstance instance)
        {
            Console.WriteLine("Got WriteError callback");
            Console.WriteLine("Printing WriteError instance ...");
            SampleCimOperation.PrintCimInstance(instance);

            // Prompt the user to get proper Cim Response Type
            return(CimResponseType.Yes);
        }
コード例 #3
0
        public void OnError(Exception error)
        {
            CimException cimException = error as CimException;

            if (cimException != null)
            {
                SampleCimOperation.PrintCimException(cimException);
            }
            else
            {
                throw error;
            }

            this.doneEvent.Set();
        }
コード例 #4
0
        public static void Main()
        {
            bool       hasComputerNameChanged = true;
            CimSession cimSession             = null;
            string     className    = null;
            string     computerName = GetName("ComputerName");

            if (String.IsNullOrEmpty(computerName))
            {
                computerName = null;
            }

            string           namespaceName    = GetName("Namespace");
            CurrentOperation currentOperation = GetCurrentOption(true);

            while (true)
            {
                if (currentOperation == CurrentOperation.OperationQuit)
                {
                    if (cimSession != null)
                    {
                        cimSession.Close();
                        cimSession = null;
                    }

                    return;
                }

                if (ClassNeeded(currentOperation))
                {
                    className = GetName("ClassName");
                }

                try
                {
                    // Create local CIM session
                    if (hasComputerNameChanged)
                    {
                        if (cimSession != null)
                        {
                            cimSession.Close();
                        }

                        WMIDCOMCimSessionOptions sessionOptions = new WMIDCOMCimSessionOptions();

                        cimSession             = CimSession.Create(computerName, sessionOptions);
                        hasComputerNameChanged = false;
                    }

                    switch (currentOperation)
                    {
                    case CurrentOperation.EnumerateAsync:
                        SampleCimOperation.EnumerateASync(cimSession, namespaceName, className);
                        break;

                    case CurrentOperation.EnumerateSync:
                        SampleCimOperation.EnumerateSync(cimSession, namespaceName, className);
                        break;

                    case CurrentOperation.GetInstanceSync:
                        SampleCimOperation.GetInstanceSync(cimSession, namespaceName, className);
                        break;

                    case CurrentOperation.GetInstanceAsync:
                        SampleCimOperation.GetInstanceASync(cimSession, namespaceName, className);
                        break;

                    case CurrentOperation.CreateInstanceAsync:
                        SampleCimOperation.CreateInstanceASync(cimSession, namespaceName, className);
                        break;

                    case CurrentOperation.CreateInstanceSync:
                        SampleCimOperation.CreateInstanceSync(cimSession, namespaceName, className);
                        break;

                    case CurrentOperation.DeleteInstanceAsync:
                        SampleCimOperation.DeleteInstanceASync(cimSession, namespaceName, className);
                        break;

                    case CurrentOperation.DeleteInstanceSync:
                        SampleCimOperation.DeleteInstanceSync(cimSession, namespaceName, className);
                        break;

                    case CurrentOperation.ModifyInstanceAsync:
                        SampleCimOperation.ModifyInstanceASync(cimSession, namespaceName, className);
                        break;

                    case CurrentOperation.ModifyInstanceSync:
                        SampleCimOperation.ModifyInstanceSync(cimSession, namespaceName, className);
                        break;

                    case CurrentOperation.QueryInstanceAsync:
                        SampleCimOperation.QueryInstanceASync(cimSession, namespaceName);
                        break;

                    case CurrentOperation.QueryInstanceSync:
                        SampleCimOperation.QueryInstanceSync(cimSession, namespaceName);
                        break;

                    case CurrentOperation.QueryAssociationSync:
                        SampleCimOperation.EnumerateAssociatedInstanceSync(cimSession, namespaceName, className);
                        break;

                    case CurrentOperation.QueryAssociationAsync:
                        SampleCimOperation.EnumerateAssociatedInstanceASync(cimSession, namespaceName, className);
                        break;

                    case CurrentOperation.InvokeMethodSync:
                        SampleCimOperation.InvokeMethodSync(cimSession, namespaceName, className);
                        break;

                    case CurrentOperation.InvokeMethodAsync:
                        SampleCimOperation.InvokeMethodASync(cimSession, namespaceName, className);
                        break;

                    case CurrentOperation.SubscribeSync:
                        SampleCimOperation.SubscribeSync(cimSession, namespaceName);
                        break;

                    case CurrentOperation.SubscribeAsync:
                        SampleCimOperation.SubscribeASync(cimSession, namespaceName);
                        break;

                    case CurrentOperation.OperationComputerName:
                        computerName = GetName("ComputerName");
                        if (String.IsNullOrEmpty(computerName))
                        {
                            computerName = null;
                        }

                        hasComputerNameChanged = true;
                        break;

                    case CurrentOperation.OperationNamespaceName:
                        namespaceName = GetName("Namespace");
                        break;

                    default:
                        break;
                    }
                }
                catch (CimException ex)
                {
                    Console.WriteLine(ex.Message);
                }

                currentOperation = GetCurrentOption(false);
            }
        }