internal CimSessionWrapper QuerySession(CimSession cimsession) { CimSessionWrapper cimSessionWrapper = null; this.curCimSessionWrapper.TryGetValue(cimsession, out cimSessionWrapper); return(cimSessionWrapper); }
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); }
/// <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); } } }
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); }
/// <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); }
/// <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); }
/// <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); }
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; } }
/// <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()); }
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(); }
/// <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; }
/// <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); }
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); }
internal CimSession QuerySession(Guid cimSessionInstanceId) { if (!this.curCimSessionsByInstanceId.ContainsKey(cimSessionInstanceId)) { return(null); } else { CimSessionWrapper item = this.curCimSessionsByInstanceId[cimSessionInstanceId]; return(item.CimSession); } }
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(); }
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()); }
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)); } } }
/// <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); } } }
/// <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(); }
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)); } } }
/// <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(); }
/// <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; }