From: <Di...@us...> - 2009-01-17 10:52:40
|
Revision: 457 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=457&view=rev Author: DixonD Date: 2009-01-17 10:52:35 +0000 (Sat, 17 Jan 2009) Log Message: ----------- Some refactoring was done. Modified Paths: -------------- ACMServer/trunk/ACMServer/Library/Connector/Getter/WebGetterOld.cs ACMServer/trunk/ACMServer/Library/Connector/SocketClient.cs ACMServer/trunk/ACMServer/Library/Connector/SocketClientTask.cs ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs ACMServer/trunk/ACMServer/Library/Connector/SocketServerTask.cs ACMServer/trunk/ACMServer/Library/Connector/WebConnector.cs ACMServer/trunk/ACMServer/Library/Data/DataMediator.cs ACMServer/trunk/ACMServer/Library/Data/Result.cs ACMServer/trunk/ACMServer/Library/Data/Submit.cs ACMServer/trunk/ACMServer/Library/Data/SubmitList.cs ACMServer/trunk/ACMServer/Library/LibraryExtention/Configuration.cs ACMServer/trunk/ACMServer/Library/LibraryExtention/IniFile.cs ACMServer/trunk/ACMServer/Library/LibraryExtention/Log.cs ACMServer/trunk/ACMServer/Library/LibraryExtention/Reader.cs ACMServer/trunk/ACMServer/Library/LibraryExtention/SystemMessage.cs ACMServer/trunk/ACMServer/Library/LibraryExtention/XML/XmlHelper.cs ACMServer/trunk/ACMServer/Library/LibraryExtention/XML/XmlSerializer.cs ACMServer/trunk/ACMServer/Library/LibraryExtention/XML/XmlValidator.cs ACMServer/trunk/ACMServer/Plugins/PluginsFramework/BaseMediatorPlugin.cs ACMServer/trunk/ACMServer/Plugins/PluginsFramework/MediatorKernel.cs ACMServer/trunk/ACMServer/Plugins/PluginsFramework/MediatorKernelGUI.cs ACMServer/trunk/ACMServer/Plugins/PluginsFramework/PluginsLoader.cs ACMServer/trunk/ACMServer/Runner/Class1.cs ACMServer/trunk/ACMServer/Tester/Form1.cs ACMServer/trunk/ACMServer/Tester/Library/SocketClientGate.cs ACMServer/trunk/ACMServer/Tester/Library/WorkMediator.cs ACMServer/trunk/ACMServer/Tester/Library/WorkRunner.cs ACMServer/trunk/ACMServer/Tester/Program.cs Modified: ACMServer/trunk/ACMServer/Library/Connector/Getter/WebGetterOld.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/Getter/WebGetterOld.cs 2009-01-17 09:16:35 UTC (rev 456) +++ ACMServer/trunk/ACMServer/Library/Connector/Getter/WebGetterOld.cs 2009-01-17 10:52:35 UTC (rev 457) @@ -1,10 +1,4 @@ using System; -using System.Threading; -using System.Windows.Forms; -using System.Net; -using System.IO; -using System.Text; -using AcmContester.Library.LibraryExtention.Data; using AcmContester.Library.LibraryExtention; namespace AcmContester.Library.Connector.Getter Modified: ACMServer/trunk/ACMServer/Library/Connector/SocketClient.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/SocketClient.cs 2009-01-17 09:16:35 UTC (rev 456) +++ ACMServer/trunk/ACMServer/Library/Connector/SocketClient.cs 2009-01-17 10:52:35 UTC (rev 457) @@ -1,4 +1,3 @@ -using System; using JadBenAutho.EasySocket; using AcmContester.Library.LibraryExtention; @@ -6,14 +5,14 @@ { public class SocketClient: AbstractConnector { - string ip = "127.0.0.1"; - int port = 4120; + readonly string ip = "127.0.0.1"; + readonly int port = 4120; EasyClient client; void init() { - client = new EasyClient(new ServerInfo(this.ip, this.port, true)); + client = new EasyClient(new ServerInfo(ip, port, true)); client.DataArrived += DataArrived; } @@ -23,13 +22,13 @@ } public SocketClient(string IP) { - this.ip = IP; + ip = IP; init(); } public SocketClient(string IP, int Port) { - this.ip = IP; - this.port = Port; + ip = IP; + port = Port; init(); } @@ -37,7 +36,7 @@ { if (client == null) { - client = new EasyClient(new ServerInfo(this.ip, this.port, true)); + client = new EasyClient(new ServerInfo(ip, port, true)); } if (client.IsConnected == false) client.ConnectToServerAsync(); @@ -46,7 +45,7 @@ { if (client != null) { - if (client.IsConnected == true) + if (client.IsConnected) client.DisconnectFromServer(); client.Dispose(); client = null; Modified: ACMServer/trunk/ACMServer/Library/Connector/SocketClientTask.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/SocketClientTask.cs 2009-01-17 09:16:35 UTC (rev 456) +++ ACMServer/trunk/ACMServer/Library/Connector/SocketClientTask.cs 2009-01-17 10:52:35 UTC (rev 457) @@ -1,24 +1,23 @@ -using System; using AcmContester.Library.LibraryExtention; namespace AcmContester.Library.Connector { public class SocketClientTask: AbstractConnector { - SocketClient client; + readonly SocketClient client; private string descriptionMessage = ""; public SocketClientTask(string IP) { client = new SocketClient(IP); - client.onDataArrived +=new SocketClient.DataArrivedDelegate(SocketClientGate_onDataArrived); + client.onDataArrived +=SocketClientGate_onDataArrived; } void SocketClientGate_onDataArrived(SystemMessage message) { - if (message.IsType("SystemTestBusyMessage") == true) + if (message.IsType("SystemTestBusyMessage")) { - if (SystemMessageX(message) == true) + if (SystemMessageX(message)) return; } @@ -38,21 +37,13 @@ if (mes[0] == "test") { OnAddLogText("SystemReceive", message); - string result = ""; - if (IsBusy() == true) - { - result = "busy"; - } - else - { - result = "free"; - } + string result = IsBusy() ? "busy" : "free"; for (int i = 1; i < mes.Length; i++) { result += " " + mes[i]; } OnAddLogText("SystemSend", result); - this.Send(new SystemMessage(result, _message.Type, _message.Description)); + Send(new SystemMessage(result, _message.Type, _message.Description)); return true; } return false; Modified: ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs 2009-01-17 09:16:35 UTC (rev 456) +++ ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs 2009-01-17 10:52:35 UTC (rev 457) @@ -6,7 +6,7 @@ { public class SocketServer: AbstractConnector { - int port = 4120; + readonly int port = 4120; EasyServer server; private void init() @@ -21,7 +21,7 @@ } public SocketServer(int Port) { - this.port = Port; + port = Port; init(); } Modified: ACMServer/trunk/ACMServer/Library/Connector/SocketServerTask.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/SocketServerTask.cs 2009-01-17 09:16:35 UTC (rev 456) +++ ACMServer/trunk/ACMServer/Library/Connector/SocketServerTask.cs 2009-01-17 10:52:35 UTC (rev 457) @@ -6,13 +6,13 @@ { public class SocketServerTask: AbstractConnector { - SocketServer server; + readonly SocketServer server; //val: //free - vilnyj //busy - zajnjatyj //unknown - nevidomyj - Dictionary<int, string> cleintStatus = new Dictionary<int, string>(); + readonly Dictionary<int, string> clientStatus = new Dictionary<int, string>(); public SocketServerTask() @@ -49,23 +49,23 @@ { //TODO: dlja cjogo bulo potribno pidkljuchyty EasySocket // potim ne zabuty jogo vidjednaty vid chogo proektu - cleintStatus[server.ClientsList[clientIndex].GetHashCode()] = "busy"; + clientStatus[server.ClientsList[clientIndex].GetHashCode()] = "busy"; message.Description = server.ClientsList[clientIndex].GetHashCode().ToString(); ServerSend(message, clientIndex); } private void DataArrived(SystemMessage sysMes) { - if (sysMes.IsType("SystemTestBusyMessage") == true) + if (sysMes.IsType("SystemTestBusyMessage")) { - if (SystemMessageX(sysMes) == true) + if (SystemMessageX(sysMes)) return; } DataArriver(sysMes); } protected virtual void DataArriver(SystemMessage message) { - cleintStatus[Int32.Parse(message.Description)] = "free"; + clientStatus[Int32.Parse(message.Description)] = "free"; OnDataArrived(message); } @@ -75,7 +75,7 @@ } - Queue<string> q = new Queue<string>(); + readonly Queue<string> q = new Queue<string>(); /// <summary> /// \xCF\xEE\xE2\xE5\xF0\xF2\xE0\xBA \xF1\xEF\xE8\xF1\xEE\xEA \xE2\xB3\xEB\xFC\xED\xE8\xF5 \xF2\xE5\xF1\xF2\xE5\xF0\xB3\xE2. @@ -97,14 +97,14 @@ string curHashCode = DateTime.Now.GetHashCode().ToString(); for (int i = 0; i < server.CountClients; i++) { - if (cleintStatus.ContainsKey(server.ClientsList[i].GetHashCode()) == false) + if (clientStatus.ContainsKey(server.ClientsList[i].GetHashCode()) == false) { - cleintStatus[server.ClientsList[i].GetHashCode()] = "unknown"; + clientStatus[server.ClientsList[i].GetHashCode()] = "unknown"; } - if (cleintStatus[server.ClientsList[i].GetHashCode()] == "unknown") + if (clientStatus[server.ClientsList[i].GetHashCode()] == "unknown") { string message = "test"; - message += " " + server.ClientsList[i].GetHashCode().ToString(); + message += " " + server.ClientsList[i].GetHashCode(); message += " " + curHashCode; SystemMessage mes = new SystemMessage(message, "SystemTestBusyMessage"); ServerSend(mes, i); @@ -115,7 +115,7 @@ Dictionary<string, int> preResult = new Dictionary<string, int>(); while (server != null && preResult.Count < server.CountClients) { - if (((TimeSpan)(DateTime.Now - start)).TotalSeconds > 1.0) + if ((DateTime.Now - start).TotalSeconds > 1.0) { break; } @@ -129,14 +129,14 @@ string[] mes = curStr.Split(chars); if (mes[0] == "free" && curHashCode == mes[2]) { - cleintStatus[Int32.Parse(mes[1])] = "free"; + clientStatus[Int32.Parse(mes[1])] = "free"; preResult.Add(mes[1], 0); } else { if (mes[0] == "busy") { - cleintStatus[Int32.Parse(mes[1])] = "busy"; + clientStatus[Int32.Parse(mes[1])] = "busy"; } } } @@ -147,9 +147,9 @@ List<int> result = new List<int>(); for (int i = 0; i < server.CountClients; i++) { - if (cleintStatus.ContainsKey(server.ClientsList[i].GetHashCode()) == false) - cleintStatus[server.ClientsList[i].GetHashCode()] = "unknown"; - if (cleintStatus[server.ClientsList[i].GetHashCode()] == "free") + if (clientStatus.ContainsKey(server.ClientsList[i].GetHashCode()) == false) + clientStatus[server.ClientsList[i].GetHashCode()] = "unknown"; + if (clientStatus[server.ClientsList[i].GetHashCode()] == "free") result.Add(i); //string hashCode = server.ClientsList[i].GetHashCode().ToString(); //if (preResult.ContainsKey(hashCode) == true) Modified: ACMServer/trunk/ACMServer/Library/Connector/WebConnector.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/WebConnector.cs 2009-01-17 09:16:35 UTC (rev 456) +++ ACMServer/trunk/ACMServer/Library/Connector/WebConnector.cs 2009-01-17 10:52:35 UTC (rev 457) @@ -7,12 +7,12 @@ { public class WebConnector: AbstractConnector { - Timer timer = new Timer(); + readonly Timer timer = new Timer(); public event EventHandler onChecking; public event EventHandler onChecked; - private IGetter getter = new WebGetterOld(); + private readonly IGetter getter = new WebGetterOld(); private WebConnector() { @@ -29,17 +29,15 @@ private void InitTimer() { timer.Interval = 10 * 1000; - timer.Elapsed += new ElapsedEventHandler(OnTimedEvent); + timer.Elapsed += OnTimedEvent; timer.Enabled = true; } public string Address { - //TODO: get { - return getter.PathToSource; } set Modified: ACMServer/trunk/ACMServer/Library/Data/DataMediator.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Data/DataMediator.cs 2009-01-17 09:16:35 UTC (rev 456) +++ ACMServer/trunk/ACMServer/Library/Data/DataMediator.cs 2009-01-17 10:52:35 UTC (rev 457) @@ -8,7 +8,7 @@ { private int secondToLive = 60; - private Dictionary<int, DateTime> d = new Dictionary<int, DateTime>(); + private readonly Dictionary<int, DateTime> d = new Dictionary<int, DateTime>(); public int SecondToLive { @@ -74,7 +74,7 @@ public void Return(Result data) { DeleteOld(); - if (Contains(data.Submit.GetHashCode()) == true) + if (Contains(data.Submit.GetHashCode())) { d.Remove(data.Submit.GetHashCode()); } Modified: ACMServer/trunk/ACMServer/Library/Data/Result.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Data/Result.cs 2009-01-17 09:16:35 UTC (rev 456) +++ ACMServer/trunk/ACMServer/Library/Data/Result.cs 2009-01-17 10:52:35 UTC (rev 457) @@ -1,4 +1,3 @@ -using System; using System.Xml.Serialization; using AcmContester.AcmLibraryExtention.XML; @@ -29,16 +28,13 @@ [XmlElement("usedMemory", typeof(int))] public int usedMemory; - string temp; + readonly string temp; - private Result() - { - } - public Result(Submit ssubmit) { submit = ssubmit; } + public Result(string message) { //TODO @@ -58,8 +54,7 @@ } public string ToStringX() { - string result = XmlSerializer<Result>.Serialization(this); - return result; + return XmlSerializer<Result>.Serialization(this); } } } Modified: ACMServer/trunk/ACMServer/Library/Data/Submit.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Data/Submit.cs 2009-01-17 09:16:35 UTC (rev 456) +++ ACMServer/trunk/ACMServer/Library/Data/Submit.cs 2009-01-17 10:52:35 UTC (rev 457) @@ -1,7 +1,5 @@ using System; using AcmContester.AcmLibraryExtention.XML; -using System.IO; -using System.Xml; using System.Xml.Serialization; namespace AcmContester.Library.LibraryExtention.Data Modified: ACMServer/trunk/ACMServer/Library/Data/SubmitList.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Data/SubmitList.cs 2009-01-17 09:16:35 UTC (rev 456) +++ ACMServer/trunk/ACMServer/Library/Data/SubmitList.cs 2009-01-17 10:52:35 UTC (rev 457) @@ -8,7 +8,7 @@ [XmlRoot("submitList")] public class SubmitList { - ArrayList listSubmits; + readonly ArrayList listSubmits; public SubmitList() { @@ -37,7 +37,7 @@ set { if (value == null) return; - Submit[] submits = (Submit[])value; + Submit[] submits = value; listSubmits.Clear(); foreach (Submit item in submits) listSubmits.Add(item); Modified: ACMServer/trunk/ACMServer/Library/LibraryExtention/Configuration.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/LibraryExtention/Configuration.cs 2009-01-17 09:16:35 UTC (rev 456) +++ ACMServer/trunk/ACMServer/Library/LibraryExtention/Configuration.cs 2009-01-17 10:52:35 UTC (rev 457) @@ -6,7 +6,7 @@ { public static string ExecutablePath; - static readonly string defaultConfigFileName = "config.ini"; + private const string defaultConfigFileName = "config.ini"; static public string DefaultConfigFileName { get @@ -37,7 +37,7 @@ { get { - if (String.IsNullOrEmpty(mainFormName) == true) + if (String.IsNullOrEmpty(mainFormName)) return "MainForm"; return mainFormName; } @@ -49,7 +49,7 @@ private static string LoadStringFromDifferentFile(string sectionName, string keyName) { - string defaultString = "#$%^$343@#$"; + const string defaultString = "#$%^$343@#$"; string result = defaultString; if (concreteConfigFileName != null) { Modified: ACMServer/trunk/ACMServer/Library/LibraryExtention/IniFile.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/LibraryExtention/IniFile.cs 2009-01-17 09:16:35 UTC (rev 456) +++ ACMServer/trunk/ACMServer/Library/LibraryExtention/IniFile.cs 2009-01-17 10:52:35 UTC (rev 457) @@ -26,7 +26,7 @@ public const int MaxSectionSize = 32767; // 32 KB //The path of the file we are operating on. - private string m_path; + private readonly string m_path; #region P/Invoke declares @@ -132,7 +132,7 @@ private string[] GetArreyKeys(string sectionName, string keyName) { - string[] allKeys = this.GetKeyNames(sectionName); + string[] allKeys = GetKeyNames(sectionName); List<string> list = new List<string>(); for (int i = 0; i < allKeys.Length; i++) { @@ -172,13 +172,13 @@ if (keyName == null) throw new ArgumentNullException("keyName"); - StringBuilder retval = new StringBuilder(IniFile.MaxSectionSize); + StringBuilder retval = new StringBuilder(MaxSectionSize); NativeMethods.GetPrivateProfileString(sectionName, keyName, defaultValue, retval, - IniFile.MaxSectionSize, + MaxSectionSize, m_path); return retval.ToString(); @@ -252,7 +252,7 @@ { string retval = GetString(sectionName, keyName, ""); - if (retval == null || retval.Length == 0) + if (string.IsNullOrEmpty(retval)) { return defaultValue; } @@ -296,23 +296,20 @@ /// </exception> public List<KeyValuePair<string, string>> GetSectionValuesAsList(string sectionName) { - List<KeyValuePair<string, string>> retval; string[] keyValuePairs; - string key, value; - int equalSignPos; if (sectionName == null) throw new ArgumentNullException("sectionName"); //Allocate a buffer for the returned section names. - IntPtr ptr = Marshal.AllocCoTaskMem(IniFile.MaxSectionSize); + IntPtr ptr = Marshal.AllocCoTaskMem(MaxSectionSize); try { //Get the section key/value pairs into the buffer. int len = NativeMethods.GetPrivateProfileSection(sectionName, ptr, - IniFile.MaxSectionSize, + MaxSectionSize, m_path); keyValuePairs = ConvertNullSeperatedStringToStringArray(ptr, len); @@ -324,17 +321,17 @@ } //Parse keyValue pairs and add them to the list. - retval = new List<KeyValuePair<string, string>>(keyValuePairs.Length); + List<KeyValuePair<string, string>> retval = new List<KeyValuePair<string, string>>(keyValuePairs.Length); for (int i = 0; i < keyValuePairs.Length; ++i) { //Parse the "key=value" string into its constituent parts - equalSignPos = keyValuePairs[i].IndexOf('='); + int equalSignPos = keyValuePairs[i].IndexOf('='); - key = keyValuePairs[i].Substring(0, equalSignPos); + string key = keyValuePairs[i].Substring(0, equalSignPos); - value = keyValuePairs[i].Substring(equalSignPos + 1, - keyValuePairs[i].Length - equalSignPos - 1); + string value = keyValuePairs[i].Substring(equalSignPos + 1, + keyValuePairs[i].Length - equalSignPos - 1); retval.Add(new KeyValuePair<string, string>(key, value)); } @@ -363,13 +360,10 @@ /// </exception> public Dictionary<string, string> GetSectionValues(string sectionName) { - List<KeyValuePair<string, string>> keyValuePairs; - Dictionary<string, string> retval; + List<KeyValuePair<string, string>> keyValuePairs = GetSectionValuesAsList(sectionName); - keyValuePairs = GetSectionValuesAsList(sectionName); - //Convert list into a dictionary. - retval = new Dictionary<string, string>(keyValuePairs.Count); + Dictionary<string, string> retval = new Dictionary<string, string>(keyValuePairs.Count); foreach (KeyValuePair<string, string> keyValuePair in keyValuePairs) { @@ -403,24 +397,23 @@ /// </exception> public string[] GetKeyNames(string sectionName) { - int len; string[] retval; if (sectionName == null) throw new ArgumentNullException("sectionName"); //Allocate a buffer for the returned section names. - IntPtr ptr = Marshal.AllocCoTaskMem(IniFile.MaxSectionSize); + IntPtr ptr = Marshal.AllocCoTaskMem(MaxSectionSize); try { //Get the section names into the buffer. - len = NativeMethods.GetPrivateProfileString(sectionName, - null, - null, - ptr, - IniFile.MaxSectionSize, - m_path); + int len = NativeMethods.GetPrivateProfileString(sectionName, + null, + null, + ptr, + MaxSectionSize, + m_path); retval = ConvertNullSeperatedStringToStringArray(ptr, len); } @@ -444,16 +437,15 @@ public string[] GetSectionNames() { string[] retval; - int len; //Allocate a buffer for the returned section names. - IntPtr ptr = Marshal.AllocCoTaskMem(IniFile.MaxSectionSize); + IntPtr ptr = Marshal.AllocCoTaskMem(MaxSectionSize); try { //Get the section names into the buffer. - len = NativeMethods.GetPrivateProfileSectionNames(ptr, - IniFile.MaxSectionSize, m_path); + int len = NativeMethods.GetPrivateProfileSectionNames(ptr, + MaxSectionSize, m_path); retval = ConvertNullSeperatedStringToStringArray(ptr, len); } @@ -627,7 +619,7 @@ //Write new element into INI file for (int i = 0; i < values.Length; i++) { - string newKey = keyName + "." + i.ToString(); + string newKey = keyName + "." + i; WriteValue(sectionName, newKey, values[i]); } Modified: ACMServer/trunk/ACMServer/Library/LibraryExtention/Log.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/LibraryExtention/Log.cs 2009-01-17 09:16:35 UTC (rev 456) +++ ACMServer/trunk/ACMServer/Library/LibraryExtention/Log.cs 2009-01-17 10:52:35 UTC (rev 457) @@ -8,7 +8,7 @@ /// </summary> public class Log { - private static Log instance = new Log(); + private static readonly Log instance = new Log(); private StreamWriter writer; Modified: ACMServer/trunk/ACMServer/Library/LibraryExtention/Reader.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/LibraryExtention/Reader.cs 2009-01-17 09:16:35 UTC (rev 456) +++ ACMServer/trunk/ACMServer/Library/LibraryExtention/Reader.cs 2009-01-17 10:52:35 UTC (rev 457) @@ -6,17 +6,17 @@ { public class Reader { - static Dictionary<string, string> strings = new Dictionary<string, string>(); + static readonly Dictionary<string, string> strings = new Dictionary<string, string>(); public static string ReadString(string fileName, bool cash) { string text = null; if (cash == false || strings.ContainsKey(fileName) == false) { text = ReadString(fileName); - if (cash == true) + if (cash) strings[fileName] = text; } - if (cash == true) + if (cash) { text = strings[fileName]; } Modified: ACMServer/trunk/ACMServer/Library/LibraryExtention/SystemMessage.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/LibraryExtention/SystemMessage.cs 2009-01-17 09:16:35 UTC (rev 456) +++ ACMServer/trunk/ACMServer/Library/LibraryExtention/SystemMessage.cs 2009-01-17 10:52:35 UTC (rev 457) @@ -8,7 +8,7 @@ [Serializable] public class SystemMessage { - string type = ""; + readonly string type = ""; public string Type { @@ -18,7 +18,7 @@ } } - string message = ""; + readonly string message = ""; public string Message { @@ -43,9 +43,9 @@ public SystemMessage(SystemMessage sysMes) { - this.message = sysMes.Message; - this.type = sysMes.Type; - this.description = sysMes.Description; + message = sysMes.Message; + type = sysMes.Type; + description = sysMes.Description; } public SystemMessage(string message) Modified: ACMServer/trunk/ACMServer/Library/LibraryExtention/XML/XmlHelper.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/LibraryExtention/XML/XmlHelper.cs 2009-01-17 09:16:35 UTC (rev 456) +++ ACMServer/trunk/ACMServer/Library/LibraryExtention/XML/XmlHelper.cs 2009-01-17 10:52:35 UTC (rev 457) @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Xml; using AcmContester.Library.LibraryExtention; @@ -45,24 +44,19 @@ /// <exception cref="ArgumentException"></exception> public static T GetObject<T>(string fullXml, string xmlPath, string pathToSchemaFile) where T: class { - if (fullXml == null) - throw new ArgumentNullException("Can't be null", "fullXml"); - if (fullXml == null) - throw new ArgumentException("Can't be empty", "fullXml"); - if (xmlPath == null) - throw new ArgumentNullException("Can't be null", "xmlPath"); - if (xmlPath == null) - throw new ArgumentException("Can't be empty", "xmlPath"); - if (pathToSchemaFile == null) - throw new ArgumentNullException("Can't be null. You can use other method without this parameter", "pathToSchemaFile"); - if (pathToSchemaFile == null) - throw new ArgumentException("Can't be null. You can use other method without this parameter", "pathToSchemaFile"); + + if (String.IsNullOrEmpty(fullXml)) + throw new ArgumentNullException("fullXml", "Can't be null or empty string."); + if (String.IsNullOrEmpty(xmlPath)) + throw new ArgumentNullException("xmlPath", "Can't be null or empty string."); + if (String.IsNullOrEmpty(pathToSchemaFile)) + throw new ArgumentNullException("pathToSchemaFile", "Can't be null or empty string."); - fullXml = XmlHelper.GetOuterXmlOfSingleNodeFromXpath(fullXml, xmlPath); - if (fullXml == null || fullXml == "") + fullXml = GetOuterXmlOfSingleNodeFromXpath(fullXml, xmlPath); + if (string.IsNullOrEmpty(fullXml)) return null; string schema = Reader.ReadString(pathToSchemaFile); - if (XmlHelper.ValidateXmlWithSchema(fullXml, schema) == false) + if (ValidateXmlWithSchema(fullXml, schema) == false) return null; T result = XmlSerializer<T>.Load(fullXml); @@ -80,17 +74,13 @@ /// <exception cref="ArgumentException"></exception> public static T GetObject<T>(string fullXml, string xmlPath) where T : class { - if (fullXml == null) - throw new ArgumentNullException("fullXml", "Can't be null"); - if (fullXml == null) - throw new ArgumentException("fullXml", "Can't be empty"); - if (xmlPath == null) - throw new ArgumentNullException("xmlPath", "Can't be null"); - if (xmlPath == null) - throw new ArgumentException("xmlPath", "Can't be empty"); + if (String.IsNullOrEmpty(fullXml)) + throw new ArgumentNullException("fullXml", "Can't be null or empty string."); + if (String.IsNullOrEmpty(xmlPath)) + throw new ArgumentNullException("xmlPath", "Can't be null or empty string."); - fullXml = XmlHelper.GetOuterXmlOfSingleNodeFromXpath(fullXml, xmlPath); - if (fullXml == null || fullXml == "") + fullXml = GetOuterXmlOfSingleNodeFromXpath(fullXml, xmlPath); + if (string.IsNullOrEmpty(fullXml)) return null; T result = XmlSerializer<T>.Load(fullXml); Modified: ACMServer/trunk/ACMServer/Library/LibraryExtention/XML/XmlSerializer.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/LibraryExtention/XML/XmlSerializer.cs 2009-01-17 09:16:35 UTC (rev 456) +++ ACMServer/trunk/ACMServer/Library/LibraryExtention/XML/XmlSerializer.cs 2009-01-17 10:52:35 UTC (rev 457) @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Text; using System.IO; @@ -21,10 +20,9 @@ public static T Load(string message) { // Deserialization - T result; TextReader r = new StringReader(message); System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(T)); - result = (T)serializer.Deserialize(r); + T result = (T)serializer.Deserialize(r); r.Close(); return result; } Modified: ACMServer/trunk/ACMServer/Library/LibraryExtention/XML/XmlValidator.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/LibraryExtention/XML/XmlValidator.cs 2009-01-17 09:16:35 UTC (rev 456) +++ ACMServer/trunk/ACMServer/Library/LibraryExtention/XML/XmlValidator.cs 2009-01-17 10:52:35 UTC (rev 457) @@ -7,7 +7,7 @@ { class XmlValidator { - string xmlDocument; + readonly string xmlDocument; bool validity; @@ -19,10 +19,8 @@ public bool Validate(string xmlSchema) { - XmlSchema schema = new XmlSchema(); - schema = XmlSchema.Read(new StringReader(xmlSchema), ValidationXmlSchemaCallBack); + XmlSchema schema = XmlSchema.Read(new StringReader(xmlSchema), ValidationXmlSchemaCallBack); - // Create the XmlSchemaSet class. XmlSchemaSet schemas = new XmlSchemaSet(); @@ -33,7 +31,7 @@ XmlReaderSettings settings = new XmlReaderSettings(); settings.ValidationType = ValidationType.Schema; settings.Schemas = schemas; - settings.ValidationEventHandler += new ValidationEventHandler(ValidationXmlCallBack); + settings.ValidationEventHandler += ValidationXmlCallBack; // Create the XmlReader object. XmlReader reader = XmlReader.Create(new StringReader(xmlDocument), settings); @@ -41,13 +39,15 @@ validity = true; // Parse the file. - while (reader.Read() && validity) ; + while (reader.Read() && validity) + { + } return validity; } // Happen validation errors when read XmlSchema - private void ValidationXmlSchemaCallBack(object sender, ValidationEventArgs e) + private static void ValidationXmlSchemaCallBack(object sender, ValidationEventArgs e) { throw new XmlSchemaException(e.Message); } Modified: ACMServer/trunk/ACMServer/Plugins/PluginsFramework/BaseMediatorPlugin.cs =================================================================== --- ACMServer/trunk/ACMServer/Plugins/PluginsFramework/BaseMediatorPlugin.cs 2009-01-17 09:16:35 UTC (rev 456) +++ ACMServer/trunk/ACMServer/Plugins/PluginsFramework/BaseMediatorPlugin.cs 2009-01-17 10:52:35 UTC (rev 457) @@ -14,7 +14,7 @@ public abstract void Send(SystemMessage message); - private UserControl control = null; + private UserControl control; public UserControl Control { Modified: ACMServer/trunk/ACMServer/Plugins/PluginsFramework/MediatorKernel.cs =================================================================== --- ACMServer/trunk/ACMServer/Plugins/PluginsFramework/MediatorKernel.cs 2009-01-17 09:16:35 UTC (rev 456) +++ ACMServer/trunk/ACMServer/Plugins/PluginsFramework/MediatorKernel.cs 2009-01-17 10:52:35 UTC (rev 457) @@ -1,6 +1,4 @@ using System; -using System.Collections; -using AcmContester.Plugins.PluginsFramework; using System.Collections.Generic; using System.Windows.Forms; using AcmContester.Library.LibraryExtention; @@ -14,8 +12,8 @@ public sealed class ControlEventArgs : EventArgs { - Control control; - string name; + readonly Control control; + readonly string name; public ControlEventArgs(Control in_Control, string in_Name) { control = in_Control; @@ -54,7 +52,7 @@ plugin.onDataArrived += DataArrivedFromTesterList; if (plugin.Control != null) { - this.OnAddControl(new ControlEventArgs(plugin.Control, plugin.GetType().Name)); + OnAddControl(new ControlEventArgs(plugin.Control, plugin.GetType().Name)); } } } @@ -66,7 +64,7 @@ plugin.onDataArrived += DataArrivedFromClientList; if (plugin.Control != null) { - this.OnAddControl(new ControlEventArgs(plugin.Control, plugin.GetType().Name)); + OnAddControl(new ControlEventArgs(plugin.Control, plugin.GetType().Name)); } } } @@ -84,7 +82,7 @@ { for (int index = 0; index < testerSideList.Count; index++) { - ((BaseMediatorPlugin)testerSideList[index]).Send(message); + testerSideList[index].Send(message); } } } @@ -94,7 +92,7 @@ { for (int index = 0; index < clientSideList.Count; index++) { - ((BaseMediatorPlugin)clientSideList[index]).Send(message); + clientSideList[index].Send(message); } } } Modified: ACMServer/trunk/ACMServer/Plugins/PluginsFramework/MediatorKernelGUI.cs =================================================================== --- ACMServer/trunk/ACMServer/Plugins/PluginsFramework/MediatorKernelGUI.cs 2009-01-17 09:16:35 UTC (rev 456) +++ ACMServer/trunk/ACMServer/Plugins/PluginsFramework/MediatorKernelGUI.cs 2009-01-17 10:52:35 UTC (rev 457) @@ -1,18 +1,13 @@ using System; using System.Collections.Generic; -using System.ComponentModel; -using System.Drawing; -using System.Data; -using System.Text; using System.Windows.Forms; -using AcmContester.Plugins.PluginsFramework; using AcmContester.Library.LibraryExtention; namespace AcmContester.Plugins.PluginsFramework { public partial class MediatorKernelGUI : UserControl { - MediatorKernel mediator = new MediatorKernel(); + readonly MediatorKernel mediator = new MediatorKernel(); private MediatorKernelGUI() { @@ -43,17 +38,17 @@ string testerFolderPath = list[0]; string clientFolderPath = list[1]; - mediator.AddControl += new EventHandler<MediatorKernel.ControlEventArgs>(mediator_AddControl); + mediator.AddControl += mediator_AddControl; mediator.LoadLists(testerFolderPath, clientFolderPath); } private delegate void AddControlCallback(object sender, MediatorKernel.ControlEventArgs e); private void mediator_AddControl(object sender, MediatorKernel.ControlEventArgs e) { - if (this.tabControl1.InvokeRequired) + if (tabControl1.InvokeRequired) { - AddControlCallback d = new AddControlCallback(mediator_AddControl); - this.Invoke(d, new object[] { sender, e }); + AddControlCallback d = mediator_AddControl; + Invoke(d, new object[] { sender, e }); } else { Modified: ACMServer/trunk/ACMServer/Plugins/PluginsFramework/PluginsLoader.cs =================================================================== --- ACMServer/trunk/ACMServer/Plugins/PluginsFramework/PluginsLoader.cs 2009-01-17 09:16:35 UTC (rev 456) +++ ACMServer/trunk/ACMServer/Plugins/PluginsFramework/PluginsLoader.cs 2009-01-17 10:52:35 UTC (rev 457) @@ -57,7 +57,6 @@ /// add them to provided list.</para> /// </summary> /// <param name="filename">Which file to scan.</param> - /// <param name="lst">Where to add found objects.</param> public static List<T> ScanAndLoad(string filename) { List<T> lst = new List<T>(); @@ -86,15 +85,15 @@ if (t.GetInterface(typeof(T).FullName) != null || t.IsSubclassOf(typeof(T))) lst.Add((T)Activator.CreateInstance(t)); } - catch (System.Reflection.TargetInvocationException) + catch (TargetInvocationException) { //throw ex; } - catch (System.MissingMethodException) + catch (MissingMethodException) { //throw ex; } - catch (System.InvalidCastException) + catch (InvalidCastException) { //throw ex; } Modified: ACMServer/trunk/ACMServer/Runner/Class1.cs =================================================================== --- ACMServer/trunk/ACMServer/Runner/Class1.cs 2009-01-17 09:16:35 UTC (rev 456) +++ ACMServer/trunk/ACMServer/Runner/Class1.cs 2009-01-17 10:52:35 UTC (rev 457) @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Text; using System.IO; using AcmContester.Library.LibraryExtention; using AcmContester.Library.LibraryExtention.Data; @@ -38,14 +37,13 @@ string code = submit.sourceCode; code = HtmlEntityDecode(code); int language = submit.language; - string id = submit.id.ToString(); Result result = new Result(submit); try { //Console.SetOut(File.CreateText("logout.txt")); string[] data = File.ReadAllLines("InData.txt"); - data[2] = data[2] + submit.pbolemID.ToString() + "\\"; + data[2] = data[2] + submit.pbolemID + "\\"; string src = code; TestEnv test = new TestEnv(src, language, data[1], data[2]); test.Compile(); @@ -59,13 +57,13 @@ log.Loging("-------------------END SOURCE---------------------------", Log.Priority.INFO); Console.WriteLine("-------------------END SOURCE---------------------------"); - log.Loging(String.Format("Compile result: {0}, details: {1}, usedtime:{2}", test.comp.Result.ToString(), test.comp.Details, test.comp.UsedTime), Log.Priority.INFO); - Console.WriteLine("Compile result: {0}, details: {1}, usedtime:{2}", test.comp.Result.ToString(), test.comp.Details, test.comp.UsedTime); + log.Loging(String.Format("Compile result: {0}, details: {1}, usedtime:{2}", test.comp.Result, test.comp.Details, test.comp.UsedTime), Log.Priority.INFO); + Console.WriteLine("Compile result: {0}, details: {1}, usedtime:{2}", test.comp.Result, test.comp.Details, test.comp.UsedTime); log.Loging(String.Format("Comp Output: {0}", test.comp.CompilerOutput), Log.Priority.INFO); Console.WriteLine("Comp Output: {0}", test.comp.CompilerOutput); - if (test.comp.Result == Test.CompRes.OK) + if (test.comp.Result == CompRes.OK) { SecureType secureType = SecureType.Double; try @@ -91,7 +89,7 @@ //TODO: result.res = test.comp.Result.ToString(); - if (test.comp.Result == Test.CompRes.OK) + if (test.comp.Result == CompRes.OK) { int usedTime = -1; int usedMemory = -1; @@ -117,7 +115,7 @@ } catch (Exception tex) { - log.Loging("Runner:GetResult - Exception (" + tex.ToString() + ": " + tex.Message, Log.Priority.INFO); + log.Loging("Runner:GetResult - Exception (" + tex + ": " + tex.Message, Log.Priority.INFO); log.Loging(tex.StackTrace, Log.Priority.INFO); result.res = "Exception"; } Modified: ACMServer/trunk/ACMServer/Tester/Form1.cs =================================================================== --- ACMServer/trunk/ACMServer/Tester/Form1.cs 2009-01-17 09:16:35 UTC (rev 456) +++ ACMServer/trunk/ACMServer/Tester/Form1.cs 2009-01-17 10:52:35 UTC (rev 457) @@ -1,9 +1,6 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; using System.Data; using System.Drawing; -using System.Text; using System.Windows.Forms; using System.IO; using AcmContester.Tester.Library; @@ -35,7 +32,7 @@ tabPage3.Controls.Add(view); } - DataTable tableLog = new DataTable(); + readonly DataTable tableLog = new DataTable(); private void initGrid() { tableLog.Columns.Add(new DataColumn("Time")); @@ -66,7 +63,7 @@ Disconnect(); } - private void Disconnect() + private static void Disconnect() { if (socket != null) { @@ -83,14 +80,14 @@ delegate void AddTextCallback(string text); public void AddText(string text) { - if (this.textBox1.InvokeRequired) + if (textBox1.InvokeRequired) { - AddTextCallback d = new AddTextCallback(AddText); - this.Invoke(d, new object[] { text }); + AddTextCallback d = AddText; + Invoke(d, new object[] { text }); } else { - string timeStr = DateTime.Now.ToLongTimeString() + "." + DateTime.Now.Millisecond.ToString(); + string timeStr = DateTime.Now.ToLongTimeString() + "." + DateTime.Now.Millisecond; textBox1.Text += timeStr + " " + text + Environment.NewLine; //if (autoScrollCheckBox.Checked) { @@ -115,7 +112,7 @@ type = _type; } - string text; + readonly string text; public string Text { get @@ -124,7 +121,7 @@ } } - string type; + readonly string type; public string Type { get @@ -152,7 +149,7 @@ { get { - return DateTime.Now.ToLongTimeString() + "." + DateTime.Now.Millisecond.ToString(); + return DateTime.Now.ToLongTimeString() + "." + DateTime.Now.Millisecond; } } } @@ -160,10 +157,10 @@ delegate void AddTextToGridLogCallback(LogMessage text); public void AddTextToGridLog(LogMessage text) { - if (this.dataGridViewLog.InvokeRequired) + if (dataGridViewLog.InvokeRequired) { - AddTextToGridLogCallback d = new AddTextToGridLogCallback(AddTextToGridLog); - this.Invoke(d, new object[] { text }); + AddTextToGridLogCallback d = AddTextToGridLog; + Invoke(d, new object[] { text }); } else { @@ -174,8 +171,7 @@ //table.Rows.Add(row); tableLog.Rows.InsertAt(row, 0); - int c = tableLog.Rows.Count - 1; - c = 0; + const int c = 0; dataGridViewLog.Rows[c].DefaultCellStyle.BackColor = text.Color; dataGridViewLog.Update(); @@ -199,10 +195,7 @@ { if (socket != null) { - if (socket.IsConnected() == true) - toolStripStatusLabel1.Text = "CONNECTED"; - else - toolStripStatusLabel1.Text = "not connected"; + toolStripStatusLabel1.Text = socket.IsConnected() ? "CONNECTED" : "not connected"; } else toolStripStatusLabel1.Text = "null"; Modified: ACMServer/trunk/ACMServer/Tester/Library/SocketClientGate.cs =================================================================== --- ACMServer/trunk/ACMServer/Tester/Library/SocketClientGate.cs 2009-01-17 09:16:35 UTC (rev 456) +++ ACMServer/trunk/ACMServer/Tester/Library/SocketClientGate.cs 2009-01-17 10:52:35 UTC (rev 457) @@ -1,4 +1,3 @@ -using System; using AcmContester.Library.LibraryExtention; using AcmContester.Library.LibraryExtention.Data; using AcmContester.Library.Connector; @@ -9,12 +8,12 @@ { ISocketMediator mediator; - SocketClientTask client; + readonly SocketClientTask client; public SocketClientGate(string IP) { client = new SocketClientTask(IP); - client.onDataArrived +=new SocketClient.DataArrivedDelegate(SocketClientGate_onDataArrived); + client.onDataArrived += SocketClientGate_onDataArrived; client.onAddLogText += OnAddLogText; client.isBusy += IsBusy; } @@ -36,7 +35,7 @@ { OnAddLogText("Receive", message.Message); - if (message.IsType("TestingSubmit") == true) + if (message.IsType("TestingSubmit")) { OnDataArrived(message); } @@ -46,7 +45,7 @@ { message = new SystemMessage(message); - if (message.IsType("TestingResult") == true) + if (message.IsType("TestingResult")) { Result res = Result.CreateFromXml(message.Message); OnAddLogText("Send", "ID " + res.Submit.id + " result - " + res.res); Modified: ACMServer/trunk/ACMServer/Tester/Library/WorkMediator.cs =================================================================== --- ACMServer/trunk/ACMServer/Tester/Library/WorkMediator.cs 2009-01-17 09:16:35 UTC (rev 456) +++ ACMServer/trunk/ACMServer/Tester/Library/WorkMediator.cs 2009-01-17 10:52:35 UTC (rev 457) @@ -5,7 +5,7 @@ { sealed class WorkMediator: ISocketMediator, IWorkerMediator { - private static WorkMediator instance = new WorkMediator(); + private static readonly WorkMediator instance = new WorkMediator(); WorkRunner runner; SocketClientGate socketClient; @@ -21,11 +21,11 @@ this.runner.onDataArrived += ((IWorkerMediator)this).Arrived; } - if (this.socketClient == null) + if (socketClient == null) { - this.socketClient = client; - this.socketClient.Mediator = (ISocketMediator)this; - this.socketClient.onDataArrived += SocketArrived; + socketClient = client; + socketClient.Mediator = this; + socketClient.onDataArrived += SocketArrived; } } public static WorkMediator GetInstance(WorkRunner runner, SocketClientGate client) @@ -39,12 +39,12 @@ } - public bool Send(SystemMessage message) + public static bool Send(SystemMessage message) { throw new Exception("The method or operation is not implemented."); } - public bool Arrived(SystemMessage message) + public static bool Arrived(SystemMessage message) { throw new Exception("The method or operation is not implemented."); } @@ -78,7 +78,7 @@ bool IWorkerMediator.Send(SystemMessage message) { - if (message.IsType("TestingSubmit") == true) + if (message.IsType("TestingSubmit")) return runner.AddWork(message.Message); return true; } Modified: ACMServer/trunk/ACMServer/Tester/Library/WorkRunner.cs =================================================================== --- ACMServer/trunk/ACMServer/Tester/Library/WorkRunner.cs 2009-01-17 09:16:35 UTC (rev 456) +++ ACMServer/trunk/ACMServer/Tester/Library/WorkRunner.cs 2009-01-17 10:52:35 UTC (rev 457) @@ -1,7 +1,6 @@ using System; using AcmContester.Library.LibraryExtention; using System.Threading; -using AcmContester.Library.LibraryExtention.Data; namespace AcmContester.Tester.Library { @@ -13,7 +12,7 @@ string source = ""; object working = 0; - Thread thread = new Thread(new ParameterizedThreadStart(Go)); + Thread thread = new Thread(Go); internal bool IsBusy() { @@ -29,7 +28,7 @@ internal bool AddWork(string message) { - if (IsBusy() == true) + if (IsBusy()) { return false; } @@ -42,7 +41,7 @@ //TODO: potribno jakos obnulyty status thread, // tak shob ne potribno bulo stvorjuvaty novyj - thread = new Thread(new ParameterizedThreadStart(Go)); + thread = new Thread(Go); thread.Start(this); return true; } @@ -86,14 +85,14 @@ //TODO: ne znaju chy tut potriben lock lock (this) { - this.Send(new SystemMessage(result, "TestingResult")); + Send(new SystemMessage(result, "TestingResult")); } } private bool Send(SystemMessage systemMessage) { if (onDataArrived != null) - return this.onDataArrived(systemMessage); + return onDataArrived(systemMessage); return true; } Modified: ACMServer/trunk/ACMServer/Tester/Program.cs =================================================================== --- ACMServer/trunk/ACMServer/Tester/Program.cs 2009-01-17 09:16:35 UTC (rev 456) +++ ACMServer/trunk/ACMServer/Tester/Program.cs 2009-01-17 10:52:35 UTC (rev 457) @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Windows.Forms; namespace Tester This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |