コード例 #1
0
        protected static string CreateQuery(CimBaseCommand cmdlet)
        {
            DebugHelper.WriteLogEx();
            GetCimInstanceCommand cmd = cmdlet as GetCimInstanceCommand;

            if (cmd != null)
            {
                StringBuilder propertyList = new();
                if (cmd.SelectProperties == null)
                {
                    propertyList.Append('*');
                }
                else
                {
                    foreach (string property in cmd.SelectProperties)
                    {
                        if (propertyList.Length > 0)
                        {
                            propertyList.Append(',');
                        }

                        propertyList.Append(property);
                    }
                }

                return((cmd.Filter == null) ?
                       string.Format(CultureInfo.CurrentUICulture, queryWithoutWhere, propertyList, cmd.ClassName) :
                       string.Format(CultureInfo.CurrentUICulture, queryWithWhere, propertyList, cmd.ClassName, cmd.Filter));
            }

            return(null);
        }
コード例 #2
0
        /// <summary>
        /// Create <see cref="CimSessionProxy"/> and set properties.
        /// </summary>
        /// <param name="session"></param>
        /// <param name="cmdlet"></param>
        /// <returns></returns>
        protected CimSessionProxy CreateSessionProxy(
            CimSession session,
            CimBaseCommand cmdlet)
        {
            CimSessionProxy proxy = CreateCimSessionProxy(session);

            SetSessionProxyProperties(ref proxy, cmdlet);
            return(proxy);
        }
コード例 #3
0
        /// <summary>
        /// <para>
        /// Create <see cref="CimSessionProxy"/> and set properties.
        /// </para>
        /// </summary>
        /// <param name="computerName"></param>
        /// <param name="cmdlet"></param>
        /// <returns></returns>
        protected CimSessionProxy CreateSessionProxy(
            string computerName,
            CimBaseCommand cmdlet)
        {
            CimSessionProxy proxy = CreateCimSessionProxy(computerName);

            SetSessionProxyProperties(ref proxy, cmdlet);
            return(proxy);
        }
コード例 #4
0
        protected static string GetClassName(CimBaseCommand cmdlet)
        {
            if (cmdlet is GetCimInstanceCommand)
            {
                return((cmdlet as GetCimInstanceCommand).ClassName);
            }

            return(null);
        }
コード例 #5
0
        /// <summary>
        /// <para>
        /// Create <see cref="CimSessionProxy"/> and set properties.
        /// </para>
        /// </summary>
        /// <param name="computerName"></param>
        /// <param name="cimInstance"></param>
        /// <param name="cmdlet"></param>
        /// <returns></returns>
        protected CimSessionProxy CreateSessionProxy(
            string computerName,
            CimInstance cimInstance,
            CimBaseCommand cmdlet,
            bool passThru)
        {
            CimSessionProxy proxy = CreateCimSessionProxy(computerName, cimInstance, passThru);

            SetSessionProxyProperties(ref proxy, cmdlet);
            return(proxy);
        }
コード例 #6
0
        internal static bool IsClassNameQuerySet(CimBaseCommand cmdlet)
        {
            DebugHelper.WriteLogEx();
            GetCimInstanceCommand cmd = cmdlet as GetCimInstanceCommand;

            if (cmd != null)
            {
                if (cmd.QueryDialect != null || cmd.SelectProperties != null || cmd.Filter != null)
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #7
0
        /// <summary>
        /// <para>
        /// Set <see cref="CimSessionProxy"/> properties
        /// </para>
        /// </summary>
        /// <param name="proxy"></param>
        /// <param name="cmdlet"></param>
        private static void SetSessionProxyProperties(
            ref CimSessionProxy proxy,
            CimBaseCommand cmdlet)
        {
            if (cmdlet is GetCimInstanceCommand)
            {
                GetCimInstanceCommand getCimInstance = cmdlet as GetCimInstanceCommand;
                proxy.KeyOnly          = getCimInstance.KeyOnly;
                proxy.Shallow          = getCimInstance.Shallow;
                proxy.OperationTimeout = getCimInstance.OperationTimeoutSec;
                if (getCimInstance.ResourceUri != null)
                {
                    proxy.ResourceUri = getCimInstance.ResourceUri;
                }
            }
            else if (cmdlet is RemoveCimInstanceCommand)
            {
                RemoveCimInstanceCommand removeCimInstance = cmdlet as RemoveCimInstanceCommand;
                proxy.OperationTimeout = removeCimInstance.OperationTimeoutSec;
                if (removeCimInstance.ResourceUri != null)
                {
                    proxy.ResourceUri = removeCimInstance.ResourceUri;
                }

                CimRemoveCimInstanceContext context = new(
                    ConstValue.GetNamespace(removeCimInstance.Namespace),
                    proxy);
                proxy.ContextObject = context;
            }
            else if (cmdlet is SetCimInstanceCommand)
            {
                SetCimInstanceCommand setCimInstance = cmdlet as SetCimInstanceCommand;
                proxy.OperationTimeout = setCimInstance.OperationTimeoutSec;
                if (setCimInstance.ResourceUri != null)
                {
                    proxy.ResourceUri = setCimInstance.ResourceUri;
                }

                CimSetCimInstanceContext context = new(
                    ConstValue.GetNamespace(setCimInstance.Namespace),
                    setCimInstance.Property,
                    proxy,
                    cmdlet.ParameterSetName,
                    setCimInstance.PassThru);
                proxy.ContextObject = context;
            }
        }
コード例 #8
0
        protected static CimInstance GetCimInstanceParameter(CimBaseCommand cmdlet)
        {
            if (cmdlet is GetCimInstanceCommand)
            {
                return((cmdlet as GetCimInstanceCommand).CimInstance);
            }
            else if (cmdlet is RemoveCimInstanceCommand)
            {
                return((cmdlet as RemoveCimInstanceCommand).CimInstance);
            }
            else if (cmdlet is SetCimInstanceCommand)
            {
                return((cmdlet as SetCimInstanceCommand).CimInstance);
            }

            return(null);
        }
コード例 #9
0
        protected static string GetQueryDialect(CimBaseCommand cmdlet)
        {
            if (cmdlet is GetCimInstanceCommand)
            {
                return((cmdlet as GetCimInstanceCommand).QueryDialect);
            }
            else if (cmdlet is RemoveCimInstanceCommand)
            {
                return((cmdlet as RemoveCimInstanceCommand).QueryDialect);
            }
            else if (cmdlet is SetCimInstanceCommand)
            {
                return((cmdlet as SetCimInstanceCommand).QueryDialect);
            }

            return(null);
        }
コード例 #10
0
        protected static CimSession[] GetCimSession(CimBaseCommand cmdlet)
        {
            if (cmdlet is GetCimInstanceCommand)
            {
                return((cmdlet as GetCimInstanceCommand).CimSession);
            }
            else if (cmdlet is RemoveCimInstanceCommand)
            {
                return((cmdlet as RemoveCimInstanceCommand).CimSession);
            }
            else if (cmdlet is SetCimInstanceCommand)
            {
                return((cmdlet as SetCimInstanceCommand).CimSession);
            }

            return(null);
        }
コード例 #11
0
        protected static string GetNamespace(CimBaseCommand cmdlet)
        {
            if (cmdlet is GetCimInstanceCommand)
            {
                return((cmdlet as GetCimInstanceCommand).Namespace);
            }
            else if (cmdlet is RemoveCimInstanceCommand)
            {
                return((cmdlet as RemoveCimInstanceCommand).Namespace);
            }
            else if (cmdlet is SetCimInstanceCommand)
            {
                return((cmdlet as SetCimInstanceCommand).Namespace);
            }

            return(null);
        }
コード例 #12
0
        protected static string[] GetComputerName(CimBaseCommand cmdlet)
        {
            if (cmdlet is GetCimInstanceCommand)
            {
                return((cmdlet as GetCimInstanceCommand).ComputerName);
            }
            else if (cmdlet is RemoveCimInstanceCommand)
            {
                return((cmdlet as RemoveCimInstanceCommand).ComputerName);
            }
            else if (cmdlet is SetCimInstanceCommand)
            {
                return((cmdlet as SetCimInstanceCommand).ComputerName);
            }

            return(null);
        }
コード例 #13
0
        /// <summary>
        /// <para>
        /// Refactor to be reused by Get-CimInstance;Remove-CimInstance;Set-CimInstance
        /// </para>
        /// </summary>
        /// <param name="cmdlet"></param>
        protected void GetCimInstanceInternal(CimBaseCommand cmdlet)
        {
            IEnumerable <string> computerNames = ConstValue.GetComputerNames(
                GetComputerName(cmdlet));
            string nameSpace;
            List <CimSessionProxy> proxys       = new();
            bool        isGetCimInstanceCommand = cmdlet is GetCimInstanceCommand;
            CimInstance targetCimInstance       = null;

            switch (cmdlet.ParameterSetName)
            {
            case CimBaseCommand.CimInstanceComputerSet:
                foreach (string computerName in computerNames)
                {
                    targetCimInstance = GetCimInstanceParameter(cmdlet);
                    CimSessionProxy proxy = CreateSessionProxy(computerName, targetCimInstance, cmdlet);
                    if (isGetCimInstanceCommand)
                    {
                        SetPreProcess(proxy, cmdlet as GetCimInstanceCommand);
                    }

                    proxys.Add(proxy);
                }

                break;

            case CimBaseCommand.ClassNameComputerSet:
            case CimBaseCommand.QueryComputerSet:
            case CimBaseCommand.ResourceUriComputerSet:
                foreach (string computerName in computerNames)
                {
                    CimSessionProxy proxy = CreateSessionProxy(computerName, cmdlet);
                    if (isGetCimInstanceCommand)
                    {
                        SetPreProcess(proxy, cmdlet as GetCimInstanceCommand);
                    }

                    proxys.Add(proxy);
                }

                break;

            case CimBaseCommand.ClassNameSessionSet:
            case CimBaseCommand.CimInstanceSessionSet:
            case CimBaseCommand.QuerySessionSet:
            case CimBaseCommand.ResourceUriSessionSet:
                foreach (CimSession session in GetCimSession(cmdlet))
                {
                    CimSessionProxy proxy = CreateSessionProxy(session, cmdlet);
                    if (isGetCimInstanceCommand)
                    {
                        SetPreProcess(proxy, cmdlet as GetCimInstanceCommand);
                    }

                    proxys.Add(proxy);
                }

                break;

            default:
                break;
            }

            switch (cmdlet.ParameterSetName)
            {
            case CimBaseCommand.ClassNameComputerSet:
            case CimBaseCommand.ClassNameSessionSet:
                nameSpace = ConstValue.GetNamespace(GetNamespace(cmdlet));
                if (IsClassNameQuerySet(cmdlet))
                {
                    string query = CreateQuery(cmdlet);
                    DebugHelper.WriteLogEx(@"Query = {0}", 1, query);
                    foreach (CimSessionProxy proxy in proxys)
                    {
                        proxy.QueryInstancesAsync(nameSpace,
                                                  ConstValue.GetQueryDialectWithDefault(GetQueryDialect(cmdlet)),
                                                  query);
                    }
                }
                else
                {
                    foreach (CimSessionProxy proxy in proxys)
                    {
                        proxy.EnumerateInstancesAsync(nameSpace, GetClassName(cmdlet));
                    }
                }

                break;

            case CimBaseCommand.CimInstanceComputerSet:
            case CimBaseCommand.CimInstanceSessionSet:
            {
                CimInstance instance = GetCimInstanceParameter(cmdlet);
                nameSpace = ConstValue.GetNamespace(instance.CimSystemProperties.Namespace);
                foreach (CimSessionProxy proxy in proxys)
                {
                    proxy.GetInstanceAsync(nameSpace, instance);
                }
            }

            break;

            case CimBaseCommand.QueryComputerSet:
            case CimBaseCommand.QuerySessionSet:
                nameSpace = ConstValue.GetNamespace(GetNamespace(cmdlet));
                foreach (CimSessionProxy proxy in proxys)
                {
                    proxy.QueryInstancesAsync(nameSpace,
                                              ConstValue.GetQueryDialectWithDefault(GetQueryDialect(cmdlet)),
                                              GetQuery(cmdlet));
                }

                break;

            case CimBaseCommand.ResourceUriSessionSet:
            case CimBaseCommand.ResourceUriComputerSet:
                foreach (CimSessionProxy proxy in proxys)
                {
                    proxy.EnumerateInstancesAsync(GetNamespace(cmdlet), GetClassName(cmdlet));
                }

                break;

            default:
                break;
            }
        }