/// <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 <uint> sessionIds = new(); List <ErrorRecord> errRecords = new(); 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> /// 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 <uint> sessionIds = new(); List <ErrorRecord> errRecords = new(); 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); }
/// <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> /// <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> /// <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(); }
/// <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); }