Exemple #1
0
        protected CimSessionProxy CreateSessionProxy(CimSession session, CimBaseCommand cmdlet, bool passThru)
        {
            CimSessionProxy cimSessionProxy = base.CreateCimSessionProxy(session, passThru);

            this.SetSessionProxyProperties(ref cimSessionProxy, cmdlet);
            return(cimSessionProxy);
        }
Exemple #2
0
 protected static CimSession[] GetCimSession(CimBaseCommand cmdlet)
 {
     if (cmdlet as GetCimInstanceCommand == null)
     {
         if (cmdlet as RemoveCimInstanceCommand == null)
         {
             if (cmdlet as SetCimInstanceCommand == null)
             {
                 return(null);
             }
             else
             {
                 return((cmdlet as SetCimInstanceCommand).CimSession);
             }
         }
         else
         {
             return((cmdlet as RemoveCimInstanceCommand).CimSession);
         }
     }
     else
     {
         return((cmdlet as GetCimInstanceCommand).CimSession);
     }
 }
Exemple #3
0
 protected static string GetNamespace(CimBaseCommand cmdlet)
 {
     if (cmdlet as GetCimInstanceCommand == null)
     {
         if (cmdlet as RemoveCimInstanceCommand == null)
         {
             if (cmdlet as SetCimInstanceCommand == null)
             {
                 return(null);
             }
             else
             {
                 return((cmdlet as SetCimInstanceCommand).Namespace);
             }
         }
         else
         {
             return((cmdlet as RemoveCimInstanceCommand).Namespace);
         }
     }
     else
     {
         return((cmdlet as GetCimInstanceCommand).Namespace);
     }
 }
Exemple #4
0
 protected static string[] GetComputerName(CimBaseCommand cmdlet)
 {
     if (cmdlet as GetCimInstanceCommand == null)
     {
         if (cmdlet as RemoveCimInstanceCommand == null)
         {
             if (cmdlet as SetCimInstanceCommand == null)
             {
                 return(null);
             }
             else
             {
                 return((cmdlet as SetCimInstanceCommand).ComputerName);
             }
         }
         else
         {
             return((cmdlet as RemoveCimInstanceCommand).ComputerName);
         }
     }
     else
     {
         return((cmdlet as GetCimInstanceCommand).ComputerName);
     }
 }
Exemple #5
0
        protected static String CreateQuery(CimBaseCommand cmdlet)
        {
            DebugHelper.WriteLogEx();
            GetCimInstanceCommand cmd = cmdlet as GetCimInstanceCommand;

            if (cmd != null)
            {
                StringBuilder propertyList = new StringBuilder();
                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);
        }
Exemple #6
0
 protected static string GetQueryDialect(CimBaseCommand cmdlet)
 {
     if (cmdlet as GetCimInstanceCommand == null)
     {
         if (cmdlet as RemoveCimInstanceCommand == null)
         {
             if (cmdlet as SetCimInstanceCommand == null)
             {
                 return(null);
             }
             else
             {
                 return((cmdlet as SetCimInstanceCommand).QueryDialect);
             }
         }
         else
         {
             return((cmdlet as RemoveCimInstanceCommand).QueryDialect);
         }
     }
     else
     {
         return((cmdlet as GetCimInstanceCommand).QueryDialect);
     }
 }
Exemple #7
0
 protected static CimInstance GetCimInstanceParameter(CimBaseCommand cmdlet)
 {
     if (cmdlet as GetCimInstanceCommand == null)
     {
         if (cmdlet as RemoveCimInstanceCommand == null)
         {
             if (cmdlet as SetCimInstanceCommand == null)
             {
                 return(null);
             }
             else
             {
                 return((cmdlet as SetCimInstanceCommand).CimInstance);
             }
         }
         else
         {
             return((cmdlet as RemoveCimInstanceCommand).CimInstance);
         }
     }
     else
     {
         return((cmdlet as GetCimInstanceCommand).CimInstance);
     }
 }
Exemple #8
0
        protected CimSessionProxy CreateSessionProxy(string computerName, CimBaseCommand cmdlet)
        {
            CimSessionProxy cimSessionProxy = null;

            if (!string.IsNullOrEmpty(computerName) && !computerName.Equals("localhost", StringComparison.OrdinalIgnoreCase))
            {
                /* Set on the fly credentials */
                System.Management.Automation.PSCredential credential = GetOnTheFlyCredentials(cmdlet);
                if (credential == null)
                {
                    cimSessionProxy = base.CreateCimSessionProxy(computerName);
                }
                else
                {
                    CimSessionOptions options = new WSManSessionOptions();
                    options.AddDestinationCredentials(cmdlet.CreateCimCredentials(credential, PasswordAuthenticationMechanism.Default, "Get-CimIstance", "Authentication"));
                    cimSessionProxy = base.CreateCimSessionProxy(computerName, options);
                }
            }
            else
            {
                cimSessionProxy = base.CreateCimSessionProxy(computerName);
            }
            this.SetSessionProxyProperties(ref cimSessionProxy, cmdlet);
            return(cimSessionProxy);
        }
Exemple #9
0
 protected static String GetClassName(CimBaseCommand cmdlet)
 {
     if (cmdlet is GetCimInstanceCommand)
     {
         return((cmdlet as GetCimInstanceCommand).ClassName);
     }
     return(null);
 }
Exemple #10
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);
        }
Exemple #11
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);
        }
Exemple #12
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);
        }
Exemple #13
0
 protected static string GetClassName(CimBaseCommand cmdlet)
 {
     if (cmdlet as GetCimInstanceCommand == null)
     {
         return(null);
     }
     else
     {
         return((cmdlet as GetCimInstanceCommand).ClassName);
     }
 }
Exemple #14
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);
        }
Exemple #15
0
        internal static bool IsClassNameQuerySet(CimBaseCommand cmdlet)
        {
            DebugHelper.WriteLogEx();
            GetCimInstanceCommand getCimInstanceCommand = cmdlet as GetCimInstanceCommand;

            if (getCimInstanceCommand == null || getCimInstanceCommand.QueryDialect == null && getCimInstanceCommand.SelectProperties == null && getCimInstanceCommand.Filter == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemple #16
0
 protected static String GetQuery(CimBaseCommand cmdlet)
 {
     if (cmdlet is GetCimInstanceCommand)
     {
         return((cmdlet as GetCimInstanceCommand).Query);
     }
     else if (cmdlet is RemoveCimInstanceCommand)
     {
         return((cmdlet as RemoveCimInstanceCommand).Query);
     }
     else if (cmdlet is SetCimInstanceCommand)
     {
         return((cmdlet as SetCimInstanceCommand).Query);
     }
     return(null);
 }
Exemple #17
0
        /// <summary>
        /// <para>
        /// Set <see cref="CimSessionProxy"/> properties
        /// </para>
        /// </summary>
        /// <param name="proxy"></param>
        /// <param name="cmdlet"></param>
        private 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 CimRemoveCimInstanceContext(
                    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 CimSetCimInstanceContext(
                    ConstValue.GetNamespace(setCimInstance.Namespace),
                    setCimInstance.Property,
                    proxy,
                    cmdlet.ParameterSetName,
                    setCimInstance.PassThru);
                proxy.ContextObject = context;
            }
        }
Exemple #18
0
        protected static string CreateQuery(CimBaseCommand cmdlet)
        {
            DebugHelper.WriteLogEx();
            GetCimInstanceCommand getCimInstanceCommand = cmdlet as GetCimInstanceCommand;

            if (getCimInstanceCommand == null)
            {
                return(null);
            }
            else
            {
                StringBuilder stringBuilder = new StringBuilder();
                if (getCimInstanceCommand.SelectProperties != null)
                {
                    string[] selectProperties = getCimInstanceCommand.SelectProperties;
                    for (int i = 0; i < (int)selectProperties.Length; i++)
                    {
                        string str = selectProperties[i];
                        if (stringBuilder.Length > 0)
                        {
                            stringBuilder.Append(",");
                        }
                        stringBuilder.Append(str);
                    }
                }
                else
                {
                    stringBuilder.Append("*");
                }
                if (getCimInstanceCommand.Filter == null)
                {
                    object[] className = new object[2];
                    className[0] = stringBuilder;
                    className[1] = getCimInstanceCommand.ClassName;
                    return(string.Format(CultureInfo.CurrentUICulture, "SELECT {0} FROM {1}", className));
                }
                else
                {
                    object[] filter = new object[3];
                    filter[0] = stringBuilder;
                    filter[1] = getCimInstanceCommand.ClassName;
                    filter[2] = getCimInstanceCommand.Filter;
                    return(string.Format(CultureInfo.CurrentUICulture, "SELECT {0} FROM {1} WHERE {2}", filter));
                }
            }
        }
Exemple #19
0
		protected static string CreateQuery(CimBaseCommand cmdlet)
		{
			DebugHelper.WriteLogEx();
			GetCimInstanceCommand getCimInstanceCommand = cmdlet as GetCimInstanceCommand;
			if (getCimInstanceCommand == null)
			{
				return null;
			}
			else
			{
				StringBuilder stringBuilder = new StringBuilder();
				if (getCimInstanceCommand.SelectProperties != null)
				{
					string[] selectProperties = getCimInstanceCommand.SelectProperties;
					for (int i = 0; i < (int)selectProperties.Length; i++)
					{
						string str = selectProperties[i];
						if (stringBuilder.Length > 0)
						{
							stringBuilder.Append(",");
						}
						stringBuilder.Append(str);
					}
				}
				else
				{
					stringBuilder.Append("*");
				}
				if (getCimInstanceCommand.Filter == null)
				{
					object[] className = new object[2];
					className[0] = stringBuilder;
					className[1] = getCimInstanceCommand.ClassName;
					return string.Format(CultureInfo.CurrentUICulture, "SELECT {0} FROM {1}", className);
				}
				else
				{
					object[] filter = new object[3];
					filter[0] = stringBuilder;
					filter[1] = getCimInstanceCommand.ClassName;
					filter[2] = getCimInstanceCommand.Filter;
					return string.Format(CultureInfo.CurrentUICulture, "SELECT {0} FROM {1} WHERE {2}", filter);
				}
			}
		}
Exemple #20
0
		protected CimSessionProxy CreateSessionProxy (string computerName, CimBaseCommand cmdlet)
		{
			CimSessionProxy cimSessionProxy = null;
			if (!string.IsNullOrEmpty (computerName) && !computerName.Equals ("localhost", StringComparison.OrdinalIgnoreCase)) {
				/* Set on the fly credentials */
				System.Management.Automation.PSCredential credential = GetOnTheFlyCredentials(cmdlet);
				if (credential == null) 
					cimSessionProxy = base.CreateCimSessionProxy (computerName);
				else {
					CimSessionOptions options = new WSManSessionOptions ();
					options.AddDestinationCredentials (cmdlet.CreateCimCredentials (credential, PasswordAuthenticationMechanism.Default, "Get-CimIstance", "Authentication"));
					cimSessionProxy = base.CreateCimSessionProxy (computerName, options);
				}
			} 
			else {
				cimSessionProxy = base.CreateCimSessionProxy (computerName);
			}
			this.SetSessionProxyProperties(ref cimSessionProxy, cmdlet);
			return cimSessionProxy;
		}
Exemple #21
0
        protected CimSessionProxy CreateSessionProxy(string computerName, CimInstance cimInstance, CimBaseCommand cmdlet)
        {
            CimSessionProxy cimSessionProxy = base.CreateCimSessionProxy(computerName, cimInstance);

            this.SetSessionProxyProperties(ref cimSessionProxy, cmdlet);
            return(cimSessionProxy);
        }
Exemple #22
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 List<CimSessionProxy>();
     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)
                 {
                     this.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)
                 {
                     this.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)
                 {
                     this.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;
     }
 }
Exemple #23
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,
     bool passThru)
 {
     CimSessionProxy proxy = CreateCimSessionProxy(session, passThru);
     SetSessionProxyProperties(ref proxy, cmdlet);
     return proxy;
 }
Exemple #24
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)
 {
     CimSessionProxy proxy = CreateCimSessionProxy(computerName, cimInstance);
     SetSessionProxyProperties(ref proxy, cmdlet);
     return proxy;
 }
Exemple #25
0
 /// <summary>
 /// <para>
 /// Set <see cref="CimSessionProxy"/> properties
 /// </para>
 /// </summary>
 /// <param name="proxy"></param>
 /// <param name="cmdlet"></param>
 private 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 CimRemoveCimInstanceContext(
             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 CimSetCimInstanceContext(
             ConstValue.GetNamespace(setCimInstance.Namespace),
             setCimInstance.Property,
             proxy,
             cmdlet.ParameterSetName,
             setCimInstance.PassThru);
         proxy.ContextObject = context;
     }
 }
Exemple #26
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;
 }
Exemple #27
0
        protected void GetCimInstanceInternal(CimBaseCommand cmdlet)
        {
            string @namespace;
            IEnumerable <string>   computerNames     = ConstValue.GetComputerNames(CimGetInstance.GetComputerName(cmdlet));
            List <CimSessionProxy> cimSessionProxies = new List <CimSessionProxy>();
            bool   flag             = cmdlet is GetCimInstanceCommand;
            string parameterSetName = cmdlet.ParameterSetName;
            string str = parameterSetName;

            if (parameterSetName != null)
            {
                switch (str)
                {
                case "CimInstanceComputerSet":
                {
                    IEnumerator <string> enumerator = computerNames.GetEnumerator();
                    using (enumerator)
                    {
                        while (enumerator.MoveNext())
                        {
                            string          current = enumerator.Current;
                            CimInstance     cimInstanceParameter = CimGetInstance.GetCimInstanceParameter(cmdlet);
                            CimSessionProxy cimSessionProxy      = this.CreateSessionProxy(current, cimInstanceParameter, cmdlet);
                            if (flag)
                            {
                                this.SetPreProcess(cimSessionProxy, cmdlet as GetCimInstanceCommand);
                            }
                            cimSessionProxies.Add(cimSessionProxy);
                        }
                    }
                }
                break;

                case "ClassNameComputerSet":
                case "QueryComputerSet":
                case "ResourceUriComputerSet":
                {
                    IEnumerator <string> enumerator1 = computerNames.GetEnumerator();
                    using (enumerator1)
                    {
                        while (enumerator1.MoveNext())
                        {
                            string          current1         = enumerator1.Current;
                            CimSessionProxy cimSessionProxy1 = this.CreateSessionProxy(current1, cmdlet);
                            if (flag)
                            {
                                this.SetPreProcess(cimSessionProxy1, cmdlet as GetCimInstanceCommand);
                            }
                            cimSessionProxies.Add(cimSessionProxy1);
                        }
                        break;
                    }
                }

                case "ClassNameSessionSet":
                case "CimInstanceSessionSet":
                case "QuerySessionSet":
                case "ResourceUriSessionSet":
                {
                    CimSession[] cimSession = CimGetInstance.GetCimSession(cmdlet);
                    for (int i = 0; i < (int)cimSession.Length; i++)
                    {
                        CimSession      cimSession1      = cimSession[i];
                        CimSessionProxy cimSessionProxy2 = this.CreateSessionProxy(cimSession1, cmdlet);
                        if (flag)
                        {
                            this.SetPreProcess(cimSessionProxy2, cmdlet as GetCimInstanceCommand);
                        }
                        cimSessionProxies.Add(cimSessionProxy2);
                    }
                }
                break;
                }
            }
            string parameterSetName1 = cmdlet.ParameterSetName;
            string str1 = parameterSetName1;

            if (parameterSetName1 != null)
            {
                if (str1 == "ClassNameComputerSet" || str1 == "ClassNameSessionSet")
                {
                    @namespace = ConstValue.GetNamespace(CimGetInstance.GetNamespace(cmdlet));
                    if (!CimGetInstance.IsClassNameQuerySet(cmdlet))
                    {
                        List <CimSessionProxy> .Enumerator enumerator2 = cimSessionProxies.GetEnumerator();
                        try
                        {
                            while (enumerator2.MoveNext())
                            {
                                CimSessionProxy current2 = enumerator2.Current;
                                current2.EnumerateInstancesAsync(@namespace, CimGetInstance.GetClassName(cmdlet));
                            }
                            return;
                        }
                        finally
                        {
                            enumerator2.Dispose();
                        }
                    }
                    else
                    {
                        string   str2     = CimGetInstance.CreateQuery(cmdlet);
                        object[] objArray = new object[1];
                        objArray[0] = str2;
                        DebugHelper.WriteLogEx("Query = {0}", 1, objArray);
                        List <CimSessionProxy> .Enumerator enumerator3 = cimSessionProxies.GetEnumerator();
                        try
                        {
                            while (enumerator3.MoveNext())
                            {
                                CimSessionProxy current3 = enumerator3.Current;
                                current3.QueryInstancesAsync(@namespace, ConstValue.GetQueryDialectWithDefault(CimGetInstance.GetQueryDialect(cmdlet)), str2);
                            }
                            return;
                        }
                        finally
                        {
                            enumerator3.Dispose();
                        }
                    }
                }
                else if (str1 == "CimInstanceComputerSet" || str1 == "CimInstanceSessionSet")
                {
                    CimInstance cimInstance = CimGetInstance.GetCimInstanceParameter(cmdlet);
                    @namespace = ConstValue.GetNamespace(cimInstance.CimSystemProperties.Namespace);
                    List <CimSessionProxy> .Enumerator enumerator4 = cimSessionProxies.GetEnumerator();
                    try
                    {
                        while (enumerator4.MoveNext())
                        {
                            CimSessionProxy cimSessionProxy3 = enumerator4.Current;
                            cimSessionProxy3.GetInstanceAsync(@namespace, cimInstance);
                        }
                        return;
                    }
                    finally
                    {
                        enumerator4.Dispose();
                    }
                }
                else if (str1 == "QueryComputerSet" || str1 == "QuerySessionSet")
                {
                    @namespace = ConstValue.GetNamespace(CimGetInstance.GetNamespace(cmdlet));
                    List <CimSessionProxy> .Enumerator enumerator5 = cimSessionProxies.GetEnumerator();
                    try
                    {
                        while (enumerator5.MoveNext())
                        {
                            CimSessionProxy current4 = enumerator5.Current;
                            current4.QueryInstancesAsync(@namespace, ConstValue.GetQueryDialectWithDefault(CimGetInstance.GetQueryDialect(cmdlet)), CimGetInstance.GetQuery(cmdlet));
                        }
                        return;
                    }
                    finally
                    {
                        enumerator5.Dispose();
                    }
                }
                else if (str1 == "ResourceUriSessionSet" || str1 == "ResourceUriComputerSet")
                {
                    List <CimSessionProxy> .Enumerator enumerator6 = cimSessionProxies.GetEnumerator();
                    try
                    {
                        while (enumerator6.MoveNext())
                        {
                            CimSessionProxy cimSessionProxy4 = enumerator6.Current;
                            cimSessionProxy4.EnumerateInstancesAsync(CimGetInstance.GetNamespace(cmdlet), CimGetInstance.GetClassName(cmdlet));
                        }
                        return;
                    }
                    finally
                    {
                        enumerator6.Dispose();
                    }
                }
                return;
            }
        }
Exemple #28
0
		protected static string GetClassName(CimBaseCommand cmdlet)
		{
			if (cmdlet as GetCimInstanceCommand == null)
			{
				return null;
			}
			else
			{
				return (cmdlet as GetCimInstanceCommand).ClassName;
			}
		}
Exemple #29
0
		protected CimSessionProxy CreateSessionProxy(CimSession session, CimBaseCommand cmdlet)
		{
			CimSessionProxy cimSessionProxy = base.CreateCimSessionProxy(session);
			this.SetSessionProxyProperties(ref cimSessionProxy, cmdlet);
			return cimSessionProxy;
		}
Exemple #30
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;
 }
Exemple #31
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;
 }
Exemple #32
0
		internal static bool IsClassNameQuerySet(CimBaseCommand cmdlet)
		{
			DebugHelper.WriteLogEx();
			GetCimInstanceCommand getCimInstanceCommand = cmdlet as GetCimInstanceCommand;
			if (getCimInstanceCommand == null || getCimInstanceCommand.QueryDialect == null && getCimInstanceCommand.SelectProperties == null && getCimInstanceCommand.Filter == null)
			{
				return false;
			}
			else
			{
				return true;
			}
		}
Exemple #33
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;
 }
Exemple #34
0
 protected static String GetClassName(CimBaseCommand cmdlet)
 {
     if (cmdlet is GetCimInstanceCommand)
     {
         return (cmdlet as GetCimInstanceCommand).ClassName;
     }
     return null;
 }
Exemple #35
0
		protected CimSessionProxy CreateSessionProxy(string computerName, CimInstance cimInstance, CimBaseCommand cmdlet, bool passThru)
		{
			CimSessionProxy cimSessionProxy = base.CreateCimSessionProxy(computerName, cimInstance, passThru);
			this.SetSessionProxyProperties(ref cimSessionProxy, cmdlet);
			return cimSessionProxy;
		}
Exemple #36
0
		protected static string GetQuery(CimBaseCommand cmdlet)
		{
			if (cmdlet as GetCimInstanceCommand == null)
			{
				if (cmdlet as RemoveCimInstanceCommand == null)
				{
					if (cmdlet as SetCimInstanceCommand == null)
					{
						return null;
					}
					else
					{
						return (cmdlet as SetCimInstanceCommand).Query;
					}
				}
				else
				{
					return (cmdlet as RemoveCimInstanceCommand).Query;
				}
			}
			else
			{
				return (cmdlet as GetCimInstanceCommand).Query;
			}
		}
Exemple #37
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;
 }
Exemple #38
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;
 }
Exemple #39
0
 protected static String CreateQuery(CimBaseCommand cmdlet)
 {
     DebugHelper.WriteLogEx();
     GetCimInstanceCommand cmd = cmdlet as GetCimInstanceCommand;
     if (cmd != null)
     {
         StringBuilder propertyList = new StringBuilder();
         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;
 }
Exemple #40
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 List <CimSessionProxy>();
            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)
                    {
                        this.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)
                    {
                        this.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)
                    {
                        this.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;
            }
        }
Exemple #41
0
		protected void GetCimInstanceInternal(CimBaseCommand cmdlet)
		{
			string @namespace;
			IEnumerable<string> computerNames = ConstValue.GetComputerNames(CimGetInstance.GetComputerName(cmdlet));
			List<CimSessionProxy> cimSessionProxies = new List<CimSessionProxy>();
			bool flag = cmdlet is GetCimInstanceCommand;
			string parameterSetName = cmdlet.ParameterSetName;
			string str = parameterSetName;
			if (parameterSetName != null)
			{
				switch (str)
				{
					case "CimInstanceComputerSet":
					{
						IEnumerator<string> enumerator = computerNames.GetEnumerator();
						using (enumerator)
						{
							while (enumerator.MoveNext())
							{
								string current = enumerator.Current;
								CimInstance cimInstanceParameter = CimGetInstance.GetCimInstanceParameter(cmdlet);
								CimSessionProxy cimSessionProxy = this.CreateSessionProxy(current, cimInstanceParameter, cmdlet);
								if (flag)
								{
									this.SetPreProcess(cimSessionProxy, cmdlet as GetCimInstanceCommand);
								}
								cimSessionProxies.Add(cimSessionProxy);
							}
						}
					}
					break;
					case "ClassNameComputerSet":
					case "QueryComputerSet":
					case "ResourceUriComputerSet":
					{
						IEnumerator<string> enumerator1 = computerNames.GetEnumerator();
						using (enumerator1)
						{
							while (enumerator1.MoveNext())
							{
								string current1 = enumerator1.Current;
								CimSessionProxy cimSessionProxy1 = this.CreateSessionProxy(current1, cmdlet);
								if (flag)
								{
									this.SetPreProcess(cimSessionProxy1, cmdlet as GetCimInstanceCommand);
								}
								cimSessionProxies.Add(cimSessionProxy1);
							}
							break;
						}
					}
					case "ClassNameSessionSet":
					case "CimInstanceSessionSet":
					case "QuerySessionSet":
					case "ResourceUriSessionSet":
					{
						CimSession[] cimSession = CimGetInstance.GetCimSession(cmdlet);
						for (int i = 0; i < (int)cimSession.Length; i++)
						{
							CimSession cimSession1 = cimSession[i];
							CimSessionProxy cimSessionProxy2 = this.CreateSessionProxy(cimSession1, cmdlet);
							if (flag)
							{
								this.SetPreProcess(cimSessionProxy2, cmdlet as GetCimInstanceCommand);
							}
							cimSessionProxies.Add(cimSessionProxy2);
						}
					}
					break;
				}
			}
			string parameterSetName1 = cmdlet.ParameterSetName;
			string str1 = parameterSetName1;
			if (parameterSetName1 != null)
			{
				if (str1 == "ClassNameComputerSet" || str1 == "ClassNameSessionSet")
				{
					@namespace = ConstValue.GetNamespace(CimGetInstance.GetNamespace(cmdlet));
					if (!CimGetInstance.IsClassNameQuerySet(cmdlet))
					{
						List<CimSessionProxy>.Enumerator enumerator2 = cimSessionProxies.GetEnumerator();
						try
						{
							while (enumerator2.MoveNext())
							{
								CimSessionProxy current2 = enumerator2.Current;
								current2.EnumerateInstancesAsync(@namespace, CimGetInstance.GetClassName(cmdlet));
							}
							return;
						}
						finally
						{
							enumerator2.Dispose();
						}
					}
					else
					{
						string str2 = CimGetInstance.CreateQuery(cmdlet);
						object[] objArray = new object[1];
						objArray[0] = str2;
						DebugHelper.WriteLogEx("Query = {0}", 1, objArray);
						List<CimSessionProxy>.Enumerator enumerator3 = cimSessionProxies.GetEnumerator();
						try
						{
							while (enumerator3.MoveNext())
							{
								CimSessionProxy current3 = enumerator3.Current;
								current3.QueryInstancesAsync(@namespace, ConstValue.GetQueryDialectWithDefault(CimGetInstance.GetQueryDialect(cmdlet)), str2);
							}
							return;
						}
						finally
						{
							enumerator3.Dispose();
						}
					}
				}
				else if (str1 == "CimInstanceComputerSet" || str1 == "CimInstanceSessionSet")
				{
					CimInstance cimInstance = CimGetInstance.GetCimInstanceParameter(cmdlet);
					@namespace = ConstValue.GetNamespace(cimInstance.CimSystemProperties.Namespace);
					List<CimSessionProxy>.Enumerator enumerator4 = cimSessionProxies.GetEnumerator();
					try
					{
						while (enumerator4.MoveNext())
						{
							CimSessionProxy cimSessionProxy3 = enumerator4.Current;
							cimSessionProxy3.GetInstanceAsync(@namespace, cimInstance);
						}
						return;
					}
					finally
					{
						enumerator4.Dispose();
					}
				}
				else if (str1 == "QueryComputerSet" || str1 == "QuerySessionSet")
				{
					@namespace = ConstValue.GetNamespace(CimGetInstance.GetNamespace(cmdlet));
					List<CimSessionProxy>.Enumerator enumerator5 = cimSessionProxies.GetEnumerator();
					try
					{
						while (enumerator5.MoveNext())
						{
							CimSessionProxy current4 = enumerator5.Current;
							current4.QueryInstancesAsync(@namespace, ConstValue.GetQueryDialectWithDefault(CimGetInstance.GetQueryDialect(cmdlet)), CimGetInstance.GetQuery(cmdlet));
						}
						return;
					}
					finally
					{
						enumerator5.Dispose();
					}
				}
				else if (str1 == "ResourceUriSessionSet" || str1 == "ResourceUriComputerSet")
				{
					List<CimSessionProxy>.Enumerator enumerator6 = cimSessionProxies.GetEnumerator();
					try
					{
						while (enumerator6.MoveNext())
						{
							CimSessionProxy cimSessionProxy4 = enumerator6.Current;
							cimSessionProxy4.EnumerateInstancesAsync(CimGetInstance.GetNamespace(cmdlet), CimGetInstance.GetClassName(cmdlet));
						}
						return;
					}
					finally
					{
						enumerator6.Dispose();
					}
				}
				return;
			}
		}