コード例 #1
0
 private void HandleCleanupTimerElapsed(object sender, ElapsedEventArgs e)
 {
     if (!this.firstTime)
     {
         lock (this.SyncRoot)
         {
             List <string> strs = new List <string>();
             foreach (KeyValuePair <string, List <CimConnectionManager.SessionEntry> > availableSession in this.availableSessions)
             {
                 List <CimConnectionManager.SessionEntry> value = availableSession.Value;
                 if (value.Count != 0)
                 {
                     for (int i = value.Count - 1; i >= 0; i--)
                     {
                         if (value[i].GetReferenceCount <= 0)
                         {
                             CimConnectionManager.SessionEntry item = value[i];
                             int iterationsRemaining = item.IterationsRemaining - 1;
                             int num = iterationsRemaining;
                             item.IterationsRemaining = iterationsRemaining;
                             if (num <= 0)
                             {
                                 value[i].Session.Close();
                                 value.RemoveAt(i);
                             }
                         }
                     }
                 }
                 else
                 {
                     strs.Add(availableSession.Key);
                 }
             }
         }
         return;
     }
     else
     {
         this.firstTime = false;
         return;
     }
 }
コード例 #2
0
        internal CimSession GetSession(string computerName, PSCredential credential, string certificateThumbprint, AuthenticationMechanism authenticationMechanism, CimSessionOptions sessionOptions, bool useSsl, uint port, PSSessionOption pssessionOption)
        {
            CimSession session;

            lock (this.SyncRoot)
            {
                if (this.availableSessions.ContainsKey(computerName))
                {
                    List <CimConnectionManager.SessionEntry> item = this.availableSessions[computerName];
                    if (item.Count > 0)
                    {
                        int num = 0;
                        while (num < item.Count)
                        {
                            CimConnectionManager.SessionEntry sessionEntry = item[num];
                            if ((sessionEntry.SessionOptions != null || sessionOptions != null) && !CimConnectionManager.CompareSessionOptions(sessionEntry, sessionOptions, credential, certificateThumbprint, authenticationMechanism, useSsl, port, pssessionOption))
                            {
                                num++;
                            }
                            else
                            {
                                sessionEntry.AddReference();
                                session = sessionEntry.Session;
                                return(session);
                            }
                        }
                    }
                }
                CimConnectionManager.SessionEntry sessionEntry1 = new CimConnectionManager.SessionEntry(computerName, credential, certificateThumbprint, authenticationMechanism, sessionOptions, useSsl, port, pssessionOption);
                sessionEntry1.IterationsRemaining = 6;
                sessionEntry1.AddReference();
                if (!this.availableSessions.ContainsKey(computerName))
                {
                    this.availableSessions.Add(computerName, new List <CimConnectionManager.SessionEntry>());
                }
                this.availableSessions[computerName].Add(sessionEntry1);
                session = sessionEntry1.Session;
            }
            return(session);
        }
コード例 #3
0
        private static bool CompareSessionOptions(CimConnectionManager.SessionEntry sessionEntry, CimSessionOptions options2, PSCredential credential2, string certificateThumbprint, AuthenticationMechanism authenticationMechanism, bool useSsl, uint port, PSSessionOption pssessionOption)
        {
            TimeSpan timeout = sessionEntry.SessionOptions.Timeout;

            if (timeout.Equals(options2.Timeout))
            {
                if (string.Equals(sessionEntry.SessionOptions.Culture.ToString(), options2.Culture.ToString(), StringComparison.OrdinalIgnoreCase))
                {
                    if (string.Equals(sessionEntry.SessionOptions.UICulture.ToString(), options2.UICulture.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        if (string.Equals(sessionEntry.CertificateThumbprint, certificateThumbprint, StringComparison.OrdinalIgnoreCase))
                        {
                            if (sessionEntry.AuthenticationMechanism == authenticationMechanism)
                            {
                                if (WorkflowUtils.CompareCredential(sessionEntry.Credential, credential2))
                                {
                                    if (sessionEntry.UseSsl == useSsl)
                                    {
                                        if (sessionEntry.Port == port)
                                        {
                                            if (!(pssessionOption == null ^ sessionEntry.PSSessionOption == null))
                                            {
                                                if (pssessionOption != null && sessionEntry.PSSessionOption != null)
                                                {
                                                    if (sessionEntry.PSSessionOption.ProxyAccessType == pssessionOption.ProxyAccessType)
                                                    {
                                                        if (sessionEntry.PSSessionOption.ProxyAuthentication == pssessionOption.ProxyAuthentication)
                                                        {
                                                            if (WorkflowUtils.CompareCredential(sessionEntry.PSSessionOption.ProxyCredential, pssessionOption.ProxyCredential))
                                                            {
                                                                if (sessionEntry.PSSessionOption.SkipCACheck == pssessionOption.SkipCACheck)
                                                                {
                                                                    if (sessionEntry.PSSessionOption.SkipCNCheck == pssessionOption.SkipCNCheck)
                                                                    {
                                                                        if (sessionEntry.PSSessionOption.SkipRevocationCheck == pssessionOption.SkipRevocationCheck)
                                                                        {
                                                                            if (sessionEntry.PSSessionOption.NoEncryption == pssessionOption.NoEncryption)
                                                                            {
                                                                                if (sessionEntry.PSSessionOption.UseUTF16 != pssessionOption.UseUTF16)
                                                                                {
                                                                                    return(false);
                                                                                }
                                                                            }
                                                                            else
                                                                            {
                                                                                return(false);
                                                                            }
                                                                        }
                                                                        else
                                                                        {
                                                                            return(false);
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                        return(false);
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    return(false);
                                                                }
                                                            }
                                                            else
                                                            {
                                                                return(false);
                                                            }
                                                        }
                                                        else
                                                        {
                                                            return(false);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        return(false);
                                                    }
                                                }
                                                return(true);
                                            }
                                            else
                                            {
                                                return(false);
                                            }
                                        }
                                        else
                                        {
                                            return(false);
                                        }
                                    }
                                    else
                                    {
                                        return(false);
                                    }
                                }
                                else
                                {
                                    return(false);
                                }
                            }
                            else
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
コード例 #4
0
ファイル: CimConnectionManager.cs プロジェクト: nickchal/pash
		internal CimSession GetSession(string computerName, PSCredential credential, string certificateThumbprint, AuthenticationMechanism authenticationMechanism, CimSessionOptions sessionOptions, bool useSsl, uint port, PSSessionOption pssessionOption)
		{
			CimSession session;
			lock (this.SyncRoot)
			{
				if (this.availableSessions.ContainsKey(computerName))
				{
					List<CimConnectionManager.SessionEntry> item = this.availableSessions[computerName];
					if (item.Count > 0)
					{
						int num = 0;
						while (num < item.Count)
						{
							CimConnectionManager.SessionEntry sessionEntry = item[num];
							if ((sessionEntry.SessionOptions != null || sessionOptions != null) && !CimConnectionManager.CompareSessionOptions(sessionEntry, sessionOptions, credential, certificateThumbprint, authenticationMechanism, useSsl, port, pssessionOption))
							{
								num++;
							}
							else
							{
								sessionEntry.AddReference();
								session = sessionEntry.Session;
								return session;
							}
						}
					}
				}
				CimConnectionManager.SessionEntry sessionEntry1 = new CimConnectionManager.SessionEntry(computerName, credential, certificateThumbprint, authenticationMechanism, sessionOptions, useSsl, port, pssessionOption);
				sessionEntry1.IterationsRemaining = 6;
				sessionEntry1.AddReference();
				if (!this.availableSessions.ContainsKey(computerName))
				{
					this.availableSessions.Add(computerName, new List<CimConnectionManager.SessionEntry>());
				}
				this.availableSessions[computerName].Add(sessionEntry1);
				session = sessionEntry1.Session;
			}
			return session;
		}