//---------------------------------------------------------------------------------------------------------------------------------------------------
//
// Copyright (C)2007 DarkWynter Studios. All rights reserved.
//
//---------------------------------------------------------------------------------------------------------------------------------------------------
// {Contact : darkwynter.com for licensing information
//---------------------------------------------------------------------------------------------------------------------------------------------------
namespace DarkWynter.Engine.Utilities
{
#region Using
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.IO;
using DarkWynter.Engine.Globals;
#endregion
///
/// Class used for logging of error messages and to throw exceptions when they occur
///
public class Logging
{
private static int NaN;
private static int Nulls;
private static System.DateTime start;
private static ArrayList Events = new ArrayList();
private int randomNumber;
public static List G2LLogList = new List();
public static List G2LSurveyLog = new List();
///
/// Record a Non-A-Number errors to log.
///
public static void addNan()
{
Logging.NaN++;
throw new Exception("NaN Error.");
}
///
/// Record a null value to log.
///
public static void addNull()
{
Logging.Nulls++;
throw new Exception("Null Error.");
}
///
/// Set the start time for logging.
///
/// Start time.
public static void setStart(System.DateTime val)
{
Logging.start = val;
}
///
/// Add an event to log.
///
/// Data from event.
public static void addEventString(String data)
{
Logging.Events.Add(data + "\r");
}
///
/// Generate the log report.
///
/// End time.
public static void genReport(System.DateTime val2)
{
System.Diagnostics.Debug.WriteLine("Run Report");
System.Diagnostics.Debug.WriteLine("Run Started: " + Logging.start.ToString());
System.Diagnostics.Debug.WriteLine("Run Ended: " + val2.ToString());
System.Diagnostics.Debug.WriteLine("Elapsed time: " + (val2.Minute - Logging.start.Minute) + ":" +
(val2.Second - Logging.start.Second));
System.Diagnostics.Debug.WriteLine("Total NaNs: " + Logging.NaN);
System.Diagnostics.Debug.WriteLine("Total Nulls: " + Logging.Nulls);
System.Diagnostics.Debug.WriteLine("Events: \n");
for (int i = 0; i < Logging.Events.Count; i++)
{
System.Diagnostics.Debug.WriteLine((String)Logging.Events[i]);
}
}
///
/// Write log to file.
///
/// End time.
public static void saveLog(System.DateTime val2)
{
FileStream fs = File.Open("log.txt", FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine("Run Report");
sw.WriteLine("Run Started: " + Logging.start.ToString());
sw.WriteLine("Run Ended: " + val2.ToString());
sw.WriteLine("Elapsed time: " + (val2.Minute - Logging.start.Minute) + ":" +
(val2.Second - Logging.start.Second));
sw.WriteLine("Total NaNs: " + Logging.NaN);
sw.WriteLine("Total Nulls: " + Logging.Nulls);
sw.WriteLine("Events: \r");
for (int i = 0; i < Logging.Events.Count; i++)
{
sw.WriteLine((String)Logging.Events[i]);
}
sw.Flush();
sw.Close();
}
///
/// Create the name of the log file and share it with the survey file
///
///
public static string CreateFileName()
{
Random rand = new Random();
string name = Statics_Engine.PlayerSettings.studentName;
if (name == "")
{
name = rand.Next(1000000).ToString();
}
return name;
}
///
/// Create the game log file
///
public static void writeG2LLog(string name)
{
string filename = "G2Llog-" + name + ".txt";
FileStream fs = File.Open(filename, FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(DateTime.Now);
for (int x = 0; x < G2LLogList.Count; x++)
{
sw.WriteLine(G2LLogList[x]);
}
sw.Flush();
sw.Close();
FtpState.Upload(filename);
}
///
/// Create the survey file
///
/// use the same name for the survey
public static void writeG2LSurvey(string name)
{
string filename = "G2LSurvey-" + name + ".txt";
FileStream fs = File.Open(filename, FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(DateTime.Now);
for (int x = 0; x < G2LSurveyLog.Count; x++)
{
sw.WriteLine(G2LSurveyLog[x]);
}
sw.Flush();
sw.Close();
FtpState.Upload(filename);
}
}
}