Exemplo n.º 1
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;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// <para>
        /// Base on parametersetName to set ciminstances
        /// </para>
        /// </summary>
        /// <param name="cmdlet"><see cref="SetCimInstanceCommand"/> object</param>
        public void SetCimInstance(SetCimInstanceCommand cmdlet)
        {
            IEnumerable <string> computerNames = ConstValue.GetComputerNames(
                GetComputerName(cmdlet));
            List <CimSessionProxy> proxys = new List <CimSessionProxy>();

            switch (cmdlet.ParameterSetName)
            {
            case CimBaseCommand.CimInstanceComputerSet:
                foreach (string computerName in computerNames)
                {
                    // create CimSessionProxySetCimInstance object internally
                    proxys.Add(CreateSessionProxy(computerName, cmdlet.CimInstance, cmdlet, cmdlet.PassThru));
                }
                break;

            case CimBaseCommand.CimInstanceSessionSet:
                foreach (CimSession session in GetCimSession(cmdlet))
                {
                    // create CimSessionProxySetCimInstance object internally
                    proxys.Add(CreateSessionProxy(session, cmdlet, cmdlet.PassThru));
                }
                break;

            default:
                break;
            }
            switch (cmdlet.ParameterSetName)
            {
            case CimBaseCommand.CimInstanceComputerSet:
            case CimBaseCommand.CimInstanceSessionSet:
                string nameSpace = ConstValue.GetNamespace(GetCimInstanceParameter(cmdlet).CimSystemProperties.Namespace);
                string target    = cmdlet.CimInstance.ToString();
                foreach (CimSessionProxy proxy in proxys)
                {
                    if (!cmdlet.ShouldProcess(target, action))
                    {
                        return;
                    }

                    Exception   exception = null;
                    CimInstance instance  = cmdlet.CimInstance;
                    // For CimInstance parameter sets, Property is an optional parameter
                    if (cmdlet.Property != null)
                    {
                        if (!SetProperty(cmdlet.Property, ref instance, ref exception))
                        {
                            cmdlet.ThrowTerminatingError(exception, action);
                            return;
                        }
                    }
                    proxy.ModifyInstanceAsync(nameSpace, instance);
                }
                break;

            case CimBaseCommand.QueryComputerSet:
            case CimBaseCommand.QuerySessionSet:
                GetCimInstanceInternal(cmdlet);
                break;

            default:
                break;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// <para>
        /// Base on parametersetName to set ciminstances
        /// </para>
        /// </summary>
        /// <param name="cmdlet"><see cref="SetCimInstanceCommand"/> object</param>
        public void SetCimInstance(SetCimInstanceCommand cmdlet)
        {
            IEnumerable<string> computerNames = ConstValue.GetComputerNames(
                GetComputerName(cmdlet));
            List<CimSessionProxy> proxys = new List<CimSessionProxy>();
            switch (cmdlet.ParameterSetName)
            {
                case CimBaseCommand.CimInstanceComputerSet:
                    foreach (string computerName in computerNames)
                    {
                        // create CimSessionProxySetCimInstance object internally
                        proxys.Add(CreateSessionProxy(computerName, cmdlet.CimInstance, cmdlet, cmdlet.PassThru));
                    }
                    break;
                case CimBaseCommand.CimInstanceSessionSet:
                    foreach (CimSession session in GetCimSession(cmdlet))
                    {
                        // create CimSessionProxySetCimInstance object internally
                        proxys.Add(CreateSessionProxy(session, cmdlet, cmdlet.PassThru));
                    }
                    break;
                default:
                    break;
            }
            switch (cmdlet.ParameterSetName)
            {
                case CimBaseCommand.CimInstanceComputerSet:
                case CimBaseCommand.CimInstanceSessionSet:
                    string nameSpace = ConstValue.GetNamespace(GetCimInstanceParameter(cmdlet).CimSystemProperties.Namespace);
                    string target = cmdlet.CimInstance.ToString();
                    foreach (CimSessionProxy proxy in proxys)
                    {
                        if (!cmdlet.ShouldProcess(target, action))
                        {
                            return;
                        }

                        Exception exception = null;
                        CimInstance instance = cmdlet.CimInstance;
                        // For CimInstance parameter sets, Property is an optional parameter
                        if (cmdlet.Property != null)
                        {
                            if (!SetProperty(cmdlet.Property, ref instance, ref exception))
                            {
                                cmdlet.ThrowTerminatingError(exception, action);
                                return;
                            }
                        }
                        proxy.ModifyInstanceAsync(nameSpace, instance);
                    }
                    break;
                case CimBaseCommand.QueryComputerSet:
                case CimBaseCommand.QuerySessionSet:
                    GetCimInstanceInternal(cmdlet);
                    break;
                default:
                    break;
            }
        }
Exemplo n.º 4
0
		public void SetCimInstance(SetCimInstanceCommand cmdlet)
		{
			IEnumerable<string> computerNames = ConstValue.GetComputerNames(CimGetInstance.GetComputerName(cmdlet));
			List<CimSessionProxy> cimSessionProxies = new List<CimSessionProxy>();
			string parameterSetName = cmdlet.ParameterSetName;
			string str = parameterSetName;
			if (parameterSetName != null)
			{
				if (str == "CimInstanceComputerSet")
				{
					foreach (string computerName in computerNames)
					{
						cimSessionProxies.Add(base.CreateSessionProxy(computerName, cmdlet.CimInstance, cmdlet, cmdlet.PassThru));
					}
				}
				else
				{
					if (str == "CimInstanceSessionSet")
					{
						CimSession[] cimSession = CimGetInstance.GetCimSession(cmdlet);
						for (int i = 0; i < (int)cimSession.Length; i++)
						{
							CimSession cimSession1 = cimSession[i];
							cimSessionProxies.Add(base.CreateSessionProxy(cimSession1, cmdlet, cmdlet.PassThru));
						}
					}
				}
			}
			string parameterSetName1 = cmdlet.ParameterSetName;
			string str1 = parameterSetName1;
			if (parameterSetName1 != null)
			{
				if (str1 == "CimInstanceComputerSet" || str1 == "CimInstanceSessionSet")
				{
					string @namespace = ConstValue.GetNamespace(CimGetInstance.GetCimInstanceParameter(cmdlet).CimSystemProperties.Namespace);
					string str2 = cmdlet.CimInstance.ToString();
					foreach (CimSessionProxy cimSessionProxy in cimSessionProxies)
					{
						if (cmdlet.ShouldProcess(str2, "Set-CimInstance"))
						{
							Exception exception = null;
							CimInstance cimInstance = cmdlet.CimInstance;
							if (cmdlet.Property == null || this.SetProperty(cmdlet.Property, ref cimInstance, ref exception))
							{
								cimSessionProxy.ModifyInstanceAsync(@namespace, cimInstance);
							}
							else
							{
								cmdlet.ThrowTerminatingError(exception, "Set-CimInstance");
								return;
							}
						}
						else
						{
							return;
						}
					}
				}
				else
				{
					if (str1 == "QueryComputerSet" || str1 == "QuerySessionSet")
					{
						base.GetCimInstanceInternal(cmdlet);
					}
					else
					{
						return;
					}
				}
			}
		}
Exemplo n.º 5
0
        public void SetCimInstance(SetCimInstanceCommand cmdlet)
        {
            IEnumerable <string>   computerNames     = ConstValue.GetComputerNames(CimGetInstance.GetComputerName(cmdlet));
            List <CimSessionProxy> cimSessionProxies = new List <CimSessionProxy>();
            string parameterSetName = cmdlet.ParameterSetName;
            string str = parameterSetName;

            if (parameterSetName != null)
            {
                if (str == "CimInstanceComputerSet")
                {
                    foreach (string computerName in computerNames)
                    {
                        cimSessionProxies.Add(base.CreateSessionProxy(computerName, cmdlet.CimInstance, cmdlet, cmdlet.PassThru));
                    }
                }
                else
                {
                    if (str == "CimInstanceSessionSet")
                    {
                        CimSession[] cimSession = CimGetInstance.GetCimSession(cmdlet);
                        for (int i = 0; i < (int)cimSession.Length; i++)
                        {
                            CimSession cimSession1 = cimSession[i];
                            cimSessionProxies.Add(base.CreateSessionProxy(cimSession1, cmdlet, cmdlet.PassThru));
                        }
                    }
                }
            }
            string parameterSetName1 = cmdlet.ParameterSetName;
            string str1 = parameterSetName1;

            if (parameterSetName1 != null)
            {
                if (str1 == "CimInstanceComputerSet" || str1 == "CimInstanceSessionSet")
                {
                    string @namespace = ConstValue.GetNamespace(CimGetInstance.GetCimInstanceParameter(cmdlet).CimSystemProperties.Namespace);
                    string str2       = cmdlet.CimInstance.ToString();
                    foreach (CimSessionProxy cimSessionProxy in cimSessionProxies)
                    {
                        if (cmdlet.ShouldProcess(str2, "Set-CimInstance"))
                        {
                            Exception   exception   = null;
                            CimInstance cimInstance = cmdlet.CimInstance;
                            if (cmdlet.Property == null || this.SetProperty(cmdlet.Property, ref cimInstance, ref exception))
                            {
                                cimSessionProxy.ModifyInstanceAsync(@namespace, cimInstance);
                            }
                            else
                            {
                                cmdlet.ThrowTerminatingError(exception, "Set-CimInstance");
                                return;
                            }
                        }
                        else
                        {
                            return;
                        }
                    }
                }
                else
                {
                    if (str1 == "QueryComputerSet" || str1 == "QuerySessionSet")
                    {
                        base.GetCimInstanceInternal(cmdlet);
                    }
                    else
                    {
                        return;
                    }
                }
            }
        }