示例#1
0
		public override CommandResult Execute(ULib.Controls.CommandTreeViewNode node = null)
		{
			CommandResult result = null;
			while (!isCancelling && (result == null || result.BoolResult != Is_Port_Opened))
			{
				result = CheckPortStatus(Ip_Address, Port_Number);
				if (!result.IsSuccessful)
				{
					break;
                }
                if (!Is_Wait)
                {
                    string content = string.Concat("Port ", Port_Number, " of server ", Ip_Address, result.BoolResult ? " is " : " is not ", "available.");
                    if (result.BoolResult != Is_Port_Opened)
                    {
                        Output(Color.Red, content);
                    }
                    else
                    {
                        Output(Color.Green, content);
                    }
                    break;
                }
				Thread.Sleep(Retry_Interval);
			}
			base.AccomplishCancellation();
			return result;

			//int port = 456; //<--- This is your value
			//bool isAvailable = true;

			//// Evaluate current system tcp connections. This is the same information provided
			//// by the netstat command line application, just in .Net strongly-typed object
			//// form.  We will look through the list, and if our port we would like to use
			//// in our TcpClient is occupied, we will set isAvailable to false.
			//IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
			//TcpConnectionInformation[] tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections();

			//foreach (TcpConnectionInformation tcpi in tcpConnInfoArray)
			//{
			//    if (tcpi.LocalEndPoint.Port == port)
			//    {
			//        isAvailable = false;
			//        break;
			//    }
			//}

			//// At this point, if isAvailable is true, we can proceed accordingly.
		}
示例#2
0
		public override CommandResult Execute(ULib.Controls.CommandTreeViewNode node = null)
		{
			CommandResult result = new CommandResult();
			MachineSettings machine = CommandExecutionContext.Instance.CurrentMachine;
			ImpersonateUser iu = new ImpersonateUser();
			try
			{
				iu.Impersonate(machine.Domain, machine.Username, machine.Password);
				result = ExecuteInternal();
				iu.Undo();
			}
			catch (Exception e)
			{
				result.LastError = e;
			}
			return result;
		}