//--------------------------------------------------------------------------------------------------------------------------------------------------- // // 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; using System.Threading; #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(); public static List G2LPositionalLog = new List(); private static string ftpFileName; /// /// 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"); } /// /// Create the name of the log file and share it with the survey file /// /// public static int CreateFileName() { Random rand = new Random(); return rand.Next(1000000); } ///// ///// 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 game log file /// public static void writeG2LLog(string filename, List logData) { FileStream fs = File.Open(filename, FileMode.Create); StreamWriter sw = new StreamWriter(fs); sw.WriteLine(DateTime.Now); for (int x = 0; x < logData.Count; x++) { sw.WriteLine(logData[x]); } sw.Flush(); sw.Close(); // Publish for threading.. ftpFileName = filename; // Form thread Thread t = new Thread(new ThreadStart(FTPThreadedUpload)); t.SetApartmentState(ApartmentState.STA); t.Start(); } private static void FTPThreadedUpload() { FtpState.Upload(Logging.ftpFileName); } } }