Exemplo n.º 1
0
		internal void NewCimSession(NewCimSessionCommand cmdlet, CimSessionOptions sessionOptions, CimCredential credential)
		{
			string localhostComputerName;
			DebugHelper.WriteLogEx();
			IEnumerable<string> computerNames = ConstValue.GetComputerNames(cmdlet.ComputerName);
			foreach (string computerName in computerNames)
			{
				if (sessionOptions == null)
				{
					DebugHelper.WriteLog("Create CimSessionOption due to NewCimSessionCommand has null sessionoption", 1);
					sessionOptions = CimSessionProxy.CreateCimSessionOption(computerName, cmdlet.OperationTimeoutSec, credential);
				}
				CimSessionProxy cimSessionProxyTestConnection = new CimSessionProxyTestConnection(computerName, sessionOptions);
				if (computerName == ConstValue.NullComputerName)
				{
					localhostComputerName = ConstValue.LocalhostComputerName;
				}
				else
				{
					localhostComputerName = computerName;
				}
				string str = localhostComputerName;
				CimSessionWrapper cimSessionWrapper = new CimSessionWrapper(0, Guid.Empty, cmdlet.Name, str, cimSessionProxyTestConnection.CimSession, cimSessionProxyTestConnection.Protocol);
				CimNewSession.CimTestCimSessionContext cimTestCimSessionContext = new CimNewSession.CimTestCimSessionContext(cimSessionProxyTestConnection, cimSessionWrapper);
				cimSessionProxyTestConnection.ContextObject = cimTestCimSessionContext;
				SwitchParameter skipTestConnection = cmdlet.SkipTestConnection;
				if (!skipTestConnection.IsPresent)
				{
					this.cimTestSession.TestCimSession(computerName, cimSessionProxyTestConnection);
				}
				else
				{
					this.AddSessionToCache(cimSessionProxyTestConnection.CimSession, cimTestCimSessionContext, new CmdletOperationBase(cmdlet));
				}
			}
		}
Exemplo n.º 2
0
        /// <summary>
        /// Create a new <see cref="CimSession"/> base on given cmdlet
        /// and its parameter
        /// </summary>        
        /// <param name="cmdlet"></param>
        /// <param name="sessionOptions"></param>
        /// <param name="credential"></param>
        internal void NewCimSession(NewCimSessionCommand cmdlet,
            CimSessionOptions sessionOptions,
            CimCredential credential)
        {
            DebugHelper.WriteLogEx();

            IEnumerable<string> computerNames = ConstValue.GetComputerNames(cmdlet.ComputerName);
            foreach (string computerName in computerNames)
            {
                CimSessionProxy proxy;
                if (sessionOptions == null)
                {
                    DebugHelper.WriteLog("Create CimSessionOption due to NewCimSessionCommand has null sessionoption", 1);
                    sessionOptions = CimSessionProxy.CreateCimSessionOption(computerName,
                        cmdlet.OperationTimeoutSec, credential);
                }
                proxy = new CimSessionProxyTestConnection(computerName, sessionOptions);
                string computerNameValue = (computerName == ConstValue.NullComputerName) ? ConstValue.LocalhostComputerName : computerName;
                CimSessionWrapper wrapper = new CimSessionWrapper(0, Guid.Empty, cmdlet.Name, computerNameValue, proxy.CimSession, proxy.Protocol);
                CimTestCimSessionContext context = new CimTestCimSessionContext(proxy, wrapper);
                proxy.ContextObject = context;
                // Skip test the connection if user intend to
                if(cmdlet.SkipTestConnection.IsPresent)
                {
                    AddSessionToCache(proxy.CimSession, context, new CmdletOperationBase(cmdlet));
                }
                else
                {
                    //CimSession will be returned as part of TestConnection
                    this.cimTestSession.TestCimSession(computerName, proxy); 
                }
            }
        }