コード例 #1
0
        internal CimSessionWrapper QuerySession(CimSession cimsession)
        {
            CimSessionWrapper cimSessionWrapper = null;

            this.curCimSessionWrapper.TryGetValue(cimsession, out cimSessionWrapper);
            return(cimSessionWrapper);
        }
コード例 #2
0
        internal IEnumerable <PSObject> QuerySession(IEnumerable <CimSession> cimsessions, out IEnumerable <ErrorRecord> errorRecords)
        {
            HashSet <PSObject> pSObjects     = new HashSet <PSObject>();
            HashSet <uint>     nums          = new HashSet <uint>();
            List <ErrorRecord> errorRecords1 = new List <ErrorRecord>();

            errorRecords = errorRecords1;
            foreach (CimSession cimsession in cimsessions)
            {
                if (!this.curCimSessionWrapper.ContainsKey(cimsession))
                {
                    this.AddErrorRecord(ref errorRecords1, CimSessionState.CimSessionClassName, CimSessionState.CimSessionObject);
                }
                else
                {
                    CimSessionWrapper item = this.curCimSessionWrapper[cimsession];
                    if (nums.Contains(item.SessionId))
                    {
                        continue;
                    }
                    nums.Add(item.SessionId);
                    pSObjects.Add(item.GetPSObject());
                }
            }
            return(pSObjects);
        }
コード例 #3
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);
                }
            }
        }
コード例 #4
0
        internal IEnumerable <PSObject> QuerySession(IEnumerable <Guid> instanceIds, out IEnumerable <ErrorRecord> errorRecords)
        {
            HashSet <PSObject> pSObjects     = new HashSet <PSObject>();
            HashSet <uint>     nums          = new HashSet <uint>();
            List <ErrorRecord> errorRecords1 = new List <ErrorRecord>();

            errorRecords = errorRecords1;
            foreach (Guid instanceId in instanceIds)
            {
                if (!this.curCimSessionsByInstanceId.ContainsKey(instanceId))
                {
                    this.AddErrorRecord(ref errorRecords1, CimSessionState.instanceidPropName, instanceId);
                }
                else
                {
                    CimSessionWrapper item = this.curCimSessionsByInstanceId[instanceId];
                    if (nums.Contains(item.SessionId))
                    {
                        continue;
                    }
                    nums.Add(item.SessionId);
                    pSObjects.Add(item.GetPSObject());
                }
            }
            return(pSObjects);
        }
コード例 #5
0
        /// <summary>
        /// Query session list by given session objects array.
        /// </summary>
        /// <param name="cimsessions"></param>
        /// <returns>List of session wrapper objects.</returns>
        internal IEnumerable <PSObject> QuerySession(IEnumerable <CimSession> cimsessions,
                                                     out IEnumerable <ErrorRecord> errorRecords)
        {
            HashSet <PSObject> sessions   = new HashSet <PSObject>();
            HashSet <uint>     sessionIds = new HashSet <uint>();
            List <ErrorRecord> errRecords = new List <ErrorRecord>();

            errorRecords = errRecords;
            foreach (CimSession cimsession in cimsessions)
            {
                if (this.curCimSessionWrapper.ContainsKey(cimsession))
                {
                    CimSessionWrapper wrapper = this.curCimSessionWrapper[cimsession];
                    if (!sessionIds.Contains(wrapper.SessionId))
                    {
                        sessionIds.Add(wrapper.SessionId);
                        sessions.Add(wrapper.GetPSObject());
                    }
                }
                else
                {
                    AddErrorRecord(ref errRecords, CimSessionClassName, CimSessionObject);
                }
            }

            return(sessions);
        }
コード例 #6
0
        /// <summary>
        /// <para>
        /// Remove given <see cref="CimSession"/> object from cache.
        /// </para>
        /// </summary>
        /// <param name="session"></param>
        internal void RemoveOneSessionObjectFromCache(CimSession session)
        {
            DebugHelper.WriteLogEx();

            if (!this.curCimSessionWrapper.ContainsKey(session))
            {
                return;
            }

            CimSessionWrapper wrapper      = this.curCimSessionWrapper[session];
            string            name         = wrapper.Name;
            string            computerName = wrapper.ComputerName;

            DebugHelper.WriteLog("name {0}, computername {1}, id {2}, instanceId {3}", 1, name, computerName, wrapper.SessionId, wrapper.InstanceId);

            HashSet <CimSessionWrapper> objects;

            if (this.curCimSessionsByComputerName.TryGetValue(computerName, out objects))
            {
                objects.Remove(wrapper);
            }

            if (this.curCimSessionsByName.TryGetValue(name, out objects))
            {
                objects.Remove(wrapper);
            }

            RemoveSessionInternal(session, wrapper);
        }
コード例 #7
0
        /// <summary>
        /// Query session list by given instance id array.
        /// </summary>
        /// <param name="instanceIds"></param>
        /// <returns>List of session wrapper objects.</returns>
        internal IEnumerable <PSObject> QuerySession(
            IEnumerable <Guid> instanceIds,
            out IEnumerable <ErrorRecord> errorRecords)
        {
            HashSet <PSObject> sessions   = new HashSet <PSObject>();
            HashSet <uint>     sessionIds = new HashSet <uint>();
            List <ErrorRecord> errRecords = new List <ErrorRecord>();

            errorRecords = errRecords;
            foreach (Guid instanceid in instanceIds)
            {
                if (this.curCimSessionsByInstanceId.ContainsKey(instanceid))
                {
                    CimSessionWrapper wrapper = this.curCimSessionsByInstanceId[instanceid];
                    if (!sessionIds.Contains(wrapper.SessionId))
                    {
                        sessionIds.Add(wrapper.SessionId);
                        sessions.Add(wrapper.GetPSObject());
                    }
                }
                else
                {
                    AddErrorRecord(ref errRecords, instanceidPropName, instanceid);
                }
            }

            return(sessions);
        }
コード例 #8
0
        internal void RemoveOneSessionObjectFromCache(CimSession session)
        {
            HashSet <CimSessionWrapper> cimSessionWrappers = null;

            DebugHelper.WriteLogEx();
            if (this.curCimSessionWrapper.ContainsKey(session))
            {
                CimSessionWrapper item         = this.curCimSessionWrapper[session];
                string            name         = item.Name;
                string            computerName = item.ComputerName;
                object[]          sessionId    = new object[4];
                sessionId[0] = name;
                sessionId[1] = computerName;
                sessionId[2] = item.SessionId;
                sessionId[3] = item.InstanceId;
                DebugHelper.WriteLog("name {0}, computername {1}, id {2}, instanceId {3}", 1, sessionId);
                if (this.curCimSessionsByComputerName.TryGetValue(computerName, out cimSessionWrappers))
                {
                    cimSessionWrappers.Remove(item);
                }
                if (this.curCimSessionsByName.TryGetValue(name, out cimSessionWrappers))
                {
                    cimSessionWrappers.Remove(item);
                }
                this.RemoveSessionInternal(session, item);
                return;
            }
            else
            {
                return;
            }
        }
コード例 #9
0
        /// <summary>
        /// <para>
        /// Add new CimSession object to cache.
        /// </para>
        /// </summary>
        /// <param name="session"></param>
        /// <param name="sessionId"></param>
        /// <param name="instanceId"></param>
        /// <param name="name"></param>
        /// <param name="computerName"></param>
        /// <param name="protocol"></param>
        /// <returns></returns>
        internal PSObject AddObjectToCache(
            CimSession session,
            uint sessionId,
            Guid instanceId,
            string name,
            string computerName,
            ProtocolType protocol)
        {
            CimSessionWrapper wrapper = new CimSessionWrapper(
                sessionId, instanceId, name, computerName, session, protocol);

            HashSet <CimSessionWrapper> objects;

            if (!this.curCimSessionsByComputerName.TryGetValue(computerName, out objects))
            {
                objects = new HashSet <CimSessionWrapper>();
                this.curCimSessionsByComputerName.Add(computerName, objects);
            }

            objects.Add(wrapper);

            if (!this.curCimSessionsByName.TryGetValue(name, out objects))
            {
                objects = new HashSet <CimSessionWrapper>();
                this.curCimSessionsByName.Add(name, objects);
            }

            objects.Add(wrapper);

            this.curCimSessionsByInstanceId.Add(instanceId, wrapper);
            this.curCimSessionsById.Add(sessionId, wrapper);
            this.curCimSessionWrapper.Add(session, wrapper);
            return(wrapper.GetPSObject());
        }
コード例 #10
0
 private void RemoveSessionInternal(CimSession session, CimSessionWrapper wrapper)
 {
     DebugHelper.WriteLogEx();
     this.curCimSessionsByInstanceId.Remove(wrapper.InstanceId);
     this.curCimSessionsById.Remove(wrapper.SessionId);
     this.curCimSessionWrapper.Remove(session);
     session.Dispose();
 }
コード例 #11
0
 /// <summary>
 /// <para>
 /// The constructor.
 /// </para>
 /// </summary>
 /// <param name="theProxy"></param>
 /// <param name="wrapper"></param>
 internal CimTestCimSessionContext(
     CimSessionProxy theProxy,
     CimSessionWrapper wrapper)
 {
     this.proxy             = theProxy;
     this.cimSessionWrapper = wrapper;
     this.nameSpace         = null;
 }
コード例 #12
0
 /// <summary>
 /// Query session object with given CimSessionInstanceID
 /// </summary>
 /// <param name="cimSessionInstanceId"></param>
 /// <returns>CimSession object</returns>
 internal CimSession QuerySession(Guid cimSessionInstanceId)
 {
     if (this.curCimSessionsByInstanceId.ContainsKey(cimSessionInstanceId))
     {
         CimSessionWrapper wrapper = this.curCimSessionsByInstanceId[cimSessionInstanceId];
         return(wrapper.CimSession);
     }
     return(null);
 }
コード例 #13
0
        internal IEnumerable <PSObject> QuerySession(IEnumerable <string> nameArray, out IEnumerable <ErrorRecord> errorRecords)
        {
            HashSet <PSObject> pSObjects     = new HashSet <PSObject>();
            HashSet <uint>     nums          = new HashSet <uint>();
            List <ErrorRecord> errorRecords1 = new List <ErrorRecord>();

            errorRecords = errorRecords1;
            foreach (var str in this.curCimSessionsByName)
            {
                bool            count           = false;
                WildcardPattern wildcardPattern = new WildcardPattern(str.Key, WildcardOptions.IgnoreCase);
                Dictionary <string, HashSet <CimSessionWrapper> > .Enumerator enumerator = this.curCimSessionsByName.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        KeyValuePair <string, HashSet <CimSessionWrapper> > keyValuePair = str;
                        if (!wildcardPattern.IsMatch(keyValuePair.Key))
                        {
                            continue;
                        }
                        HashSet <CimSessionWrapper> value = keyValuePair.Value;
                        count = value.Count > 0;
                        HashSet <CimSessionWrapper> .Enumerator enumerator1 = value.GetEnumerator();
                        try
                        {
                            while (enumerator1.MoveNext())
                            {
                                CimSessionWrapper current = enumerator1.Current;
                                if (nums.Contains(current.SessionId))
                                {
                                    continue;
                                }
                                nums.Add(current.SessionId);
                                pSObjects.Add(current.GetPSObject());
                            }
                        }
                        finally
                        {
                            enumerator1.Dispose();
                        }
                    }
                }
                finally
                {
                    enumerator.Dispose();
                }
                if (count || WildcardPattern.ContainsWildcardCharacters(str.Key))
                {
                    continue;
                }
                this.AddErrorRecord(ref errorRecords1, CimSessionState.namePropName, str.Key);
            }
            return(pSObjects);
        }
コード例 #14
0
 internal CimSession QuerySession(Guid cimSessionInstanceId)
 {
     if (!this.curCimSessionsByInstanceId.ContainsKey(cimSessionInstanceId))
     {
         return(null);
     }
     else
     {
         CimSessionWrapper item = this.curCimSessionsByInstanceId[cimSessionInstanceId];
         return(item.CimSession);
     }
 }
コード例 #15
0
ファイル: CimSessionState.cs プロジェクト: nickchal/pash
		internal PSObject AddObjectToCache(CimSession session, uint sessionId, Guid instanceId, string name, string computerName, ProtocolType protocol)
		{
			HashSet<CimSessionWrapper> cimSessionWrappers = null;
			CimSessionWrapper cimSessionWrapper = new CimSessionWrapper(sessionId, instanceId, name, computerName, session, protocol);
			if (!this.curCimSessionsByComputerName.TryGetValue(computerName, out cimSessionWrappers))
			{
				cimSessionWrappers = new HashSet<CimSessionWrapper>();
				this.curCimSessionsByComputerName.Add(computerName, cimSessionWrappers);
			}
			cimSessionWrappers.Add(cimSessionWrapper);
			if (!this.curCimSessionsByName.TryGetValue(name, out cimSessionWrappers))
			{
				cimSessionWrappers = new HashSet<CimSessionWrapper>();
				this.curCimSessionsByName.Add(name, cimSessionWrappers);
			}
			cimSessionWrappers.Add(cimSessionWrapper);
			this.curCimSessionsByInstanceId.Add(instanceId, cimSessionWrapper);
			this.curCimSessionsById.Add(sessionId, cimSessionWrapper);
			this.curCimSessionWrapper.Add(session, cimSessionWrapper);
			return cimSessionWrapper.GetPSObject();
		}
コード例 #16
0
        internal PSObject AddObjectToCache(CimSession session, uint sessionId, Guid instanceId, string name, string computerName, ProtocolType protocol)
        {
            HashSet <CimSessionWrapper> cimSessionWrappers = null;
            CimSessionWrapper           cimSessionWrapper  = new CimSessionWrapper(sessionId, instanceId, name, computerName, session, protocol);

            if (!this.curCimSessionsByComputerName.TryGetValue(computerName, out cimSessionWrappers))
            {
                cimSessionWrappers = new HashSet <CimSessionWrapper>();
                this.curCimSessionsByComputerName.Add(computerName, cimSessionWrappers);
            }
            cimSessionWrappers.Add(cimSessionWrapper);
            if (!this.curCimSessionsByName.TryGetValue(name, out cimSessionWrappers))
            {
                cimSessionWrappers = new HashSet <CimSessionWrapper>();
                this.curCimSessionsByName.Add(name, cimSessionWrappers);
            }
            cimSessionWrappers.Add(cimSessionWrapper);
            this.curCimSessionsByInstanceId.Add(instanceId, cimSessionWrapper);
            this.curCimSessionsById.Add(sessionId, cimSessionWrapper);
            this.curCimSessionWrapper.Add(session, cimSessionWrapper);
            return(cimSessionWrapper.GetPSObject());
        }
コード例 #17
0
ファイル: CimNewSession.cs プロジェクト: modulexcite/pash-1
        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));
                }
            }
        }
コード例 #18
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); 
                }
            }
        }
コード例 #19
0
        /// <summary>
        /// <para>
        /// Remove given <see cref="CimSession"/> object from partial of the cache only.
        /// </para>
        /// </summary>
        /// <param name="session"></param>
        /// <param name="psObject"></param>
        private void RemoveSessionInternal(CimSession session, CimSessionWrapper wrapper)
        {
            DebugHelper.WriteLogEx();

            this.curCimSessionsByInstanceId.Remove(wrapper.InstanceId);
            this.curCimSessionsById.Remove(wrapper.SessionId);
            this.curCimSessionWrapper.Remove(session);
            session.Dispose();
        }
コード例 #20
0
ファイル: CimNewSession.cs プロジェクト: nickchal/pash
		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));
				}
			}
		}
コード例 #21
0
        /// <summary>
        /// <para>
        /// Add new CimSession object to cache
        /// </para>
        /// </summary>
        /// <param name="session"></param>
        /// <param name="sessionId"></param>
        /// <param name="instanceId"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        internal PSObject AddObjectToCache(
            CimSession session,
            UInt32 sessionId,
            Guid instanceId,
            String name,
            String computerName,
            ProtocolType protocol)
        {
            CimSessionWrapper wrapper = new CimSessionWrapper(
                sessionId, instanceId, name, computerName, session, protocol);

            HashSet<CimSessionWrapper> objects;
            if (!this.curCimSessionsByComputerName.TryGetValue(computerName, out objects))
            {
                objects = new HashSet<CimSessionWrapper>();
                this.curCimSessionsByComputerName.Add(computerName, objects);
            }
            objects.Add(wrapper);

            if (!this.curCimSessionsByName.TryGetValue(name, out objects))
            {
                objects = new HashSet<CimSessionWrapper>();
                this.curCimSessionsByName.Add(name, objects);
            }
            objects.Add(wrapper);

            this.curCimSessionsByInstanceId.Add(instanceId, wrapper);
            this.curCimSessionsById.Add(sessionId, wrapper);
            this.curCimSessionWrapper.Add(session, wrapper);
            return wrapper.GetPSObject();
        }
コード例 #22
0
 /// <summary>
 /// <para>
 /// Constructor
 /// </para>
 /// </summary>
 /// <param name="theProxy"></param>
 /// <param name="wrapper"></param>
 internal CimTestCimSessionContext(
     CimSessionProxy theProxy,
     CimSessionWrapper wrapper)
 {
     this.proxy = theProxy;
     this.cimSessionWrapper = wrapper;
     this.nameSpace = null;
 }