| 64 |
Kevin |
1 |
using System;
|
|
|
2 |
using System.Collections.Generic;
|
|
|
3 |
using System.Linq;
|
|
|
4 |
using System.Text;
|
|
|
5 |
using System.Windows.Forms;
|
|
|
6 |
using System.IO;
|
|
|
7 |
using System.Xml.Linq;
|
|
|
8 |
|
|
|
9 |
namespace SWAT_Office_App
|
|
|
10 |
{
|
|
|
11 |
class Stat_Logging
|
|
|
12 |
{
|
|
|
13 |
private static string logFileLocation = "StatLog.xml";
|
|
|
14 |
public static int AccountsCreated { get; set; }
|
|
|
15 |
public static int SharesCreated { get; set; }
|
|
|
16 |
|
|
|
17 |
public static void ImportSettings()
|
|
|
18 |
{
|
|
|
19 |
try
|
|
|
20 |
{
|
|
|
21 |
if (File.Exists(logFileLocation))
|
|
|
22 |
{
|
|
|
23 |
XElement Log = XElement.Load(logFileLocation);
|
|
|
24 |
AccountsCreated = int.Parse(Log.Element("AccountsCreated").Value);
|
|
|
25 |
SharesCreated = int.Parse(Log.Element("SharesCreated").Value);
|
|
|
26 |
Debug.appendText("Stats from " + logFileLocation + " has been imported");
|
|
|
27 |
}
|
|
|
28 |
else
|
|
|
29 |
{
|
|
|
30 |
Debug.appendText("No existing stat logging file detected.");
|
|
|
31 |
WriteDefaultConfigFile();
|
|
|
32 |
}
|
|
|
33 |
}
|
|
|
34 |
catch (Exception e)
|
|
|
35 |
{
|
|
|
36 |
//MessageBox.Show(e.ToString(), "Error");
|
|
|
37 |
Debug.appendText(e.ToString());
|
|
|
38 |
MessageBox.Show("An error has occured. Please notify a supervisor to debug.", "Error");
|
|
|
39 |
}
|
|
|
40 |
}
|
|
|
41 |
public static void ExportSettings()
|
|
|
42 |
{
|
|
|
43 |
try
|
|
|
44 |
{
|
|
|
45 |
XElement Log = XElement.Load(logFileLocation);
|
|
|
46 |
Log.SetElementValue("AccountsCreated", AccountsCreated);
|
|
|
47 |
Log.SetElementValue("SharesCreated", SharesCreated);
|
|
|
48 |
Log.Save(logFileLocation);
|
|
|
49 |
Debug.appendText("Stats has been exported to " + logFileLocation);
|
|
|
50 |
}
|
|
|
51 |
catch (Exception e)
|
|
|
52 |
{
|
|
|
53 |
//MessageBox.Show(e.ToString(), "Error");
|
|
|
54 |
Debug.appendText(e.ToString());
|
|
|
55 |
MessageBox.Show("An error has occured. Please notify a supervisor to debug.", "Error");
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
private static void WriteDefaultConfigFile()
|
|
|
59 |
{
|
|
|
60 |
try
|
|
|
61 |
{
|
|
|
62 |
XElement Log = new XElement("StatLog",
|
|
|
63 |
new XElement("AccountsCreated", 0),
|
|
|
64 |
new XElement("SharesCreated", 0)
|
|
|
65 |
);
|
|
|
66 |
Log.Save(logFileLocation);
|
|
|
67 |
Debug.appendText("A blank stat logging file has been created");
|
|
|
68 |
}
|
|
|
69 |
catch (Exception e)
|
|
|
70 |
{
|
|
|
71 |
//MessageBox.Show(e.ToString(), "Error");
|
|
|
72 |
Debug.appendText(e.ToString());
|
|
|
73 |
MessageBox.Show("An error has occured. Please notify a supervisor to debug.", "Error");
|
|
|
74 |
}
|
|
|
75 |
}
|
|
|
76 |
}
|
|
|
77 |
}
|