Powered by Twitter Tools.

September 2003
M T W T F S S
« Jun   Jun »
1234567
891011121314
15161718192021
22232425262728
2930  

Chris Donnan : Programming - Brooklyn Style

software, trading, family, fun


How to encapsulate a Load Balancer - Server Iron - Foundry Networks :)

using System;
using System.Net.Sockets;
using System.Net;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading;
using System.Configuration;
using System.Web;
using System.Diagnostics;
using System.Collections;
using log4net;

namespace ServerFarm.ServerIron
{
///


/// Available protocols for the Load Balancer’s bindings
///

public enum Protocol
{
Http = 1,
Ssl = 2,
Smtp = 3
}
///
/// possible states of the connection to a load balancer
///

public enum ConnectionState
{
Closed = 1,
Open = 2,
Connecting = 3
}
///
/// All the commands that can be sent to the Server Iron Load Balancer
///

public class Commands
{
public static string Config = “conf t”;
public static string ServerReal = “server real #REALSERVERNAME#”;
public static string HttpDisable = “port http disable”;
public static string SslDisable = “port ssl disable”;
public static string HttpEnable = “no port http disable”;
public static string SslEnable = “no port ssl disable”;
public static string SmtpDisable = “port 25 disable”;
public static string SmtpEnable = “no port 25 disable”;
public static string Show = “show server real”;
public static string ShowBind = “show server bind”;
//public static string NoPage = “enable skip-page-display”;
public static string NoPage = “skip-page-display”;
public static string Page = “page-display”;
}
///
/// Encapsulates all of the LoadBalancer functionality.
///

public class LoadBalancer
{
string loadBalancerIP;
string loadBalancerUserName;
string loadBalancerPassword;
DateTime loginStartTime ;
DateTime wiatForPromptTime;
int timeout;
int wiatForPromptTimeOut;
long startTicks;
long nowTicks;
StringBuilder loadBalancerText = new StringBuilder();
TcpClient telnetServer;
NetworkStream writeStream ;
StreamReader readStream;
StringBuilder bindText = new StringBuilder();
StringBuilder realText = new StringBuilder();
ConnectionState connectionState = ConnectionState.Closed;
bool doPage = true;
// Create a logger for use in this class
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
///
/// zero argument constructor.
/// you must set the IPAddress, UserName and Password
/// properties to use this class’s methods
///

public LoadBalancer()
{
Init();
}
///
/// constructor with all needed values
///

/// IP Address of the load balancer /// a valid username /// a valid password public LoadBalancer(string iPAddress, string userName, string password)
{

//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsInfoEnabled)log.Info(”LoadBalancer.Ctor():”+ iPAddress +”,”+ userName +”,”+ password);
this.IPAddress = iPAddress;
this.UserName = userName;
this.Password = password;
Init();
}
private void Init()
{
}
///


/// Paged data back
///

public bool Page
{
get { return doPage; }
set { doPage = value; }
}
///
/// IP Address of the load balancer
///

public string IPAddress
{
get { return loadBalancerIP; }
set { loadBalancerIP = value; }
}
///
/// IP Address of the load balancer
///

public ConnectionState CurrentConnectionState
{
get { return connectionState; }
}
///
/// a valid username for this load balancer
///

public string UserName
{
get { return loadBalancerUserName; }
set { loadBalancerUserName = value; }
}
///
/// password that matches username
///

public string Password
{
get { return loadBalancerPassword; }
set { loadBalancerPassword = value; }
}
///
/// TcpClient that connects to Load Balancer
///

public TcpClient TcpObject
{
get { return telnetServer; }
}
///
/// NetworkStream used to write to Load Balancer
///

public NetworkStream WriteStream
{
get { return writeStream; }
}
///
/// StreamReader used to read from Load Balancer
///

public StreamReader ReadStream
{
get { return readStream; }
}

///


/// string bindings text from Load Balancer
///

public string ShowBindText
{
get { return bindText.ToString(); }
}
///
/// string show server real text from Load Balancer
///

public string ServerRealText
{
get { return realText.ToString(); }
}
public void Close()
{
try
{
if( connectionState == ConnectionState.Open)
{
//if still in config mode, end it
SendLine(”end”);
WiatForPrompt();
SendLine(Commands.Page);
WiatForPrompt();
doPage = true;
}
if(telnetServer != null)
{
telnetServer.Close();
telnetServer = null;
}
connectionState = ConnectionState.Closed;
}
catch(Exception e)
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsErrorEnabled)log.Error(”LoadBalancer.Close() failed”,e);
throw new ApplicationException(”LoadBalancer.Close() failed”, e);
}
}
///
/// enables a site to recieve requests according to
/// it’s currently bound VIP.
///

///
/// note that this will enable both ssl and http.
/// To enable one or the other use the overridden
///
/// SiteEnable(string site,Protocol protocol)
///
method
///

/// the name of the site to be put in service public void SiteEnable(string site)
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsInfoEnabled)log.Info(”LoadBalancer.SiteEnable(string site):”+ site);
try
{
// connect with the server
Connect();
// Change real server reference
SendLine(Commands.ServerReal.Replace(”#REALSERVERNAME#”,site));
WiatForPrompt();
// Enable Http
SendLine(Commands.HttpEnable);
WiatForPrompt();
// Enable Ssl
SendLine(Commands.SslEnable);
WiatForPrompt();

// Get back global reference
SendLine(”exit”);
WiatForPrompt();
}
catch(Exception e)
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsErrorEnabled)log.Error(”SiteEnable(string site)”,e);
throw new ApplicationException(”SiteEnable(string site)”, e);
}
finally
{
if(telnetServer != null)
{
telnetServer.Close();
telnetServer = null;
}
}
}
///


/// Disables a site from recieving requests according to
/// it’s currently bound VIP
///

///
/// note that this will disable both ssl and http bindings.
/// To disable one or the other use the overridden
///
/// SiteDisable(string site,Protocol protocol)
///
method
///

/// the site name to disable public void SiteDisable(string site)
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsInfoEnabled)log.Info(”LoadBalancer.SiteDisable(string site):”+ site);
try
{
// connect with the server
Connect();
// Change real server reference
SendLine(Commands.ServerReal.Replace(”#REALSERVERNAME#”,site));
WiatForPrompt();
// Disable Http
SendLine(Commands.HttpDisable);
WiatForPrompt();
// Disable Ssl
SendLine(Commands.SslDisable);
WiatForPrompt();

// Get back global reference
SendLine(”exit”);
WiatForPrompt();
}
catch(Exception e)
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsErrorEnabled)log.Error(”SiteDisable(string site)”,e);
throw new ApplicationException(”SiteDisable(string site)”, e);
}
finally
{
if(telnetServer != null)
{
telnetServer.Close();
telnetServer = null;
}
}
}
///


/// enables a site to recieve requests according to
/// it’s currently bound VIP
///

/// the name of the site to be put in service /// the protocol to enable public void SiteEnable(string site, Protocol protocol)
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsInfoEnabled)log.Info(”LoadBalancer.SiteEnable(string site, Protocol protocol):”+ site +” : “+ protocol.ToString());
try
{
// connect with the server
Connect();
//return loadBalancerText.ToString();

// Change real server reference
SendLine(Commands.ServerReal.Replace(”#REALSERVERNAME#”,site));
WiatForPrompt();
switch(protocol)
{
case Protocol.Http:
// Enable Http
SendLine(Commands.HttpEnable);
WiatForPrompt();
break;
case Protocol.Ssl:
// Enable Ssl
SendLine(Commands.SslEnable);
WiatForPrompt();
break;
case Protocol.Smtp:
// Enable Smtp
SendLine(Commands.SmtpEnable);
WiatForPrompt();
break;
}
// Get back global reference
SendLine(”exit”);
WiatForPrompt();
}
catch(Exception e)
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsErrorEnabled)log.Error(”SiteEnable(string site, Protocol protocol)”,e);
throw new ApplicationException(”SiteEnable(string site, Protocol protocol)”, e);
}
finally
{
if(telnetServer != null)
{
telnetServer.Close();
telnetServer = null;
}
}
}
///


/// disables a site from recieving requests according to
/// it’s currently bound VIP
///

/// the name of the site to be put out of service /// the protocol to disable public void SiteDisable(string site, Protocol protocol)
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsInfoEnabled)log.Info(”LoadBalancer.SiteDisable(string site, Protocol protocol):”+ site +” : “+ protocol.ToString());
try
{
// connect with the server
Connect();

// Change real server reference
SendLine(Commands.ServerReal.Replace(”#REALSERVERNAME#”,site));
WiatForPrompt();
switch(protocol)
{
case Protocol.Http:
// Enable Http
SendLine(Commands.HttpDisable);
WiatForPrompt();
break;
case Protocol.Ssl:
// Enable Ssl
SendLine(Commands.SslDisable);
WiatForPrompt();
break;
case Protocol.Smtp:
// Enable Smtp
SendLine(Commands.SmtpDisable);
WiatForPrompt();
break;
}

// Get back global reference
SendLine(”exit”);
WiatForPrompt();
}
catch(Exception e)
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsErrorEnabled)log.Error(”SiteDisable(string site, Protocol protocol)”,e);
throw new ApplicationException(”SiteDisable(string site, Protocol protocol)”, e);
}
finally
{
if(telnetServer != null)
{
telnetServer.Close();
telnetServer = null;
}
}
}
///


/// enable http and ssl for
///

/// a SiteDictionary of sites public void SiteEnable(SiteDictionary sites)
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsInfoEnabled)log.Info(”LoadBalancer.SiteEnable(SiteDictionary sites)”);
try
{
ArrayList sitesToProcess = new ArrayList();
ICollection keys = sites.Keys;
foreach(int key in keys)
{
Site siteCurrent = (Site)sites[key];
sitesToProcess.Add( siteCurrent.Name );
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsInfoEnabled)log.Info(siteCurrent.Name);
}
SiteEnable((string[])sitesToProcess.ToArray(typeof(string)));
}
catch(Exception e)
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsErrorEnabled)log.Error(”LoadBalancer.SiteEnable(SiteDictionary sites)”,e);
throw new ApplicationException(”LoadBalancer.SiteEnable(SiteDictionary sites)”, e);
}
finally
{
if(telnetServer != null)
{
telnetServer.Close();
telnetServer = null;
}
}
}
///
/// disable http and ssl for
///

/// a SiteDictionary of sites public void SiteDisable(SiteDictionary sites)
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsInfoEnabled)log.Info(”LoadBalancer.SiteDisable(SiteDictionary sites)”);
ArrayList sitesToProcess = new ArrayList();
ICollection keys = sites.Keys;
foreach(int key in keys)
{
Site siteCurrent = (Site)sites[key];
sitesToProcess.Add( siteCurrent.Name );
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsInfoEnabled)log.Info(siteCurrent.Name);
}
SiteDisable((string[])sitesToProcess.ToArray(typeof(string)));
}
///
/// enables a collection of site to recieve requests
/// according to their currently bound VIPs.
///

///
/// note that this will enable both ssl and http.
/// To enable one or the other use the overridden
///
/// SiteEnable(string site[],Protocol protocol)
///
method
///

/// a string array of sites to be enabled public void SiteEnable(string[] sites)
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsInfoEnabled)log.Info(”LoadBalancer.SiteEnable(string[] sites)”);
try
{
for(int i = 0; i < sites.Length; i++)
{
// Change real server reference
SiteEnable(sites[i]);
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsInfoEnabled)log.Info(sites[i]);
}
}
catch(Exception e)
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsErrorEnabled)log.Error("LoadBalancer.SiteEnable(string[] sites)",e);
throw new ApplicationException("LoadBalancer.SiteEnable(string[] sites)", e);
}
finally
{
if(telnetServer != null)
{
telnetServer.Close();
telnetServer = null;
}
}
}
///
/// Disables a collection of sites from recieving
/// requests according to their currently bound VIPs
///

///
/// note that this will disable both ssl and http bindings.
/// To disable one or the other use the overridden
///
/// SiteDisable(string site[],Protocol protocol)
///
method
///

/// an array of strings of the site names to disable public void SiteDisable(string[] sites)
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsInfoEnabled)log.Info(”LoadBalancer.SiteDisable(string[] sites)”);
try
{
for(int i = 0; i < sites.Length; i++)
{
SiteDisable(sites[i]);
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsInfoEnabled)log.Info(sites[i]);
}
}
catch(Exception e)
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsErrorEnabled)log.Error("LoadBalancer.SiteDisable(string[] sites, Protocol protocol)",e);
throw new ApplicationException("LoadBalancer.SiteDisable(string[] sites)", e);
}
finally
{
if(telnetServer != null)
{
telnetServer.Close();
telnetServer = null;
}
}
}
///
/// enables a collection of sites to recieve requests according to
/// it’s currently bound VIP
///

/// a string array of the the names of the
/// sites to be put in service /// the protocol to enable public void SiteEnable(string[] sites, Protocol protocol)
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsInfoEnabled)log.Info(”LoadBalancer.SiteEnable(string[] sites, Protocol protocol)”);
try
{
for(int i = 0; i < sites.Length; i++)
{
SiteEnable(sites[i],protocol);
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsInfoEnabled)log.Info( sites[i] +" "+ protocol.ToString() );
}
}
catch(Exception e)
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsErrorEnabled)log.Error("LoadBalancer.SiteEnable(string[] sites, Protocol protocol)",e);
throw new ApplicationException("LoadBalancer.SiteEnable(string[] sites, Protocol protocol",e);
}
finally
{
if(telnetServer != null)
{
telnetServer.Close();
telnetServer = null;
}
}
}
///
/// disables a collection of sites from recieving requests according to
/// their currently bound VIP
///

/// string array of the the names of the sites to be put out of service /// the protocol to disable /// Login Timeout
public void SiteDisable(string[] sites, Protocol protocol)
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsInfoEnabled)log.Info(”LoadBalancer.SiteDisable(string[] sites, Protocol protocol)”);
try
{
for(int i = 0; i < sites.Length; i++)
{
SiteDisable(sites[i],protocol);
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsInfoEnabled)log.Info( sites[i] +" "+ protocol.ToString() );
}
}
catch(Exception e)
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsErrorEnabled)log.Error("LoadBalancer.SiteDisable(string[] sites, Protocol protocol)",e);
throw new ApplicationException("LoadBalancer.SiteDisable(string[] sites, Protocol protocol)",e);
}
finally
{
if(telnetServer != null)
{
telnetServer.Close();
telnetServer = null;
}
}
}
///
/// send the show bind command
///

/// bindings raw text
public string GetBindings()
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsInfoEnabled)log.Info(”LoadBalancer.GetBindings()”);
try
{
// connect with the server
Connect();

//CLEAR text buffer so we can only store ShowBind data
loadBalancerText.Remove(0,loadBalancerText.Length);
WiatForPrompt();
// ShowBind
SendLine(Commands.ShowBind);
WiatForPrompt();
//set binding text property
bindText.Remove(0,bindText.Length);
bindText.Append(loadBalancerText.ToString());
return loadBalancerText.ToString();
}
catch(Exception e)
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsErrorEnabled)log.Error(”GetStatus()”,e);
throw new ApplicationException(”LoadBalancer.GetBindings()”,e);
}
finally
{
if(telnetServer != null)
{
telnetServer.Close();
telnetServer = null;
}
}
}
///


/// send the show server real command
///

/// show server real command result raw text
public string GetStatus()
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsInfoEnabled)log.Info(”LoadBalancer.GetStatus()”);
try
{
// connect with the server
Connect();

//CLEAR text buffer so we can only store Show data
loadBalancerText.Remove(0,loadBalancerText.Length);
// Show
SendLine(Commands.Show);
WiatForPrompt();
//set real text property
realText.Remove(0,realText.Length);
realText.Append(loadBalancerText.ToString());
return loadBalancerText.ToString();
}
catch(Exception e)
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsErrorEnabled)log.Error(”GetStatus()”,e);
throw new ApplicationException(”LoadBalancer.GetStatus()”,e);
}
finally
{
if(telnetServer != null)
{
telnetServer.Close();
telnetServer = null;
}
}
}
///


/// send the show bind and the show server real commands to the server iron
///

public void SetStatusAndBindings()
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsInfoEnabled)log.Info(”LoadBalancer.SetStatusAndBindings()”);
try
{

// connect with the server
Connect();

//CLEAR text buffer so we can only store Show and ShowBind data
loadBalancerText.Remove(0,loadBalancerText.Length);
//WiatForPrompt();
// Show
SendLine(Commands.Show);
WiatForPrompt();
//set real text property
realText.Remove(0,realText.Length);
realText.Append(loadBalancerText.ToString());
loadBalancerText.Remove(0,loadBalancerText.Length);
// ShowBind
SendLine(Commands.ShowBind);
WiatForPrompt();
//set binding text property
bindText.Remove(0,bindText.Length);
bindText.Append(loadBalancerText.ToString());
}
catch(Exception e)
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsErrorEnabled)log.Error(”SetStatusAndBindings()”,e);
throw new ApplicationException(”LoadBalancer.SetStatusAndBindings”,e);
}
finally
{
if(telnetServer != null)
{
telnetServer.Close();
telnetServer = null;
}
}
}
///


/// send the sendString param to the server iron
///

/// string value to send to loadd balancer private void SendLine(string sendString)
{

//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsInfoEnabled)log.Info(”LoadBalancer.SendLine(string sendString)<<"+ this.IPAddress +">>”+ sendString);
byte[] dataToSend = Encoding.ASCII.GetBytes(sendString + “\r\n”);
writeStream.Write(dataToSend,0,dataToSend.Length);
}
///


/// wiat for the # character to come back from the Server Iron
///

private void WiatForPrompt()
{

//* * * * * * * * * * log info * * * * * * * * * *
//if(log.IsInfoEnabled)log.Info(”LoadBalancer.WiatForPrompt():<<"+ this.IPAddress +">>” );
StringBuilder logString = new StringBuilder();
int currentCharacter = readStream.Read();
logString.Append((char)currentCharacter);
loadBalancerText.Append((char)currentCharacter);
// setup vairiables for Wiat For Prompt timeout
wiatForPromptTimeOut = Convert.ToInt32(ConfigurationSettings.AppSettings["WiatForPromptTimeoutSeconds"]);
wiatForPromptTime = System.DateTime.Now;
while(currentCharacter != 35)
{
currentCharacter = readStream.Read();
logString.Append((char)currentCharacter);
loadBalancerText.Append((char)currentCharacter);
//timeouts
startTicks = (long)((DateTime)(wiatForPromptTime.AddSeconds(wiatForPromptTimeOut))).Ticks;
nowTicks = System.DateTime.Now.Ticks;
if(startTicks < nowTicks)
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsFatalEnabled)log.Fatal("WiatForPrompt timeout failure current return value: "+ logString.ToString());
throw new ApplicationException("WiatForPromptt timeout (timespan)");
}
}
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsInfoEnabled)log.Info("LoadBalancer.WiatForPrompt()<<"+ this.IPAddress +">>”+ logString.ToString() );
}
///


/// Connect to load balancer
///

private void Connect()
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsInfoEnabled)log.Info(”LoadBalancer.Connect()”+ connectionState.ToString());

try
{
Connect(true,true);
}
catch(Exception e)
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsErrorEnabled)log.Error(”LoadBalancer.Connect()”,e);
throw new ApplicationException(”LoadBalancer.Connect()”,e);
}
finally
{
if(telnetServer != null)
{
telnetServer.Close();
telnetServer = null;
}
}
}
///


/// Connect to load balancer
///

/// send config mode command automatically /// send no page mode command automatically private void Connect(bool configMode, bool noPage)
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsInfoEnabled)log.Info(”LoadBalancer.Connect(bool configMode, bool noPage):”+ configMode.ToString() +” : “+ noPage.ToString());
try
{
if(connectionState == ConnectionState.Closed)
{
connectionState = ConnectionState.Connecting;
// connect with the server
telnetServer = new TcpClient(loadBalancerIP,23);
writeStream = telnetServer.GetStream();
readStream = new StreamReader(telnetServer.GetStream());
StringBuilder logonString = new StringBuilder();
int currentLogonCharacter = readStream.Read();
logonString.Append((char)currentLogonCharacter);
// setup vairiables for login timeout
timeout = Convert.ToInt32(ConfigurationSettings.AppSettings["LogInTimeoutSeconds"]);
loginStartTime = System.DateTime.Now;
while(logonString.ToString().IndexOf(”Username: “)<0)
{
currentLogonCharacter = readStream.Read();
logonString.Append((char)currentLogonCharacter);
//timeouts
startTicks = (long)((DateTime)(loginStartTime.AddSeconds(timeout))).Ticks;
nowTicks = System.DateTime.Now.Ticks;
if(startTicks < nowTicks)
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsFatalEnabled)log.Fatal(”Username prompt failure current return value: “+ logonString.ToString());
throw new ApplicationException(”Username prompt timeout (timespan)”);
}
if(currentLogonCharacter == -1)
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsFatalEnabled)log.Fatal(”Login failure current return value: “+ logonString.ToString());
throw new ApplicationException(”Log on timeout”);
}
}
// sending username to the server
SendLine(loadBalancerUserName);
currentLogonCharacter = readStream.Read();
logonString.Append((char)currentLogonCharacter);
loginStartTime = System.DateTime.Now;
while((logonString.ToString().IndexOf(”Enter PASSCODE: “)<0) && (logonString.ToString().IndexOf(”Password:”)<0))
{
currentLogonCharacter = readStream.Read();
logonString.Append((char)currentLogonCharacter);
//timeouts
startTicks = (long)((DateTime)(loginStartTime.AddSeconds(timeout))).Ticks;
nowTicks = System.DateTime.Now.Ticks;
if(startTicks < nowTicks)
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsFatalEnabled)log.Fatal(”Password prompt failure current return value: “+ logonString.ToString());
throw new ApplicationException(”Password prompt timeout (timespan)”);
}
}
// sending password to the server
SendLine(loadBalancerPassword);
loginStartTime = System.DateTime.Now;
while(logonString.ToString().IndexOf(”User login successful.”)<0)
{
currentLogonCharacter = readStream.Read();
logonString.Append((char)currentLogonCharacter);
//timeouts
startTicks = (long)((DateTime)(loginStartTime.AddSeconds(timeout))).Ticks;
nowTicks = System.DateTime.Now.Ticks;
if(startTicks < nowTicks)
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsFatalEnabled)log.Fatal(”Login failure current return value: “+ logonString.ToString());
throw new ApplicationException(”Login Timeout (timespan)”);
}
if(currentLogonCharacter == -1)
{
Thread.Sleep(1000);
//* * * * * * * * * * log info * * * * * * * * *
if(log.IsWarnEnabled)log.Warn(”Connect() internal - Thread.Sleep(1000) “);
}
}
WiatForPrompt();
if(noPage)
{
// no page
SendLine(Commands.NoPage);
WiatForPrompt();
doPage = false;
}
if(configMode)
{
// enter config mode
SendLine(Commands.Config);
WiatForPrompt();
}

connectionState = ConnectionState.Open;
}
}
catch(Exception e)
{
//* * * * * * * * * * log info * * * * * * * * * *
if(log.IsErrorEnabled)log.Error(”LoadBalancer.Connect()”,e);
throw new ApplicationException(”LoadBalancer.Connect()”,e);
}
finally
{
if(telnetServer != null)
{
telnetServer.Close();
telnetServer = null;
}
}
}
}
}

Share and Enjoy:
  • del.icio.us
  • digg
  • blinkbits
  • BlinkList
  • blogmarks
  • YahooMyWeb
  • connotea
  • De.lirio.us
  • Fark
  • Furl
  • Reddit
  • description
  • Shadows
  • Smarking
  • Spurl
  • TailRank
  • Wists

Comment on this post below

You must be logged in to post a comment.


You can leave a response, or trackback from your own site.