Below is a full set of classes to use. (Including a proper and finished Log class.)
They include the following:
WebClientEx
AccountManagement
Account
FullAccount
Log
These will make your life easier, as you can just plug and play.
Note: The AccountManagement class below includes much more 'stuff' to check other things. (It's an older version of my current class, so the regex and content checking is a little... erm... bad)
Account classes:
Code:
public enum AccountStatus
{
Frozen,
Banned,
Active,
Trial,
Unknown
}
public class Account : IEquatable<Account>
{
private static readonly List<char> passChars = new List<char> {'!', '"', '#', '$', ',', '%'};
public Account(string accountName, string password)
{
Name = accountName;
Password = password;
}
public Account()
{
}
public string Name { get; set; }
public string Password { get; set; }
public static bool ValidateAccount(string username, string password)
{
if (!ValidateUsername(username) || !ValidatePassword(password))
{
return false;
}
return username != password;
}
public static bool ValidatePassword(string password)
{
foreach (char c in password)
{
if (!char.IsLetterOrDigit(c) && !passChars.Contains(c))
{
return false;
}
}
return password.Length >= 8 && password.Length <= 16;
}
public static bool ValidateUsername(string username)
{
foreach (char c in username)
{
if (!char.IsLetterOrDigit(c))
{
return false;
}
}
return username.Length >= 3 && username.Length <= 16;
}
#region IEquatable<Account> Members
/// <summary>
/// Indicates whether the current object is equal to another object of the same type.
/// </summary>
/// <returns>
/// true if the current object is equal to the <paramref name="obj" /> parameter; otherwise, false.
/// </returns>
/// <param name="obj">An object to compare with this object.</param>
public bool Equals(Account obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
return Equals(obj.Name, Name) && Equals(obj.Password, Password);
}
#endregion
#region Overrides
/// <summary>
/// Determines whether the specified <see cref="T:System.Object" /> is equal to the current <see cref="T:System.Object" />.
/// </summary>
/// <returns>
/// true if the specified <see cref="T:System.Object" /> is equal to the current <see cref="T:System.Object" />; otherwise, false.
/// </returns>
/// <param name="obj">The <see cref="T:System.Object" /> to compare with the current <see cref="T:System.Object" />. </param>
/// <exception cref="T:System.NullReferenceException">The <paramref name="obj" /> parameter is null.</exception><filterpriority>2</filterpriority>
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
return obj.GetType() == typeof (Account) && Equals((Account) obj);
}
/// <summary>
/// Serves as a hash function for a particular type.
/// </summary>
/// <returns>
/// A hash code for the current <see cref="T:System.Object" />.
/// </returns>
/// <filterpriority>2</filterpriority>
public override int GetHashCode()
{
unchecked
{
return (Name.GetHashCode() * 397) ^ Password.GetHashCode();
}
}
public static bool operator ==(Account left, Account right)
{
return Equals(left, right);
}
public static bool operator !=(Account left, Account right)
{
return !Equals(left, right);
}
/// <summary>
/// Returns a <see cref="T:System.String" /> that represents the current <see cref="T:System.Object" />.
/// </summary>
/// <returns>
/// A <see cref="T:System.String" /> that represents the current <see cref="T:System.Object" />.
/// </returns>
/// <filterpriority>2</filterpriority>
public override string ToString()
{
return string.Format("Name: {0}, Password: {1}", Name, Password);
}
#endregion
}
public class FullAccount : Account, IEquatable<FullAccount>
{
public FullAccount(Account account, LogonType type) : this(account.Name, account.Password, type) {}
public FullAccount(string account, string password, LogonType type) : base(account, password)
{
Type = type;
}
internal bool Active { get; set; }
internal bool Banned { get; set; }
public bool BC { get; set; }
internal bool Frozen { get; set; }
internal bool Trial { get; set; }
public LogonType Type { get; set; }
public AccountStatus Status
{
get
{
if (Active)
{
return AccountStatus.Active;
}
if (Banned)
{
return AccountStatus.Banned;
}
if (Frozen)
{
return AccountStatus.Frozen;
}
if (Trial)
{
return AccountStatus.Trial;
}
return AccountStatus.Unknown;
}
}
#region IEquatable<FullAccount> Members
/// <summary>
/// Indicates whether the current object is equal to another object of the same type.
/// </summary>
/// <returns>
/// true if the current object is equal to the <paramref name="obj" /> parameter; otherwise, false.
/// </returns>
/// <param name="obj">An object to compare with this object.</param>
public bool Equals(FullAccount obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
return base.Equals(obj) && Equals(obj.Type, Type);
}
#endregion
/// <summary>
/// Determines whether the specified <see cref="T:System.Object" /> is equal to the current <see cref="T:System.Object" />.
/// </summary>
/// <returns>
/// true if the specified <see cref="T:System.Object" /> is equal to the current <see cref="T:System.Object" />; otherwise, false.
/// </returns>
/// <param name="obj">The <see cref="T:System.Object" /> to compare with the current <see cref="T:System.Object" />. </param>
/// <exception cref="T:System.NullReferenceException">The <paramref name="obj" /> parameter is null.</exception><filterpriority>2</filterpriority>
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
return ReferenceEquals(this, obj) || Equals(obj as FullAccount);
}
/// <summary>
/// Serves as a hash function for a particular type.
/// </summary>
/// <returns>
/// A hash code for the current <see cref="T:System.Object" />.
/// </returns>
/// <filterpriority>2</filterpriority>
public override int GetHashCode()
{
unchecked
{
{
return (base.GetHashCode() * 397) ^ Type.GetHashCode();
}
}
}
public static bool operator ==(FullAccount left, FullAccount right)
{
return Equals(left, right);
}
public static bool operator !=(FullAccount left, FullAccount right)
{
return !Equals(left, right);
}
/// <summary>
/// Returns a <see cref="T:System.String" /> that represents the current <see cref="T:System.Object" />.
/// </summary>
/// <returns>
/// A <see cref="T:System.String" /> that represents the current <see cref="T:System.Object" />.
/// </returns>
/// <filterpriority>2</filterpriority>
public override string ToString()
{
return string.Format("{0}, Status: {1}, BC: {2}, Type: {3}", base.ToString(), Status, BC, Type);
}
}
WebClientEx class:
Code:
/// <summary>
/// WebClientEx is a replacement for the WebClient class. This extended class has support for cookies.
/// </summary>
public class WebClientEx : WebClient
{
// Our CookieContainer object that we'll be using.
private CookieContainer cookieJar;
/// <summary>
/// Gets or sets the cookies.
/// </summary>
/// <value>The cookies.</value>
public CookieContainer Cookies
{
get
{
// We don't want to be grabbing a null item.
// So let's initialize it.
if (cookieJar == null)
{
cookieJar = new CookieContainer();
}
return cookieJar;
}
set { cookieJar = value; }
}
/// <summary>
/// Clears the cookies.
/// </summary>
public void ClearCookies()
{
cookieJar = new CookieContainer();
}
///<summary>
///Returns a <see cref="T:System.Net.WebRequest" /> object for the specified resource.
///</summary>
///
///<returns>
///A new <see cref="T:System.Net.WebRequest" /> object for the specified resource.
///</returns>
///
///<param name="address">A <see cref="T:System.Uri" /> that identifies the resource to request.</param>
protected override WebRequest GetWebRequest(Uri address)
{
// Let our parent method do what it needs to do
// and grab that request. (It does some initial
// setup, and checks that we don't need to rewrite)
WebRequest webRequest = base.GetWebRequest(address);
// Keep ourselves typesafe :)
if (webRequest is HttpWebRequest)
{
// Set our cookie container property so we can now
// store cookies with the WebClient class!
(webRequest as HttpWebRequest).CookieContainer = cookieJar;
}
return webRequest;
}
}
AccountManagement class:
Code:
public enum LogonType
{
EU,
US,
Null
}
public class AccountManagement
{
public const string EU_LOGOUT_URL = @"https://www.wow-europe.com/account/logout.html";
public const string US_LOGOUT_URL = @"https://www.worldofwarcraft.com/account/logout.html";
public const string EU_LOGIN_URL = @"https://www.wow-europe.com/login/login?service=https%3A%2F%2Fwww.wow-europe.com%2Faccount%2F";
public const string US_LOGIN_URL = @"https://www.worldofwarcraft.com/login/login?service=https%3A%2F%2Fwww.worldofwarcraft.com%2Faccount%2F";
public readonly WebClientEx Web;
public AccountManagement()
{
Web = new WebClientEx();
Type = LogonType.US;
}
public static bool UsLoginOffline { get; set; }
public static bool EuLoginOffline { get; set; }
private LogonType Type { get; set; }
public string CurrentPage { get; private set; }
private void SetCurrPage(string page)
{
Log.WriteLine(OutputType.Diagnostic, page);
CurrentPage = page;
}
private string GetLtSignature(string page)
{
return Regex.Match(page, @"(?<=B<input type=""hidden"" name=""lt"" value="").+b").Value;
}
private string GetStSignature(string page)
{
switch (Type)
{
case LogonType.US:
return Regex.Match(page,
@"(?<=https://www.worldofwarcraft.com/account/index.html?ticket=).*(?="";)")
.Value;
case LogonType.EU:
return
Regex.Match(page, @"(?<=https://www.wow-europe.com/account/?ticket=).*(?="";)").
Value;
default:
return null;
}
}
private static NameValueCollection GetPostData(string account, string password, string ltSignature)
{
NameValueCollection postData = new NameValueCollection
{
{"username", account},
{"password", password},
{"lt", ltSignature},
{"Login", "Login"}
};
return postData;
}
private void Logout(LogonType type)
{
switch (type)
{
case LogonType.US:
try
{
Web.DownloadString(US_LOGOUT_URL);
}
catch (Exception ex)
{
Log.WriteLine(OutputType.Normal,
string.Format("Exception while logging out of the US website: {0}", ex.Message), 0);
throw;
}
break;
case LogonType.EU:
try
{
Web.DownloadString(EU_LOGOUT_URL);
}
catch (Exception ex)
{
Log.WriteLine(OutputType.Normal,
string.Format("Exception while logging out of the EU website: {0}", ex.Message), 0);
throw;
}
break;
default:
throw new Exception("Type specified was Null.");
}
// Make sure we clear our cookies so we don't have some random login left over.
Web.ClearCookies();
}
public FullAccount Login(Account account, bool checkAllInfo)
{
if (!UsLoginOffline)
{
try
{
//this.Type = LogonType.US;
Log.WriteLine(OutputType.Detailed, "Logging out of the US website.");
Logout(LogonType.US);
SetCurrPage(Web.DownloadString(US_LOGIN_URL));
Log.WriteLine(OutputType.Detailed, "Checking if the US login site is online");
if (PageIsOffline(CurrentPage))
{
UsLoginOffline = true;
goto Hell;
//throw new LoginPageOfflineException("US Login page is offline.");
}
Log.WriteLine(OutputType.Detailed, "Setting US POST data string.");
NameValueCollection postData = GetPostData(account.Name, account.Password,
GetLtSignature(CurrentPage));
Log.WriteLine(OutputType.Detailed, "Sending US POST message to log in.");
Web.UploadValues(US_LOGIN_URL, "POST", postData);
Log.WriteLine(OutputType.Detailed, "Checking if we logged in successfully to US");
SetCurrPage(Web.DownloadString(@"https://www.worldofwarcraft.com/account/index.html?ticket="));
if (LoginSuccess(CurrentPage))
{
Log.WriteLine(OutputType.Minimal, "Logged in successfully to US!");
if (UserSettings.PlaySounds)
{
SystemSounds.Asterisk.Play();
}
if (!checkAllInfo)
{
return new FullAccount(account.Name, account.Password, LogonType.US);
}
FullAccount fa = new FullAccount(account.Name, account.Password, LogonType.US);
string loginAddress =
string.Format(@"https://www.worldofwarcraft.com/account/index.html?ticket={0}",
GetStSignature(
Web.DownloadString(
@"https://www.worldofwarcraft.com/account/index.html?ticket=" +
GetLtSignature(CurrentPage))));
SetCurrPage(Web.DownloadString(loginAddress));
fa.BC = BurningCrusadeEnabled(CurrentPage, LogonType.US);
fa.Active = AccountActive(CurrentPage, LogonType.US);
fa.Frozen = AccountFrozen(CurrentPage, LogonType.US);
fa.Trial = TrialAccount(CurrentPage, LogonType.US);
fa.Banned = AccountBanned(CurrentPage);
Log.WriteLine(OutputType.Detailed, fa.ToString());
if (fa.Status == AccountStatus.Unknown)
{
Log.SaveUnknownHtml(CurrentPage, fa.Name, LogonType.US);
}
return fa;
}
}
catch (WebException ex)
{
Log.WriteException(OutputType.Quiet, ex);
Log.WriteLine(OutputType.Quiet, "{0} ~ Status: {1} ({2}) - {3}", ex.Message,
((HttpWebResponse)ex.Response).StatusCode,
((HttpWebResponse)ex.Response).StatusDescription, (int)ex.Status);
MessageBox.Show(String.Format("{0} ~ Status: {1} ({2})", ex.Message, ex.Status, (int)ex.Status));
}
catch (Exception ex)
{
Log.WriteException(OutputType.Quiet, ex);
}
}
else if (!EuLoginOffline)
{
try
{
Log.WriteLine(OutputType.Detailed, "Logging out of the EU website.");
Logout(LogonType.EU);
SetCurrPage(Web.DownloadString(EU_LOGIN_URL));
Log.WriteLine(OutputType.Detailed, "Checking if the EU login site is online");
if (PageIsOffline(CurrentPage))
{
EuLoginOffline = true;
goto Hell;
//throw new LoginPageOfflineException("US Login page is offline.");
}
Log.WriteLine(OutputType.Detailed, "Setting EU POST data string.");
NameValueCollection postData = GetPostData(account.Name, account.Password,
GetLtSignature(CurrentPage));
Log.WriteLine(OutputType.Detailed, "Sending EU POST message to log in.");
Web.UploadValues(EU_LOGIN_URL, "POST", postData);
Log.WriteLine(OutputType.Detailed, "Checking if we logged in successfully to EU");
SetCurrPage(Web.DownloadString(@"https://www.wow-europe.com/account/?ticket="));
if (LoginSuccess(CurrentPage))
{
Log.WriteLine(OutputType.Minimal, "Logged in successfully to EU!");
if (UserSettings.PlaySounds)
{
SystemSounds.Asterisk.Play();
}
if (!checkAllInfo)
{
return new FullAccount(account.Name, account.Password, LogonType.EU);
}
FullAccount fa = new FullAccount(account.Name, account.Password, LogonType.EU);
string loginAddress = string.Format(@"https://www.wow-europe.com/account/?ticket={0}",
GetStSignature(
Web.DownloadString(
@"https://www.wow-europe.com/account/?ticket=" +
GetLtSignature(CurrentPage))));
SetCurrPage(Web.DownloadString(loginAddress));
fa.BC = BurningCrusadeEnabled(CurrentPage, LogonType.EU);
fa.Active = AccountActive(CurrentPage, LogonType.EU);
fa.Frozen = AccountFrozen(CurrentPage, LogonType.EU);
fa.Trial = TrialAccount(CurrentPage, LogonType.EU);
fa.Banned = AccountBanned(CurrentPage);
if (fa.Status == AccountStatus.Unknown)
{
Log.SaveUnknownHtml(CurrentPage, fa.Name, LogonType.EU);
}
return fa;
}
}
catch (WebException ex)
{
Log.WriteException(OutputType.Quiet, ex);
Log.WriteLine(OutputType.Quiet, "{0} ~ Status: {1} ({2}) - {3}", ex.Message,
((HttpWebResponse)ex.Response).StatusCode,
((HttpWebResponse)ex.Response).StatusDescription, (int)ex.Status);
MessageBox.Show(String.Format("{0} ~ Status: {1} ({2})", ex.Message, ex.Status, (int)ex.Status));
}
catch (Exception ex)
{
Log.WriteException(OutputType.Quiet, ex);
}
}
Hell:
return null;
}
#region General Page Status Indicators
private bool LoginSuccess(string page)
{
return page.ToUpper().Contains("LOGIN SUCCESSFUL");
}
private bool PageIsOffline(string page)
{
return page.ToUpper().Contains("SERVICE TEMPORARILY UNAVAILABLE");
}
private bool AccountBanned(string page)
{
return
page.ToUpper().Contains(
"ACCESS TO THIS WORLD OF WARCRAFT ACCOUNT HAS BEEN DISABLED BY BLIZZARD ENTERTAINMENT");
}
#endregion
#region Account Status Indicators
private bool BurningCrusadeEnabled(string currPage, LogonType type)
{
switch (type)
{
case LogonType.US:
return currPage.Contains("Burning Crusade [<a href = "/account/download_wow.html">Download</a>]");
case LogonType.EU:
return currPage.Contains("World of Warcraft + Burning Crusade");
default:
return false;
}
}
private bool AccountActive(string currPage, LogonType type)
{
switch (type)
{
case LogonType.US:
return currPage.Contains(@"This account is active and can be used for playing.");
case LogonType.EU:
return currPage.Contains("Active");
default:
return false;
}
}
private bool TrialAccount(string currPage, LogonType type)
{
switch (type)
{
case LogonType.US:
return
currPage.Contains(
"This account is a Trial account. A retail Authentication Key will be required to continue playing after the trial time period expires.") ||
currPage.Contains("Trial restrictions may remain on the account for up to 72 hours.");
default:
return false;
}
}
private bool AccountFrozen(string currPage, LogonType type)
{
switch (type)
{
case LogonType.US:
return
currPage.Contains(
@"This account has been frozen and cannot be used for playing. Please add a payment below to reactivate this account.");
default:
return false;
}
}
#endregion
}
Log class:
Code:
public delegate void OutputHandler(OutputEventArgs e);
public delegate void LogHandler(LogEventArgs e);
public enum LogType
{
Quiet,
Minimal,
Normal,
Detailed,
Diagnostic
}
public enum OutputType
{
Quiet,
Minimal,
Normal,
Detailed,
Diagnostic
}
internal static class Log
{
/// <summary>
/// Gets or sets a value indicating whether output is enabled.
/// </summary>
/// <value>
/// <see langword="true"/> if output is enabled; otherwise, <see langword="false"/>.
/// </value>
public static bool EnableOutput { get { return Settings.Default.EnableOutput; } set { Settings.Default.EnableOutput = value; } }
/// <summary>
/// Gets or sets a value indicating whether logging is enabled.
/// </summary>
/// <value>
/// <see langword="true"/> if [enable logging]; otherwise, <see langword="false"/>.
/// </value>
public static bool EnableLogging { get { return Settings.Default.EnableLogging; } set { Settings.Default.EnableLogging = value; } }
/// <summary>
/// Gets or sets a value indicating whether logging and output messages should append a short time
/// string to the prefix of the message. (I.E: [12:51 AM] My Message)
/// </summary>
/// <value>
/// <see langword="true"/> if [append short time]; otherwise, <see langword="false"/>.
/// </value>
public static bool AppendShortTime { get { return Settings.Default.LogAppendShortTime; } set { Settings.Default.LogAppendShortTime = value; } }
/// <summary>
/// Gets or sets a value indicating whether to log output messages.
/// </summary>
/// <value>
/// <see langword="true"/> if [log when output]; otherwise, <see langword="false"/>.
/// </value>
public static bool LogWhenOutput { get { return Settings.Default.LogWhenOutput; } set { Settings.Default.LogWhenOutput = value; } }
private static string _shortTime { get { return string.Format(CultureInfo.InvariantCulture, "[{0}] ", DateTime.Now.ToShortTimeString()); } }
/// <summary>
/// Gets or sets the log level.
/// </summary>
/// <value>The log level.</value>
public static LogType LogLevel { get { return (LogType)Settings.Default.LoggingLevel; } set { Settings.Default.LoggingLevel = (int)value; } }
/// <summary>
/// Gets or sets the output level.
/// </summary>
/// <value>The output level.</value>
public static OutputType OutputLevel { get { return (OutputType)Settings.Default.OutputLevel; } set { Settings.Default.OutputLevel = (int)value; } }
/// <summary>
/// Gets or sets the name of the log file.
/// </summary>
/// <value>The name of the log file.</value>
public static string LogFileName { get { return Settings.Default.LogFileName; } set { Settings.Default.LogFileName = value; } }
/// <summary>
/// Occurs when a message is sent to the Output system via Write or WriteLine
/// </summary>
public static event OutputHandler OnOutput;
/// <summary>
/// Occurs when a message is sent to the Logging system via LogMessage. Or Write/WriteLine if LogWhenOutput is set to true.
/// </summary>
public static event LogHandler OnLog;
private static string _shortDate { get { return DateTime.Now.ToShortDateString().Replace('/', '-'); } }
/// <summary>
/// Logs the message.
/// May be used also as a shortcut for String.Format()
/// </summary>
/// <param name="level">The level.</param>
/// <param name="message">The message.</param>
/// <param name="args">The args.</param>
public static void LogMessage(LogType level, string message, params object[] args)
{
if (level > LogLevel)
{
return;
}
if (string.IsNullOrEmpty(LogFileName))
{
throw new LoggingException("LogFileName cannot be null or empty.");
}
if (string.IsNullOrEmpty(message))
{
throw new ArgumentNullException("message", "Message cannot be null or empty.");
}
message = string.Format(CultureInfo.InvariantCulture, message, args);
using (TextWriter tw = new StreamWriter(string.Format(Application.StartupPath + "\Logs\{0} {1}.txt", _shortDate, LogFileName), true))
{
if (AppendShortTime)
{
message = _shortTime + message;
}
tw.Write(message);
InvokeOnLog(new LogEventArgs(message, LogFileName));
}
}
private static void _logMessage(LogType level, string message, bool ignoreLevel)
{
if (!ignoreLevel && level > LogLevel)
{
return;
}
if (string.IsNullOrEmpty(LogFileName))
{
throw new LoggingException("LogFileName cannot be null or empty.");
}
if (string.IsNullOrEmpty(message))
{
throw new ArgumentNullException("message", "Message cannot be null or empty.");
}
using (TextWriter tw = new StreamWriter(string.Format(Application.StartupPath+"\Logs\{0} {1}.txt", _shortDate, LogFileName), true))
{
tw.Write(message);
InvokeOnLog(new LogEventArgs(message, LogFileName));
}
}
/// <summary>
/// Acts as a form of Console.Write where it does not include the NewLine character.
/// May be used also as a shortcut for String.Format()
/// </summary>
/// <param name="level">The level.</param>
/// <param name="message">The message.</param>
/// <param name="args">The args.</param>
public static void Write(OutputType level, string message, params object[] args)
{
if (level > OutputLevel)
{
return;
}
if (string.IsNullOrEmpty(message))
{
throw new ArgumentNullException("message", "Message cannot be null or empty.");
}
message = string.Format(CultureInfo.InvariantCulture, message, args);
if (AppendShortTime)
{
message = _shortTime + message;
}
InvokeOnOutput(new OutputEventArgs(message));
if (LogWhenOutput)
{
_logMessage((LogType) level, message, true);
}
}
/// <summary>
/// Acts as a form of Console.WriteLine where it includes the NewLine character at the end of the message.
/// May be used also as a shortcut for String.Format()
/// </summary>
/// <param name="level">The level.</param>
/// <param name="message">The message.</param>
/// <param name="args">The args.</param>
public static void WriteLine(OutputType level, string message, params object[] args)
{
if (level > OutputLevel)
{
return;
}
if (string.IsNullOrEmpty(message))
{
throw new ArgumentNullException("message", "Message cannot be null or empty.");
}
message = string.Format(CultureInfo.InvariantCulture, message, args);
Write(level, message + Environment.NewLine);
}
/// <summary>
/// Writes the summary output for an exception thrown during run-time.
/// </summary>
/// <param name="level">The level.</param>
/// <param name="exception">The exception to be summarized and output.</param>
public static void WriteException(OutputType level, Exception exception)
{
if (exception == null)
{
throw new ArgumentNullException("exception", "Exception cannot be null.");
}
string message = string.Format(CultureInfo.InvariantCulture, "Exception thrown: {0}{1}{2}{1}{3}",
exception, Environment.NewLine, exception.Source,
exception.InnerException);
WriteLine(level, message);
using (TextWriter tw = new StreamWriter(string.Format(Application.StartupPath + "\Exception Logs\{0} {1}.txt", _shortDate, LogFileName), true))
{
tw.WriteLine(message);
InvokeOnLog(new LogEventArgs(message, LogFileName));
}
}
//Log.SaveUnknownHtml(CurrentPage, fa.Name, LogonType.US);
public static void SaveUnknownHtml(string htmlPage, string accountName, LogonType type)
{
if (!Directory.Exists("Html Pages"))
{
Directory.CreateDirectory("Html Pages");
}
using (TextWriter tw = new StreamWriter(string.Format(Application.StartupPath + @"Html PagesUnknown {0} - {1}.html", accountName, type)))
{
tw.Write(htmlPage);
}
}
#region Event Invokers
private static void InvokeOnOutput(OutputEventArgs e)
{
OutputHandler Handler = OnOutput;
if (Handler != null)
{
Handler(e);
}
}
private static void InvokeOnLog(LogEventArgs e)
{
LogHandler Handler = OnLog;
if (Handler != null)
{
Handler(e);
}
}
#endregion
#region Nested type: LoggingException
[Serializable]
public class LoggingException : Exception
{
//
// For guidelines regarding the creation of new exception types, see
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconerrorraisinghandlingguidelines.asp
// and
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp07192001.asp
//
public LoggingException() {}
public LoggingException(string message) : base(message) {}
public LoggingException(string message, Exception inner) : base(message, inner) {}
protected LoggingException(
SerializationInfo info,
StreamingContext context)
: base(info, context) {}
}
#endregion
}
public class OutputEventArgs : EventArgs
{
public OutputEventArgs(string message)
{
Message = message;
}
public string Message { get; private set; }
}
public class LogEventArgs : EventArgs
{
public LogEventArgs(string message, string fileName)
{
Message = message;
FileName = fileName;
}
public string Message { get; private set; }
public string FileName { get; private set; }
}