You can subscribe to this list here.
2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(128) |
Jun
(97) |
Jul
(13) |
Aug
(40) |
Sep
(50) |
Oct
(27) |
Nov
(7) |
Dec
(15) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2009 |
Jan
(18) |
Feb
(47) |
Mar
(7) |
Apr
|
May
|
Jun
|
Jul
(32) |
Aug
|
Sep
(14) |
Oct
(22) |
Nov
|
Dec
|
From: <br...@us...> - 2008-10-10 19:05:48
|
Revision: 413 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=413&view=rev Author: brus07 Date: 2008-10-10 19:05:39 +0000 (Fri, 10 Oct 2008) Log Message: ----------- Clear including list Modified Paths: -------------- ACMServer/trunk/ACMServer/Library/Connector/SocketClientTask.cs ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs ACMServer/trunk/ACMServer/Library/Connector/SocketServerTask.cs Modified: ACMServer/trunk/ACMServer/Library/Connector/SocketClientTask.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/SocketClientTask.cs 2008-10-08 13:15:26 UTC (rev 412) +++ ACMServer/trunk/ACMServer/Library/Connector/SocketClientTask.cs 2008-10-10 19:05:39 UTC (rev 413) @@ -1,7 +1,5 @@ using System; -using AcmContester.Library.Connector; using AcmContester.Library.LibraryExtention; -using AcmContester.Library.LibraryExtention.Data; namespace AcmContester.Library.Connector { Modified: ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs 2008-10-08 13:15:26 UTC (rev 412) +++ ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs 2008-10-10 19:05:39 UTC (rev 413) @@ -1,6 +1,6 @@ using System; +using JadBenAutho.EasySocket; using AcmContester.Library.LibraryExtention; -using JadBenAutho.EasySocket; namespace AcmContester.Library.Connector { Modified: ACMServer/trunk/ACMServer/Library/Connector/SocketServerTask.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/SocketServerTask.cs 2008-10-08 13:15:26 UTC (rev 412) +++ ACMServer/trunk/ACMServer/Library/Connector/SocketServerTask.cs 2008-10-10 19:05:39 UTC (rev 413) @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using AcmContester.Library.LibraryExtention; -using AcmContester.Library.Connector; namespace AcmContester.Library.Connector { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2008-10-08 13:15:42
|
Revision: 412 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=412&view=rev Author: brus07 Date: 2008-10-08 13:15:26 +0000 (Wed, 08 Oct 2008) Log Message: ----------- Continues added new class architecture for Connector module. Added/Moved SocketClientTask/SocketServerTask to Connector module. Modified Paths: -------------- ACMServer/trunk/ACMServer/Library/Connector/Connector.csproj ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGatePlugin.csproj ACMServer/trunk/ACMServer/Tester/Library/SocketClientGate.cs Added Paths: ----------- ACMServer/trunk/ACMServer/Library/Connector/SocketClientTask.cs ACMServer/trunk/ACMServer/Library/Connector/SocketServerTask.cs Removed Paths: ------------- ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerTask.cs Modified: ACMServer/trunk/ACMServer/Library/Connector/Connector.csproj =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/Connector.csproj 2008-10-07 21:07:31 UTC (rev 411) +++ ACMServer/trunk/ACMServer/Library/Connector/Connector.csproj 2008-10-08 13:15:26 UTC (rev 412) @@ -43,9 +43,11 @@ <Compile Include="Getter\WebGetterOld.cs" /> <Compile Include="SocketClient.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="SocketClientTask.cs" /> <Compile Include="SocketServer.cs"> <SubType>Code</SubType> </Compile> + <Compile Include="SocketServerTask.cs" /> <Compile Include="WebConnector.cs" /> </ItemGroup> <ItemGroup> Copied: ACMServer/trunk/ACMServer/Library/Connector/SocketClientTask.cs (from rev 411, ACMServer/trunk/ACMServer/Tester/Library/SocketClientGate.cs) =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/SocketClientTask.cs (rev 0) +++ ACMServer/trunk/ACMServer/Library/Connector/SocketClientTask.cs 2008-10-08 13:15:26 UTC (rev 412) @@ -0,0 +1,100 @@ +using System; +using AcmContester.Library.Connector; +using AcmContester.Library.LibraryExtention; +using AcmContester.Library.LibraryExtention.Data; + +namespace AcmContester.Library.Connector +{ + public class SocketClientTask: AbstractConnector + { + SocketClient client; + private string descriptionMessage = ""; + + public SocketClientTask(string IP) + { + client = new SocketClient(IP); + client.onDataArrived +=new SocketClient.DataArrivedDelegate(SocketClientGate_onDataArrived); + } + + void SocketClientGate_onDataArrived(SystemMessage message) + { + if (message.IsType("SystemTestBusyMessage") == true) + { + if (SystemMessageX(message) == true) + return; + } + + descriptionMessage = message.Description; + + OnDataArrived(message); + } + + + + private bool SystemMessageX(SystemMessage _message) + { + string message = _message.Message; + char[] chars = new char[1]; + chars[0] = ' '; + string[] mes = message.Split(chars); + if (mes[0] == "test") + { + OnAddLogText("SystemReceive", message); + string result = ""; + if (IsBusy() == true) + { + result = "busy"; + } + else + { + result = "free"; + } + for (int i = 1; i < mes.Length; i++) + { + result += " " + mes[i]; + } + OnAddLogText("SystemSend", result); + this.Send(new SystemMessage(result, _message.Type, _message.Description)); + return true; + } + return false; + } + + public override bool Send(SystemMessage message) + { + message = new SystemMessage(message); + message.Description = descriptionMessage; + return client.Send(message); + } + + public delegate void AddLogTextDelegate(string type, string text); + public event AddLogTextDelegate onAddLogText; + private void OnAddLogText(string type, string text) + { + if (onAddLogText != null) + onAddLogText(type,text); + } + + public void Connect() + { + client.Connect(); + } + public void Disconnect() + { + client.Disconnect(); + } + public bool IsConnected() + { + return client.IsConnected(); + } + + public delegate bool IsBusyDelegate(); + public event IsBusyDelegate isBusy; + public bool IsBusy() + { + if (isBusy != null) + return isBusy(); + return false; + } + } +} Property changes on: ACMServer/trunk/ACMServer/Library/Connector/SocketClientTask.cs ___________________________________________________________________ Added: svn:mergeinfo + Copied: ACMServer/trunk/ACMServer/Library/Connector/SocketServerTask.cs (from rev 411, ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerTask.cs) =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/SocketServerTask.cs (rev 0) +++ ACMServer/trunk/ACMServer/Library/Connector/SocketServerTask.cs 2008-10-08 13:15:26 UTC (rev 412) @@ -0,0 +1,182 @@ +using System; +using System.Collections.Generic; +using AcmContester.Library.LibraryExtention; +using AcmContester.Library.Connector; + +namespace AcmContester.Library.Connector +{ + public class SocketServerTask: AbstractConnector + { + SocketServer server; + + //val: + //free - vilnyj + //busy - zajnjatyj + //unknown - nevidomyj + Dictionary<int, string> cleintStatus = new Dictionary<int, string>(); + + + public SocketServerTask() + { + server = new SocketServer(); + server.onDataArrived += DataArrived; + } + + public void Start() + { + server.Start(); + } + public void Stop() + { + server.Stop(); + } + + private bool ServerSend(SystemMessage mes, int TargetClientIndex) + { + return server.Send(mes, TargetClientIndex); + } + public override bool Send(SystemMessage message) + { + List<int> freeTesters = GetFreeTesters(); + if (freeTesters.Count != 0) + { + Random random = new Random(); + DataSender(message, freeTesters[random.Next() % freeTesters.Count]); + return true; + } + return false; + } + protected virtual void DataSender(SystemMessage message, int clientIndex) + { + //TODO: dlja cjogo bulo potribno pidkljuchyty EasySocket + // potim ne zabuty jogo vidjednaty vid chogo proektu + cleintStatus[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 (SystemMessageX(sysMes) == true) + return; + } + DataArriver(sysMes); + } + protected virtual void DataArriver(SystemMessage message) + { + cleintStatus[Int32.Parse(message.Description)] = "free"; + OnDataArrived(message); + } + + public int CountClients() + { + return server.CountClients; + } + + + 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. + /// ³\xE4\xEF\xF0\xE0\xE2\xEB\xFF\xBA \xEA\xEE\xE6\xED\xEE\xEC\xF3 \xF2\xE5\xF1\xF2\xE5\xF0\xF3 \xEF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xE5\xED\xED\xFF \xE2\xE8\xE3\xEB\xFF\xE4\xF3: + /// test HashCodeTester HashCode\xC7\xE0\xEF\xE8\xF2\xF3 + /// \xC4\xE5 HashCode\xC7\xE0\xEF\xE8\xF2\xF3 - \xF6\xE5 \xF3\xED\xB3\xEA\xE0\xEB\xFC\xED\xE8\xE9 \xF5\xE5\xF8 \xEA\xEE\xE4 \xEA\xEE\xE6\xED\xEE\xE3\xEE \xF2\xE0\xEA\xEE\xE3\xEE \xE7\xE0\xEF\xE8\xF2\xF3. + /// \xCF\xEE\xF2\xB3\xEC \xF7\xE5\xEA\xE0\xBA \xEE\xE4\xED\xF3 (1) \xF1\xE5\xEA\xF3\xED\xE4\xF3 \xEA\xEE\xEB\xE8 \xE7\xE0\xEF\xEE\xE2\xED\xE8\xF2\xFC\xF1\xFF q \xF1\xEF\xE8\xF1\xEA\xEE\xEC \xEF\xF0\xE8\xF1\xEB\xE0\xED\xE8\xF5 \xEF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xE5\xED\xFC + /// \xDF\xEA\xF9\xEE \xF2\xE5\xF1\xF2\xE5\xF0 \xEF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xFF\xBA \xF9\xEE \xE2\xB3\xED \xE2\xB3\xEB\xFC\xED\xE8\xE9, \xF2\xEE\xE4\xB3 \xE9\xEE\xE3\xEE \xED\xEE\xEC\xE5\xF0 \xE7\xE0\xED\xEE\xF1\xE8\xF2\xFC\xF1\xFF \xE4\xEE \xF0\xE5\xE7\xF3\xEB\xFC\xF2\xE0\xF2\xF3. + /// </summary> + /// <returns>\xD1\xEF\xE8\xF1\xEE\xEA \xE2\xB3\xEB\xFC\xED\xE8\xF5 \xF2\xE5\xF1\xF2\xE5\xF0\xB3\xE2</returns> + private List<int> GetFreeTesters() + { + if (server == null) + { + return new List<int>(); + } + + q.Clear(); + string curHashCode = DateTime.Now.GetHashCode().ToString(); + 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()] == "unknown") + { + string message = "test"; + message += " " + server.ClientsList[i].GetHashCode().ToString(); + message += " " + curHashCode; + SystemMessage mes = new SystemMessage(message, "SystemTestBusyMessage"); + ServerSend(mes, i); + } + } + + DateTime start = DateTime.Now; + Dictionary<string, int> preResult = new Dictionary<string, int>(); + while (server != null && preResult.Count < server.CountClients) + { + if (((TimeSpan)(DateTime.Now - start)).TotalSeconds > 1.0) + { + break; + } + lock (q) + { + while (q.Count != 0) + { + string curStr = q.Dequeue(); + char[] chars = new char[1]; + chars[0] = ' '; + string[] mes = curStr.Split(chars); + if (mes[0] == "free" && curHashCode == mes[2]) + { + cleintStatus[Int32.Parse(mes[1])] = "free"; + preResult.Add(mes[1], 0); + } + else + { + if (mes[0] == "busy") + { + cleintStatus[Int32.Parse(mes[1])] = "busy"; + } + } + } + } + System.Threading.Thread.Sleep(50); + } + + 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") + result.Add(i); + //string hashCode = server.ClientsList[i].GetHashCode().ToString(); + //if (preResult.ContainsKey(hashCode) == true) + // result.Add(i); + } + return result; + } + + /// <summary> + /// \xCF\xE5\xF0\xE5\xE2\xB3\xF0\xE0\xBA \xF7\xE8 \xF6\xE5 \xF1\xEB\xF3\xE6\xE1\xEE\xE2\xE5 \xEF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xE5\xED\xED\xFF. + /// \xDF\xEA\xF9\xEE \xF1\xEB\xF3\xE6\xE1\xEE\xE2\xE5, \xF2\xEE\xE4\xB3 \xE2\xEE\xED\xEE \xE7\xE0\xED\xEE\xF1\xE8\xF2\xFC\xF1\xFF \xE4\xEE \xF1\xEF\xE8\xF1\xEA\xF3 q + /// </summary> + /// <param name="message">\xCF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xE5\xED\xED\xFF</param> + /// <returns>\xDF\xEA\xF9\xEE \xF6\xE5 \xF1\xEB\xF3\xE6\xE1\xEE\xE2\xE5 \xEF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xE5\xED\xED\xFF, \xF2\xEE\xE4\xB3 \xEF\xEE\xE2\xE5\xF0\xF2\xE0\xBA\xF2\xFC\xF1\xFF true \xEF\xEE \xB3\xED\xE0\xEA\xF8\xEE\xEC\xF3 false</returns> + private bool SystemMessageX(SystemMessage message) + { + char[] chars = new char[1]; + chars[0] = ' '; + string[] mes = message.Message.Split(chars); + if (mes[0] == "busy" || mes[0] == "free") + { + lock(q) + q.Enqueue(message.Message); + return true; + } + return false; + } + } +} Modified: ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGatePlugin.csproj =================================================================== --- ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGatePlugin.csproj 2008-10-07 21:07:31 UTC (rev 411) +++ ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGatePlugin.csproj 2008-10-08 13:15:26 UTC (rev 412) @@ -28,10 +28,6 @@ <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> - <Reference Include="EasySocket, Version=1.0.2082.18867, Culture=neutral"> - <SpecificVersion>False</SpecificVersion> - <HintPath>..\..\..\Resource\EasySocket.dll</HintPath> - </Reference> <Reference Include="LogDataGridView, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>..\..\..\Resource\LogDataGridView.dll</HintPath> @@ -52,7 +48,6 @@ <Compile Include="SocketServerGatePluginUserControl.Designer.cs"> <DependentUpon>SocketServerGatePluginUserControl.cs</DependentUpon> </Compile> - <Compile Include="SocketServerTask.cs" /> <Compile Include="WorkingPool.cs" /> </ItemGroup> <ItemGroup> Deleted: ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerTask.cs =================================================================== --- ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerTask.cs 2008-10-07 21:07:31 UTC (rev 411) +++ ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerTask.cs 2008-10-08 13:15:26 UTC (rev 412) @@ -1,182 +0,0 @@ -using System; -using System.Collections.Generic; -using AcmContester.Library.LibraryExtention; -using AcmContester.Library.Connector; - -namespace AcmContester.Plugins.MediatorPlugins.SocketServerGatePlugin -{ - public class SocketServerTask: AbstractConnector - { - SocketServer server; - - //val: - //free - vilnyj - //busy - zajnjatyj - //unknown - nevidomyj - Dictionary<int, string> cleintStatus = new Dictionary<int, string>(); - - - public SocketServerTask() - { - server = new SocketServer(); - server.onDataArrived += DataArrived; - } - - public void Start() - { - server.Start(); - } - public void Stop() - { - server.Stop(); - } - - private bool ServerSend(SystemMessage mes, int TargetClientIndex) - { - return server.Send(mes, TargetClientIndex); - } - public override bool Send(SystemMessage message) - { - List<int> freeTesters = GetFreeTesters(); - if (freeTesters.Count != 0) - { - Random random = new Random(); - DataSender(message, freeTesters[random.Next() % freeTesters.Count]); - return true; - } - return false; - } - protected virtual void DataSender(SystemMessage message, int clientIndex) - { - //TODO: dlja cjogo bulo potribno pidkljuchyty EasySocket - // potim ne zabuty jogo vidjednaty vid chogo proektu - cleintStatus[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 (SystemMessageX(sysMes) == true) - return; - } - DataArriver(sysMes); - } - protected virtual void DataArriver(SystemMessage message) - { - cleintStatus[Int32.Parse(message.Description)] = "free"; - OnDataArrived(message); - } - - public int CountClients() - { - return server.CountClients; - } - - - 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. - /// ³\xE4\xEF\xF0\xE0\xE2\xEB\xFF\xBA \xEA\xEE\xE6\xED\xEE\xEC\xF3 \xF2\xE5\xF1\xF2\xE5\xF0\xF3 \xEF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xE5\xED\xED\xFF \xE2\xE8\xE3\xEB\xFF\xE4\xF3: - /// test HashCodeTester HashCode\xC7\xE0\xEF\xE8\xF2\xF3 - /// \xC4\xE5 HashCode\xC7\xE0\xEF\xE8\xF2\xF3 - \xF6\xE5 \xF3\xED\xB3\xEA\xE0\xEB\xFC\xED\xE8\xE9 \xF5\xE5\xF8 \xEA\xEE\xE4 \xEA\xEE\xE6\xED\xEE\xE3\xEE \xF2\xE0\xEA\xEE\xE3\xEE \xE7\xE0\xEF\xE8\xF2\xF3. - /// \xCF\xEE\xF2\xB3\xEC \xF7\xE5\xEA\xE0\xBA \xEE\xE4\xED\xF3 (1) \xF1\xE5\xEA\xF3\xED\xE4\xF3 \xEA\xEE\xEB\xE8 \xE7\xE0\xEF\xEE\xE2\xED\xE8\xF2\xFC\xF1\xFF q \xF1\xEF\xE8\xF1\xEA\xEE\xEC \xEF\xF0\xE8\xF1\xEB\xE0\xED\xE8\xF5 \xEF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xE5\xED\xFC - /// \xDF\xEA\xF9\xEE \xF2\xE5\xF1\xF2\xE5\xF0 \xEF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xFF\xBA \xF9\xEE \xE2\xB3\xED \xE2\xB3\xEB\xFC\xED\xE8\xE9, \xF2\xEE\xE4\xB3 \xE9\xEE\xE3\xEE \xED\xEE\xEC\xE5\xF0 \xE7\xE0\xED\xEE\xF1\xE8\xF2\xFC\xF1\xFF \xE4\xEE \xF0\xE5\xE7\xF3\xEB\xFC\xF2\xE0\xF2\xF3. - /// </summary> - /// <returns>\xD1\xEF\xE8\xF1\xEE\xEA \xE2\xB3\xEB\xFC\xED\xE8\xF5 \xF2\xE5\xF1\xF2\xE5\xF0\xB3\xE2</returns> - private List<int> GetFreeTesters() - { - if (server == null) - { - return new List<int>(); - } - - q.Clear(); - string curHashCode = DateTime.Now.GetHashCode().ToString(); - 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()] == "unknown") - { - string message = "test"; - message += " " + server.ClientsList[i].GetHashCode().ToString(); - message += " " + curHashCode; - SystemMessage mes = new SystemMessage(message, "SystemTestBusyMessage"); - ServerSend(mes, i); - } - } - - DateTime start = DateTime.Now; - Dictionary<string, int> preResult = new Dictionary<string, int>(); - while (server != null && preResult.Count < server.CountClients) - { - if (((TimeSpan)(DateTime.Now - start)).TotalSeconds > 1.0) - { - break; - } - lock (q) - { - while (q.Count != 0) - { - string curStr = q.Dequeue(); - char[] chars = new char[1]; - chars[0] = ' '; - string[] mes = curStr.Split(chars); - if (mes[0] == "free" && curHashCode == mes[2]) - { - cleintStatus[Int32.Parse(mes[1])] = "free"; - preResult.Add(mes[1], 0); - } - else - { - if (mes[0] == "busy") - { - cleintStatus[Int32.Parse(mes[1])] = "busy"; - } - } - } - } - System.Threading.Thread.Sleep(50); - } - - 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") - result.Add(i); - //string hashCode = server.ClientsList[i].GetHashCode().ToString(); - //if (preResult.ContainsKey(hashCode) == true) - // result.Add(i); - } - return result; - } - - /// <summary> - /// \xCF\xE5\xF0\xE5\xE2\xB3\xF0\xE0\xBA \xF7\xE8 \xF6\xE5 \xF1\xEB\xF3\xE6\xE1\xEE\xE2\xE5 \xEF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xE5\xED\xED\xFF. - /// \xDF\xEA\xF9\xEE \xF1\xEB\xF3\xE6\xE1\xEE\xE2\xE5, \xF2\xEE\xE4\xB3 \xE2\xEE\xED\xEE \xE7\xE0\xED\xEE\xF1\xE8\xF2\xFC\xF1\xFF \xE4\xEE \xF1\xEF\xE8\xF1\xEA\xF3 q - /// </summary> - /// <param name="message">\xCF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xE5\xED\xED\xFF</param> - /// <returns>\xDF\xEA\xF9\xEE \xF6\xE5 \xF1\xEB\xF3\xE6\xE1\xEE\xE2\xE5 \xEF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xE5\xED\xED\xFF, \xF2\xEE\xE4\xB3 \xEF\xEE\xE2\xE5\xF0\xF2\xE0\xBA\xF2\xFC\xF1\xFF true \xEF\xEE \xB3\xED\xE0\xEA\xF8\xEE\xEC\xF3 false</returns> - private bool SystemMessageX(SystemMessage message) - { - char[] chars = new char[1]; - chars[0] = ' '; - string[] mes = message.Message.Split(chars); - if (mes[0] == "busy" || mes[0] == "free") - { - lock(q) - q.Enqueue(message.Message); - return true; - } - return false; - } - } -} Modified: ACMServer/trunk/ACMServer/Tester/Library/SocketClientGate.cs =================================================================== --- ACMServer/trunk/ACMServer/Tester/Library/SocketClientGate.cs 2008-10-07 21:07:31 UTC (rev 411) +++ ACMServer/trunk/ACMServer/Tester/Library/SocketClientGate.cs 2008-10-08 13:15:26 UTC (rev 412) @@ -1,77 +1,44 @@ using System; -using AcmContester.Library.Connector; using AcmContester.Library.LibraryExtention; using AcmContester.Library.LibraryExtention.Data; +using AcmContester.Library.Connector; namespace AcmContester.Tester.Library { class SocketClientGate: AbstractConnector { - SocketClient client; - private string descriptionMessage = ""; + SocketClientTask client; //TODO: tut vin tymchasovo, potribno bude perenesty jogo kudys dali private WorkRunner workRunner = new WorkRunner(); public SocketClientGate(string IP) { - client = new SocketClient(IP); + client = new SocketClientTask(IP); client.onDataArrived +=new SocketClient.DataArrivedDelegate(SocketClientGate_onDataArrived); + client.onAddLogText += OnAddLogText; + client.isBusy += IsBusy; workRunner.onDataArrived += Send; } + bool IsBusy() + { + return workRunner.IsBusy(); + } + void SocketClientGate_onDataArrived(SystemMessage message) { - if (message.IsType("SystemTestBusyMessage") == true) - { - if (SystemMessageX(message) == true) - return; - } OnAddLogText("Receive", message.Message); - descriptionMessage = message.Description; - if (message.IsType("TestingSubmit") == true) { workRunner.AddWork(message.Message); } } - - - private bool SystemMessageX(SystemMessage _message) - { - string message = _message.Message; - char[] chars = new char[1]; - chars[0] = ' '; - string[] mes = message.Split(chars); - if (mes[0] == "test") - { - OnAddLogText("SystemReceive", message); - string result = ""; - if (workRunner.IsBusy() == true) - { - result = "busy"; - } - else - { - result = "free"; - } - for (int i = 1; i < mes.Length; i++) - { - result += " " + mes[i]; - } - OnAddLogText("SystemSend", result); - this.Send(new SystemMessage(result, _message.Type, _message.Description)); - return true; - } - return false; - } - public override bool Send(SystemMessage message) { message = new SystemMessage(message); - message.Description = descriptionMessage; if (message.IsType("TestingResult") == true) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2008-10-07 21:07:38
|
Revision: 411 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=411&view=rev Author: brus07 Date: 2008-10-07 21:07:31 +0000 (Tue, 07 Oct 2008) Log Message: ----------- Continues added new class architecture for Connector module. Modified Paths: -------------- ACMServer/trunk/ACMServer/Library/Connector/Connector.csproj ACMServer/trunk/ACMServer/Library/Connector/SocketClient.cs ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGate.cs ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGatePlugin.csproj ACMServer/trunk/ACMServer/Tester/Library/SocketClientGate.cs Added Paths: ----------- ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerTask.cs Removed Paths: ------------- ACMServer/trunk/ACMServer/Library/Connector/SocketClientTask.cs ACMServer/trunk/ACMServer/Library/Connector/SocketServerTask.cs Modified: ACMServer/trunk/ACMServer/Library/Connector/Connector.csproj =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/Connector.csproj 2008-10-07 20:32:33 UTC (rev 410) +++ ACMServer/trunk/ACMServer/Library/Connector/Connector.csproj 2008-10-07 21:07:31 UTC (rev 411) @@ -42,9 +42,10 @@ <Compile Include="Getter\IGetter.cs" /> <Compile Include="Getter\WebGetterOld.cs" /> <Compile Include="SocketClient.cs" /> - <Compile Include="SocketClientTask.cs" /> - <Compile Include="SocketServer.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="SocketServer.cs"> + <SubType>Code</SubType> + </Compile> <Compile Include="WebConnector.cs" /> </ItemGroup> <ItemGroup> Modified: ACMServer/trunk/ACMServer/Library/Connector/SocketClient.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/SocketClient.cs 2008-10-07 20:32:33 UTC (rev 410) +++ ACMServer/trunk/ACMServer/Library/Connector/SocketClient.cs 2008-10-07 21:07:31 UTC (rev 411) @@ -6,20 +6,32 @@ { public class SocketClient: AbstractConnector { - EasyClient client; - string ip = "127.0.0.1"; int port = 4120; + EasyClient client; + + void init() + { + client = new EasyClient(new ServerInfo(this.ip, this.port, true)); + client.DataArrived += DataArrived; + } + public SocketClient() { + init(); } public SocketClient(string IP) { this.ip = IP; - client = new EasyClient(new ServerInfo(this.ip, this.port, true)); - client.DataArrived += DataArrived; + init(); } + public SocketClient(string IP, int Port) + { + this.ip = IP; + this.port = Port; + init(); + } public void Connect() { @@ -32,11 +44,21 @@ } public void Disconnect() { - if (client.IsConnected == true) - client.DisconnectFromServer(); - client.Dispose(); - client = null; + if (client != null) + { + if (client.IsConnected == true) + client.DisconnectFromServer(); + client.Dispose(); + client = null; + } } + public bool IsConnected() + { + if (client == null) + return false; + return client.IsConnected; + } + public override bool Send(SystemMessage message) { byte[] bytes = SystemMessage.Serialize(message); @@ -50,11 +72,5 @@ OnDataArrived(mes); } - public bool IsConnected() - { - if (client == null) - return false; - return client.IsConnected; - } } } Deleted: ACMServer/trunk/ACMServer/Library/Connector/SocketClientTask.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/SocketClientTask.cs 2008-10-07 20:32:33 UTC (rev 410) +++ ACMServer/trunk/ACMServer/Library/Connector/SocketClientTask.cs 2008-10-07 21:07:31 UTC (rev 411) @@ -1,37 +0,0 @@ -using System; -using AcmContester.Library.LibraryExtention; - -namespace AcmContester.Library.Connector -{ - public class SocketClientTask: AbstractConnector - { - SocketClient client; - - public SocketClientTask(string IP) - { - client = new SocketClient(IP); - client.onDataArrived += base.OnDataArrived; - } - - public override bool Send(SystemMessage message) - { - return client.Send(message); - } - - public void Connect() - { - client.Connect(); - } - - public void Disconnect() - { - if (client.IsConnected() == true) - client.Disconnect(); - } - - public bool IsConnected() - { - return client.IsConnected(); - } - } -} Deleted: ACMServer/trunk/ACMServer/Library/Connector/SocketServerTask.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/SocketServerTask.cs 2008-10-07 20:32:33 UTC (rev 410) +++ ACMServer/trunk/ACMServer/Library/Connector/SocketServerTask.cs 2008-10-07 21:07:31 UTC (rev 411) @@ -1,180 +0,0 @@ -using System; -using JadBenAutho.EasySocket; -using System.Collections.Generic; -using AcmContester.Library.LibraryExtention; - -namespace AcmContester.Library.Connector -{ - public class SocketServerTask: AbstractConnector - { - SocketServer server; - - //val: - //free - vilnyj - //busy - zajnjatyj - //unknown - nevidomyj - Dictionary<int, string> cleintStatus = new Dictionary<int, string>(); - - - public SocketServerTask() - { - server = new SocketServer(); - server.onDataArrived += DataArrived; - } - - public void Start() - { - server.Start(); - } - public void Stop() - { - server.Stop(); - } - - private bool ServerSend(SystemMessage mes, int TargetClientIndex) - { - return server.Send(mes, TargetClientIndex); - } - public override bool Send(SystemMessage message) - { - List<int> freeTesters = GetFreeTesters(); - if (freeTesters.Count != 0) - { - Random random = new Random(); - DataSender(message, freeTesters[random.Next() % freeTesters.Count]); - return true; - } - return false; - } - protected virtual void DataSender(SystemMessage message, int clientIndex) - { - cleintStatus[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 (SystemMessageX(sysMes) == true) - return; - } - DataArriver(sysMes); - } - protected virtual void DataArriver(SystemMessage message) - { - cleintStatus[Int32.Parse(message.Description)] = "free"; - OnDataArrived(message); - } - - public int CountClients() - { - return server.CountClients; - } - - - 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. - /// ³\xE4\xEF\xF0\xE0\xE2\xEB\xFF\xBA \xEA\xEE\xE6\xED\xEE\xEC\xF3 \xF2\xE5\xF1\xF2\xE5\xF0\xF3 \xEF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xE5\xED\xED\xFF \xE2\xE8\xE3\xEB\xFF\xE4\xF3: - /// test HashCodeTester HashCode\xC7\xE0\xEF\xE8\xF2\xF3 - /// \xC4\xE5 HashCode\xC7\xE0\xEF\xE8\xF2\xF3 - \xF6\xE5 \xF3\xED\xB3\xEA\xE0\xEB\xFC\xED\xE8\xE9 \xF5\xE5\xF8 \xEA\xEE\xE4 \xEA\xEE\xE6\xED\xEE\xE3\xEE \xF2\xE0\xEA\xEE\xE3\xEE \xE7\xE0\xEF\xE8\xF2\xF3. - /// \xCF\xEE\xF2\xB3\xEC \xF7\xE5\xEA\xE0\xBA \xEE\xE4\xED\xF3 (1) \xF1\xE5\xEA\xF3\xED\xE4\xF3 \xEA\xEE\xEB\xE8 \xE7\xE0\xEF\xEE\xE2\xED\xE8\xF2\xFC\xF1\xFF q \xF1\xEF\xE8\xF1\xEA\xEE\xEC \xEF\xF0\xE8\xF1\xEB\xE0\xED\xE8\xF5 \xEF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xE5\xED\xFC - /// \xDF\xEA\xF9\xEE \xF2\xE5\xF1\xF2\xE5\xF0 \xEF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xFF\xBA \xF9\xEE \xE2\xB3\xED \xE2\xB3\xEB\xFC\xED\xE8\xE9, \xF2\xEE\xE4\xB3 \xE9\xEE\xE3\xEE \xED\xEE\xEC\xE5\xF0 \xE7\xE0\xED\xEE\xF1\xE8\xF2\xFC\xF1\xFF \xE4\xEE \xF0\xE5\xE7\xF3\xEB\xFC\xF2\xE0\xF2\xF3. - /// </summary> - /// <returns>\xD1\xEF\xE8\xF1\xEE\xEA \xE2\xB3\xEB\xFC\xED\xE8\xF5 \xF2\xE5\xF1\xF2\xE5\xF0\xB3\xE2</returns> - private List<int> GetFreeTesters() - { - if (server == null) - { - return new List<int>(); - } - - q.Clear(); - string curHashCode = DateTime.Now.GetHashCode().ToString(); - 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()] == "unknown") - { - string message = "test"; - message += " " + server.ClientsList[i].GetHashCode().ToString(); - message += " " + curHashCode; - SystemMessage mes = new SystemMessage(message, "SystemTestBusyMessage"); - ServerSend(mes, i); - } - } - - DateTime start = DateTime.Now; - Dictionary<string, int> preResult = new Dictionary<string, int>(); - while (server != null && preResult.Count < server.CountClients) - { - if (((TimeSpan)(DateTime.Now - start)).TotalSeconds > 1.0) - { - break; - } - lock (q) - { - while (q.Count != 0) - { - string curStr = q.Dequeue(); - char[] chars = new char[1]; - chars[0] = ' '; - string[] mes = curStr.Split(chars); - if (mes[0] == "free" && curHashCode == mes[2]) - { - cleintStatus[Int32.Parse(mes[1])] = "free"; - preResult.Add(mes[1], 0); - } - else - { - if (mes[0] == "busy") - { - cleintStatus[Int32.Parse(mes[1])] = "busy"; - } - } - } - } - System.Threading.Thread.Sleep(50); - } - - 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") - result.Add(i); - //string hashCode = server.ClientsList[i].GetHashCode().ToString(); - //if (preResult.ContainsKey(hashCode) == true) - // result.Add(i); - } - return result; - } - - /// <summary> - /// \xCF\xE5\xF0\xE5\xE2\xB3\xF0\xE0\xBA \xF7\xE8 \xF6\xE5 \xF1\xEB\xF3\xE6\xE1\xEE\xE2\xE5 \xEF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xE5\xED\xED\xFF. - /// \xDF\xEA\xF9\xEE \xF1\xEB\xF3\xE6\xE1\xEE\xE2\xE5, \xF2\xEE\xE4\xB3 \xE2\xEE\xED\xEE \xE7\xE0\xED\xEE\xF1\xE8\xF2\xFC\xF1\xFF \xE4\xEE \xF1\xEF\xE8\xF1\xEA\xF3 q - /// </summary> - /// <param name="message">\xCF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xE5\xED\xED\xFF</param> - /// <returns>\xDF\xEA\xF9\xEE \xF6\xE5 \xF1\xEB\xF3\xE6\xE1\xEE\xE2\xE5 \xEF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xE5\xED\xED\xFF, \xF2\xEE\xE4\xB3 \xEF\xEE\xE2\xE5\xF0\xF2\xE0\xBA\xF2\xFC\xF1\xFF true \xEF\xEE \xB3\xED\xE0\xEA\xF8\xEE\xEC\xF3 false</returns> - private bool SystemMessageX(SystemMessage message) - { - char[] chars = new char[1]; - chars[0] = ' '; - string[] mes = message.Message.Split(chars); - if (mes[0] == "busy" || mes[0] == "free") - { - lock(q) - q.Enqueue(message.Message); - return true; - } - return false; - } - } -} Modified: ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGate.cs =================================================================== --- ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGate.cs 2008-10-07 20:32:33 UTC (rev 410) +++ ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGate.cs 2008-10-07 21:07:31 UTC (rev 411) @@ -10,7 +10,7 @@ /// <summary> /// Pattern: Singleton /// </summary> - class SocketServerGate : SocketServer + class SocketServerGate : SocketServerTask { private static SocketServerGate instance = new SocketServerGate(); Modified: ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGatePlugin.csproj =================================================================== --- ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGatePlugin.csproj 2008-10-07 20:32:33 UTC (rev 410) +++ ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGatePlugin.csproj 2008-10-07 21:07:31 UTC (rev 411) @@ -28,6 +28,10 @@ <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> + <Reference Include="EasySocket, Version=1.0.2082.18867, Culture=neutral"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\..\..\Resource\EasySocket.dll</HintPath> + </Reference> <Reference Include="LogDataGridView, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>..\..\..\Resource\LogDataGridView.dll</HintPath> @@ -48,6 +52,7 @@ <Compile Include="SocketServerGatePluginUserControl.Designer.cs"> <DependentUpon>SocketServerGatePluginUserControl.cs</DependentUpon> </Compile> + <Compile Include="SocketServerTask.cs" /> <Compile Include="WorkingPool.cs" /> </ItemGroup> <ItemGroup> Copied: ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerTask.cs (from rev 410, ACMServer/trunk/ACMServer/Library/Connector/SocketServerTask.cs) =================================================================== --- ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerTask.cs (rev 0) +++ ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerTask.cs 2008-10-07 21:07:31 UTC (rev 411) @@ -0,0 +1,182 @@ +using System; +using System.Collections.Generic; +using AcmContester.Library.LibraryExtention; +using AcmContester.Library.Connector; + +namespace AcmContester.Plugins.MediatorPlugins.SocketServerGatePlugin +{ + public class SocketServerTask: AbstractConnector + { + SocketServer server; + + //val: + //free - vilnyj + //busy - zajnjatyj + //unknown - nevidomyj + Dictionary<int, string> cleintStatus = new Dictionary<int, string>(); + + + public SocketServerTask() + { + server = new SocketServer(); + server.onDataArrived += DataArrived; + } + + public void Start() + { + server.Start(); + } + public void Stop() + { + server.Stop(); + } + + private bool ServerSend(SystemMessage mes, int TargetClientIndex) + { + return server.Send(mes, TargetClientIndex); + } + public override bool Send(SystemMessage message) + { + List<int> freeTesters = GetFreeTesters(); + if (freeTesters.Count != 0) + { + Random random = new Random(); + DataSender(message, freeTesters[random.Next() % freeTesters.Count]); + return true; + } + return false; + } + protected virtual void DataSender(SystemMessage message, int clientIndex) + { + //TODO: dlja cjogo bulo potribno pidkljuchyty EasySocket + // potim ne zabuty jogo vidjednaty vid chogo proektu + cleintStatus[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 (SystemMessageX(sysMes) == true) + return; + } + DataArriver(sysMes); + } + protected virtual void DataArriver(SystemMessage message) + { + cleintStatus[Int32.Parse(message.Description)] = "free"; + OnDataArrived(message); + } + + public int CountClients() + { + return server.CountClients; + } + + + 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. + /// ³\xE4\xEF\xF0\xE0\xE2\xEB\xFF\xBA \xEA\xEE\xE6\xED\xEE\xEC\xF3 \xF2\xE5\xF1\xF2\xE5\xF0\xF3 \xEF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xE5\xED\xED\xFF \xE2\xE8\xE3\xEB\xFF\xE4\xF3: + /// test HashCodeTester HashCode\xC7\xE0\xEF\xE8\xF2\xF3 + /// \xC4\xE5 HashCode\xC7\xE0\xEF\xE8\xF2\xF3 - \xF6\xE5 \xF3\xED\xB3\xEA\xE0\xEB\xFC\xED\xE8\xE9 \xF5\xE5\xF8 \xEA\xEE\xE4 \xEA\xEE\xE6\xED\xEE\xE3\xEE \xF2\xE0\xEA\xEE\xE3\xEE \xE7\xE0\xEF\xE8\xF2\xF3. + /// \xCF\xEE\xF2\xB3\xEC \xF7\xE5\xEA\xE0\xBA \xEE\xE4\xED\xF3 (1) \xF1\xE5\xEA\xF3\xED\xE4\xF3 \xEA\xEE\xEB\xE8 \xE7\xE0\xEF\xEE\xE2\xED\xE8\xF2\xFC\xF1\xFF q \xF1\xEF\xE8\xF1\xEA\xEE\xEC \xEF\xF0\xE8\xF1\xEB\xE0\xED\xE8\xF5 \xEF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xE5\xED\xFC + /// \xDF\xEA\xF9\xEE \xF2\xE5\xF1\xF2\xE5\xF0 \xEF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xFF\xBA \xF9\xEE \xE2\xB3\xED \xE2\xB3\xEB\xFC\xED\xE8\xE9, \xF2\xEE\xE4\xB3 \xE9\xEE\xE3\xEE \xED\xEE\xEC\xE5\xF0 \xE7\xE0\xED\xEE\xF1\xE8\xF2\xFC\xF1\xFF \xE4\xEE \xF0\xE5\xE7\xF3\xEB\xFC\xF2\xE0\xF2\xF3. + /// </summary> + /// <returns>\xD1\xEF\xE8\xF1\xEE\xEA \xE2\xB3\xEB\xFC\xED\xE8\xF5 \xF2\xE5\xF1\xF2\xE5\xF0\xB3\xE2</returns> + private List<int> GetFreeTesters() + { + if (server == null) + { + return new List<int>(); + } + + q.Clear(); + string curHashCode = DateTime.Now.GetHashCode().ToString(); + 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()] == "unknown") + { + string message = "test"; + message += " " + server.ClientsList[i].GetHashCode().ToString(); + message += " " + curHashCode; + SystemMessage mes = new SystemMessage(message, "SystemTestBusyMessage"); + ServerSend(mes, i); + } + } + + DateTime start = DateTime.Now; + Dictionary<string, int> preResult = new Dictionary<string, int>(); + while (server != null && preResult.Count < server.CountClients) + { + if (((TimeSpan)(DateTime.Now - start)).TotalSeconds > 1.0) + { + break; + } + lock (q) + { + while (q.Count != 0) + { + string curStr = q.Dequeue(); + char[] chars = new char[1]; + chars[0] = ' '; + string[] mes = curStr.Split(chars); + if (mes[0] == "free" && curHashCode == mes[2]) + { + cleintStatus[Int32.Parse(mes[1])] = "free"; + preResult.Add(mes[1], 0); + } + else + { + if (mes[0] == "busy") + { + cleintStatus[Int32.Parse(mes[1])] = "busy"; + } + } + } + } + System.Threading.Thread.Sleep(50); + } + + 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") + result.Add(i); + //string hashCode = server.ClientsList[i].GetHashCode().ToString(); + //if (preResult.ContainsKey(hashCode) == true) + // result.Add(i); + } + return result; + } + + /// <summary> + /// \xCF\xE5\xF0\xE5\xE2\xB3\xF0\xE0\xBA \xF7\xE8 \xF6\xE5 \xF1\xEB\xF3\xE6\xE1\xEE\xE2\xE5 \xEF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xE5\xED\xED\xFF. + /// \xDF\xEA\xF9\xEE \xF1\xEB\xF3\xE6\xE1\xEE\xE2\xE5, \xF2\xEE\xE4\xB3 \xE2\xEE\xED\xEE \xE7\xE0\xED\xEE\xF1\xE8\xF2\xFC\xF1\xFF \xE4\xEE \xF1\xEF\xE8\xF1\xEA\xF3 q + /// </summary> + /// <param name="message">\xCF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xE5\xED\xED\xFF</param> + /// <returns>\xDF\xEA\xF9\xEE \xF6\xE5 \xF1\xEB\xF3\xE6\xE1\xEE\xE2\xE5 \xEF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xE5\xED\xED\xFF, \xF2\xEE\xE4\xB3 \xEF\xEE\xE2\xE5\xF0\xF2\xE0\xBA\xF2\xFC\xF1\xFF true \xEF\xEE \xB3\xED\xE0\xEA\xF8\xEE\xEC\xF3 false</returns> + private bool SystemMessageX(SystemMessage message) + { + char[] chars = new char[1]; + chars[0] = ' '; + string[] mes = message.Message.Split(chars); + if (mes[0] == "busy" || mes[0] == "free") + { + lock(q) + q.Enqueue(message.Message); + return true; + } + return false; + } + } +} Modified: ACMServer/trunk/ACMServer/Tester/Library/SocketClientGate.cs =================================================================== --- ACMServer/trunk/ACMServer/Tester/Library/SocketClientGate.cs 2008-10-07 20:32:33 UTC (rev 410) +++ ACMServer/trunk/ACMServer/Tester/Library/SocketClientGate.cs 2008-10-07 21:07:31 UTC (rev 411) @@ -1,22 +1,22 @@ using System; using AcmContester.Library.Connector; -using System.Threading; using AcmContester.Library.LibraryExtention; using AcmContester.Library.LibraryExtention.Data; namespace AcmContester.Tester.Library { - class SocketClientGate: SocketClientTask + class SocketClientGate: AbstractConnector { + SocketClient client; private string descriptionMessage = ""; //TODO: tut vin tymchasovo, potribno bude perenesty jogo kudys dali private WorkRunner workRunner = new WorkRunner(); public SocketClientGate(string IP) - : base(IP) { - base.onDataArrived +=new SocketClient.DataArrivedDelegate(SocketClientGate_onDataArrived); + client = new SocketClient(IP); + client.onDataArrived +=new SocketClient.DataArrivedDelegate(SocketClientGate_onDataArrived); workRunner.onDataArrived += Send; } @@ -37,11 +37,6 @@ } } - public new void Disconnect() - { - workRunner.Stop(); - base.Disconnect(); - } private bool SystemMessageX(SystemMessage _message) @@ -67,7 +62,7 @@ result += " " + mes[i]; } OnAddLogText("SystemSend", result); - base.Send(new SystemMessage(result, _message.Type, _message.Description)); + this.Send(new SystemMessage(result, _message.Type, _message.Description)); return true; } return false; @@ -78,10 +73,13 @@ message = new SystemMessage(message); message.Description = descriptionMessage; - Result res = Result.CreateFromXml(message.Message); - OnAddLogText("Send", "ID " + res.Submit.id + " result - " + res.res); + if (message.IsType("TestingResult") == true) + { + Result res = Result.CreateFromXml(message.Message); + OnAddLogText("Send", "ID " + res.Submit.id + " result - " + res.res); + } - return base.Send(message); + return client.Send(message); } public delegate void AddLogTextDelegate(string type, string text); @@ -91,5 +89,19 @@ if (onAddLogText != null) onAddLogText(type,text); } + + public void Connect() + { + client.Connect(); + } + public void Disconnect() + { + client.Disconnect(); + workRunner.Stop(); + } + public bool IsConnected() + { + return client.IsConnected(); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2008-10-07 20:32:42
|
Revision: 410 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=410&view=rev Author: brus07 Date: 2008-10-07 20:32:33 +0000 (Tue, 07 Oct 2008) Log Message: ----------- Preparing commit. Added Paths: ----------- ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs ACMServer/trunk/ACMServer/Library/Connector/SocketServerTask.cs Removed Paths: ------------- ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs Deleted: ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs 2008-10-07 16:01:38 UTC (rev 409) +++ ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs 2008-10-07 20:32:33 UTC (rev 410) @@ -1,190 +0,0 @@ -using System; -using JadBenAutho.EasySocket; -using System.Collections.Generic; -using AcmContester.Library.LibraryExtention; - -namespace AcmContester.Library.Connector -{ - public class SocketServer: AbstractConnector - { - int port = 4120; - EasyServer server; - - //val: - //free - vilnyj - //busy - zajnjatyj - //unknown - nevidomyj - Dictionary<int, string> cleintStatus = new Dictionary<int, string>(); - - - public SocketServer() - { - server = new EasyServer(port, true); - server.DataArrived += new DataArrived2Server_EventHandler(DataArrived); - } - - public void Start() - { - if (server == null) - server = new EasyServer(port, true); - server.StartListen(); - } - public void Stop() - { - if (server != null) - { - server.StopListen(); - server.Dispose(); - server = null; - } - } - - private void ServerSend(SystemMessage mes, int TargetClientIndex) - { - byte[] bytes = SystemMessage.Serialize(mes); - server.SendData(bytes, TargetClientIndex); - } - public override bool Send(SystemMessage message) - { - List<int> freeTesters = GetFreeTesters(); - if (freeTesters.Count != 0) - { - Random random = new Random(); - DataSender(message, freeTesters[random.Next() % freeTesters.Count]); - return true; - } - return false; - } - protected virtual void DataSender(SystemMessage message, int clientIndex) - { - cleintStatus[server.ClientsList[clientIndex].GetHashCode()] = "busy"; - message.Description = server.ClientsList[clientIndex].GetHashCode().ToString(); - ServerSend(message, clientIndex); - } - - private void DataArrived(object Data, SocketStream DataSender) - { - SystemMessage sysMes = SystemMessage.Deserialize((byte[])Data); - if (sysMes.IsType("SystemTestBusyMessage") == true) - { - if (SystemMessageX(sysMes) == true) - return; - } - DataArriver(sysMes); - } - protected virtual void DataArriver(SystemMessage message) - { - cleintStatus[Int32.Parse(message.Description)] = "free"; - OnDataArrived(message); - } - - public int CountClients() - { - return server.CountClients; - } - - - 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. - /// ³\xE4\xEF\xF0\xE0\xE2\xEB\xFF\xBA \xEA\xEE\xE6\xED\xEE\xEC\xF3 \xF2\xE5\xF1\xF2\xE5\xF0\xF3 \xEF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xE5\xED\xED\xFF \xE2\xE8\xE3\xEB\xFF\xE4\xF3: - /// test HashCodeTester HashCode\xC7\xE0\xEF\xE8\xF2\xF3 - /// \xC4\xE5 HashCode\xC7\xE0\xEF\xE8\xF2\xF3 - \xF6\xE5 \xF3\xED\xB3\xEA\xE0\xEB\xFC\xED\xE8\xE9 \xF5\xE5\xF8 \xEA\xEE\xE4 \xEA\xEE\xE6\xED\xEE\xE3\xEE \xF2\xE0\xEA\xEE\xE3\xEE \xE7\xE0\xEF\xE8\xF2\xF3. - /// \xCF\xEE\xF2\xB3\xEC \xF7\xE5\xEA\xE0\xBA \xEE\xE4\xED\xF3 (1) \xF1\xE5\xEA\xF3\xED\xE4\xF3 \xEA\xEE\xEB\xE8 \xE7\xE0\xEF\xEE\xE2\xED\xE8\xF2\xFC\xF1\xFF q \xF1\xEF\xE8\xF1\xEA\xEE\xEC \xEF\xF0\xE8\xF1\xEB\xE0\xED\xE8\xF5 \xEF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xE5\xED\xFC - /// \xDF\xEA\xF9\xEE \xF2\xE5\xF1\xF2\xE5\xF0 \xEF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xFF\xBA \xF9\xEE \xE2\xB3\xED \xE2\xB3\xEB\xFC\xED\xE8\xE9, \xF2\xEE\xE4\xB3 \xE9\xEE\xE3\xEE \xED\xEE\xEC\xE5\xF0 \xE7\xE0\xED\xEE\xF1\xE8\xF2\xFC\xF1\xFF \xE4\xEE \xF0\xE5\xE7\xF3\xEB\xFC\xF2\xE0\xF2\xF3. - /// </summary> - /// <returns>\xD1\xEF\xE8\xF1\xEE\xEA \xE2\xB3\xEB\xFC\xED\xE8\xF5 \xF2\xE5\xF1\xF2\xE5\xF0\xB3\xE2</returns> - private List<int> GetFreeTesters() - { - if (server == null) - { - return new List<int>(); - } - - q.Clear(); - string curHashCode = DateTime.Now.GetHashCode().ToString(); - 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()] == "unknown") - { - string message = "test"; - message += " " + server.ClientsList[i].GetHashCode().ToString(); - message += " " + curHashCode; - SystemMessage mes = new SystemMessage(message, "SystemTestBusyMessage"); - ServerSend(mes, i); - } - } - - DateTime start = DateTime.Now; - Dictionary<string, int> preResult = new Dictionary<string, int>(); - while (server != null && preResult.Count < server.CountClients) - { - if (((TimeSpan)(DateTime.Now - start)).TotalSeconds > 1.0) - { - break; - } - lock (q) - { - while (q.Count != 0) - { - string curStr = q.Dequeue(); - char[] chars = new char[1]; - chars[0] = ' '; - string[] mes = curStr.Split(chars); - if (mes[0] == "free" && curHashCode == mes[2]) - { - cleintStatus[Int32.Parse(mes[1])] = "free"; - preResult.Add(mes[1], 0); - } - else - { - if (mes[0] == "busy") - { - cleintStatus[Int32.Parse(mes[1])] = "busy"; - } - } - } - } - System.Threading.Thread.Sleep(50); - } - - 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") - result.Add(i); - //string hashCode = server.ClientsList[i].GetHashCode().ToString(); - //if (preResult.ContainsKey(hashCode) == true) - // result.Add(i); - } - return result; - } - - /// <summary> - /// \xCF\xE5\xF0\xE5\xE2\xB3\xF0\xE0\xBA \xF7\xE8 \xF6\xE5 \xF1\xEB\xF3\xE6\xE1\xEE\xE2\xE5 \xEF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xE5\xED\xED\xFF. - /// \xDF\xEA\xF9\xEE \xF1\xEB\xF3\xE6\xE1\xEE\xE2\xE5, \xF2\xEE\xE4\xB3 \xE2\xEE\xED\xEE \xE7\xE0\xED\xEE\xF1\xE8\xF2\xFC\xF1\xFF \xE4\xEE \xF1\xEF\xE8\xF1\xEA\xF3 q - /// </summary> - /// <param name="message">\xCF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xE5\xED\xED\xFF</param> - /// <returns>\xDF\xEA\xF9\xEE \xF6\xE5 \xF1\xEB\xF3\xE6\xE1\xEE\xE2\xE5 \xEF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xE5\xED\xED\xFF, \xF2\xEE\xE4\xB3 \xEF\xEE\xE2\xE5\xF0\xF2\xE0\xBA\xF2\xFC\xF1\xFF true \xEF\xEE \xB3\xED\xE0\xEA\xF8\xEE\xEC\xF3 false</returns> - private bool SystemMessageX(SystemMessage message) - { - char[] chars = new char[1]; - chars[0] = ' '; - string[] mes = message.Message.Split(chars); - if (mes[0] == "busy" || mes[0] == "free") - { - lock(q) - q.Enqueue(message.Message); - return true; - } - return false; - } - } -} Added: ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs (rev 0) +++ ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs 2008-10-07 20:32:33 UTC (rev 410) @@ -0,0 +1,79 @@ +using System; +using AcmContester.Library.LibraryExtention; +using JadBenAutho.EasySocket; + +namespace AcmContester.Library.Connector +{ + public class SocketServer: AbstractConnector + { + int port = 4120; + EasyServer server; + + private void init() + { + server = new EasyServer(port, true); + server.DataArrived += DataArrived; + } + + public SocketServer() + { + init(); + } + public SocketServer(int Port) + { + this.port = Port; + init(); + } + + public void Start() + { + if (server == null) + server = new EasyServer(port, true); + server.StartListen(); + } + public void Stop() + { + if (server != null) + { + server.StopListen(); + server.Dispose(); + server = null; + } + } + public int CountClients + { + get + { + return server.CountClients; + } + } + + public virtual bool Send(SystemMessage mes, int TargetClientIndex) + { + byte[] bytes = SystemMessage.Serialize(mes); + return server.SendData(bytes, TargetClientIndex); + } + + public override bool Send(SystemMessage message) + { + //TODO: jogo ne mozna juzaty u cjomu vypadku + throw new Exception("The method or operation is not implemented."); + } + + private void DataArrived(object Data, SocketStream DataSender) + { + SystemMessage sysMes = SystemMessage.Deserialize((byte[])Data); + OnDataArrived(sysMes); + } + + //TODO: tymchasovo haj bude + // ale potim potribno bude braty hash naprjami iz realnogo Client'a (haj persylajutsja) + public SocketsList ClientsList + { + get + { + return server.ClientsList; + } + } + } +} Copied: ACMServer/trunk/ACMServer/Library/Connector/SocketServerTask.cs (from rev 409, ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs) =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/SocketServerTask.cs (rev 0) +++ ACMServer/trunk/ACMServer/Library/Connector/SocketServerTask.cs 2008-10-07 20:32:33 UTC (rev 410) @@ -0,0 +1,180 @@ +using System; +using JadBenAutho.EasySocket; +using System.Collections.Generic; +using AcmContester.Library.LibraryExtention; + +namespace AcmContester.Library.Connector +{ + public class SocketServerTask: AbstractConnector + { + SocketServer server; + + //val: + //free - vilnyj + //busy - zajnjatyj + //unknown - nevidomyj + Dictionary<int, string> cleintStatus = new Dictionary<int, string>(); + + + public SocketServerTask() + { + server = new SocketServer(); + server.onDataArrived += DataArrived; + } + + public void Start() + { + server.Start(); + } + public void Stop() + { + server.Stop(); + } + + private bool ServerSend(SystemMessage mes, int TargetClientIndex) + { + return server.Send(mes, TargetClientIndex); + } + public override bool Send(SystemMessage message) + { + List<int> freeTesters = GetFreeTesters(); + if (freeTesters.Count != 0) + { + Random random = new Random(); + DataSender(message, freeTesters[random.Next() % freeTesters.Count]); + return true; + } + return false; + } + protected virtual void DataSender(SystemMessage message, int clientIndex) + { + cleintStatus[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 (SystemMessageX(sysMes) == true) + return; + } + DataArriver(sysMes); + } + protected virtual void DataArriver(SystemMessage message) + { + cleintStatus[Int32.Parse(message.Description)] = "free"; + OnDataArrived(message); + } + + public int CountClients() + { + return server.CountClients; + } + + + 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. + /// ³\xE4\xEF\xF0\xE0\xE2\xEB\xFF\xBA \xEA\xEE\xE6\xED\xEE\xEC\xF3 \xF2\xE5\xF1\xF2\xE5\xF0\xF3 \xEF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xE5\xED\xED\xFF \xE2\xE8\xE3\xEB\xFF\xE4\xF3: + /// test HashCodeTester HashCode\xC7\xE0\xEF\xE8\xF2\xF3 + /// \xC4\xE5 HashCode\xC7\xE0\xEF\xE8\xF2\xF3 - \xF6\xE5 \xF3\xED\xB3\xEA\xE0\xEB\xFC\xED\xE8\xE9 \xF5\xE5\xF8 \xEA\xEE\xE4 \xEA\xEE\xE6\xED\xEE\xE3\xEE \xF2\xE0\xEA\xEE\xE3\xEE \xE7\xE0\xEF\xE8\xF2\xF3. + /// \xCF\xEE\xF2\xB3\xEC \xF7\xE5\xEA\xE0\xBA \xEE\xE4\xED\xF3 (1) \xF1\xE5\xEA\xF3\xED\xE4\xF3 \xEA\xEE\xEB\xE8 \xE7\xE0\xEF\xEE\xE2\xED\xE8\xF2\xFC\xF1\xFF q \xF1\xEF\xE8\xF1\xEA\xEE\xEC \xEF\xF0\xE8\xF1\xEB\xE0\xED\xE8\xF5 \xEF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xE5\xED\xFC + /// \xDF\xEA\xF9\xEE \xF2\xE5\xF1\xF2\xE5\xF0 \xEF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xFF\xBA \xF9\xEE \xE2\xB3\xED \xE2\xB3\xEB\xFC\xED\xE8\xE9, \xF2\xEE\xE4\xB3 \xE9\xEE\xE3\xEE \xED\xEE\xEC\xE5\xF0 \xE7\xE0\xED\xEE\xF1\xE8\xF2\xFC\xF1\xFF \xE4\xEE \xF0\xE5\xE7\xF3\xEB\xFC\xF2\xE0\xF2\xF3. + /// </summary> + /// <returns>\xD1\xEF\xE8\xF1\xEE\xEA \xE2\xB3\xEB\xFC\xED\xE8\xF5 \xF2\xE5\xF1\xF2\xE5\xF0\xB3\xE2</returns> + private List<int> GetFreeTesters() + { + if (server == null) + { + return new List<int>(); + } + + q.Clear(); + string curHashCode = DateTime.Now.GetHashCode().ToString(); + 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()] == "unknown") + { + string message = "test"; + message += " " + server.ClientsList[i].GetHashCode().ToString(); + message += " " + curHashCode; + SystemMessage mes = new SystemMessage(message, "SystemTestBusyMessage"); + ServerSend(mes, i); + } + } + + DateTime start = DateTime.Now; + Dictionary<string, int> preResult = new Dictionary<string, int>(); + while (server != null && preResult.Count < server.CountClients) + { + if (((TimeSpan)(DateTime.Now - start)).TotalSeconds > 1.0) + { + break; + } + lock (q) + { + while (q.Count != 0) + { + string curStr = q.Dequeue(); + char[] chars = new char[1]; + chars[0] = ' '; + string[] mes = curStr.Split(chars); + if (mes[0] == "free" && curHashCode == mes[2]) + { + cleintStatus[Int32.Parse(mes[1])] = "free"; + preResult.Add(mes[1], 0); + } + else + { + if (mes[0] == "busy") + { + cleintStatus[Int32.Parse(mes[1])] = "busy"; + } + } + } + } + System.Threading.Thread.Sleep(50); + } + + 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") + result.Add(i); + //string hashCode = server.ClientsList[i].GetHashCode().ToString(); + //if (preResult.ContainsKey(hashCode) == true) + // result.Add(i); + } + return result; + } + + /// <summary> + /// \xCF\xE5\xF0\xE5\xE2\xB3\xF0\xE0\xBA \xF7\xE8 \xF6\xE5 \xF1\xEB\xF3\xE6\xE1\xEE\xE2\xE5 \xEF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xE5\xED\xED\xFF. + /// \xDF\xEA\xF9\xEE \xF1\xEB\xF3\xE6\xE1\xEE\xE2\xE5, \xF2\xEE\xE4\xB3 \xE2\xEE\xED\xEE \xE7\xE0\xED\xEE\xF1\xE8\xF2\xFC\xF1\xFF \xE4\xEE \xF1\xEF\xE8\xF1\xEA\xF3 q + /// </summary> + /// <param name="message">\xCF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xE5\xED\xED\xFF</param> + /// <returns>\xDF\xEA\xF9\xEE \xF6\xE5 \xF1\xEB\xF3\xE6\xE1\xEE\xE2\xE5 \xEF\xEE\xE2\xB3\xE4\xEE\xEC\xEB\xE5\xED\xED\xFF, \xF2\xEE\xE4\xB3 \xEF\xEE\xE2\xE5\xF0\xF2\xE0\xBA\xF2\xFC\xF1\xFF true \xEF\xEE \xB3\xED\xE0\xEA\xF8\xEE\xEC\xF3 false</returns> + private bool SystemMessageX(SystemMessage message) + { + char[] chars = new char[1]; + chars[0] = ' '; + string[] mes = message.Message.Split(chars); + if (mes[0] == "busy" || mes[0] == "free") + { + lock(q) + q.Enqueue(message.Message); + return true; + } + return false; + } + } +} Property changes on: ACMServer/trunk/ACMServer/Library/Connector/SocketServerTask.cs ___________________________________________________________________ Added: svn:mergeinfo + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2008-10-07 16:01:45
|
Revision: 409 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=409&view=rev Author: brus07 Date: 2008-10-07 16:01:38 +0000 (Tue, 07 Oct 2008) Log Message: ----------- Added new class architecture for Connector module. Modified Paths: -------------- ACMServer/trunk/ACMServer/Library/Connector/Connector.csproj ACMServer/trunk/ACMServer/Library/Connector/SocketClient.cs ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs ACMServer/trunk/ACMServer/Library/Connector/WebConnector.cs ACMServer/trunk/ACMServer/Tester/Form1.cs ACMServer/trunk/ACMServer/Tester/Library/SocketClientGate.cs ACMServer/trunk/ACMServer/Tester/Tester.csproj Added Paths: ----------- ACMServer/trunk/ACMServer/Library/Connector/AbstractConnector.cs ACMServer/trunk/ACMServer/Library/Connector/SocketClientTask.cs ACMServer/trunk/ACMServer/Tester/Library/WorkRunner.cs Added: ACMServer/trunk/ACMServer/Library/Connector/AbstractConnector.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/AbstractConnector.cs (rev 0) +++ ACMServer/trunk/ACMServer/Library/Connector/AbstractConnector.cs 2008-10-07 16:01:38 UTC (rev 409) @@ -0,0 +1,20 @@ +using System; +using AcmContester.Library.LibraryExtention; + +namespace AcmContester.Library.Connector +{ + public abstract class AbstractConnector + { + public delegate void DataArrivedDelegate(SystemMessage message); + public event DataArrivedDelegate onDataArrived; + + protected void OnDataArrived(SystemMessage message) + { + DataArrivedDelegate tempEvent = onDataArrived; + if (tempEvent != null) + tempEvent(message); + } + + public abstract bool Send(SystemMessage message); + } +} Modified: ACMServer/trunk/ACMServer/Library/Connector/Connector.csproj =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/Connector.csproj 2008-10-07 15:08:49 UTC (rev 408) +++ ACMServer/trunk/ACMServer/Library/Connector/Connector.csproj 2008-10-07 16:01:38 UTC (rev 409) @@ -38,9 +38,11 @@ <Reference Include="System.Xml" /> </ItemGroup> <ItemGroup> + <Compile Include="AbstractConnector.cs" /> <Compile Include="Getter\IGetter.cs" /> <Compile Include="Getter\WebGetterOld.cs" /> <Compile Include="SocketClient.cs" /> + <Compile Include="SocketClientTask.cs" /> <Compile Include="SocketServer.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="WebConnector.cs" /> Modified: ACMServer/trunk/ACMServer/Library/Connector/SocketClient.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/SocketClient.cs 2008-10-07 15:08:49 UTC (rev 408) +++ ACMServer/trunk/ACMServer/Library/Connector/SocketClient.cs 2008-10-07 16:01:38 UTC (rev 409) @@ -4,13 +4,10 @@ namespace AcmContester.Library.Connector { - public class SocketClient + public class SocketClient: AbstractConnector { EasyClient client; - public delegate void DataArrivedDelegate(SystemMessage s); - public event DataArrivedDelegate onDataArrived; - string ip = "127.0.0.1"; int port = 4120; @@ -40,10 +37,11 @@ client.Dispose(); client = null; } - public void Send(SystemMessage message) + public override bool Send(SystemMessage message) { byte[] bytes = SystemMessage.Serialize(message); client.SendData(bytes); + return true; } private void DataArrived(object Data) @@ -51,19 +49,12 @@ SystemMessage mes = SystemMessage.Deserialize((byte[])Data); OnDataArrived(mes); } + public bool IsConnected() { if (client == null) return false; return client.IsConnected; } - - private void OnDataArrived(SystemMessage message) - { - if (onDataArrived != null) - { - onDataArrived(message); - } - } } } Added: ACMServer/trunk/ACMServer/Library/Connector/SocketClientTask.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/SocketClientTask.cs (rev 0) +++ ACMServer/trunk/ACMServer/Library/Connector/SocketClientTask.cs 2008-10-07 16:01:38 UTC (rev 409) @@ -0,0 +1,37 @@ +using System; +using AcmContester.Library.LibraryExtention; + +namespace AcmContester.Library.Connector +{ + public class SocketClientTask: AbstractConnector + { + SocketClient client; + + public SocketClientTask(string IP) + { + client = new SocketClient(IP); + client.onDataArrived += base.OnDataArrived; + } + + public override bool Send(SystemMessage message) + { + return client.Send(message); + } + + public void Connect() + { + client.Connect(); + } + + public void Disconnect() + { + if (client.IsConnected() == true) + client.Disconnect(); + } + + public bool IsConnected() + { + return client.IsConnected(); + } + } +} Modified: ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs 2008-10-07 15:08:49 UTC (rev 408) +++ ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs 2008-10-07 16:01:38 UTC (rev 409) @@ -5,7 +5,7 @@ namespace AcmContester.Library.Connector { - public class SocketServer + public class SocketServer: AbstractConnector { int port = 4120; EasyServer server; @@ -16,8 +16,6 @@ //unknown - nevidomyj Dictionary<int, string> cleintStatus = new Dictionary<int, string>(); - public delegate void DataArrivedDelegate(SystemMessage s); - public event DataArrivedDelegate onDataArrived; public SocketServer() { @@ -46,7 +44,7 @@ byte[] bytes = SystemMessage.Serialize(mes); server.SendData(bytes, TargetClientIndex); } - public bool Send(SystemMessage message) + public override bool Send(SystemMessage message) { List<int> freeTesters = GetFreeTesters(); if (freeTesters.Count != 0) @@ -79,13 +77,6 @@ cleintStatus[Int32.Parse(message.Description)] = "free"; OnDataArrived(message); } - private void OnDataArrived(SystemMessage message) - { - if (onDataArrived != null) - { - onDataArrived(message); - } - } public int CountClients() { Modified: ACMServer/trunk/ACMServer/Library/Connector/WebConnector.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/WebConnector.cs 2008-10-07 15:08:49 UTC (rev 408) +++ ACMServer/trunk/ACMServer/Library/Connector/WebConnector.cs 2008-10-07 16:01:38 UTC (rev 409) @@ -5,13 +5,10 @@ namespace AcmContester.Library.Connector { - public class WebConnector + public class WebConnector: AbstractConnector { Timer timer = new Timer(); - public delegate void DataArrivedDelegate(SystemMessage s); - public event DataArrivedDelegate onDataArrived; - public event EventHandler onChecking; public event EventHandler onChecked; @@ -60,7 +57,7 @@ OnChecking(); SystemMessage message = getter.GetData(); OnChecked(); - DataArrived(message); + OnDataArrived(message); timer.Enabled = true; } @@ -75,17 +72,10 @@ onChecked(this, null); } - private void DataArrived(SystemMessage Data) + public override bool Send(SystemMessage message) { - if (onDataArrived != null) - { - onDataArrived(Data); - } - } - - public void Send(SystemMessage message) - { getter.Send(message); + return true; } protected void SetTimerInterval(int valueOfSeconds) Modified: ACMServer/trunk/ACMServer/Tester/Form1.cs =================================================================== --- ACMServer/trunk/ACMServer/Tester/Form1.cs 2008-10-07 15:08:49 UTC (rev 408) +++ ACMServer/trunk/ACMServer/Tester/Form1.cs 2008-10-07 16:01:38 UTC (rev 409) @@ -49,7 +49,6 @@ { socket = new SocketClientGate(textBox3.Text); socket.onAddLogText += AddText; - //socket.onDataArrived += DataArrived; } socket.Connect(); } @@ -63,8 +62,7 @@ { if (socket != null) { - if (socket.IsConnected() == true) - socket.Disconnect(); + socket.Disconnect(); socket = null; } } Modified: ACMServer/trunk/ACMServer/Tester/Library/SocketClientGate.cs =================================================================== --- ACMServer/trunk/ACMServer/Tester/Library/SocketClientGate.cs 2008-10-07 15:08:49 UTC (rev 408) +++ ACMServer/trunk/ACMServer/Tester/Library/SocketClientGate.cs 2008-10-07 16:01:38 UTC (rev 409) @@ -6,17 +6,18 @@ namespace AcmContester.Tester.Library { - class SocketClientGate: SocketClient + class SocketClientGate: SocketClientTask { private string descriptionMessage = ""; - public new delegate void DataArrivedDelegate(SystemMessage s); - public new event DataArrivedDelegate onDataArrived; + //TODO: tut vin tymchasovo, potribno bude perenesty jogo kudys dali + private WorkRunner workRunner = new WorkRunner(); public SocketClientGate(string IP) : base(IP) { base.onDataArrived +=new SocketClient.DataArrivedDelegate(SocketClientGate_onDataArrived); + workRunner.onDataArrived += Send; } void SocketClientGate_onDataArrived(SystemMessage message) @@ -27,32 +28,22 @@ return; } OnAddLogText("Receive", message.Message); - //OnDataArrived(message); + descriptionMessage = message.Description; if (message.IsType("TestingSubmit") == true) { - AddWork(message.Message); + workRunner.AddWork(message.Message); } } public new void Disconnect() { - if (thread != null) - thread.Abort(); + workRunner.Stop(); base.Disconnect(); } - private void OnDataArrived(SystemMessage message) - { - if (onDataArrived != null) - { - onDataArrived(message); - } - } - - private bool SystemMessageX(SystemMessage _message) { string message = _message.Message; @@ -63,7 +54,7 @@ { OnAddLogText("SystemReceive", message); string result = ""; - if (IsBusy() == true) + if (workRunner.IsBusy() == true) { result = "busy"; } @@ -82,87 +73,17 @@ return false; } - string source = ""; - object working = 0; - Thread thread = new Thread(new ParameterizedThreadStart(Go)); - private bool IsBusy() + public override bool Send(SystemMessage message) { - lock (working) - { - if ((int)working == 1 || (thread.ThreadState == ThreadState.Running)) - { - return true; - } - } - return false; - } + message = new SystemMessage(message); + message.Description = descriptionMessage; - private void AddWork(string message) - { - if (IsBusy() == true) - { - OnAddLogText("info", "--------- busy ---------"); - return; - } + Result res = Result.CreateFromXml(message.Message); + OnAddLogText("Send", "ID " + res.Submit.id + " result - " + res.res); - //TODO: tut potribno stavyty lock - // a znimaty vze u samomu Thread'i - // (dyv. na inshe TODO:) - lock(source) - source = message; - - //TODO: potribno jakos obnulyty status thread, - // tak shob ne potribno bulo stvorjuvaty novyj - thread = new Thread(new ParameterizedThreadStart(Go)); - thread.Start(this); + return base.Send(message); } - static void Go(object data) - { - if (data is SocketClient == false) - throw new ArgumentException(); - - SocketClientGate gate = (SocketClientGate)data; - - lock (gate.working) - gate.working = 1; - - string copySource; - //TODO: tut potribno znimaty postavlenyj lock - // toj lock postavlenyj u potoci sho vyklykav cej - lock (gate.source) - copySource = gate.source; - gate.Run(copySource); - - lock (gate.working) - gate.working = 0; - } - - void Run(string message) - { - string result; - try - { - result = Checker.Checker.GetResult(message); - } - catch (Exception ex) - { - Log log = Log.GetLog(); - log.Loging("Form1::DataArrived: Error: " + ex.Message, Log.Priority.ERR); - log.Loging("Form1::DataArrived: Error: " + ex.StackTrace, Log.Priority.ERR); - return; - } - - //TODO: ne znaju chy tut potriben lcok - lock (this) - { - Result res = Result.CreateFromXml(result); - OnAddLogText("Send", "ID " + res.Submit.id + " result - " + res.res); - this.Send(new SystemMessage(result, "TestingResult", descriptionMessage)); - } - } - - public delegate void AddLogTextDelegate(string type, string text); public event AddLogTextDelegate onAddLogText; private void OnAddLogText(string type, string text) Added: ACMServer/trunk/ACMServer/Tester/Library/WorkRunner.cs =================================================================== --- ACMServer/trunk/ACMServer/Tester/Library/WorkRunner.cs (rev 0) +++ ACMServer/trunk/ACMServer/Tester/Library/WorkRunner.cs 2008-10-07 16:01:38 UTC (rev 409) @@ -0,0 +1,105 @@ +using System; +using AcmContester.Library.LibraryExtention; +using System.Threading; +using AcmContester.Library.LibraryExtention.Data; + +namespace AcmContester.Tester.Library +{ + class WorkRunner + { + + public delegate bool DataArrivedDelegate(SystemMessage message); + public event DataArrivedDelegate onDataArrived; + + string source = ""; + object working = 0; + Thread thread = new Thread(new ParameterizedThreadStart(Go)); + + internal bool IsBusy() + { + lock (working) + { + if ((int)working == 1 || (thread.ThreadState == ThreadState.Running)) + { + return true; + } + } + return false; + } + + internal void AddWork(string message) + { + if (IsBusy() == true) + { + return; + } + + //TODO: tut potribno stavyty lock + // a znimaty vze u samomu Thread'i + // (dyv. na inshe TODO:) + lock (source) + source = message; + + //TODO: potribno jakos obnulyty status thread, + // tak shob ne potribno bulo stvorjuvaty novyj + thread = new Thread(new ParameterizedThreadStart(Go)); + thread.Start(this); + } + + static void Go(object data) + { + if (data is WorkRunner == false) + throw new ArgumentException(); + + WorkRunner gate = (WorkRunner)data; + + lock (gate.working) + gate.working = 1; + + string copySource; + //TODO: tut potribno znimaty postavlenyj lock + // toj lock postavlenyj u potoci sho vyklykav cej + lock (gate.source) + copySource = gate.source; + gate.Run(copySource); + + lock (gate.working) + gate.working = 0; + } + + void Run(string message) + { + string result; + try + { + result = Checker.Checker.GetResult(message); + } + catch (Exception ex) + { + Log log = Log.GetLog(); + log.Loging("Form1::DataArrived: Error: " + ex.Message, Log.Priority.ERR); + log.Loging("Form1::DataArrived: Error: " + ex.StackTrace, Log.Priority.ERR); + return; + } + + //TODO: ne znaju chy tut potriben lock + lock (this) + { + this.Send(new SystemMessage(result, "TestingResult")); + } + } + + private bool Send(SystemMessage systemMessage) + { + if (onDataArrived != null) + return this.onDataArrived(systemMessage); + return true; + } + + internal void Stop() + { + if (thread != null) + thread.Abort(); + } + } +} Modified: ACMServer/trunk/ACMServer/Tester/Tester.csproj =================================================================== --- ACMServer/trunk/ACMServer/Tester/Tester.csproj 2008-10-07 15:08:49 UTC (rev 408) +++ ACMServer/trunk/ACMServer/Tester/Tester.csproj 2008-10-07 16:01:38 UTC (rev 409) @@ -46,6 +46,7 @@ <Compile Include="Form1.Designer.cs"> <DependentUpon>Form1.cs</DependentUpon> </Compile> + <Compile Include="Library\WorkRunner.cs" /> <Compile Include="Program.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <EmbeddedResource Include="Form1.resx"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2008-10-07 15:13:10
|
Revision: 408 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=408&view=rev Author: brus07 Date: 2008-10-07 15:08:49 +0000 (Tue, 07 Oct 2008) Log Message: ----------- Added copy constructor. Modified Paths: -------------- ACMServer/trunk/ACMServer/Library/LibraryExtention/SystemMessage.cs Modified: ACMServer/trunk/ACMServer/Library/LibraryExtention/SystemMessage.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/LibraryExtention/SystemMessage.cs 2008-10-05 15:20:17 UTC (rev 407) +++ ACMServer/trunk/ACMServer/Library/LibraryExtention/SystemMessage.cs 2008-10-07 15:08:49 UTC (rev 408) @@ -41,6 +41,13 @@ } } + public SystemMessage(SystemMessage sysMes) + { + this.message = sysMes.Message; + this.type = sysMes.Type; + this.description = sysMes.Description; + } + public SystemMessage(string message) { this.message = message; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pan...@us...> - 2008-10-05 16:47:16
|
Revision: 407 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=407&view=rev Author: panzaboi Date: 2008-10-05 15:20:17 +0000 (Sun, 05 Oct 2008) Log Message: ----------- See R405 Comment Added Paths: ----------- website/application/layouts/ website/application/layouts/layout.phtml Property changes on: website/application/layouts ___________________________________________________________________ Added: tsvn:logminsize + 5 Added: website/application/layouts/layout.phtml =================================================================== --- website/application/layouts/layout.phtml (rev 0) +++ website/application/layouts/layout.phtml 2008-10-05 15:20:17 UTC (rev 407) @@ -0,0 +1,87 @@ +<?= $this->doctype() ?> +<? $this->dojo()->enable() + ->setDjConfigOption('parseOnLoad', true) + ->registerModulePath('custom', '../custom/') + ->requireModule('dijit.form.FilteringSelect') ?> +<html> + <head> + <base href="<?= 'http://' . $_SERVER["HTTP_HOST"] . $this->baseUrl() ?>/" /> + <?= $this->headTitle($this->placeholder('title')->toString()) ?> + <?= $this->headMeta()->appendHttpEquiv('Content-Type', 'text/html; charset=UTF-8') ?> + + <?= $this->headLink()->appendStylesheet('styles/style.css') ?> + <?= /*$this->headLink()->appendStylesheet('styles/ie6.css', 'screen', 'IE 6')*/'' ?> + <?= /*$this->headLink()->appendStylesheet('styles/ie7.css', 'screen', 'IE 7')*/'' ?> + + <? if ($this->dojo()->isEnabled()): + $this->dojo()->setLocalPath('/scripts/dojo/dojo.js') + ->addStyleSheetModule('dijit.themes.tundra'); + + echo $this->dojo(); + endif; ?> + <?= $this->headScript()->appendFile('/scripts/main.js') ?> + </head> + <body class="tundra"> + <table border="0" cellpadding="0" cellspacing="0" width="100%"> + <tr bgcolor="#122a5b"> + <td><img height="43" src="images/logo.gif" width="490"></td> + </tr> + <tr bgcolor="#e1e1e1"> + <td><img height=26 src="images/logod.gif" width="490"></td> + </tr> + <tr> + <td bgcolor=#122a5b colspan=2><img height=2 src="images/0.gif" width=1></td> + </tr> + </table> + <table border=0 cellpadding=0 cellspacing=0 width="100%" summary="" height="20%"> + <tr> + <td bgcolor=#e1e1e1 valign=top width="200"> + <table width="100%" border="0" cellpadding="0" cellspacing="5"> + <tr><td><img border="0" src="images/arrow.gif" width="8" height="8" hspace="5"><a href="index/about">Що це за проект</a></td></tr> + <tr><td><img border="0" src="images/arrow.gif" width="8" height="8" hspace="5"><a href="index/rule">Правила</a></td></tr> + <tr><td><img border="0" src="images/arrow.gif" width="8" height="8" hspace="5"><a href="archieve/index">Набір завдань</a></td></tr> + <tr><td><img border="0" src="images/arrow.gif" width="8" height="8" hspace="5"><a href="archieve/submit">Протестувати Розв'язок</a></td></tr> + <tr><td><img border="0" src="images/arrow.gif" width="8" height="8" hspace="5"><a href="archieve/results">Результати Тестувань</a></td></tr> + <tr><td><img border="0" src="images/arrow.gif" width="8" height="8" hspace="5"><a href="archieve/ranks">Рейтинг Учасників</a></td></tr> + <tr><td><hr></td></tr> + </table> + + <table border=0 cellpadding=4 cellspacing=0 width="100%" summary=""> + <tr><td align=middle bgcolor=#122a5b><font color=#d4d0e2><b><small>вхід</small></b></font></td></tr> + <tr><td> + <form onsubmit="return checkform(this);" method="post" action="login.php?rid=45fed5d9b297f" style="margin:0"> + <input type="hidden" name="path" value="/"> + <table border=0 cellPadding=1 cellSpacing=0 summary="" width=100%> + <tr> + <td class=name nowrap><small><font color=#122a5b> логін:</font></small></td> + <td><input name=lgn style="height: 18px; width: 100px"></td> + <td> </td> + </tr> + <tr> + <td class=name nowrap><small><font color=#122a5b> пароль:</font></small></td> + <td><input name=pswd type=password style="height: 18px; width: 100px"></td> + <td><input name="login" src="images/b_find.gif" type="image"> + </tr> + </table> + </form> + +<CENTER><A href="register.php">Зареєструватись</a><BR><a href=createteam.php>Створити команду</a></CENTER> +</TABLE><TABLE border=0 cellPadding=4 cellSpacing=0 width="100%"> +<TR><TD align=middle bgColor=#122a5b> +<FONT color=#d4d0e2><B><SMALL>F.A.Q.</SMALL></B></FONT> +<TR><TD><TABLE border=0 cellPadding=0 cellSpacing=2 width="100%"><TR><TD><P>Мені здається що програма написана правильно, але система видає "Помилка під час виконання"... +<P>Якщо Ви використовуєте С++, і описали функцію void main(){...} - навіть якщо програма видасть +правильний результат, то система видасть "помилка під час виконання". Це пов'язано з тим, що +в такому випадку код завершення програми непердбачуваний, і практично ніколи небуває нульовим. +<BR>Для того, щоб програму Вам зарахувало (якщо все правильно), необхідно описувати основну +функцію як int main(){...} і обов'язково завершувати програму через return 0. +<TR><TD align=right><P><SMALL><A href="allfaq.php">[ Всі питання ]</p></SMALL></TABLE><TR><TD align=middle bgColor=#122a5b> +<FONT color=#d4d0e2> </FONT> +<TR><TD><TABLE border=0 cellPadding=0 cellSpacing=2 width="100%"><TR><TD align=center> + +</TABLE></TABLE><TD bgColor=#f4f3f8 vAlign=top height=100%><?= $this->placeholder('message') ?><br /><?= $this->layout()->content ?></table></table> +<TABLE> +<TR vAlign=Bottom><TABLE border=0 cellPadding=0 cellSpacing=0 width="100%" summary=""><TR bgColor=#122a5b><TD colSpan=3><IMG alt="" height=5 src="images/pixel.gif" width=1><TR bgColor=#122a5b><TD class=copyright>© 2004-2005, <a class=copyrightlink href="mailto: ac...@ia..."><B><FONT COLOR="#d1d1d1">A-S</FONT>tudio</B></A><TD align=middle><TD align=right class=copyright><A class=copyrightlink href="http://www.acm.lviv.ua">ACM Контестер</A><TR bgColor=#122a5b><TD colSpan=3><IMG alt="" height=5 src="images/pixel.gif" width=1></TABLE> + <?= $this->debugInfo(true) ?> + </body> +</html> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pan...@us...> - 2008-10-05 16:03:07
|
Revision: 406 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=406&view=rev Author: panzaboi Date: 2008-10-05 15:18:47 +0000 (Sun, 05 Oct 2008) Log Message: ----------- See R405 Comment Added Paths: ----------- website/application/modules/ website/application/modules/acm/ website/application/modules/acm/controllers/ website/application/modules/acm/controllers/ArchieveController.php website/application/modules/acm/controllers/ErrorController.php website/application/modules/acm/controllers/IndexController.php website/application/modules/acm/models/ website/application/modules/acm/models/Archieve.php website/application/modules/acm/models/Form/ website/application/modules/acm/models/Form/Login.php website/application/modules/acm/models/Index.php website/application/modules/acm/views/ website/application/modules/acm/views/helpers/ website/application/modules/acm/views/scripts/ website/application/modules/acm/views/scripts/archieve/ website/application/modules/acm/views/scripts/archieve/entry.phtml website/application/modules/acm/views/scripts/archieve/index.phtml website/application/modules/acm/views/scripts/archieve/view.phtml website/application/modules/acm/views/scripts/error/ website/application/modules/acm/views/scripts/error/error.phtml website/application/modules/acm/views/scripts/index/ website/application/modules/acm/views/scripts/index/index.phtml website/application/modules/default/ website/application/modules/default/controllers/ website/application/modules/default/controllers/ErrorController.php website/application/modules/default/controllers/IndexController.php website/application/modules/default/views/ website/application/modules/default/views/helpers/ website/application/modules/default/views/scripts/ website/application/modules/default/views/scripts/error/ website/application/modules/default/views/scripts/error/error.phtml Removed Paths: ------------- website/application/default/ website/library/Ostacium/View/Helper/CurrentUrl.php Property Changed: ---------------- website/httpdocs/scripts/ Property changes on: website/application/modules ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/application/modules/acm ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/application/modules/acm/controllers ___________________________________________________________________ Added: tsvn:logminsize + 5 Added: website/application/modules/acm/controllers/ArchieveController.php =================================================================== --- website/application/modules/acm/controllers/ArchieveController.php (rev 0) +++ website/application/modules/acm/controllers/ArchieveController.php 2008-10-05 15:18:47 UTC (rev 406) @@ -0,0 +1,25 @@ +<?php + +class Acm_ArchieveController extends Ostacium_Controller_Action +{ + public function indexAction() + { + $this->view->challenges = $this->_model->getChallenges(); + } + + public function viewAction() + { + $id = $this->_getParam('id'); + $problem = $this->_model->get($id); + + if (!$problem) + return $this->_forward('index', null, null, $this->_getAllParams() + array('message' => 'noProblem')); + + $this->view->problem = $problem; + } + + public function submitAction() + { + + } +} \ No newline at end of file Added: website/application/modules/acm/controllers/ErrorController.php =================================================================== --- website/application/modules/acm/controllers/ErrorController.php (rev 0) +++ website/application/modules/acm/controllers/ErrorController.php 2008-10-05 15:18:47 UTC (rev 406) @@ -0,0 +1,37 @@ +<?php + +class ErrorController extends Ostacium_Controller_Action +{ + public function errorAction() + { + $this->getResponse()->clearBody(); + $error = $this->_getParam('error_handler'); + + switch ($error->type) { + case Ostacium_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: + case Ostacium_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION: + $this->getResponse()->setHttpResponseCode(404); + + $this->view->msg = $this->view->translate('error_404'); + break; + case Ostacium_Controller_Plugin_ErrorHandler::EXCEPTION_NOTALLOWED: + $this->getResponse()->setHttpResponseCode(403); + + $this->view->msg = $this->view->translate('error_403'); + break; + default: + $this->view->msg = $this->view->translate('error_other'); + break; + } + + Zend_Registry::get('Zend_Log')->log('Type:'.$error->type.($error->exception ? "\nTrace:".$error->exception->getTraceAsString() : ""), Zend_Log::ERR); + + $this->view->env = $this->getInvokeArg('environment'); + $this->view->request = ($error->request ? $error->request : $this->getRequest()); + + if ($error->exception) + $this->view->exception = $error->exception; + else + $this->view->other_message = $this->_getParam('message'); + } +} \ No newline at end of file Added: website/application/modules/acm/controllers/IndexController.php =================================================================== --- website/application/modules/acm/controllers/IndexController.php (rev 0) +++ website/application/modules/acm/controllers/IndexController.php 2008-10-05 15:18:47 UTC (rev 406) @@ -0,0 +1,66 @@ +<?php + +class Acm_IndexController extends Ostacium_Controller_Action +{ + public function indexAction() + { + echo $this->getLoginForm(); + } + + public function loginAction() + { + $form = $this->getLoginForm(); + + if (!$this->getRequest()->isPost()) + { + return $this->_forward('index', null, null, $this->_getAllParams()); + } + + if (!$form->isValid($this->getRequest()->getPost())) + { + $this->view->form = $form; + $this->renderScript('layout/loginform.phtml', 'login'); + return $this->_forward('index'); + } + + $values = $form->getValues(); + + $result = $this->_model->authoricate($values); + + if (!$result) + { + $form->setDescription($this->view->translate('wrongEmailPwd')); + $this->view->form = $form; + //$this->renderScript('layout/loginform.phtml', 'login'); + + return $this->_forward('index'); + } + + $redirect = new Zend_Session_Namespace('Redirect'); + if ($redirect->to) + { + $this->getRequest()->setParam('redirect', $redirect->to); + $redirect->unsetAll(); + } + else + { + return $this->_redirect('/acm/index/index'); + } + + $this->_helper->getHelper('viewRenderer')->setNoRender(true); + } + + public function logoutAction() + { + Zend_Auth::getInstance()->clearIdentity(); + } + + protected function getLoginForm() + { + return new Form_Login(array( + 'action' => $this->getRequest()->getBaseUrl() . 'acm/index/login', + 'method' => 'post', + 'name' => 'loginform', + )); + } +} \ No newline at end of file Property changes on: website/application/modules/acm/models ___________________________________________________________________ Added: tsvn:logminsize + 5 Added: website/application/modules/acm/models/Archieve.php =================================================================== --- website/application/modules/acm/models/Archieve.php (rev 0) +++ website/application/modules/acm/models/Archieve.php 2008-10-05 15:18:47 UTC (rev 406) @@ -0,0 +1,27 @@ +<?php + +class Archieve extends Ostacium_Model +{ + public function getChallenges() + { + $challenges = new Challenges(); + return $challenges->getAll(); + } + + public function get($id) + { + $challenges = new Challenges(); + return $challenges->get($id); + } +} + +class Challenges extends Ostacium_Db_Table +{ + protected $_name = 'challenges'; + protected $_primary = 'id'; + + public function getAll() + { + return $this->select()->from($this)->where('enabled = ?', 1)->query()->fetchAll(); + } +} \ No newline at end of file Property changes on: website/application/modules/acm/models/Form ___________________________________________________________________ Added: tsvn:logminsize + 5 Added: website/application/modules/acm/models/Form/Login.php =================================================================== --- website/application/modules/acm/models/Form/Login.php (rev 0) +++ website/application/modules/acm/models/Form/Login.php 2008-10-05 15:18:47 UTC (rev 406) @@ -0,0 +1,80 @@ +<?php + +class Form_Login extends Zend_Dojo_Form +{ + public $elementDecorators = array( + 'DijitElement', + 'Errors', + array('Label', array('class' => 'overlabel')), + array('HtmlTag', array('tag' => 'div', 'class' => 'elcontainer')) + ); + + public $buttonDecorators = array( + 'DijitElement', + ); + + public function init() + { + $translate = Zend_Registry::get('Zend_Translate'); + //$this->addElementPrefixPath('Ostacium_Form', 'Ostacium/Form/'); + + $this->addElement('ValidationTextBox', 'username', array( + 'decorators' => $this->elementDecorators, + 'filters' => array('StringTrim', 'StringToLower'), + 'validators' => array( + array('StringLength', false, array(5, 50)), + ), + 'required' => true, + 'maxlength' => 50, + 'trim' => true, + 'lowercase' => true, + 'style' => 'height: 18px; width: 100px;', + 'regExp' => '[\S]{5,50}', + 'invalidMessage' => sprintf($translate->_('errorBetween'), 5, 50), + 'title' => 'Username', + 'label' => 'Username:', + )); + + + + $this->addElement('PasswordTextBox', 'password', array( + 'decorators' => $this->elementDecorators, + 'filters' => array('StringTrim'), + 'validators' => array( + 'Alnum', + array('StringLength', false, array(5, 32)), + ), + 'required' => true, + 'trim' => true, + 'style' => 'height: 18px; width: 100px;', + 'regExp' => '^[a-z0-9]{5,32}$', + 'invalidMessage' => sprintf($translate->_('errorBetween'), 5, 32), + 'title' => 'Password', + 'label' => 'Password:', + )); + + + + $this->addElement('SubmitButton', 'loginbutton', array( + 'decorators' => $this->buttonDecorators, + 'required' => false, + 'ignore' => true, + 'label' => 'Login', + )); + } + + public function loadDefaultDecorators() + { +// $this->setDecorators(array( +// 'FormElements', +// 'Form', +// array('Description', array('placement' => 'prepend', 'tag' => 'div', 'class' => 'error')), +// )); + + $this->setDecorators(array( + 'FormElements', + 'DijitForm', + array('Description', array('placement' => 'prepend', 'tag' => 'div', 'class' => 'error')), + )); + } +} \ No newline at end of file Added: website/application/modules/acm/models/Index.php =================================================================== --- website/application/modules/acm/models/Index.php (rev 0) +++ website/application/modules/acm/models/Index.php 2008-10-05 15:18:47 UTC (rev 406) @@ -0,0 +1,24 @@ +<?php + +class Index extends Ostacium_Model +{ + public function authoricate($login) + { + $auth = Zend_Auth::getInstance(); + $adapter = Zend_Registry::get('auth'); + $acl = Zend_Registry::get('acl'); + + $adapter->setIdentity($login['username']) + ->setCredential($login['password']); + + $result = $adapter->authenticate(); + + if ($result->isValid()) { + $row = $adapter->getResultRowObject(); + + $auth->getStorage()->write($row); + } + + return $result->isValid(); + } +} \ No newline at end of file Property changes on: website/application/modules/acm/views ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/application/modules/acm/views/helpers ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/application/modules/acm/views/scripts ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/application/modules/acm/views/scripts/archieve ___________________________________________________________________ Added: tsvn:logminsize + 5 Added: website/application/modules/acm/views/scripts/archieve/entry.phtml =================================================================== --- website/application/modules/acm/views/scripts/archieve/entry.phtml (rev 0) +++ website/application/modules/acm/views/scripts/archieve/entry.phtml 2008-10-05 15:18:47 UTC (rev 406) @@ -0,0 +1,18 @@ +<tr bgcolor="#f4f3f8" align="middle"> + <td style="border-left: 0px none; border-right: 1px solid rgb(196, 196, 219);"> + <a href="<?= $this->url( array('action' => 'view', 'id' => $this->id), null) ?>"><?= $this->id ?></a> + </td> + + <td align="left" style="border-left: 0px none; border-right: 1px solid rgb(196, 196, 219);"> + <a href="<?= $this->url( array('action' => 'view', 'id' => $this->id), null) ?>"><?= $this->name ?></a> + </td> + + <td style="border-left: 0px none; border-right: 1px solid rgb(196, 196, 219);"><?= $this->tries ?></td> + + <td style="border-left: 0px none; border-right: 1px solid rgb(196, 196, 219);"><?= $this->accepted ?></td> + + <td style="border-left: 0px none; border-right: 0px solid rgb(196, 196, 219);"> + <img height="17" width="22" alt="Здати" src="images/b_find.gif"/> + <img height="17" width="22" alt="Показати як здають" src="images/probstatus.png"/> + </td> +</tr> \ No newline at end of file Added: website/application/modules/acm/views/scripts/archieve/index.phtml =================================================================== --- website/application/modules/acm/views/scripts/archieve/index.phtml (rev 0) +++ website/application/modules/acm/views/scripts/archieve/index.phtml 2008-10-05 15:18:47 UTC (rev 406) @@ -0,0 +1,5 @@ +<table cellspacing="1" cellpadding="8" border="0" width="100%"><tbody><tr><td width="100%" valign="top" class="name"><table cellspacing="0" cellpadding="0" border="0" width="100%"><tbody><tr><td bgcolor="#d0d4de" width="4" class="name"><img height="18" width="4" src="http://web.archive.org/web/20070323032706/http://acm.lviv.ua/"/></td><td nowrap="" bgcolor="#122a5b" width="*" class="name"> <font color="#d4d0e2"><b><small>Набiр задач</small></b><small/></font></td><td nowrap="" bgcolor="#122a5b" align="right" class="name"> <font color="#d4d0e2"><b><small> 05:26 23 березня 2007 року </small></b><small/></font></td></tr></tbody></table> <table cellspacing="0" cellpadding="0" border="0" width="100%" summary=""><tbody><tr><td bgcolor="#f4f3f8" align="middle" colspan="14"><b>Архів задач</b></td></tr><tr><td bgcolor="#c4c4db" colspan="20"><img height="1" width="1" src="http://web.archive.org/web/20070323032706/http://acm.lviv.ua/" alt=""/></td></tr><tr bgcolor="#e1e1e1" align="middle"> +<th width="70">Задача</th><th align="left" width="*"> Назва</th><th width="70">Спробували</th><th width="70">Здали</th><th align="middle" width="70">Дії</th></tr><tr><td height="1" bgcolor="#c4c4db" colspan="20"><img height="1" width="1" src="http://web.archive.org/web/20070323032706/http://acm.lviv.ua/" alt=""/></td></tr> +<?= $this->partialLoop('archieve/entry.phtml', $this->challenges) ?> + +</table><br/></td></tr></table> \ No newline at end of file Added: website/application/modules/acm/views/scripts/archieve/view.phtml =================================================================== --- website/application/modules/acm/views/scripts/archieve/view.phtml (rev 0) +++ website/application/modules/acm/views/scripts/archieve/view.phtml 2008-10-05 15:18:47 UTC (rev 406) @@ -0,0 +1,5 @@ +<?php + +var_dump($this->problem); + +?> \ No newline at end of file Property changes on: website/application/modules/acm/views/scripts/error ___________________________________________________________________ Added: tsvn:logminsize + 5 Added: website/application/modules/acm/views/scripts/error/error.phtml =================================================================== --- website/application/modules/acm/views/scripts/error/error.phtml (rev 0) +++ website/application/modules/acm/views/scripts/error/error.phtml 2008-10-05 15:18:47 UTC (rev 406) @@ -0,0 +1,14 @@ +<h1>An error occurred</h1> +<h2><?= $this->msg ?></h2> +<? if ('development' == $this->env): ?> +<h3>Exception information:</h3> + <p> + <b>Message:</b> <?= $this->exception->getMessage() ?> + </p> + + <h3>Stack trace:</h3> + <pre><?= $this->exception->getTraceAsString() ?></pre> + + <h3>Request Parameters:</h3> + <pre><? var_dump($this->request->getParams()) ?></pre> +<? endif ?> Property changes on: website/application/modules/acm/views/scripts/index ___________________________________________________________________ Added: tsvn:logminsize + 5 Added: website/application/modules/acm/views/scripts/index/index.phtml =================================================================== --- website/application/modules/acm/views/scripts/index/index.phtml (rev 0) +++ website/application/modules/acm/views/scripts/index/index.phtml 2008-10-05 15:18:47 UTC (rev 406) @@ -0,0 +1 @@ +<table cellspacing="1" cellpadding="8" border="0" width="100%"><tbody><tr><td width="100%" valign="top" class="name"><table cellspacing="0" cellpadding="0" border="0" width="100%"><tbody><tr><td bgcolor="#d0d4de" width="4" class="name"><img height="18" width="4" src="http://web.archive.org/web/20070323032459/http://acm.lviv.ua/"/></td><td nowrap="" bgcolor="#122a5b" width="*" class="name"> <font color="#d4d0e2"><b><small>Про систему</small></b><small/></font></td><td nowrap="" bgcolor="#122a5b" align="right" class="name"> <font color="#d4d0e2"><b><small> 05:24 23 березня 2007 року </small></b><small/></font></td></tr></tbody></table> <p style="font-size: 20px; font-family: arial; text-align: center;"><b>ACM Contester</b></p><p align="justify" style="font-size: 20px; font-family: arial; text-align: justify;"><font size="3">Ми, команда розробників цієї системи, дуже раді вітати Вас - учасників цієї системи. </font></p><p align="justify" style="font-size: 20px; font-family: arial; text-align: justify;"><font size="3">Тут Ви маєте можливість спробувати свої сили у розв'язанні різних типів задач. Змагайтесь!!!</font></p><p> </p></td></tr></tbody></table> \ No newline at end of file Property changes on: website/application/modules/default ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/application/modules/default/controllers ___________________________________________________________________ Added: tsvn:logminsize + 5 Added: website/application/modules/default/controllers/ErrorController.php =================================================================== --- website/application/modules/default/controllers/ErrorController.php (rev 0) +++ website/application/modules/default/controllers/ErrorController.php 2008-10-05 15:18:47 UTC (rev 406) @@ -0,0 +1,37 @@ +<?php + +class ErrorController extends Ostacium_Controller_Action +{ + public function errorAction() + { + $this->getResponse()->clearBody(); + $error = $this->_getParam('error_handler'); + + switch ($error->type) { + case Ostacium_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: + case Ostacium_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION: + $this->getResponse()->setHttpResponseCode(404); + + $this->view->msg = $this->view->translate('error_404'); + break; + case Ostacium_Controller_Plugin_ErrorHandler::EXCEPTION_NOTALLOWED: + $this->getResponse()->setHttpResponseCode(403); + + $this->view->msg = $this->view->translate('error_403'); + break; + default: + $this->view->msg = $this->view->translate('error_other'); + break; + } + + Zend_Registry::get('Zend_Log')->log('Type:'.$error->type.($error->exception ? "\nTrace:".$error->exception->getTraceAsString() : ""), Zend_Log::ERR); + + $this->view->env = $this->getInvokeArg('environment'); + $this->view->request = ($error->request ? $error->request : $this->getRequest()); + + if ($error->exception) + $this->view->exception = $error->exception; + else + $this->view->other_message = $this->_getParam('message'); + } +} \ No newline at end of file Added: website/application/modules/default/controllers/IndexController.php =================================================================== --- website/application/modules/default/controllers/IndexController.php (rev 0) +++ website/application/modules/default/controllers/IndexController.php 2008-10-05 15:18:47 UTC (rev 406) @@ -0,0 +1,11 @@ +<?php + +class IndexController extends Ostacium_Controller_Action +{ + public function indexAction() + { + $this->getHelper('viewRenderer')->setNoRender(true); + //return $this->_redirect('/acm/'); + var_dump($this->view->url()); + } +} \ No newline at end of file Property changes on: website/application/modules/default/views ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/application/modules/default/views/helpers ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/application/modules/default/views/scripts ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/application/modules/default/views/scripts/error ___________________________________________________________________ Added: tsvn:logminsize + 5 Added: website/application/modules/default/views/scripts/error/error.phtml =================================================================== --- website/application/modules/default/views/scripts/error/error.phtml (rev 0) +++ website/application/modules/default/views/scripts/error/error.phtml 2008-10-05 15:18:47 UTC (rev 406) @@ -0,0 +1,14 @@ +<h1>An error occurred</h1> +<h2><?= $this->msg ?></h2> +<? if ('development' == $this->env): ?> +<h3>Exception information:</h3> + <p> + <b>Message:</b> <?= ($this->exception ? $this->exception->getMessage() : ($this->other_message ? $this->other_message : $this->translate("unknownError"))) ?> + </p> + + <h3>Stack trace:</h3> + <pre><?= ($this->exception ? $this->exception->getTraceAsString() : "") ?></pre> + + <h3>Request Parameters:</h3> + <pre><? var_dump($this->request->getParams()) ?></pre> +<? endif ?> Property changes on: website/httpdocs/scripts ___________________________________________________________________ Added: svn:ignore + dojo dojox dijit util Deleted: website/library/Ostacium/View/Helper/CurrentUrl.php =================================================================== --- website/library/Ostacium/View/Helper/CurrentUrl.php 2008-10-05 15:06:51 UTC (rev 405) +++ website/library/Ostacium/View/Helper/CurrentUrl.php 2008-10-05 15:18:47 UTC (rev 406) @@ -1,13 +0,0 @@ -<?php - -class Ostacium_View_Helper_CurrentUrl -{ - public function currentUrl() - { - $request = Zend_Controller_Front::getInstance()->getRequest(); - - return $request->getBaseUrl() . ($request->getModuleName() != 'default' ? '/' . $request->getModuleName() : '' ) . '/' . $request->getControllerName() . '/' . $request->getActionName(); - } -} - -?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pan...@us...> - 2008-10-05 15:11:16
|
Revision: 405 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=405&view=rev Author: panzaboi Date: 2008-10-05 15:06:51 +0000 (Sun, 05 Oct 2008) Log Message: ----------- Application() -> __construct() Added Logger Dynamic DB Encoding (From UTF-8) Changed Structure -> modules with multi-lang support Extended Error_Handler to catch NOT_ALLOWED,NO_CONTROLLER,NO_ACTION errors on preDispatch + NOTALLOwED - new Exception Type Ostacium_Controller_Plugin_Router_Exception More flexible configuration for Zend_View + Zend_Layout Extended Zend_Auth_Adapter_DbTable to be able to select from multiple tables during authorication Added Multilanguage support (ability to change language during navigation/set per user) Removed Messages from DB (translations will be read from file) Added Custom Routes Support Extended Zend_Controller_Router_Route_Module to support :lang/:module/:controller/:action/:params Removed ?> at the end of files Ostacium_Date: Small fix + removed ?> Ostacium_View_Helper_BaseUrl: New implementation from Zend Framework proposals with slashes stripping Ostacium_View_Helper_Currency: Added default options - can be set statically in bootstrap from config Ostacium_View_Helper_CurrentUrl: Removed as duplicate of: $this->url(); Ostacium_View_Helper_Truncate: fixed to extend Zend_View_Helper_Abstract db.sql: Updated DB Structure Ostacium_Controller_Plugin_Layout: Support separate layouts for different modules + general one in failuture Ostacium_Controller_Request_Http: Added getIP function Ostacium_View_Helper_DebugInfo: Ability to show debug info + write to logger during development stage todo.txt: update Todo List index.php: changed DIRECTORY_SEPARATOR to / as make no difference config.ini: updated configurations Modified Paths: -------------- website/config/config.ini website/httpdocs/index.php website/lang/en.csv website/lang/uk.csv website/library/Application.php website/library/Ostacium/Acl.php website/library/Ostacium/Controller/Action.php website/library/Ostacium/Controller/Plugin/ErrorHandler.php website/library/Ostacium/Controller/Plugin/Router.php website/library/Ostacium/Date.php website/library/Ostacium/Db/Table/Rowset.php website/library/Ostacium/Db/Table.php website/library/Ostacium/Model.php website/library/Ostacium/View/Helper/BaseUrl.php website/library/Ostacium/View/Helper/Currency.php website/library/Ostacium/View/Helper/FormFile.php website/library/Ostacium/View/Helper/ListTable.php website/library/Ostacium/View/Helper/Truncate.php website/other/db.sql Added Paths: ----------- website/library/Ostacium/Auth/ website/library/Ostacium/Auth/Adapter/ website/library/Ostacium/Auth/Adapter/DbTable.php website/library/Ostacium/Controller/Plugin/Layout.php website/library/Ostacium/Controller/Request/ website/library/Ostacium/Controller/Request/Http.php website/library/Ostacium/Controller/Router/ website/library/Ostacium/Controller/Router/Route/ website/library/Ostacium/Controller/Router/Route/Language.php website/library/Ostacium/Log/ website/library/Ostacium/Log/Writer/ website/library/Ostacium/Log/Writer/Db.php website/library/Ostacium/View/Helper/DebugInfo.php website/other/todo.txt Modified: website/config/config.ini =================================================================== --- website/config/config.ini 2008-10-04 23:18:38 UTC (rev 404) +++ website/config/config.ini 2008-10-05 15:06:51 UTC (rev 405) @@ -4,7 +4,7 @@ error.display = "1" error.throw = "1" -date.timezone = "Europe/Kiev" +#date.timezone = "Europe/Kiev" truncate.length = "300" truncate.ending = "..." @@ -13,6 +13,8 @@ table.perpage = "10" +date.format_type = "php" + #auth.noauth.module = "default" auth.noauth.controller = "index" auth.noauth.action = "index" @@ -26,18 +28,50 @@ auth.user = "username" auth.pass = "password" auth.passtreat = "MD5(?) AND activated IS NULL" +auth.referenceMap.0.table = "usersdetails"; +auth.referenceMap.0.reference = "usersdetails.username=users.username"; +auth.referenceMap.0.columns = "*"; +auth.referenceMap.1.table = "roles"; +auth.referenceMap.1.reference = "roles.id=users.roleid"; +auth.referenceMap.1.columns = "roles.name as role"; +lang.languageKey = "language"; lang.path = "lang/"; lang.default = "uk"; lang.langs[] = "uk"; lang.langs[] = "en"; +layout.layoutpath = "application/layouts"; +layout.layout = "layout"; +layout.contentKey = "content"; +layout.pluginclass = "Ostacium_Controller_Plugin_Layout"; + +view.encoding = "UTF-8"; +view.helperPathPrefix = "Ostacium_View_Helper"; +view.helperPath = "/library/Ostacium/View/Helper"; + +log.table = "log"; +log.columnMap.type = "priorityName"; +log.columnMap.message = "message"; +log.columnMap.username = "username"; +log.columnMap.when = "timestamp"; +log.columnMap.ip = "ip"; + +email.admin = "admin" + +listtable.class = "crudtable" + +#currency.format = "1" +#currency.precision = "2" +currency.display = "2" + title = "ACM Contester" titlesep = " - " [development: general] db.adapter = "Mysqli" +db.encoding = "UTF8" db.params.host = "localhost" db.params.dbname = "acm" db.params.username = "acm" Modified: website/httpdocs/index.php =================================================================== --- website/httpdocs/index.php 2008-10-04 23:18:38 UTC (rev 404) +++ website/httpdocs/index.php 2008-10-05 15:06:51 UTC (rev 405) @@ -6,10 +6,8 @@ $_docroot = dirname($_SERVER["DOCUMENT_ROOT"]); $_approot = dirname(__FILE__); -require_once $_docroot . DIRECTORY_SEPARATOR . 'library/Application.php'; +require_once $_docroot . '/library/Application.php'; $app = new Application($_approot); $app->setEnvironment('development'); -$app->bootstrap(); - -?> \ No newline at end of file +$app->bootstrap(); \ No newline at end of file Modified: website/lang/en.csv =================================================================== --- website/lang/en.csv 2008-10-04 23:18:38 UTC (rev 404) +++ website/lang/en.csv 2008-10-05 15:06:51 UTC (rev 405) @@ -5,6 +5,7 @@ error_other;There was unknow error, please contact administrator error_404;The page you requested was not found +error_403;You don't have the rights to access that page errorBetween;Value should be between %1$s and %2$s characters Modified: website/lang/uk.csv =================================================================== --- website/lang/uk.csv 2008-10-04 23:18:38 UTC (rev 404) +++ website/lang/uk.csv 2008-10-05 15:06:51 UTC (rev 405) @@ -5,6 +5,7 @@ error_other;There was unknow error, please contact administrator error_404;The page you requested was not found +error_403;You don't have the rights to access that page errorBetween;Value should be between %1$s and %2$s characters Modified: website/library/Application.php =================================================================== --- website/library/Application.php 2008-10-04 23:18:38 UTC (rev 404) +++ website/library/Application.php 2008-10-05 15:06:51 UTC (rev 405) @@ -4,18 +4,25 @@ { protected $_environment; protected static $_approot; + protected static $_start; protected $_docroot; - public function Application($_approot) + public function __construct($_approot) { self::$_approot = $_approot; $this->_docroot = dirname($_SERVER["DOCUMENT_ROOT"]); + self::$_start = microtime(true); } public static function getAppRoot() { return self::$_approot; } + + public static function getRunTime() + { + return (microtime(true) - self::$_start); + } public function setEnvironment($environment) { @@ -32,15 +39,18 @@ if (!$this->_environment) { throw new Exception('Please set the environment using ::setEnvironment'); } - + try { $frontController = $this->_initialize(); - $this->setupRoutes($frontController); + $this->_setupRoutes($frontController); $frontController->dispatch(); } catch (Exception $e) { - var_dump($e); + if(Zend_Registry::offsetExists('Zend_Log')) + Zend_Registry::get('Zend_Log')->log($e->getMessage(), Zend_Log::ERR); + else + var_dump($e); } } @@ -61,29 +71,29 @@ // Setup Session Zend_Session::start(); - // Setup Date - Ostacium_Date::setOptions(array('format_type' => 'php')); - // Setup Config $_config = $this->_setupConfig(); + + // Setup Front Controller + $frontController = $this->_setupFrontController(); + + // Setup Date + Ostacium_Date::setOptions($_config->date->toArray()); + //date_default_timezone_set($_config->date->timezone); // Setup DB $this->_setupDB(); - + // Setup Helpers Ostacium_View_Helper_Truncate::setDefault($_config->truncate->toArray()); - Ostacium_View_Helper_listTable::setDefaultAttribs(array('class' => 'crudtable')); - - // Setup Front Controller - $frontController = $this->_setupFrontController(); + Ostacium_View_Helper_listTable::setDefaultAttribs($_config->listtable->toArray()); - // Setup Error Handler - $frontController->registerPlugin(new Ostacium_Controller_Plugin_ErrorHandler(array( - 'module' => $_config->auth->noacl->module, - 'controller' => $_config->auth->noacl->controller, - 'action' => $_config->auth->noacl->action - ))); + // Setup Log + $this->_setupLog(); + // Setup Authorication + $acl = $this->_setupAuth(); + // Setup Languages $this->_setupLang(); @@ -92,15 +102,13 @@ // Setup View $this->_setupView(); - - // Setup Authorication - $acl = $this->_setupAuth(); // Setup Email - $mail = new Zend_Mail_Transport_Sendmail('-fadmin@'.$_SERVER["SERVER_NAME"]); + $mail = new Zend_Mail_Transport_Sendmail('-f'.$_config->email->admin.'@'.$_SERVER["SERVER_NAME"]); Zend_Mail::setDefaultTransport($mail); - $routerPlugin = new Ostacium_Controller_Plugin_Router($acl, $_config->auth->noauth->toArray(), $_config->auth->noacl->toArray()); + // Setup Plugins + $routerPlugin = new Ostacium_Controller_Plugin_Router($acl, $_config->auth->noauth->toArray(), $_config->auth->noacl->toArray()); $frontController->registerPlugin($routerPlugin, -1); return $frontController; @@ -127,7 +135,6 @@ error_reporting((int)$_config->error->report); ini_set('display_errors', (int)$_config->error->display); - date_default_timezone_set($_config->date->timezone); Zend_Registry::set('config', $_config); @@ -139,7 +146,8 @@ $_config = Zend_Registry::get('config'); $_db = Zend_Db::factory($_config->db); - $_db->query("SET NAMES UTF8"); + $_db->query("SET NAMES ".$_config->db->encoding); + Ostacium_Db_Table::setDefaultAdapter($_db); Ostacium_Db_CrudTable::setPerPage($_config->table->perpage); @@ -153,10 +161,17 @@ $frontController = Zend_Controller_Front::getInstance(); $frontController->throwExceptions((bool) $_config->error->throw); $frontController->setParam('environment', $this->_environment); - $frontController->setControllerDirectory(array( - 'default' => $this->_docroot . '/application/default/controllers', - 'admin' => $this->_docroot . '/application/admin/controllers', - )); + $frontController->setModuleControllerDirectoryName('controllers'); + $frontController->addModuleDirectory($this->_docroot . '/application/modules/'); + $frontController->setRequest('Ostacium_Controller_Request_Http'); + + // Error Handler + $frontController->setParam('noErrorHandler', 1); + $frontController->registerPlugin(new Ostacium_Controller_Plugin_ErrorHandler(array( + 'module' => $_config->auth->noacl->module, + 'controller' => $_config->auth->noacl->controller, + 'action' => $_config->auth->noacl->action + ))); return $frontController; } @@ -165,21 +180,20 @@ { $_config = Zend_Registry::get('config'); - Zend_Layout::startMvc(array('layoutPath' => $this->_docroot . '/application/default/layouts')); - - $view = new Zend_View( array( - 'encoding' => 'UTF-8', - 'helperPathPrefix' => 'Ostacium_View_Helper', - 'helperPath' => $this->_docroot . '/library/Ostacium/View/Helper' - )); - + $options = $_config->view->toArray(); + $options['helperPath'] = $this->_docroot . '/' . $options['helperPath']; + $view = new Zend_View($options); + + // Setup DocType $view->doctype('XHTML1_TRANSITIONAL'); // Setup Title - //$view->placeholder('title')->set($_config->title); $view->headTitle($_config->title)->setSeparator($_config->titlesep); // Setup Dojo Zend_Dojo::enableView($view); + $options = $_config->layout->toArray(); + $options['layoutpath'] = $this->_docroot . '/' . $options['layoutpath']; + Zend_Layout::startMvc($options + array('view' => $view)); $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view); Zend_Controller_Action_HelperBroker::addHelper($viewRenderer); @@ -190,7 +204,8 @@ $_config = Zend_Registry::get('config'); $acl = new Ostacium_Acl($_config->auth->order); - $auth = new Zend_Auth_Adapter_DbTable(Zend_Registry::get('db'), $_config->auth->table, $_config->auth->user, $_config->auth->pass, $_config->auth->passtreat); + $auth = new Ostacium_Auth_Adapter_DbTable(Zend_Registry::get('db'), $_config->auth->table, $_config->auth->user, $_config->auth->pass, $_config->auth->passtreat); + $auth->setReferenceMap($_config->auth->referenceMap->toArray()); Zend_Registry::set('auth', $auth); Zend_Registry::set('acl', $acl); @@ -202,50 +217,51 @@ { $_config = Zend_Registry::get('config'); $_db = Zend_Registry::get('db'); + $_auth = Zend_Auth::getInstance(); - $translate = new Zend_Translate('csv', $this->_docroot.'/'.$_config->lang->path . $_config->lang->default . '.csv', $_config->lang->default); + $translate = new Zend_Translate('csv', $this->_docroot . '/' . $_config->lang->path . $_config->lang->default . '.csv', $_config->lang->default); foreach($_config->lang->langs as $lang) { if ($lang != $_config->lang->default) - $translate->addTranslation($this->_docroot.'/'.$_config->lang->path . $lang .'.csv', 'en'); + $translate->addTranslation($this->_docroot . '/' . $_config->lang->path . $lang .'.csv', 'en'); } - $translate->setLocale($_config->lang->default); + if ($_auth->hasIdentity()) + $language = $_auth->getIdentity()->language; + else + $language = $_config->lang->default; + + $translate->setLocale($language); Zend_Registry::set('Zend_Translate', $translate); - - /**********************************************/ - $user_messages = $_db->select()->from('messages')->query()->fetchAll(); - - $stdMessages = new stdClass(); - foreach ($user_messages as $values) - { - $stdMessages->{$values['name']} = $values['message']; - } - - Zend_Registry::set('messages', $stdMessages); } - protected function setupRoutes(Zend_Controller_Front $frontController) + protected function _setupRoutes(Zend_Controller_Front $frontController) { - // Retrieve the router from the frontcontroller + $_config = Zend_Registry::get('config'); $router = $frontController->getRouter(); + + $router->addRoute('default', new Ostacium_Controller_Router_Route_Language(array(), $frontController->getDispatcher(), $frontController->getRequest())); + + if ($_config->routes) + $router->addConfig($_config->routes); - /* - * You can add routes here like so: - * $router->addRoute( - * 'home', - * new Zend_Controller_Router_Route('home', array( - * 'controller' => 'index', - * 'action' => 'index' - * )) - * ); - */ - return $router; } + + protected function _setupLog() + { + $_db = Zend_Registry::get('db'); + $_config = Zend_Registry::get('config'); + + $writer = new Ostacium_Log_Writer_Db($_db, $_config->log->table, $_config->log->columnMap); + $log = new Zend_Log($writer); + $log->addWriter(new Zend_Log_Writer_Firebug()); + + Zend_Registry::set('Zend_Log', $log); + } }; -function br2nl($text) +/*function br2nl($text) { return preg_replace('/<br\\\\s*?\\/??>/i', "\\n", $text); } @@ -258,5 +274,4 @@ return $string; } -} -?> \ No newline at end of file +}*/ \ No newline at end of file Modified: website/library/Ostacium/Acl.php =================================================================== --- website/library/Ostacium/Acl.php 2008-10-04 23:18:38 UTC (rev 404) +++ website/library/Ostacium/Acl.php 2008-10-05 15:06:51 UTC (rev 405) @@ -63,12 +63,9 @@ } } - public function getRoleById($id) { return (isset($this->_idtorole[$id]) ? $this->_idtorole[$id] : 'guest' ); } -} - -?> \ No newline at end of file +} \ No newline at end of file Property changes on: website/library/Ostacium/Auth ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/library/Ostacium/Auth/Adapter ___________________________________________________________________ Added: tsvn:logminsize + 5 Added: website/library/Ostacium/Auth/Adapter/DbTable.php =================================================================== --- website/library/Ostacium/Auth/Adapter/DbTable.php (rev 0) +++ website/library/Ostacium/Auth/Adapter/DbTable.php 2008-10-05 15:06:51 UTC (rev 405) @@ -0,0 +1,69 @@ +<?php + +class Ostacium_Auth_Adapter_DbTable extends Zend_Auth_Adapter_DbTable +{ + /** + * $_referenceMap - Other tables to be used while fetching result rows + * + * @var array + */ + protected $_referenceMap = null; + + /** + * __construct() - Sets configuration options + * + * @param Zend_Db_Adapter_Abstract $zendDb + * @param string $tableName + * @param string $identityColumn + * @param string $credentialColumn + * @param string $credentialTreatment + * @param array $referenceMap + * @return void + */ + public function __construct(Zend_Db_Adapter_Abstract $zendDb, $tableName = null, $identityColumn = null, + $credentialColumn = null, $credentialTreatment = null, $referenceMap = null) + { + parent::__construct($zendDb, $tableName, $identityColumn, $credentialColumn, $credentialTreatment); + + if (null !== $referenceMap) { + $this->setReferenceMap($referenceMap); + } + } + + + /** + * setReferenceMap() - set the reference of the tables to be fetched during authotication + * + * @param array $referenceMap + * @return Zend_Auth_Adapter_DbTable Provides a fluent interface + */ + public function setReferenceMap($referenceMap) + { + $this->_referenceMap = $referenceMap; + return $this; + } + + /** + * _authenticateCreateSelect() - This method creates a Zend_Db_Select object that + * is completely configured to be queried against the database. + * + * @return Zend_Db_Select + */ + protected function _authenticateCreateSelect() + { + $dbSelect = parent::_authenticateCreateSelect(); + + if (null !== $this->_referenceMap && is_array($this->_referenceMap)) + { + foreach ($this->_referenceMap as $options) + { + $dbSelect->joinInner($options['table'], $options['reference'], $options['columns']); + } + } + + $dbSelect->reset( Zend_Db_Select::WHERE ); + $dbSelect->where($this->_zendDb->quoteIdentifier($this->_tableName . '.' . $this->_identityColumn, true) . ' = ?', $this->_identity); + + return $dbSelect; + } +} \ No newline at end of file Modified: website/library/Ostacium/Controller/Action.php =================================================================== --- website/library/Ostacium/Controller/Action.php 2008-10-04 23:18:38 UTC (rev 404) +++ website/library/Ostacium/Controller/Action.php 2008-10-05 15:06:51 UTC (rev 405) @@ -12,11 +12,11 @@ $name = ucfirst($this->getRequest()->getControllerName()); // Setup LayoutPath - $layoutPath = $this->_helper->getHelper('viewRenderer')->getModuleDirectory() . DIRECTORY_SEPARATOR . 'layouts'; - $this->_helper->layout()->setLayoutPath($layoutPath); + //$layoutPath = $this->_helper->getHelper('viewRenderer')->getModuleDirectory() . '/layouts'; + //$this->_helper->layout()->setLayoutPath($layoutPath); // Setup ModelPath - $modelPath = $this->_helper->getHelper('viewRenderer')->getModuleDirectory() . DIRECTORY_SEPARATOR . 'models'; + $modelPath = $this->_helper->getHelper('viewRenderer')->getModuleDirectory() . '/models'; set_include_path( $modelPath . PATH_SEPARATOR . get_include_path() ); // Setup Model @@ -74,6 +74,4 @@ { return $this->_translate->_($msg); } -} - -?> \ No newline at end of file +} \ No newline at end of file Modified: website/library/Ostacium/Controller/Plugin/ErrorHandler.php =================================================================== --- website/library/Ostacium/Controller/Plugin/ErrorHandler.php 2008-10-04 23:18:38 UTC (rev 404) +++ website/library/Ostacium/Controller/Plugin/ErrorHandler.php 2008-10-05 15:06:51 UTC (rev 405) @@ -4,29 +4,38 @@ { protected $_isPreDispatch = false; + const EXCEPTION_NOTALLOWED = 'EXCEPTION_NOTALLOWED'; + public function preDispatch(Zend_Controller_Request_Abstract $request) - { + { $frontController = Zend_Controller_Front::getInstance(); $dispatcher = $frontController->getDispatcher(); $response = $this->getResponse(); - if ($frontController->getParam('noErrorHandler') || $this->_isInsideErrorHandlerLoop) { - return; - } - $error = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS); $error->exception = current($response->getException()); if (!$dispatcher->isDispatchable($request)) { $error->type = self::EXCEPTION_NO_CONTROLLER; + if (!$error->exception) + $error->exception = new Zend_Controller_Dispatcher_Exception("Resource doesn't exist", 404); } elseif (!$this->isProperAction($dispatcher, $request)) { $error->type = self::EXCEPTION_NO_ACTION; + if (!$error->exception) + $error->exception = new Zend_Controller_Dispatcher_Exception("Resource doesn't exist", 404); + } elseif ($error->exception) { + $error->type = self::EXCEPTION_OTHER; + } elseif ($request->getParam('error_message') != "") + { + $error->type = self::EXCEPTION_NOTALLOWED; + if (!$error->exception) + $error->exception = new Ostacium_Controller_Plugin_Router_Exception("No rights to access the resouce", 403); } if (isset($error->type)) { $this->_isInsideErrorHandlerLoop = true; $this->_isPreDispatch = true; - $this->_exceptionCountAtFirstEncounter = count($response->getException()); + $this->_exceptionCountAtFirstEncounter = count($response->getException()); $error->request = clone $request; $request->setParam('error_handler', $error) @@ -38,27 +47,78 @@ public function postDispatch(Zend_Controller_Request_Abstract $request) { - $response = $this->getResponse(); - if (!$this->_isInsideErrorHandlerLoop && count($response->getException()) > $this->_exceptionCountAtFirstEncounter) + $response = $this->getResponse(); + + if (!$this->_isInsideErrorHandlerLoop && count($response->getException()) > $this->_exceptionCountAtFirstEncounter) { - parent::postDispatch($request); + + if ($this->_isInsideErrorHandlerLoop) { + $exceptions = $response->getException(); + if (count($exceptions) > $this->_exceptionCountAtFirstEncounter) { + // Exception thrown by error handler; tell the front controller to throw it + $frontController->throwExceptions(true); + throw array_pop($exceptions); + } + } + + // check for an exception AND allow the error handler controller the option to forward + if (($response->isException()) && (!$this->_isInsideErrorHandlerLoop)) { + $this->_isInsideErrorHandlerLoop = true; + + // Get exception information + $error = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS); + $exceptions = $response->getException(); + $exception = $exceptions[0]; + $exceptionType = get_class($exception); + $error->exception = $exception; + switch ($exceptionType) { + case 'Zend_Controller_Dispatcher_Exception': + $error->type = self::EXCEPTION_NO_CONTROLLER; + break; + case 'Zend_Controller_Action_Exception': + if (404 == $exception->getCode()) { + $error->type = self::EXCEPTION_NO_ACTION; + } else { + $error->type = self::EXCEPTION_OTHER; + } + break; + default: + $error->type = self::EXCEPTION_OTHER; + break; + } + + // Keep a copy of the original request + $error->request = clone $request; + + // get a count of the number of exceptions encountered + $this->_exceptionCountAtFirstEncounter = count($exceptions); + + // Forward to the error handler + $request->setParam('error_handler', $error) + ->setModuleName($this->getErrorHandlerModule()) + ->setControllerName($this->getErrorHandlerController()) + ->setActionName($this->getErrorHandlerAction()) + ->setDispatched(false); + } } - } public function isProperAction($dispatcher, $request) { $className = $dispatcher->loadClass($dispatcher->getControllerClass($request)); $actionName = $request->getActionName(); + if (empty($actionName)) { $actionName = $dispatcher->getDefaultAction(); } + $methodName = $dispatcher->formatActionName($actionName); + $class = new ReflectionClass($className); - $class = new ReflectionClass($className); if ($class->hasMethod($methodName)) { return true; } + return false; } } \ No newline at end of file Added: website/library/Ostacium/Controller/Plugin/Layout.php =================================================================== --- website/library/Ostacium/Controller/Plugin/Layout.php (rev 0) +++ website/library/Ostacium/Controller/Plugin/Layout.php 2008-10-05 15:06:51 UTC (rev 405) @@ -0,0 +1,25 @@ +<?php + +class Ostacium_Controller_Plugin_Layout extends Zend_Layout_Controller_Plugin_Layout +{ + protected $_defaultLayoutPath = ''; + + public function __construct(Zend_Layout $layout = null) + { + parent::__construct($layout); + + $this->_defaultLayoutPath = $this->getLayout()->getLayoutPath(); + } + + public function preDispatch(Zend_Controller_Request_Abstract $request) + { + $_config = Zend_Registry::get('config'); + $path = Zend_Controller_Front::getInstance()->getModuleDirectory() . '/layouts/'; + + if (file_exists($path . $this->getLayout()->getLayout() . '.' . $this->getLayout()->getViewSuffix())) + $this->getLayout()->setLayoutPath($path); + else + $this->getLayout()->setLayoutPath($this->_defaultLayoutPath); + } + +} \ No newline at end of file Modified: website/library/Ostacium/Controller/Plugin/Router.php =================================================================== --- website/library/Ostacium/Controller/Plugin/Router.php 2008-10-04 23:18:38 UTC (rev 404) +++ website/library/Ostacium/Controller/Plugin/Router.php 2008-10-05 15:06:51 UTC (rev 405) @@ -1,7 +1,9 @@ <?php -class Ostacium_Controller_Plugin_Router extends Zend_Controller_Plugin_Abstract { +class Ostacium_Controller_Plugin_Router_Exception extends Zend_Controller_Exception {} +class Ostacium_Controller_Plugin_Router extends Zend_Controller_Plugin_Abstract +{ private $_acl; private $_noauth = array( /*'module' => 'default',*/ 'controller' => 'index', @@ -19,6 +21,7 @@ public function preDispatch(Zend_Controller_Request_Abstract $request) { $auth = Zend_Auth::getInstance(); + $dispatcher = Zend_Controller_Front::getInstance()->getDispatcher(); if ($auth->hasIdentity()) { $role = $this->_acl->getRoleById($auth->getIdentity()->roleid) ? $this->_acl->getRoleById($auth->getIdentity()->roleid) : 'guest'; @@ -31,16 +34,12 @@ $module = $request->getModuleName(); $resource = ($module != 'default' ? $module . ':' . $controller : $controller); - if (!$this->_acl->has($resource)) + if (!$this->_acl->has($resource) || !$dispatcher->isDispatchable($request) || !$this->isProperAction($dispatcher, $request)) { $e = new Zend_Controller_Dispatcher_Exception("Resource doesn't exist", 404); $response = $this->getResponse(); $response->setException($e); - -// $module = $this->_noacl['module']; -// $controller = $this->_noacl['controller']; -// $action = $this->_noacl['action']; } elseif (!$this->_acl->isAllowed($role, $resource, $action)) { if (!$auth->hasIdentity()) { @@ -48,13 +47,13 @@ $controller = $this->_noauth['controller']; $action = $this->_noauth['action']; - $request->setParam('message', 'nologin'); + $request->setParam('error_message', 'nologin'); } else { $module = $this->_noacl['module']; $controller = $this->_noacl['controller']; $action = $this->_noacl['action']; - $request->setParam('message', 'noallowed'); + $request->setParam('error_message', 'noallowed'); } } @@ -62,6 +61,23 @@ $request->setControllerName($controller); $request->setActionName($action); } -} - -?> \ No newline at end of file + + public function isProperAction($dispatcher, $request) + { + $className = $dispatcher->loadClass($dispatcher->getControllerClass($request)); + $actionName = $request->getActionName(); + + if (empty($actionName)) { + $actionName = $dispatcher->getDefaultAction(); + } + + $methodName = $dispatcher->formatActionName($actionName); + $class = new ReflectionClass($className); + + if ($class->hasMethod($methodName)) { + return true; + } + + return false; + } +} \ No newline at end of file Property changes on: website/library/Ostacium/Controller/Request ___________________________________________________________________ Added: tsvn:logminsize + 5 Added: website/library/Ostacium/Controller/Request/Http.php =================================================================== --- website/library/Ostacium/Controller/Request/Http.php (rev 0) +++ website/library/Ostacium/Controller/Request/Http.php 2008-10-05 15:06:51 UTC (rev 405) @@ -0,0 +1,9 @@ +<?php + +class Ostacium_Controller_Request_Http extends Zend_Controller_Request_Http +{ + public function getIP() + { + return $this->getServer('HTTP_X_FORWARDED_FOR', $this->getServer('HTTP_VIA', $this->getServer('REMOTE_ADDR', '0.0.0.0') ) ); + } +} \ No newline at end of file Property changes on: website/library/Ostacium/Controller/Router ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/library/Ostacium/Controller/Router/Route ___________________________________________________________________ Added: tsvn:logminsize + 5 Added: website/library/Ostacium/Controller/Router/Route/Language.php =================================================================== --- website/library/Ostacium/Controller/Router/Route/Language.php (rev 0) +++ website/library/Ostacium/Controller/Router/Route/Language.php 2008-10-05 15:06:51 UTC (rev 405) @@ -0,0 +1,139 @@ +<?php + +class Ostacium_Controller_Router_Route_Language extends Zend_Controller_Router_Route_Module +{ + protected $translate; + protected $config; + + protected $_languageKey = 'language'; + + public function __construct(array $defaults = array(), + Zend_Controller_Dispatcher_Interface $dispatcher = null, + Zend_Controller_Request_Abstract $request = null) + { + parent::__construct($defaults, $dispatcher, $request); + + $this->translate = Zend_Registry::get('Zend_Translate'); + $this->config = Zend_Registry::get('config'); + } + + protected function _setRequestKeys() + { + parent::_setRequestKeys(); + + $this->_languageKey = $this->config->lang->languageKey; + $language = $this->translate->getLocale(); + + if (null !== $this->_dispatcher) { + $this->_defaults += array($this->_languageKey => $language); + } + } + + public function match($path) + { + $this->_setRequestKeys(); + + $values = array(); + $params = array(); + $path = trim($path, self::URI_DELIMITER); + + if ($path != '') { + $path = explode(self::URI_DELIMITER, $path); + + if ($this->translate->isAvailable($path[0])) { + $values[$this->_languageKey] = array_shift($path); + $this->translate->setLocale($values[$this->_languageKey]); + } + + if (count($path) && !empty($path[0]) && $this->_dispatcher && $this->_dispatcher->isValidModule($path[0])) { + $values[$this->_moduleKey] = array_shift($path); + $this->_moduleValid = true; + } + + if (count($path) && !empty($path[0])) { + $values[$this->_controllerKey] = array_shift($path); + } + + if (count($path) && !empty($path[0])) { + $values[$this->_actionKey] = array_shift($path); + } + + if ($numSegs = count($path)) { + for ($i = 0; $i < $numSegs; $i = $i + 2) { + $key = urldecode($path[$i]); + $val = isset($path[$i + 1]) ? urldecode($path[$i + 1]) : null; + $params[$key] = $val; + } + } + } + + $this->_values = $values + $params; + + return $this->_values + $this->_defaults; + } + + public function assemble($data = array(), $reset = false, $encode = true) + { + if (!$this->_keysSet) { + $this->_setRequestKeys(); + } + + $params = (!$reset) ? $this->_values : array(); + + foreach ($data as $key => $value) { + if ($value !== null) { + $params[$key] = $value; + } elseif (isset($params[$key])) { + unset($params[$key]); + } + } + + $params += $this->_defaults; + + $url = ''; + + $language = $params[$this->_languageKey]; + unset($params[$this->_languageKey]); + + if ($this->_moduleValid || array_key_exists($this->_moduleKey, $data)) { + if ($params[$this->_moduleKey] != $this->_defaults[$this->_moduleKey]) { + $module = $params[$this->_moduleKey]; + } + } + unset($params[$this->_moduleKey]); + + $controller = $params[$this->_controllerKey]; + unset($params[$this->_controllerKey]); + + $action = $params[$this->_actionKey]; + unset($params[$this->_actionKey]); + + foreach ($params as $key => $value) { + if ($encode) $value = urlencode($value); + $url .= '/' . $key; + $url .= '/' . $value; + } + + if (!empty($url) || $action !== $this->_defaults[$this->_actionKey]) { + if ($encode) $action = urlencode($action); + $url = '/' . $action . $url; + } + + if (!empty($url) || $controller !== $this->_defaults[$this->_controllerKey]) { + if ($encode) $controller = urlencode($controller); + $url = '/' . $controller . $url; + } + + if (isset($module)) { + if ($encode) $module = urlencode($module); + $url = '/' . $module . $url; + } + + if ($this->translate->isAvailable($language)) { + if ($encode) $language = urlencode($language); + $url = '/' . $language . $url; + } + + return ltrim($url, self::URI_DELIMITER); + } +} \ No newline at end of file Modified: website/library/Ostacium/Date.php =================================================================== --- website/library/Ostacium/Date.php 2008-10-04 23:18:38 UTC (rev 404) +++ website/library/Ostacium/Date.php 2008-10-05 15:06:51 UTC (rev 405) @@ -8,8 +8,6 @@ } public static function getInstance($date = null, $part = null, $locale = null) { - return new self($date = null, $part = null, $locale = null); + return new self($date, $part, $locale); } -} - -?> \ No newline at end of file +} \ No newline at end of file Modified: website/library/Ostacium/Db/Table/Rowset.php =================================================================== --- website/library/Ostacium/Db/Table/Rowset.php 2008-10-04 23:18:38 UTC (rev 404) +++ website/library/Ostacium/Db/Table/Rowset.php 2008-10-05 15:06:51 UTC (rev 405) @@ -38,6 +38,4 @@ return parent::toArray(); } } -} - -?> \ No newline at end of file +} \ No newline at end of file Modified: website/library/Ostacium/Db/Table.php =================================================================== --- website/library/Ostacium/Db/Table.php 2008-10-04 23:18:38 UTC (rev 404) +++ website/library/Ostacium/Db/Table.php 2008-10-05 15:06:51 UTC (rev 405) @@ -10,10 +10,8 @@ public function get($pPrimaryKey) { $get = parent::find($pPrimaryKey)->current(); - if ($get) - return $get->toArray(); - else - return $get; + + return $get; } public function insert($data) @@ -31,8 +29,7 @@ public function count($_where = null) { - $select = $this->select() - ->from($this->_name, new Zend_Db_Expr('COUNT(*)')); + $select = $this->select()->from($this->_name, new Zend_Db_Expr('COUNT(*)')); if ($_where !== null) { @@ -60,6 +57,4 @@ $data = array_intersect_key($data, array_flip($this->_cols)); } -} - -?> \ No newline at end of file +} \ No newline at end of file Property changes on: website/library/Ostacium/Log ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/library/Ostacium/Log/Writer ___________________________________________________________________ Added: tsvn:logminsize + 5 Added: website/library/Ostacium/Log/Writer/Db.php =================================================================== --- website/library/Ostacium/Log/Writer/Db.php (rev 0) +++ website/library/Ostacium/Log/Writer/Db.php 2008-10-05 15:06:51 UTC (rev 405) @@ -0,0 +1,20 @@ +<?php + +class Ostacium_Log_Writer_Db extends Zend_Log_Writer_Db +{ + protected function _write($event) + { + $auth = Zend_Auth::getInstance(); + $_config = Zend_Registry::get('config'); + + if ($auth->hasIdentity()) + $event['username'] = $auth->getIdentity()->{$_config->auth->user}; + else + $event['username'] = 'guest'; + + $event['ip'] = Zend_Controller_Front::getInstance()->getRequest()->getIp(); + $event['timestamp'] = time(); + + return parent::_write($event); + } +} \ No newline at end of file Modified: website/library/Ostacium/Model.php =================================================================== --- website/library/Ostacium/Model.php 2008-10-04 23:18:38 UTC (rev 404) +++ website/library/Ostacium/Model.php 2008-10-05 15:06:51 UTC (rev 405) @@ -13,6 +13,4 @@ } public function init() {} -} - -?> \ No newline at end of file +} \ No newline at end of file Modified: website/library/Ostacium/View/Helper/BaseUrl.php =================================================================== --- website/library/Ostacium/View/Helper/BaseUrl.php 2008-10-04 23:18:38 UTC (rev 404) +++ website/library/Ostacium/View/Helper/BaseUrl.php 2008-10-05 15:06:51 UTC (rev 405) @@ -1,12 +1,18 @@ <?php -class Ostacium_View_Helper_BaseUrl +class Ostacium_View_Helper_BaseUrl extends Zend_View_Helper_Abstract { public function baseUrl($file = null) { - return Zend_Controller_Front::getInstance()->getRequest()->getBaseUrl() - . ($file ? ('/' . trim((string) $file, '/\\')) : ''); + // Get baseUrl + $baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl(); + + // Remove trailing slashes + $file = ($file !== null) ? ltrim($file, '/\\') : null; + + // Build return + $return = rtrim($baseUrl, '/\\') . (($file !== null) ? ('/' . $file) : ''); + + return $return; } -} - -?> \ No newline at end of file +} \ No newline at end of file Modified: website/library/Ostacium/View/Helper/Currency.php =================================================================== --- website/library/Ostacium/View/Helper/Currency.php 2008-10-04 23:18:38 UTC (rev 404) +++ website/library/Ostacium/View/Helper/Currency.php 2008-10-05 15:06:51 UTC (rev 405) @@ -1,16 +1,19 @@ <?php -class Ostacium_View_Helper_Currency +class Ostacium_View_Helper_Currency extends Zend_View_Helper_Abstract { + public static $default_options = array('display' => Zend_Currency::USE_SYMBOL); + + public static function setDefault(array $options) { + self::$default_options = $options; + } + public function currency($amount, $currency, $locale = null) { - if (isset($locale)) - $c = new Zend_Currency($currency, $locale); - else - $c = new Zend_Currency($currency); - - return $c->toCurrency($amount, array('display' => Zend_Currency::USE_SYMBOL)); + if (!isset($locale)) + $locale = Zend_Registry::get('Zend_Translate')->getLocale(); + + $currency = new Zend_Currency($currency, $locale); + return $currency->toCurrency($amount, self::$default_options); } -} - -?> \ No newline at end of file +} \ No newline at end of file Added: website/library/Ostacium/View/Helper/DebugInfo.php =================================================================== --- website/library/Ostacium/View/Helper/DebugInfo.php (rev 0) +++ website/library/Ostacium/View/Helper/DebugInfo.php 2008-10-05 15:06:51 UTC (rev 405) @@ -0,0 +1,24 @@ +<?php + +class Ostacium_View_Helper_DebugInfo extends Zend_View_Helper_Abstract +{ + public function debugInfo($writetolog = false) + { + $translate = Zend_Registry::get('Zend_Translate'); + $profiler = Zend_Registry::get('db')->getProfiler(); + $environment = Zend_Controller_Front::getInstance()->getParam('environment'); + $return = null; + + if ($environment == 'development') + { + $return = $translate->_('runtime') . ': ' .Application::getRunTime() . '; ' . $translate->_('totalqueries') . ': ' . $profiler->getTotalNumQueries() . '; ' . $translate->_('totalqueriestime') . ': ' . $profiler->getTotalElapsedSecs(); + + if ($writetolog) + { + Zend_Registry::get('Zend_Log')->log($return, Zend_Log::NOTICE); + } + } + + return $return; + } +} \ No newline at end of file Modified: website/library/Ostacium/View/Helper/FormFile.php =================================================================== --- website/library/Ostacium/View/Helper/FormFile.php 2008-10-04 23:18:38 UTC (rev 404) +++ website/library/Ostacium/View/Helper/FormFile.php 2008-10-05 15:06:51 UTC (rev 405) @@ -18,6 +18,4 @@ return $xhtml; } -} - -?> \ No newline at end of file +} \ No newline at end of file Modified: website/library/Ostacium/View/Helper/ListTable.php =================================================================== --- website/library/Ostacium/View/Helper/ListTable.php 2008-10-04 23:18:38 UTC (rev 404) +++ website/library/Ostacium/View/Helper/ListTable.php 2008-10-05 15:06:51 UTC (rev 405) @@ -140,6 +140,4 @@ break; } } -} - -?> \ No newline at end of file +} \ No newline at end of file Modified: website/library/Ostacium/View/Helper/Truncate.php =================================================================== --- website/library/Ostacium/View/Helper/Truncate.php 2008-10-04 23:18:38 UTC (rev 404) +++ website/library/Ostacium/View/Helper/Truncate.php 2008-10-05 15:06:51 UTC (rev 405) @@ -1,8 +1,7 @@ <?php -class Ostacium_View_Helper_Truncate +class Ostacium_View_Helper_Truncate extends Zend_View_Helper_Abstract { - public $view; public static $default_options = array( 'length' => 300, 'ending' => '...', @@ -10,10 +9,6 @@ 'considerHtml' => true ); - public function setView(Zend_View_Interface $view) { - $this->view = $view; - } - public static function setDefault(array $options) { self::$default_options = $options; } @@ -131,9 +126,6 @@ } return $truncate; - } -} - -?> \ No newline at end of file +} \ No newline at end of file Modified: website/other/db.sql =================================================================== --- website/other/db.sql 2008-10-04 23:18:38 UTC (rev 404) +++ website/other/db.sql 2008-10-05 15:06:51 UTC (rev 405) @@ -3,7 +3,7 @@ -- http://www.phpmyadmin.net -- -- Host: localhost --- Generation Time: Sep 20, 2008 at 10:52 PM +-- Generation Time: Oct 05, 2008 at 05:59 PM -- Server version: 5.0.51 -- PHP Version: 5.2.6 @@ -46,8 +46,6 @@ CREATE TABLE IF NOT EXISTS `challenges` ( `id` int(11) NOT NULL auto_increment, - `name` varchar(200) NOT NULL, - `description` text NOT NULL, `timelimit` double NOT NULL default '0', `memorylimit` int(11) NOT NULL default '0', `outputlimit` int(11) NOT NULL default '0', @@ -62,216 +60,431 @@ -- Dumping data for table `challenges` -- -INSERT INTO `challenges` (`id`, `name`, `description`, `timelimit`, `memorylimit`, `outputlimit`, `tries`, `accepted`, `author`, `enabled`) VALUES -(1000, 'Swap', '<P align=left><B>Завдання</B></P><P>Дано два цілих числа a та b. Написати програму, яка б міняла їхні значення місцями. Тобто після виконання програми замість а значення b, а замість b - а. <P><B>Вхідні дані</B></P><P>В єдиному рядку записано два числа - а та b. (-32000 < a, b < 32000). <P><B>Вихідні дані</B></P><P>Вивести в єдиний рядок через пропуск два числа: спочатку b, а потім a. <P><B>Приклад введення 1</B></P><P><PRE>1 2</PRE><P><B>Приклад виведення 1</B></P><P><PRE>2 1</PRE><BR><P><B>Приклад введення 2</B></P><P><PRE>2 3</PRE><P><B>Приклад виведення 2</B></P><P><PRE>3 2</PRE><BR>', 1000, 5120000, 204800, 0, 0, '', 1), -(1001, 'A in power k', '<P align=left><B>Завдання</B></P><P>Для заданого цілого а та натурального k обчислити a<SUP>k</SUP>.<P><B>Вхідні дані</B></P><P>В єдиному рядку записано два числа a та k (-32000 < a <= 32000, 0 < k < 32000).<P><B>Вихідні дані</B></P><P>Єдине число - відповідь. Гарантується, що відповідь не більша за 2*10<SUP>9</SUP>.<P><B>Приклад введення 1</B></P><P><PRE>1 1</PRE><P><B>Приклад виведення 1</B></P><P><PRE>1</PRE><BR><P><B>Приклад введення 2</B></P><P><PRE>2 3</PRE><P><B>Приклад виведення 2</B></P><P><PRE>8</PRE><BR>', 1000, 5120000, 204800, 0, 0, '', 1), -(1002, 'Послідовність Фібоначчі', '<P align=left><B>Завдання</B></P><P>Послідовність фібоначчі визначається наступним чином:<BR></P><UL><LI>a<SUB>0</SUB>=0;<LI>a<SUB>1</SUB>=1;<LI>a<SUB>k</SUB>=a<SUB>k-1</SUB> + a<SUB>k-2</SUB></LI></UL><BR><BR>Для заданого n знайти значення n-го елемента послідовності Фібоначчі (a<SUB>n</SUB>).<P><B>Вхідні дані</B></P><P>В єдиному рядку записане єдине число N (1 <= N <= 40).<P><B>Вихідні дані</B></P><P>Єдине число - відповідь.<P><B>Приклад введення 1</B></P><P><PRE>1</PRE><P><B>Приклад виведення 1</B></P><P><PRE>1</PRE><BR><P><B>Приклад введення 2</B></P><P><PRE>5</PRE><P><B>Приклад виведення 2</B></P><P><PRE>5</PRE><BR><P><B>Приклад введення 3</B></P><P><PRE>8</PRE><P><B>Приклад виведення 3</B></P><P><PRE>21</PRE><BR>', 1000, 5120000, 204800, 0, 0, '', 1), -(1003, 'Рукавички', '<P align=left><B>Завдання</B></P><P>Комірник видає по К рукавичок кожному робітнику. Тобто другий робітник отримає рукавички від (K+1)-шої до (2∙K)-ї включно, рукавички номер (2∙K+2) отримає третій робітник і для нього вони будуть другими.<P>Напишіть програму, яка за номером виданих рукавичок визначає номер робітника, якому їх видано та порядковий номер цих рукавичок в цього робітника<P><B>Вхідні дані</B></P><P>В єдиному рядку записано два числа - K та N. K - кількість рукавичок кожному робітнику, N - номер пари рукавичок (1 <= K <= 200, 1 <= N <= 20000) розділені пропуском.<P><B>Вихідні дані</B></P><P>Номер робітника та номер рукавичок в цього робітника, розділені пропуском.<P><B>Приклад введення 1</B></P><P><PRE>50 1</PRE><P><B>Приклад виведення 1</B></P><P><PRE>1 1</PRE><BR><P><B>Приклад введення 2</B></P><P><PRE>20 25</PRE><P><B>Приклад виведення 2</B></P><P><PRE>2 5</PRE><BR><P><B>Приклад введення 3</B></P><P><PRE>15 43</PRE><P><B>Приклад виведення 3</B></P><P><PRE>3 13</PRE><BR>', 1000, 5120000, 204800, 0, 0, '', 1), -(1004, 'Супер проста проблема', '<P align=left><B>Завдання</B></P><P>Знайти квадрат N-го простого числа.<P><B>Вхідні дані</B></P><P>В єдиному рядку записане єдине число N (1 <= N <= 100).<P><B>Вихідні дані</B></P><P>Єдине число - квадрат N-го простого числа<P><B>Приклад введення 1</B></P><P><PRE>1</PRE><P><B>Приклад виведення 1</B></P><P><PRE>4</PRE><BR><P><B>Приклад введення 2</B></P><P><PRE>2</PRE><P><B>Приклад виведення 2</B></P><P><PRE>9</PRE><BR><P><B>Приклад введення 3</B></P><P><PRE>5</PRE><P><B>Приклад виведення 3</B></P><P><PRE>121</PRE><BR>', 1000, 3072000, 204800, 0, 0, '', 1), -(1005, '0-1 проблема', '<P align=left><B>Завдання</B></P><P>Над рядочком 01 виконаємо наступні операції:<UL><LI>Скопіюємо в кінець рядочка самого себе (отримаємо 0101)<LI>В другій половині рядка всі 0 змінимо на 1, а всі 1 на 0 (отримаємо 0110)</LI></UL>Над рядочком 0110 виконаємо ті самі операції. Отримаємо 01101001. І т. д.Таким чином отримаємо нескінченний рядочок нулів та одиниць.Ваше завдання – знайти n-тий символ такого рядочка.<P><B>Вхідні дані</B></P><P>В єдиному рядку записане єдине число N (1 <= N <= 2000000000).<P><B>Вихідні дані</B></P><P>Єдиний символ, який буде на N-й позиції.<P><B>Приклад введення 1</B></P><P><PRE>1</PRE><P><B>Приклад виведення 1</B></P><P><PRE>0</PRE><BR><P><B>Приклад введення 2</B></P><P><PRE>2</PRE><P><B>Приклад виведення 2</B></P><P><PRE>1</PRE><BR><P><B>Приклад введення 3</B></P><P><PRE>5</PRE><P><B>Приклад виведення 3</B></P><P><PRE>1</PRE><BR>', 1000, 3072000, 2048, 0, 0, '', 1), -(1006, 'Одинадцять', '<P align=left><B>Завдання</B></P><P>Ваше завдання – визначити чи ділиться дане число на 11.<P><B>Вхідні дані</B></P><P>В єдиному рядку записане єдине число N (1 <= n). Число має не більше тисячі знаків.<P><B>Вихідні дані</B></P><P>Вам потрібно вивести “Yes” – якщо число ділиться на 11, і “No” – в протилежному випадку.<P><B>Приклад введення 1</B></P><P><PRE>323455693</PRE><P><B>Приклад виведення 1</B></P><P><PRE>Yes</PRE><BR><P><B>Приклад введення 2</B></P><P><PRE>5038297</PRE><P><B>Приклад виведення 2</B></P><P><PRE>Yes</PRE><BR><P><B>Приклад введення 3</B></P><P><PRE>112234</PRE><P><B>Приклад виведення 3</B></P><P><PRE>No</PRE><BR>', 1000, 3072000, 2048, 0, 0, '', 1), -(1007, 'Супер послідовність', '<P align=left><B>Завдання</B></P><P>Послідовність чисел a1, a2, … an називається супер послідовністю, якщо виконуються наступні умови:<UL><LI>0 < a1 < a2 < … < an<LI>жодне з чисел не є сумою двох або більше інших чисел</LI></UL><P><B>Вхідні дані</B></P><P>В єдиному рядку записане число N (1 <= n <= 50), далі задано N чисел, кожне з яких не менше 1 і не більше 1000.<P><B>Вихідні дані</B></P><P>Вам необхідно вивести “Yes” – якщо дано супер послідовність, “No” – в протилежному випадку.<P><B>Приклад введення 1</B></P><P><PRE>2 1 2</PRE><P><B>Приклад виведення 1</B></P><P><PRE>Yes</PRE><BR><P><B>Приклад введення 2</B></P><P><PRE>3 1 2 3</PRE><P><B>Приклад виведення 2</B></P><P><PRE>No</PRE><BR><P><B>Приклад введення 3</B></P><P><PRE>10 1 3 16 19 25 70 100 243 245 306</PRE><P><B>Приклад виведення 3</B></P><P><PRE>No</PRE><BR>', 1000, 3072000, 2048, 0, 0, '', 1), -(1008, 'Супер яйця', '<P align=left><B>Задання</B></P><P>Нехай у вас є n супер яєць і ви живете в k поверховому будинку. Вам необхідно визначити за найменшу кількість кидків найбільший номер поверху з якого кинуте вниз супер яйце не розбивається. Тобто, за яку найменшу кількість спроб можна визначити найвищий поверх, з якого супер яйце не розбивається. Зауважте, якщо в результаті деякої спроби яйце не розбилось, то воно може бути використане в наступних спробах.<P><B>Вхідні дані</B></P><P>В єдиному рядку записано 2 цілих числа N (N<=30)- кількість яєць та M (M<=2 000 000 000)- кількість поверхів.<P><B>Вихідні дані</B></P><P>У єдиному рядку треба вивести єдине число – мінімальна необхідна кількість спроб. Якщо необхідно більше 30 спроб виведіть -1.<P><B>Приклад введення 1</B></P><P><PRE>1 15</PRE><P><B>Приклад виведення 1</B></P><P><PRE>15</PRE><BR><P><B>Приклад введення 2</B></P><P><PRE>2 100</PRE><P><B>Приклад виведення 2</B></P><P><PRE>14</PRE><BR><P><B>Приклад введення 3</B></P><P><PRE>10 786599</PRE><P><B>Приклад виведення 3</B></P><P><PRE>21</PRE><BR><P><B>Приклад введення 4</B></P><P><PRE>4 786599</PRE><P><B>Приклад виведення 3</B></P><P><PRE>-1</PRE><BR>', 1000, 5120000, 2048, 0, 0, '', 1), -(1009, 'Супер карти', '<P align=left><B>Завдання</B></P><P>Дана колода впорядкованих супер карт від 1 до n. Верхня супер карта має номер 1, нижня – n. Поки в колоді є хоча б дві супер карти викидаємо верхню карту, а наступну ставимо вниз колоди.<P>Необхідно знайти номер супер карти, що залишиться.<P><B>Вхідні дані</B></P><P>В єдиному рядку записане єдине число N - число супер карт в колоді (1 <= n <= 1000000).<P><B>Вихідні дані</B></P><P>Єдине число - номер супер карти, що залишиться.<P><B>Приклад введення 1</B></P><P><PRE>7</PRE><P><B>Приклад виведення 1</B></P><P><PRE>6</PRE><BR><P><B>Приклад введення 2</B></P><P><PRE>19</PRE><P><B>Приклад виведення 2</B></P><P><PRE>6</PRE><BR><P><B>Приклад введення 3</B></P><P><PRE>10</PRE><P><B>Приклад виведення 3</B></P><P><PRE>4</PRE><BR><P><B>Приклад введення 4</B></P><P><PRE>6</PRE><P><B>Приклад виведення 4</B></P><P><PRE>4</PRE><BR>', 1000, 3072000, 2048, 0, 0, '', 1), -(1010, 'Остання проблема', '<P align=left><B>Завдання</B></P><P>Ваше завдання – визначити чи дане число N можна представити у вигляді суми двох простих чисел.<P><B>Вхідні дані</B></P><P>В єдиному рядку записане єдине число N (1 <= N <= 1000000).<P><B>Вихідні дані</B></P><P>Cума двох простих чисел, що рівна n, або -1, якщо такої не існує. В сумі перше число не більше другого і якщо існує декілька таких можливих сум – вивести ту, в якої перший доданок найменший.<P><B>Приклад введення 1</B></P><P><PRE>9</PRE><P><B>Приклад виведення 1</B></P><P><PRE>2+7</PRE><BR><P><B>Приклад введення 2</B></P><P><PRE>10</PRE><P><B>Приклад виведення 2</B></P><P><PRE>3+7</PRE><BR><P><B>Приклад введення 3</B></P><P><PRE>11</PRE><P><B>Приклад виведення 3</B></P><P><PRE>-1</PRE><BR>', 1000, 3072000, 2048, 0, 0, '', 1), -(1011, 'Медіанний фільтр', '<P align=left><B>Завдання</B></P><P>Медіаною у відсортованому по неспаданню масиву розмірності N називається елемент, який знаходиться у середній позиції масиву, тобто у позиції (N+1)/2 (цілочисельне ділення). <P>Медіанним фільтром для растрового зображення називається таке перетворення кожної точки, колір якої вибирається як медіана із множини точок з певного околу (радіусом R) цієї точки (квадратної області із центром у вибраній точці – розміри квадрата рівні [R+1+ R]×[ R+1+R]). Медіанний фільтр використовують для видалення дрібного шуму із зображення. На межі зображення точки, що виходять за межі, вважаються точками із кольором фону (абсолютне значення рівне нулю).<P>Для заданого малюнку прямокутної форми шириною W та висотою H знайдіть максимальне значення медіани для розміру околу R. Вважається, що малюнок монохромний із 256 градаціями одного кольору.<P><B>Вхідні дані</B></P><P>В першому рядку задані 3 числа: розмір околу R (1≤R≤20), H(1≤H≤400), W(1≤W≤250). В наступних H рядках знаходиться по W чисел розділених пропуском. Числа – це кольори відповідних точок.<P><B>Вихідні дані</B></P><P>Виведіть результат – максимальне значення медіани для заданого малюнку та радіусу.<P><B>Приклад введення</B></P><P><PRE>1 4 3</PRE><PRE>1 1 1</PRE><PRE>1 2 4</PRE><PRE>2 3 2</PRE><PRE>1 1 1</PRE><P><B>Приклад виведення</B></P><P><PRE>2</PRE>', 1500, 3072000, 204800, 0, 0, '', 1), -(1012, 'Дужки і Нобелівська премія', '<P align=left><B>Завдання</B></P><P>Директор однієї відомої програмістської фірми Білл (ви напевно його знаєте) захотів одержати Нобелівську премію. Для цього він запропонував додати в арифметичні вирази крім круглих дужок ще й квадратні, причому: спочатку виконуються обчислення в квадратних дужках, що стоять лівіше, потім в наступних квадратних і т.д.; в такому ж порядку виконуються обчислення в круглих дужках. Наприклад: у виразі порядок обчислення виразів в дужках такий: <CENTER><IMG src="/fusion/images/problems/1012/pic1.jpg"></CENTER><P>Працівники фірми встигнуть в запланований термін реалізувати тільки виконання всіх потрібних операцій в виразах без дужок. Тому пан Білл звернувся до нас за допомогою. Отже, ваше завдання таке: <BR>1) виведіть на екран "YES", якщо дужки у виразі розставлені правильно і "NO" в протилежному випадку;<BR>2) у випадку правильно розставлених дужок виведіть на екран через пропуск в окремому рядку для кожної пари дужок позиції їх розташування в заданому виразі, якщо він буде обчислюватися згідно описаних вище правил. <P><B>Вхідні дані</B></P><P>В першому рядку знаходиться вираз. Довжина рядка не перевищує 255 символів. <P><B>Вихідні дані</B></P><P>Результат виконання програми. <P><B>Приклад введення</B></P><P><PRE>а+(2-с)-[21-8*b+(-2)]+[3]</PRE><P><B>Приклад виведення</B></P><P><PRE>YES</PRE><PRE>17 20</PRE><PRE>9 21</PRE><PRE>23 25</PRE><PRE>3 7<BR></PRE>', 500, 3072000, 2048, 0, 0, '', 1), -(1013, 'Електронний пристрій', '<P align=left><B>Завдання</B></P><P>Одному визначному вченому майже вдалося побудувати новий електронний пристрій визначення поведінки погоди. Йому потрібна програма, яка б дозволяла аналізувати вміст результатів дослідження. Ваше завдання – допомогти йому. <P>Результати – це послідовність чисел (нуль або один). Вам потрібно дати відповідь чи всі числа рівні між і-тим та j-тим елементами послідовності включно. <P><B>Вхідні дані</B></P><P>В першому рядку задано число N(0 < N ≤ 3*10<SUP>5</SUP>) – кількість елементів послідовності. В другому рядку розділені пропуском записані елементи послідовності. В третьому рядку записано число M(0 < M ≤ 5*10<SUP>4</SUP>) – кількість запитань. Далі в M рядках розділ... [truncated message content] |
From: <br...@us...> - 2008-10-04 23:21:19
|
Revision: 404 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=404&view=rev Author: brus07 Date: 2008-10-04 23:18:38 +0000 (Sat, 04 Oct 2008) Log Message: ----------- Refactoring in using SystemMessageType. Modified Paths: -------------- ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs ACMServer/trunk/ACMServer/Tester/Library/SocketClientGate.cs Modified: ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs 2008-10-03 14:16:07 UTC (rev 403) +++ ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs 2008-10-04 23:18:38 UTC (rev 404) @@ -67,8 +67,11 @@ private void DataArrived(object Data, SocketStream DataSender) { SystemMessage sysMes = SystemMessage.Deserialize((byte[])Data); - if (SystemMessageX(sysMes) == true) - return; + if (sysMes.IsType("SystemTestBusyMessage") == true) + { + if (SystemMessageX(sysMes) == true) + return; + } DataArriver(sysMes); } protected virtual void DataArriver(SystemMessage message) @@ -121,7 +124,7 @@ string message = "test"; message += " " + server.ClientsList[i].GetHashCode().ToString(); message += " " + curHashCode; - SystemMessage mes = new SystemMessage(message); + SystemMessage mes = new SystemMessage(message, "SystemTestBusyMessage"); ServerSend(mes, i); } } Modified: ACMServer/trunk/ACMServer/Tester/Library/SocketClientGate.cs =================================================================== --- ACMServer/trunk/ACMServer/Tester/Library/SocketClientGate.cs 2008-10-03 14:16:07 UTC (rev 403) +++ ACMServer/trunk/ACMServer/Tester/Library/SocketClientGate.cs 2008-10-04 23:18:38 UTC (rev 404) @@ -21,12 +21,19 @@ void SocketClientGate_onDataArrived(SystemMessage message) { - if (SystemMessageX(message) == true) - return; + if (message.IsType("SystemTestBusyMessage") == true) + { + if (SystemMessageX(message) == true) + return; + } OnAddLogText("Receive", message.Message); //OnDataArrived(message); descriptionMessage = message.Description; - AddWork(message.Message); + + if (message.IsType("TestingSubmit") == true) + { + AddWork(message.Message); + } } public new void Disconnect() @@ -69,7 +76,7 @@ result += " " + mes[i]; } OnAddLogText("SystemSend", result); - base.Send(new SystemMessage(result)); + base.Send(new SystemMessage(result, _message.Type, _message.Description)); return true; } return false; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2008-10-03 14:16:14
|
Revision: 403 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=403&view=rev Author: brus07 Date: 2008-10-03 14:16:07 +0000 (Fri, 03 Oct 2008) Log Message: ----------- Modify LogDataGridView. Time column split to 2 columns: Time, Date. And fix some small bugs. Modified Paths: -------------- ACMServer/trunk/ACMServer/Resource/LogDataGridView.dll ACMServer/trunk/tasks/LogDataGridView/LogDataGridView/Properties/AssemblyInfo.cs ACMServer/trunk/tasks/LogDataGridView/LogDataGridView/SystemMessage.cs Modified: ACMServer/trunk/tasks/LogDataGridView/LogDataGridView/Properties/AssemblyInfo.cs =================================================================== --- ACMServer/trunk/tasks/LogDataGridView/LogDataGridView/Properties/AssemblyInfo.cs 2008-10-02 21:00:45 UTC (rev 402) +++ ACMServer/trunk/tasks/LogDataGridView/LogDataGridView/Properties/AssemblyInfo.cs 2008-10-03 14:16:07 UTC (rev 403) @@ -31,5 +31,5 @@ // // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.1.*")] +[assembly: AssemblyFileVersion("1.1.0.0")] Modified: ACMServer/trunk/tasks/LogDataGridView/LogDataGridView/SystemMessage.cs =================================================================== --- ACMServer/trunk/tasks/LogDataGridView/LogDataGridView/SystemMessage.cs 2008-10-02 21:00:45 UTC (rev 402) +++ ACMServer/trunk/tasks/LogDataGridView/LogDataGridView/SystemMessage.cs 2008-10-03 14:16:07 UTC (rev 403) @@ -13,15 +13,17 @@ private ContextMenuStrip contextMenuStrip = new ContextMenuStrip(); private ToolStripMenuItem toolStripMenuItemTime = new ToolStripMenuItem(); + private ToolStripMenuItem toolStripMenuItemDate = new ToolStripMenuItem(); private ToolStripMenuItem toolStripMenuItemText = new ToolStripMenuItem(); private ToolStripMenuItem toolStripMenuItemMode = new ToolStripMenuItem(); private void InitContexMenu() { contextMenuStrip.Items.AddRange(new ToolStripItem[]{ toolStripMenuItemTime, + toolStripMenuItemDate, toolStripMenuItemText, toolStripMenuItemMode}); - contextMenuStrip.Name = "ContexMenoStrip"; + contextMenuStrip.Name = "ContexMenuStrip"; contextMenuStrip.ShowCheckMargin = true; contextMenuStrip.ShowImageMargin = false; contextMenuStrip.Size = new Size(180, 92); @@ -31,6 +33,11 @@ toolStripMenuItemTime.Checked = true; toolStripMenuItemTime.Click += new EventHandler(toolStripMenuItem_Click); + toolStripMenuItemDate.Size = new Size(179, 22); + toolStripMenuItemDate.Text = "Visible Date Column"; + toolStripMenuItemDate.Checked = true; + toolStripMenuItemDate.Click += new EventHandler(toolStripMenuItem_Click); + toolStripMenuItemText.Size = new Size(179, 22); toolStripMenuItemText.Text = "Visible Text Column"; toolStripMenuItemText.Checked = true; @@ -44,6 +51,8 @@ void toolStripMenuItem_Click(object sender, EventArgs e) { + //Bug: jaksho shovaty vsi kolonky, todi ne mozna vidkryty ContextMenu + ToolStripMenuItem toolStrip = (ToolStripMenuItem)sender; if (toolStrip == toolStripMenuItemTime) { @@ -58,29 +67,48 @@ toolStripMenuItemTime.Checked = true; } } + if (toolStrip == toolStripMenuItemDate) + { + if (toolStripMenuItemDate.Checked) + { + columns[1].Visible = false; + toolStripMenuItemDate.Checked = false; + } + else + { + columns[1].Visible = true; + toolStripMenuItemDate.Checked = true; + } + } if (toolStrip == toolStripMenuItemText) { if (toolStripMenuItemText.Checked) { - columns[1].Visible = false; + columns[2].Visible = false; toolStripMenuItemText.Checked = false; } else { - columns[1].Visible = true; + columns[2].Visible = true; toolStripMenuItemText.Checked = true; + + //Hack: jaksho shovaty, a potim vidobrazyty Text'ovu kolonky + // todi vysota rjadkiv stane defoltnoju, a ne roztjagnetsja avtomatom, po tekstu. + // Tomu roblju she taki dvi zminy, shob updejtnyty GridView + columns[1].Visible = !columns[1].Visible; + columns[1].Visible = !columns[1].Visible; } } if (toolStrip == toolStripMenuItemMode) { if (toolStripMenuItemMode.Checked) { - columns[2].Visible = false; + columns[3].Visible = false; toolStripMenuItemMode.Checked = false; } else { - columns[2].Visible = true; + columns[3].Visible = true; toolStripMenuItemMode.Checked = true; } } @@ -100,6 +128,12 @@ result.Add(column); column = new DataGridViewTextBoxColumn(); + column.Name = "Date"; + column.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; + column.ContextMenuStrip = this.contextMenuStrip; + result.Add(column); + + column = new DataGridViewTextBoxColumn(); column.Name = "Log text"; column.MinimumWidth = 150; column.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; @@ -137,10 +171,11 @@ public override object[] GetValues() { - object[] result = new object[3]; + object[] result = new object[4]; result[0] = this.Time; - result[1] = this.Text; - result[2] = this.Mode; + result[1] = this.Date; + result[2] = this.Text; + result[3] = this.Mode; return result; } @@ -150,14 +185,22 @@ { DateTime dt = DateTime.Now; string result = ""; - result += dt.ToShortDateString(); - result += Environment.NewLine; result += dt.ToLongTimeString(); result += "."; result += dt.Millisecond.ToString(); return result; } } + private string Date + { + get + { + DateTime dt = DateTime.Now; + string result = ""; + result += dt.ToShortDateString(); + return result; + } + } private string Text { get This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2008-10-02 21:46:12
|
Revision: 402 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=402&view=rev Author: brus07 Date: 2008-10-02 21:00:45 +0000 (Thu, 02 Oct 2008) Log Message: ----------- Added helper file, for understanding where need to be "Zend" folder. Added Paths: ----------- website/library/Library_Zend here.txt Added: website/library/Library_Zend here.txt =================================================================== --- website/library/Library_Zend here.txt (rev 0) +++ website/library/Library_Zend here.txt 2008-10-02 21:00:45 UTC (rev 402) @@ -0,0 +1 @@ +Folder "Zend" need to be insert here. \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <vl...@us...> - 2008-10-02 18:02:15
|
Revision: 401 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=401&view=rev Author: vladykx Date: 2008-10-02 18:02:05 +0000 (Thu, 02 Oct 2008) Log Message: ----------- Renamed to standart as other View Helpers Added Paths: ----------- website/library/Ostacium/View/Helper/ListTable.php Removed Paths: ------------- website/library/Ostacium/View/Helper/listTable.php Copied: website/library/Ostacium/View/Helper/ListTable.php (from rev 400, website/library/Ostacium/View/Helper/listTable.php) =================================================================== --- website/library/Ostacium/View/Helper/ListTable.php (rev 0) +++ website/library/Ostacium/View/Helper/ListTable.php 2008-10-02 18:02:05 UTC (rev 401) @@ -0,0 +1,145 @@ +<?php + +class Ostacium_View_Helper_listTable extends Zend_View_Helper_FormElement +{ + protected static $defaultAttribs; + protected $primarykey; + protected $defaultURL; + + public function __construct() + { + $params = Zend_Controller_Front::getInstance()->getRequest()->getParams(); + + $this->defaultURL = array_intersect_key($params, array('controller' => 1, 'module' => 1)); + } + + public function listTable($primarykey, $rows, $headers = null, $actions, $topactions = null, $sortedby = null, $attribs = null) + { + if (!$attribs) + { + $attribs = self::$defaultAttribs; + } + + $this->primarykey = $primarykey; + + $html = ''; + + if ($topactions != null && is_array($topactions)) + { + $html .= '<div class="crudtopaction">'; + + foreach ($topactions as $key => $title) + { + $html .= '<a href="' . $this->view->url($this->defaultURL + array('action' => $key), null, true) . '">' . $title . '</a>'; + } + + $html .= '</div>'; + } + + $html .= '<form method="post" onsubmit="return sureMessage(\'' . $this->view->translate('sureMessageAll') . '\');" action="' . $this->view->url($this->defaultURL + array('action' => 'delete'), null, true) . '" id="crudlistform">'; + + $html .= '<table'; + + if ($attribs != null) $html .= $this->_htmlAttribs($attribs); + + $html .= '>' . "\n"; + + if ($headers != null && is_array($headers)) + { + $html .= '<tr>' . "\n"; + + if ($actions != null && is_array($actions)) + { + $html .= '<th>' . $this->view->formCheckbox('selectall', 'all', array('onclick' => 'toggleCheck(this.checked);')) . '</th>'; + } + + foreach ($headers as $key => $options) + { + $urlparams = array('sort' => $key, 'type' => (isset($sortedby[$key]) && $sortedby[$key] == 'ASC' ? 'DESC' : 'ASC') ); + + $html .= '<th>' .(isset($options['sort']) && $options['sort'] ? '<a href="' . $this->view->url($urlparams + $this->defaultURL, null, true) . '">' . $options['label'] . '</a>' : $options['label']) . '</th>' . "\n"; + } + + if ($actions != null && is_array($actions)) + { + foreach ($actions as $key => $title) + { + $html .= '<th>' . $title . '</th>' . "\n"; + } + } + + $html .= '</tr>' . "\n"; + } + + $html .= '<tr>' . "\n"; + + foreach($rows as $row) { + $html .= '<tr>' . "\n"; + + if ($actions != null && is_array($actions)) + { + $html .= '<td align="center">' . $this->view->formCheckbox('cruditems[' . $row[$this->primarykey] . ']', $row[$this->primarykey]) . '</td>'; + } + + foreach($headers as $key => $options) + { + if (isset($options['convert'])) + { + $html .= '<td'.(isset($options['align']) ? ' align="' . $options['align'] . '"' : '' ).(isset($options['class']) ? ' class="' . $options['class'] . '"' : '' ).'>' . $this->convert($row[$this->primarykey], $row[$key], $options) . '</td>' . "\n"; + } + else + { + $html .= '<td'.(isset($options['align']) ? ' align="' . $options['align'] . '"' : '' ).(isset($options['class']) ? ' class="' . $options['class'] . '"' : '' ).'>' . $row[$key] . '</td>' . "\n"; + } + } + + if ($actions != null && is_array($actions)) + { + foreach ($actions as $key => $title) + { + $alert = ''; + + if ($key == 'delete') + { + $alert = ' onclick="return sureMessage(\'' . $this->view->translate('sureMessage', ($this->primarykey . ': ' . $row[$this->primarykey])) . '\');"'; + } + + $html .= '<td class="actions"><a'.($alert ? $alert : '').' href="' . $this->view->url(array($this->primarykey => $row[$this->primarykey]) + $this->defaultURL + array('action' => $key), null, true) . '">' . $title . '</a></td>' . "\n"; + } + } + + $html .= '</tr>' . "\n"; + } + + if ($actions != null && is_array($actions)) + { + $html .= '<tr><td align="center" colspan="'.(count($actions + $headers) + 1).'">' . $this->view->formSubmit('delete', 'Стерти Вибрані') . '</td></tr>'; + } + + $html .= '</table>' . "\n"; + + $html .= '</form>'; + + return $html; + } + + public function setDefaultAttribs($attribs) + { + self::$defaultAttribs = $attribs; + } + + public function convert($id, $value, $options) + { + switch ($options['convert']) + { + case 'order': + return '<a href="'.$this->view->url(array('action' => 'up', 'id' => $id)).'">Вверх</a> (' . $value . ') <a href="'.$this->view->url(array('action' => 'down', 'id' => $id)).'">Вниз</a>'; + break; + default: + return $value; + break; + } + } +} + +?> \ No newline at end of file Deleted: website/library/Ostacium/View/Helper/listTable.php =================================================================== --- website/library/Ostacium/View/Helper/listTable.php 2008-10-01 09:58:09 UTC (rev 400) +++ website/library/Ostacium/View/Helper/listTable.php 2008-10-02 18:02:05 UTC (rev 401) @@ -1,145 +0,0 @@ -<?php - -class Ostacium_View_Helper_listTable extends Zend_View_Helper_FormElement -{ - protected static $defaultAttribs; - protected $primarykey; - protected $defaultURL; - - public function __construct() - { - $params = Zend_Controller_Front::getInstance()->getRequest()->getParams(); - - $this->defaultURL = array_intersect_key($params, array('controller' => 1, 'module' => 1)); - } - - public function listTable($primarykey, $rows, $headers = null, $actions, $topactions = null, $sortedby = null, $attribs = null) - { - if (!$attribs) - { - $attribs = self::$defaultAttribs; - } - - $this->primarykey = $primarykey; - - $html = ''; - - if ($topactions != null && is_array($topactions)) - { - $html .= '<div class="crudtopaction">'; - - foreach ($topactions as $key => $title) - { - $html .= '<a href="' . $this->view->url($this->defaultURL + array('action' => $key), null, true) . '">' . $title . '</a>'; - } - - $html .= '</div>'; - } - - $html .= '<form method="post" onsubmit="return sureMessage(\'' . $this->view->translate('sureMessageAll') . '\');" action="' . $this->view->url($this->defaultURL + array('action' => 'delete'), null, true) . '" id="crudlistform">'; - - $html .= '<table'; - - if ($attribs != null) $html .= $this->_htmlAttribs($attribs); - - $html .= '>' . "\n"; - - if ($headers != null && is_array($headers)) - { - $html .= '<tr>' . "\n"; - - if ($actions != null && is_array($actions)) - { - $html .= '<th>' . $this->view->formCheckbox('selectall', 'all', array('onclick' => 'toggleCheck(this.checked);')) . '</th>'; - } - - foreach ($headers as $key => $options) - { - $urlparams = array('sort' => $key, 'type' => (isset($sortedby[$key]) && $sortedby[$key] == 'ASC' ? 'DESC' : 'ASC') ); - - $html .= '<th>' .(isset($options['sort']) && $options['sort'] ? '<a href="' . $this->view->url($urlparams + $this->defaultURL, null, true) . '">' . $options['label'] . '</a>' : $options['label']) . '</th>' . "\n"; - } - - if ($actions != null && is_array($actions)) - { - foreach ($actions as $key => $title) - { - $html .= '<th>' . $title . '</th>' . "\n"; - } - } - - $html .= '</tr>' . "\n"; - } - - $html .= '<tr>' . "\n"; - - foreach($rows as $row) { - $html .= '<tr>' . "\n"; - - if ($actions != null && is_array($actions)) - { - $html .= '<td align="center">' . $this->view->formCheckbox('cruditems[' . $row[$this->primarykey] . ']', $row[$this->primarykey]) . '</td>'; - } - - foreach($headers as $key => $options) - { - if (isset($options['convert'])) - { - $html .= '<td'.(isset($options['align']) ? ' align="' . $options['align'] . '"' : '' ).(isset($options['class']) ? ' class="' . $options['class'] . '"' : '' ).'>' . $this->convert($row[$this->primarykey], $row[$key], $options) . '</td>' . "\n"; - } - else - { - $html .= '<td'.(isset($options['align']) ? ' align="' . $options['align'] . '"' : '' ).(isset($options['class']) ? ' class="' . $options['class'] . '"' : '' ).'>' . $row[$key] . '</td>' . "\n"; - } - } - - if ($actions != null && is_array($actions)) - { - foreach ($actions as $key => $title) - { - $alert = ''; - - if ($key == 'delete') - { - $alert = ' onclick="return sureMessage(\'' . $this->view->translate('sureMessage', ($this->primarykey . ': ' . $row[$this->primarykey])) . '\');"'; - } - - $html .= '<td class="actions"><a'.($alert ? $alert : '').' href="' . $this->view->url(array($this->primarykey => $row[$this->primarykey]) + $this->defaultURL + array('action' => $key), null, true) . '">' . $title . '</a></td>' . "\n"; - } - } - - $html .= '</tr>' . "\n"; - } - - if ($actions != null && is_array($actions)) - { - $html .= '<tr><td align="center" colspan="'.(count($actions + $headers) + 1).'">' . $this->view->formSubmit('delete', 'Стерти Вибрані') . '</td></tr>'; - } - - $html .= '</table>' . "\n"; - - $html .= '</form>'; - - return $html; - } - - public function setDefaultAttribs($attribs) - { - self::$defaultAttribs = $attribs; - } - - public function convert($id, $value, $options) - { - switch ($options['convert']) - { - case 'order': - return '<a href="'.$this->view->url(array('action' => 'up', 'id' => $id)).'">Вверх</a> (' . $value . ') <a href="'.$this->view->url(array('action' => 'down', 'id' => $id)).'">Вниз</a>'; - break; - default: - return $value; - break; - } - } -} - -?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2008-10-01 09:58:25
|
Revision: 400 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=400&view=rev Author: brus07 Date: 2008-10-01 09:58:09 +0000 (Wed, 01 Oct 2008) Log Message: ----------- Refactoring in using SystemMessageType. Modified Paths: -------------- ACMServer/trunk/ACMServer/Library/Data/DataMediator.cs ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGate.cs ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/WebGatePlugin/WebGatePlugin.cs ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/WebGatePlugin/WebGetter.cs Modified: ACMServer/trunk/ACMServer/Library/Data/DataMediator.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Data/DataMediator.cs 2008-09-30 18:19:23 UTC (rev 399) +++ ACMServer/trunk/ACMServer/Library/Data/DataMediator.cs 2008-10-01 09:58:09 UTC (rev 400) @@ -20,6 +20,14 @@ } } + public int Count + { + get + { + return d.Count; + } + } + /// <summary> /// \xDF\xEA\xF9\xEE \xF1\xE0\xE1\xEC\xB3\xF2 \xF3 \xF7\xE5\xF0\xE7\xB3 \xE7\xED\xE0\xF5\xEE\xE4\xE8\xF2\xFC\xF1\xFF \xE1\xB3\xEB\xFC\xF8\xE5 \xED\xB3\xE6 secondToLive \xF1\xE5\xEA\xF3\xED\xE4, \xF2\xEE \xE2\xB3\xED \xEF\xF0\xEE\xF1\xF2\xEE \xE2\xE8\xE4\xE0\xEB\xFF\xBA\xF2\xFC\xF1\xFF \xE7 \xED\xE5\xBF /// </summary> Modified: ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGate.cs =================================================================== --- ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGate.cs 2008-09-30 18:19:23 UTC (rev 399) +++ ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGate.cs 2008-10-01 09:58:09 UTC (rev 400) @@ -34,12 +34,18 @@ protected override void DataSender(SystemMessage message, int clientIndex) { - Submit submit = Submit.CreateFromXml(message.Message); - if (dataContainer.Add(submit) == true) + if (message.IsType("TestingSubmit") == true) { - OnLogMessage("Send", submit.id + " to " + clientIndex); - base.DataSender(message, clientIndex); + Submit submit = Submit.CreateFromXml(message.Message); + if (dataContainer.Add(submit) == true) + { + OnLogMessage("Send", submit.id + " to " + clientIndex); + base.DataSender(message, clientIndex); + } + return; } + + base.DataSender(message, clientIndex); } @@ -57,22 +63,24 @@ public new bool Send(SystemMessage message) { - if (message.IsType("TestingSubmitList") == false) - return false; + if (message.IsType("TestingSubmitList") == true) + { + SubmitList submitList = SubmitList.CreateFromXml(message.Message); - SubmitList submitList = SubmitList.CreateFromXml(message.Message); + GenerateLogMessageWirhIDs(submitList); - GenerateLogMessageWirhIDs(submitList); - - for (int index = 0; index < submitList.Items.Length; index++) - { - if (dataContainer.Contains(submitList.Items[index]) == false) + for (int index = 0; index < submitList.Items.Length; index++) { - SystemMessage sysMes = new SystemMessage(submitList.Items[index].ToString(), "TestingSubmit"); - pool.Send(sysMes); + if (dataContainer.Contains(submitList.Items[index]) == false) + { + SystemMessage sysMes = new SystemMessage(submitList.Items[index].ToString(), "TestingSubmit"); + pool.Send(sysMes); + } } + return true; } - return true; + + return false; } protected override void DataArriver(SystemMessage message) Modified: ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/WebGatePlugin/WebGatePlugin.cs =================================================================== --- ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/WebGatePlugin/WebGatePlugin.cs 2008-09-30 18:19:23 UTC (rev 399) +++ ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/WebGatePlugin/WebGatePlugin.cs 2008-10-01 09:58:09 UTC (rev 400) @@ -22,11 +22,13 @@ public override void Send(SystemMessage message) { - if (message.IsType("ApplicationSystem") && message.Message == "stop") + if (message.IsType("ApplicationSystem")) { - return; + if (message.Message == "stop") + return; } - string text = message.Message.Length + " bytes" + Environment.NewLine; + + string text = message.Message.Length + " bytes"; ((WebGatePluginUserControl)base.Control).AddText("Send", text); webGate.Send(message); @@ -34,11 +36,21 @@ protected override void DataArrived(SystemMessage message) { + if (message.IsType("Empty") == true) + { + ((WebGatePluginUserControl)base.Control).AddText("SystemReceive", "0 bytes"); + return; + } + if (message.IsType("SystemResult") == true) + { + ((WebGatePluginUserControl)base.Control).AddText("SystemReceive", message.Message); + return; + } + string text = message.Message.Length + " bytes"; ((WebGatePluginUserControl)base.Control).AddText("Receive", text); + base.DataArrived(message); - if (message.IsType("Empty") == false) - base.DataArrived(message); } private void OnChecked(object o,EventArgs a) Modified: ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/WebGatePlugin/WebGetter.cs =================================================================== --- ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/WebGatePlugin/WebGetter.cs 2008-09-30 18:19:23 UTC (rev 399) +++ ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/WebGatePlugin/WebGetter.cs 2008-10-01 09:58:09 UTC (rev 400) @@ -49,17 +49,14 @@ public SystemMessage GetData() { checkAddress(); - object ob = MediatorGetInfoFromSiteX(); - if (ob == null) - return new SystemMessage("", "Empty"); - SystemMessage sysMes = new SystemMessage(ob.ToString(), "TestingSubmitList"); - return sysMes; + return GetMessageFromSite();; } public void Send(SystemMessage message) { if (message.IsType("TestingResult") == true) - MediatorSendX(message.Message); + SendTestingResultToSite(message.Message); + //jaksho inakshyj typ, todi potribno bude inakshu funkciju vyklykaty } public string PathToSource @@ -76,31 +73,20 @@ #endregion - void MediatorSendX(string message) + void SendTestingResultToSite(string message) { - Result result = Result.CreateFromXml(message); - SendX(message); - container.Return(result); - } - void SendX(string message) - { string res = ""; string id = ""; string usedMemory = ""; string usedTime = ""; - try - { - //TODO: - Result result = Result.CreateFromXml(message); - res = result.res; - id = result.Submit.id.ToString(); - usedMemory = result.usedMemory.ToString(); - usedTime = result.usedTime.ToString(); - } - catch (Exception) - { - return; - } + + //TODO: + Result result = Result.CreateFromXml(message); + res = result.res; + id = result.Submit.id.ToString(); + usedMemory = result.usedMemory.ToString(); + usedTime = result.usedTime.ToString(); + string fullURL = fullPathToWebPages + "/set.php?"; fullURL += "res=" + res; fullURL += "&id=" + id; @@ -110,14 +96,31 @@ myRequest.Method = "GET"; WebResponse myResponse = myRequest.GetResponse(); myResponse.Close(); + + container.Return(result); } - string MediatorGetInfoFromSiteX() + SystemMessage GetMessageFromSite() { - string getAll = GetInfoFromSiteX(); + string getAll = GetFullInfoFromSite(); if (String.IsNullOrEmpty(getAll) == true) - return null; - SubmitList list = SubmitList.CreateFromXml(getAll); + return new SystemMessage("", "Empty"); + if (getAll.Contains("submitList") == true) + { + return CreateTestingSubmitListMessageFromText(getAll); + } + if (getAll.Contains("SystemResult") == true) + { + return new SystemMessage(getAll, "SystemResult"); + } + + //tut potribno realizuvaty vidpovidni sturktury i vyklykaty ihshyt danyh + return new SystemMessage(getAll, "UnknownContent"); + } + + SystemMessage CreateTestingSubmitListMessageFromText(string info) + { + SubmitList list = SubmitList.CreateFromXml(info); List<Submit> result = new List<Submit>(); for (int i = 0; i < list.Items.Length; i++) { @@ -130,22 +133,35 @@ } } if (result.Count == 0) - return null; + return new SystemMessage("Web checked: All submits in queue (queue size " + container.Count.ToString() + ")", "SystemResult"); SubmitList resultList = new SubmitList(); resultList.Items = result.ToArray(); - return resultList.ToString(); + return new SystemMessage(resultList.ToString(), "TestingSubmitList"); } - string GetInfoFromSiteX() + + string GetFullInfoFromSite() { - HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(fullPathToWebPages + "/get.php"); - myRequest.Method = "GET"; - WebResponse myResponse = myRequest.GetResponse(); - StreamReader sr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8); - string result = sr.ReadToEnd(); - sr.Close(); - myResponse.Close(); - if (result.Length == 0) - return null; + string result = null; + try + { + HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(fullPathToWebPages + "/get.php"); + myRequest.Method = "GET"; + //myRequest.Timeout = 100000; + WebResponse myResponse = myRequest.GetResponse(); + StreamReader sr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8); + result = sr.ReadToEnd(); + sr.Close(); + myResponse.Close(); + if (result.Length == 0) + return null; + } + catch (WebException wex) + { + if (wex.Status == WebExceptionStatus.Timeout) + { + return "SystemResult: Timeout"; + } + } return result; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2008-09-30 18:19:42
|
Revision: 399 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=399&view=rev Author: brus07 Date: 2008-09-30 18:19:23 +0000 (Tue, 30 Sep 2008) Log Message: ----------- Added different logmessage type for view in LogDataGridView in WebGatePlugin and SocketServerGatePlugin. Modified Paths: -------------- ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGate.cs ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGatePlugin.cs ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGatePluginUserControl.cs ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/WebGatePlugin/WebGatePlugin.cs ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/WebGatePlugin/WebGatePluginUserControl.cs Modified: ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGate.cs =================================================================== --- ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGate.cs 2008-09-30 12:59:52 UTC (rev 398) +++ ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGate.cs 2008-09-30 18:19:23 UTC (rev 399) @@ -37,7 +37,7 @@ Submit submit = Submit.CreateFromXml(message.Message); if (dataContainer.Add(submit) == true) { - OnLogMessage("send " + submit.id + " to " + clientIndex); + OnLogMessage("Send", submit.id + " to " + clientIndex); base.DataSender(message, clientIndex); } } @@ -45,13 +45,14 @@ private void GenerateLogMessageWirhIDs(SubmitList submitList) { - OnLogMessage("Get submits"); + string message = "Get submits" + Environment.NewLine; string ids = ""; for (int i = 0; i < submitList.Items.Length; i++) { ids += " " + submitList.Items[i].id.ToString(); } - OnLogMessage("\t ID: " + ids); + message += " ID: " + ids; + OnLogMessage("Receive", message); } public new bool Send(SystemMessage message) @@ -78,8 +79,9 @@ { Result result = Result.CreateFromXml(message.Message); - OnLogMessage("result " + result.Submit.id); - OnLogMessage("\t " + result.res); + string mes = "result " + result.Submit.id; + mes += " " + result.res; + OnLogMessage("Receive", mes); base.DataArriver(message); dataContainer.Return(result); @@ -93,18 +95,20 @@ public class LogMessageEventArgs : EventArgs { + public string type; public string message; - public LogMessageEventArgs(string mes) + public LogMessageEventArgs(string type, string message) { - message = mes; + this.type = type; + this.message = message; } } public event EventHandler<LogMessageEventArgs> LogMessage; - private void OnLogMessage(string p) + private void OnLogMessage(string type, string p) { EventHandler<LogMessageEventArgs> temp = LogMessage; if (temp != null) - temp(this, new LogMessageEventArgs(p)); + temp(this, new LogMessageEventArgs(type, p)); } } } Modified: ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGatePlugin.cs =================================================================== --- ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGatePlugin.cs 2008-09-30 12:59:52 UTC (rev 398) +++ ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGatePlugin.cs 2008-09-30 18:19:23 UTC (rev 399) @@ -29,16 +29,14 @@ socketServerGate.Send(message); } - private void AddTextToContorl(string message) + private void AddTextToContorl(string type, string message) { - string result = DateTime.Now.ToLongTimeString() + "." + DateTime.Now.Millisecond.ToString(); - result += " " + message + Environment.NewLine; - ((SocketServerGatePluginUserControl)base.Control).AddText(result); + ((SocketServerGatePluginUserControl)base.Control).AddText(type, message); } void socketServerGate_LogMessage(object sender, SocketServerGate.LogMessageEventArgs e) { - AddTextToContorl(e.message); + AddTextToContorl(e.type, e.message); } } } Modified: ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGatePluginUserControl.cs =================================================================== --- ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGatePluginUserControl.cs 2008-09-30 12:59:52 UTC (rev 398) +++ ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGatePluginUserControl.cs 2008-09-30 18:19:23 UTC (rev 399) @@ -35,7 +35,8 @@ } else { - textBox1.Text += text; + string timeStr = DateTime.Now.ToLongTimeString() + "." + DateTime.Now.Millisecond.ToString(); + textBox1.Text += timeStr + " " + text + Environment.NewLine; if (autoScrollCheckBox.Checked) { textBox1.Select(textBox1.Text.Length, 0); @@ -43,10 +44,10 @@ } } } - public void AddText(string text) + public void AddText(string type, string text) { - AddTextToTextLog(text); - view.AddRow(new LogDataGridView.SystemMessage(text, LogDataGridView.SystemMessageMode.Other)); + AddTextToTextLog(type + ": " + text); + view.AddRow(new LogDataGridView.SystemMessage(text, type)); } delegate void UpdateClientsCountStatusCallback(int clientsCount); Modified: ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/WebGatePlugin/WebGatePlugin.cs =================================================================== --- ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/WebGatePlugin/WebGatePlugin.cs 2008-09-30 12:59:52 UTC (rev 398) +++ ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/WebGatePlugin/WebGatePlugin.cs 2008-09-30 18:19:23 UTC (rev 399) @@ -26,16 +26,16 @@ { return; } - string text = " Send: " + message.Message.Length + " bytes" + Environment.NewLine; - ((WebGatePluginUserControl)base.Control).AddText(text); + string text = message.Message.Length + " bytes" + Environment.NewLine; + ((WebGatePluginUserControl)base.Control).AddText("Send", text); webGate.Send(message); } protected override void DataArrived(SystemMessage message) { - string text = "Arrived: " + message.Message.Length + " bytes"; - ((WebGatePluginUserControl)base.Control).AddText(text); + string text = message.Message.Length + " bytes"; + ((WebGatePluginUserControl)base.Control).AddText("Receive", text); if (message.IsType("Empty") == false) base.DataArrived(message); Modified: ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/WebGatePlugin/WebGatePluginUserControl.cs =================================================================== --- ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/WebGatePlugin/WebGatePluginUserControl.cs 2008-09-30 12:59:52 UTC (rev 398) +++ ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/WebGatePlugin/WebGatePluginUserControl.cs 2008-09-30 18:19:23 UTC (rev 399) @@ -65,10 +65,10 @@ } } - public void AddText(string text) + public void AddText(string type, string text) { - AddTextToTextLog(text); - view.AddRow(new LogDataGridView.SystemMessage(text, LogDataGridView.SystemMessageMode.Other)); + AddTextToTextLog(type + ": " + text); + view.AddRow(new LogDataGridView.SystemMessage(text, type)); } public string MainStatusMessage This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Or...@us...> - 2008-09-30 13:00:08
|
Revision: 398 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=398&view=rev Author: Oracle_ Date: 2008-09-30 12:59:52 +0000 (Tue, 30 Sep 2008) Log Message: ----------- Deleted Kernel part from used time. Modified Paths: -------------- ACMServer/trunk/sharp tester/SourceTest 2.0/Test/Test.cpp Modified: ACMServer/trunk/sharp tester/SourceTest 2.0/Test/Test.cpp =================================================================== --- ACMServer/trunk/sharp tester/SourceTest 2.0/Test/Test.cpp 2008-09-30 09:24:53 UTC (rev 397) +++ ACMServer/trunk/sharp tester/SourceTest 2.0/Test/Test.cpp 2008-09-30 12:59:52 UTC (rev 398) @@ -153,7 +153,7 @@ result->res=TestResult::RealTimeLimit; break; } - if (plug->p->TimeLimit((int)(acc.TotalKernelTime.QuadPart+acc.TotalUserTime.QuadPart)/10000,data->TimeLimit,result->Details)) + if (plug->p->TimeLimit((int)((acc.TotalUserTime.QuadPart)/10000),data->TimeLimit,result->Details)) { TerminateJobObject(job,0); result->res=TestResult::TimeLimit; @@ -215,7 +215,7 @@ QueryInformationJobObject(job,JobObjectExtendedLimitInformation,&mem,sizeof(mem),NULL); QueryInformationJobObject(job,JobObjectBasicAccountingInformation,&acc,sizeof(acc),NULL); result->UsedMemory=mem.PeakJobMemoryUsed; - result->UsedTime=(int)((acc.TotalKernelTime.QuadPart+acc.TotalUserTime.QuadPart)/10000); + result->UsedTime=(int)((acc.TotalUserTime.QuadPart)/10000); if (result->res!=TestResult::NotTested) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2008-09-30 09:25:11
|
Revision: 397 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=397&view=rev Author: brus07 Date: 2008-09-30 09:24:53 +0000 (Tue, 30 Sep 2008) Log Message: ----------- Fixed bug. Modified Paths: -------------- ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/WorkingPool.cs Modified: ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs 2008-09-30 08:48:32 UTC (rev 396) +++ ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs 2008-09-30 09:24:53 UTC (rev 397) @@ -103,6 +103,11 @@ /// <returns>\xD1\xEF\xE8\xF1\xEE\xEA \xE2\xB3\xEB\xFC\xED\xE8\xF5 \xF2\xE5\xF1\xF2\xE5\xF0\xB3\xE2</returns> private List<int> GetFreeTesters() { + if (server == null) + { + return new List<int>(); + } + q.Clear(); string curHashCode = DateTime.Now.GetHashCode().ToString(); for (int i = 0; i < server.CountClients; i++) Modified: ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/WorkingPool.cs =================================================================== --- ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/WorkingPool.cs 2008-09-30 08:48:32 UTC (rev 396) +++ ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/WorkingPool.cs 2008-09-30 09:24:53 UTC (rev 397) @@ -35,10 +35,11 @@ break; foreach (SystemMessage sysMes in poolWork.Keys) { - //TODO: potribno zrobyty, shot pry posylci "poolWork" ne buv zalokanyj + //TODO: potribno zrobyty, shob pry posylci "poolWork" ne buv zalokanyj if (OnSendData(sysMes) == true) { poolWork.Remove(sysMes); + break; } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2008-09-30 08:48:45
|
Revision: 396 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=396&view=rev Author: brus07 Date: 2008-09-30 08:48:32 +0000 (Tue, 30 Sep 2008) Log Message: ----------- Added LogDataGridView to WebGatePlugin and SocketServerGatePlugin. Modified Paths: -------------- ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGatePlugin.csproj ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGatePluginUserControl.Designer.cs ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGatePluginUserControl.cs ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/WebGatePlugin/WebGatePlugin.csproj ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/WebGatePlugin/WebGatePluginUserControl.Designer.cs ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/WebGatePlugin/WebGatePluginUserControl.cs Modified: ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGatePlugin.csproj =================================================================== --- ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGatePlugin.csproj 2008-09-29 13:39:57 UTC (rev 395) +++ ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGatePlugin.csproj 2008-09-30 08:48:32 UTC (rev 396) @@ -28,6 +28,10 @@ <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> + <Reference Include="LogDataGridView, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\..\..\Resource\LogDataGridView.dll</HintPath> + </Reference> <Reference Include="System" /> <Reference Include="System.Data" /> <Reference Include="System.Drawing" /> Modified: ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGatePluginUserControl.Designer.cs =================================================================== --- ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGatePluginUserControl.Designer.cs 2008-09-29 13:39:57 UTC (rev 395) +++ ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGatePluginUserControl.Designer.cs 2008-09-30 08:48:32 UTC (rev 396) @@ -34,19 +34,22 @@ this.clientsCountToolStripStatusLabel = new System.Windows.Forms.ToolStripStatusLabel(); this.clientCountTimer = new System.Windows.Forms.Timer(this.components); this.autoScrollCheckBox = new System.Windows.Forms.CheckBox(); + this.tabControl1 = new System.Windows.Forms.TabControl(); + this.tabPage1 = new System.Windows.Forms.TabPage(); + this.tabPage2 = new System.Windows.Forms.TabPage(); this.socketGateStatusStrip.SuspendLayout(); + this.tabControl1.SuspendLayout(); + this.tabPage2.SuspendLayout(); this.SuspendLayout(); // // textBox1 // - this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.textBox1.Location = new System.Drawing.Point(3, 26); + this.textBox1.Dock = System.Windows.Forms.DockStyle.Fill; + this.textBox1.Location = new System.Drawing.Point(3, 3); this.textBox1.Multiline = true; this.textBox1.Name = "textBox1"; this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both; - this.textBox1.Size = new System.Drawing.Size(211, 130); + this.textBox1.Size = new System.Drawing.Size(197, 98); this.textBox1.TabIndex = 1; // // socketGateStatusStrip @@ -82,18 +85,55 @@ this.autoScrollCheckBox.Text = "AutoScroll"; this.autoScrollCheckBox.UseVisualStyleBackColor = true; // + // tabControl1 + // + this.tabControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tabControl1.Controls.Add(this.tabPage1); + this.tabControl1.Controls.Add(this.tabPage2); + this.tabControl1.Location = new System.Drawing.Point(3, 26); + this.tabControl1.Name = "tabControl1"; + this.tabControl1.SelectedIndex = 0; + this.tabControl1.Size = new System.Drawing.Size(211, 130); + this.tabControl1.TabIndex = 5; + // + // tabPage1 + // + this.tabPage1.Location = new System.Drawing.Point(4, 22); + this.tabPage1.Name = "tabPage1"; + this.tabPage1.Padding = new System.Windows.Forms.Padding(3); + this.tabPage1.Size = new System.Drawing.Size(203, 104); + this.tabPage1.TabIndex = 0; + this.tabPage1.Text = "tabPage1"; + this.tabPage1.UseVisualStyleBackColor = true; + // + // tabPage2 + // + this.tabPage2.Controls.Add(this.textBox1); + this.tabPage2.Location = new System.Drawing.Point(4, 22); + this.tabPage2.Name = "tabPage2"; + this.tabPage2.Padding = new System.Windows.Forms.Padding(3); + this.tabPage2.Size = new System.Drawing.Size(203, 104); + this.tabPage2.TabIndex = 1; + this.tabPage2.Text = "tabPage2"; + this.tabPage2.UseVisualStyleBackColor = true; + // // SocketServerGatePluginUserControl // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.tabControl1); this.Controls.Add(this.autoScrollCheckBox); this.Controls.Add(this.socketGateStatusStrip); - this.Controls.Add(this.textBox1); this.Name = "SocketServerGatePluginUserControl"; this.Size = new System.Drawing.Size(217, 181); this.Load += new System.EventHandler(this.SocketServerGatePluginUserControl_Load); this.socketGateStatusStrip.ResumeLayout(false); this.socketGateStatusStrip.PerformLayout(); + this.tabControl1.ResumeLayout(false); + this.tabPage2.ResumeLayout(false); + this.tabPage2.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -106,5 +146,8 @@ private System.Windows.Forms.ToolStripStatusLabel clientsCountToolStripStatusLabel; private System.Windows.Forms.Timer clientCountTimer; private System.Windows.Forms.CheckBox autoScrollCheckBox; + private System.Windows.Forms.TabControl tabControl1; + private System.Windows.Forms.TabPage tabPage1; + private System.Windows.Forms.TabPage tabPage2; } } Modified: ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGatePluginUserControl.cs =================================================================== --- ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGatePluginUserControl.cs 2008-09-29 13:39:57 UTC (rev 395) +++ ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/SocketServerGatePlugin/SocketServerGatePluginUserControl.cs 2008-09-30 08:48:32 UTC (rev 396) @@ -14,14 +14,23 @@ public SocketServerGatePluginUserControl() { InitializeComponent(); + + initGridSe(); } + LogDataGridView.LogDataGridView view = new LogDataGridView.LogDataGridView(); + private void initGridSe() + { + view.Dock = DockStyle.Fill; + tabPage1.Controls.Add(view); + } + delegate void AddTextCallback(string text); - public void AddText(string text) + private void AddTextToTextLog(string text) { if (this.textBox1.InvokeRequired) { - AddTextCallback d = new AddTextCallback(AddText); + AddTextCallback d = new AddTextCallback(AddTextToTextLog); this.Invoke(d, new object[] { text }); } else @@ -34,6 +43,11 @@ } } } + public void AddText(string text) + { + AddTextToTextLog(text); + view.AddRow(new LogDataGridView.SystemMessage(text, LogDataGridView.SystemMessageMode.Other)); + } delegate void UpdateClientsCountStatusCallback(int clientsCount); public void UpdateClientsCountStatus(int clientsCount) Modified: ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/WebGatePlugin/WebGatePlugin.csproj =================================================================== --- ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/WebGatePlugin/WebGatePlugin.csproj 2008-09-29 13:39:57 UTC (rev 395) +++ ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/WebGatePlugin/WebGatePlugin.csproj 2008-09-30 08:48:32 UTC (rev 396) @@ -28,6 +28,10 @@ <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> + <Reference Include="LogDataGridView, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\..\..\Resource\LogDataGridView.dll</HintPath> + </Reference> <Reference Include="System" /> <Reference Include="System.Data" /> <Reference Include="System.Drawing" /> Modified: ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/WebGatePlugin/WebGatePluginUserControl.Designer.cs =================================================================== --- ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/WebGatePlugin/WebGatePluginUserControl.Designer.cs 2008-09-29 13:39:57 UTC (rev 395) +++ ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/WebGatePlugin/WebGatePluginUserControl.Designer.cs 2008-09-30 08:48:32 UTC (rev 396) @@ -36,20 +36,23 @@ this.label2 = new System.Windows.Forms.Label(); this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.MainToolStripStatusLabel = new System.Windows.Forms.ToolStripStatusLabel(); + this.tabControl1 = new System.Windows.Forms.TabControl(); + this.tabPage1 = new System.Windows.Forms.TabPage(); + this.tabPage2 = new System.Windows.Forms.TabPage(); ((System.ComponentModel.ISupportInitialize)(this.CheckingIntervalNumericUpDown)).BeginInit(); this.statusStrip1.SuspendLayout(); + this.tabControl1.SuspendLayout(); + this.tabPage2.SuspendLayout(); this.SuspendLayout(); // // textBox2 // - this.textBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.textBox2.Location = new System.Drawing.Point(3, 58); + this.textBox2.Dock = System.Windows.Forms.DockStyle.Fill; + this.textBox2.Location = new System.Drawing.Point(3, 3); this.textBox2.Multiline = true; this.textBox2.Name = "textBox2"; this.textBox2.ScrollBars = System.Windows.Forms.ScrollBars.Both; - this.textBox2.Size = new System.Drawing.Size(263, 145); + this.textBox2.Size = new System.Drawing.Size(246, 113); this.textBox2.TabIndex = 2; // // setAddressButton @@ -133,23 +136,60 @@ this.MainToolStripStatusLabel.Name = "MainToolStripStatusLabel"; this.MainToolStripStatusLabel.Size = new System.Drawing.Size(0, 17); // + // tabControl1 + // + this.tabControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tabControl1.Controls.Add(this.tabPage1); + this.tabControl1.Controls.Add(this.tabPage2); + this.tabControl1.Location = new System.Drawing.Point(6, 58); + this.tabControl1.Name = "tabControl1"; + this.tabControl1.SelectedIndex = 0; + this.tabControl1.Size = new System.Drawing.Size(260, 145); + this.tabControl1.TabIndex = 9; + // + // tabPage1 + // + this.tabPage1.Location = new System.Drawing.Point(4, 22); + this.tabPage1.Name = "tabPage1"; + this.tabPage1.Padding = new System.Windows.Forms.Padding(3); + this.tabPage1.Size = new System.Drawing.Size(252, 119); + this.tabPage1.TabIndex = 0; + this.tabPage1.Text = "tabPage1"; + this.tabPage1.UseVisualStyleBackColor = true; + // + // tabPage2 + // + this.tabPage2.Controls.Add(this.textBox2); + this.tabPage2.Location = new System.Drawing.Point(4, 22); + this.tabPage2.Name = "tabPage2"; + this.tabPage2.Padding = new System.Windows.Forms.Padding(3); + this.tabPage2.Size = new System.Drawing.Size(252, 119); + this.tabPage2.TabIndex = 1; + this.tabPage2.Text = "tabPage2"; + this.tabPage2.UseVisualStyleBackColor = true; + // // WebGatePluginUserControl // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.tabControl1); this.Controls.Add(this.statusStrip1); this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.Controls.Add(this.CheckingIntervalNumericUpDown); this.Controls.Add(this.addressComboBox); this.Controls.Add(this.setAddressButton); - this.Controls.Add(this.textBox2); this.Name = "WebGatePluginUserControl"; this.Size = new System.Drawing.Size(269, 228); this.Load += new System.EventHandler(this.WebGatePluginUserControl_Load); ((System.ComponentModel.ISupportInitialize)(this.CheckingIntervalNumericUpDown)).EndInit(); this.statusStrip1.ResumeLayout(false); this.statusStrip1.PerformLayout(); + this.tabControl1.ResumeLayout(false); + this.tabPage2.ResumeLayout(false); + this.tabPage2.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -165,5 +205,8 @@ private System.Windows.Forms.Label label2; private System.Windows.Forms.StatusStrip statusStrip1; private System.Windows.Forms.ToolStripStatusLabel MainToolStripStatusLabel; + private System.Windows.Forms.TabControl tabControl1; + private System.Windows.Forms.TabPage tabPage1; + private System.Windows.Forms.TabPage tabPage2; } } Modified: ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/WebGatePlugin/WebGatePluginUserControl.cs =================================================================== --- ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/WebGatePlugin/WebGatePluginUserControl.cs 2008-09-29 13:39:57 UTC (rev 395) +++ ACMServer/trunk/ACMServer/Plugins/MediatorPlugins/WebGatePlugin/WebGatePluginUserControl.cs 2008-09-30 08:48:32 UTC (rev 396) @@ -14,8 +14,18 @@ public WebGatePluginUserControl() { InitializeComponent(); + + initGridSe(); + } + + LogDataGridView.LogDataGridView view = new LogDataGridView.LogDataGridView(); + private void initGridSe() + { + view.Dock = DockStyle.Fill; + tabPage1.Controls.Add(view); } + private void setAddressButton_Click(object sender, EventArgs e) { WebGate gate = WebGate.GetInstance(); @@ -36,11 +46,11 @@ } delegate void AddTextCallback(string text); - public void AddText(string text) + private void AddTextToTextLog(string text) { if (this.textBox2.InvokeRequired) { - AddTextCallback d = new AddTextCallback(AddText); + AddTextCallback d = new AddTextCallback(AddTextToTextLog); this.Invoke(d, new object[] { text }); } else @@ -55,6 +65,12 @@ } } + public void AddText(string text) + { + AddTextToTextLog(text); + view.AddRow(new LogDataGridView.SystemMessage(text, LogDataGridView.SystemMessageMode.Other)); + } + public string MainStatusMessage { set This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pan...@us...> - 2008-09-29 13:40:03
|
Revision: 394 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=394&view=rev Author: panzaboi Date: 2008-09-29 13:39:49 +0000 (Mon, 29 Sep 2008) Log Message: ----------- update Modified Paths: -------------- website/library/Ostacium/Controller/CrudAction.php Modified: website/library/Ostacium/Controller/CrudAction.php =================================================================== --- website/library/Ostacium/Controller/CrudAction.php 2008-09-28 18:32:15 UTC (rev 393) +++ website/library/Ostacium/Controller/CrudAction.php 2008-09-29 13:39:49 UTC (rev 394) @@ -6,21 +6,25 @@ protected $primary; protected $reference; - /*protected $reference = array( + /* + protected $reference = array( 'categories' => array( 'refColumns' => array('books.categoryid = categories.id'), 'columns' => array('books.name AS category'), ) - );*/ + ); + */ protected $listFields;// listFields = array( 'name' => array( 'label' => ' ) ) - protected $listActions; + protected $listActions = array( + 'edit', + 'delete' + ); protected $createFields; protected $updateFields; - /* - array( + /*array( 'decorators' => $this->elementDecorators, 'filters' => array('StringTrim', 'StringToLower'), 'validators' => array( @@ -31,10 +35,12 @@ 'tabindex' => 1, 'title' => 'Емейл', 'label' => 'Ваш емейл:', - ) - */ + )*/ - protected $generalActions; + protected $generalActions = array( + 'new', + ); + protected $defaultSort; public function init() @@ -42,7 +48,8 @@ parent::init(); // Setup Model - try { + try + { $this->_model = new Ostacium_Db_CrudTable($this->table, $this->primary, array( 'listFields' => $this->listFields, 'createFields' => $this->createFields, @@ -53,24 +60,14 @@ } catch(Exception $e){} - $scriptPath = $this->_helper->viewRenderer->getModuleDirectory() . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'scripts' . DIRECTORY_SEPARATOR . 'crud'; + $scriptPath = $this->_helper->viewRenderer->getModuleDirectory() . '/views/scripts/crud'; $this->_helper->getHelper('viewRenderer')->setNoController(true); - $this->_helper->getHelper('viewRenderer')->view->addScriptPath($scriptPath); - - if (!$this->listActions) - { - $this->listActions = array( - 'edit' => 'Редагувати', - 'delete' => 'Стерти' - ); - } + $this->view->addScriptPath($scriptPath); - if (!$this->generalActions) + if (!$this->defaultSort) { - $this->generalActions = array( - 'new' => 'Створити', - ); + $this->defaultSort = array($this->primary => 'ASC'); } } @@ -102,23 +99,24 @@ public function newAction() { $form = $this->buildForm('create'); + echo $form; - $this->view->form = $form; - return $this->_helper->getHelper('viewRenderer')->setScriptAction('form'); + return $this->_helper->getHelper('viewRenderer')->setNoRender(true); } public function createAction() { - if (!$this->getRequest()->isPost()) { + if (!$this->getRequest()->isPost()) + { return $this->_forward('new'); } $form = $this->buildForm('create'); - if (!$form->isValid($_POST)) { - $this->view->form = $form; - - return $this->_helper->getHelper('viewRenderer')->setScriptAction('form'); + if (!$form->isValid($_POST)) + { + echo $form; + return $this->_helper->getHelper('viewRenderer')->setNoRender(true); } $values = $form->getValues(); @@ -132,51 +130,55 @@ public function editAction() { - $id = (int)$this->_getParam($this->primary); + $id = $this->_getParam($this->primary); $values = $this->_model->getData($id); - $form = $this->buildForm('update', $this->primary . '/' . $id); - - foreach ($form->getElements() as $key => $element) - { - if (isset($values[$key])) - { - $element->setValue($values[$key]); - } - } + $form = $this->buildForm('update', array($this->primary => $id)); - $this->view->form = $form; - return $this->_helper->getHelper('viewRenderer')->setScriptAction('form'); + $this->beforeEdit($values, $id); + $form->populate($values); + + echo $form; + return $this->_helper->getHelper('viewRenderer')->setNoRender(true); } public function updateAction() { - $id = (int)$this->_getParam($this->primary); + $id = $this->_getParam($this->primary); - if (!$this->getRequest()->isPost()) { + if (!$this->getRequest()->isPost()) + { return $this->_forward('edit', null, null, array($this->primary => $id)); } - $form = $this->buildForm('update', $this->primary . '/' . $id); + $form = $this->buildForm('update', array($this->primary => $id)); - if (!$form->isValid($_POST)) { - $this->view->form = $form; - - return $this->_helper->getHelper('viewRenderer')->setScriptAction('form'); + if (!$form->isValid($_POST)) + { + echo $form; + return $this->_helper->getHelper('viewRenderer')->setNoRender(true); } $values = $form->getValues(); + $result = $this->_model->updateData($values, $id); + $this->afterUpdate($values, $form, $id, $result); if (!$result) { return $this->_forward('edit', null, null, array($this->primary => $id, 'message' => 'updateError')); } + else + { + return $this->_forward('list', null, null, $this->_getAllParams() + array('message' => 'recordUpdated')); + } } public function deleteAction() { - if ($this->_getParam('delete')) + $msg = $this->view->translate('deleteErrors'); + + if ($this->_getParam('delete') && count($this->_getParam('cruditems')) > 0) { $Dcount = 0; $count = 0; @@ -198,9 +200,9 @@ $msg = $this->view->translate('recordsDeleted', array($Dcount, $count)); } - else + elseif($this->_getParam($this->primary)) { - $id = (int)$this->_getParam($this->primary); + $id = $this->_getParam($this->primary); $this->beforeDelete($id); $result = $this->_model->deleteData($id); @@ -226,8 +228,7 @@ public function upAction() { - $id = (int)$this->_getParam('id'); - + $id = $this->_getParam('id'); $this->_model->up($id); return $this->_forward('list', null, null, $this->_getAllParams() + array('message' => 'recordUp')); @@ -235,8 +236,7 @@ public function downAction() { - $id = (int)$this->_getParam('id'); - + $id = $this->_getParam('id'); $this->_model->down($id); return $this->_forward('list', null, null, $this->_getAllParams() + array('message' => 'recordDown')); @@ -262,12 +262,22 @@ { } + + protected function beforeEdit(&$values, $id) + { + + } + + protected function afterUpdate(&$values, &$form, $id, $result) + { + + } /****************************/ protected function buildForm($action, $other = null) { $form = new CrudForm(); - $form->setAction( $this->getRequest()->getBaseUrl() . ($this->getRequest()->getModuleName() != 'default' ? '/' . $this->getRequest()->getModuleName() : '') . '/' . $this->getRequest()->getControllerName() . '/' . $action . ($other ? '/' . $other : '')) + $form->setAction( $this->view->url(array('module' => $this->getRequest()->getModuleName(), 'controller' => $this->getRequest()->getControllerName(), 'action' => $action) + (array)$other, false, true) ) ->setMethod('post'); foreach ($this->{$action . 'Fields'} as $field => $options) @@ -277,9 +287,10 @@ $form->addElement($options['type'], $field, $options['options']); } - $label = $this->getLabel(); + $label = $this->getLabel($action); - $form->addElement('submit', 'login', array('label' => $label)); + $form->addElement('submit', 'submit', array('label' => $label)); + $form->addElement('button', 'goback', array('label' => 'Назад', 'onclick' => 'return goTo(\'' . $this->view->url(array('module' => $this->getRequest()->getModuleName(), 'controller' => $this->getRequest()->getControllerName(), 'action' => 'index'), false, true) . '\');')); return $form; } @@ -318,57 +329,12 @@ protected function getLabel() { - $label = $this->getRequest()-> getActionName(); - - $label = (isset($this->listActions[$label]) ? $this->listActions[$label] : (isset($this->generalActions[$label]) ? $this->generalActions[$label] : ucfirst($label) ) ); + $label = $this->getRequest()->getActionName(); + //$label = (isset($this->labels[$label]) ? $this->labels[$label] : ucfirst($label)); + $label = mb_ucfirst($this->translate($label)); return $label; } - - protected function saveUploadedImage($from, $to, $maxheight, $maxwidth) - { - $newfrom = $to . '.tmp'; - move_uploaded_file($from, $newfrom); - - $from_type = exif_imagetype($newfrom); - - switch ($from_type) { - case IMAGETYPE_GIF: - $im = imagecreatefromgif($newfrom); - break; - case IMAGETYPE_JPEG: - $im = imagecreatefromjpeg($newfrom); - break; - case IMAGETYPE_PNG: - $im = imagecreatefrompng($newfrom); - break; - default: - return false; - break; - } - - $width = Imagesx($im); - $height = Imagesy($im); - - $width_alpha = $maxwidth/$width; - $height_alpha = $maxheight/$height; - - $alpha = min($width_alpha, $height_alpha); - - $newwidth = $width * $alpha; - $newheight = $height * $alpha; - - $newim = imagecreatetruecolor($newwidth, $newheight); - imagecopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); - - imagejpeg($newim, $to . '.jpg', 100); - - imagedestroy($newim); - imagedestroy($im); - @unlink($newfrom); - - return true; - } } ?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pan...@us...> - 2008-09-29 13:40:02
|
Revision: 395 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=395&view=rev Author: panzaboi Date: 2008-09-29 13:39:57 +0000 (Mon, 29 Sep 2008) Log Message: ----------- update Modified Paths: -------------- website/library/Ostacium/Db/CrudTable.php Modified: website/library/Ostacium/Db/CrudTable.php =================================================================== --- website/library/Ostacium/Db/CrudTable.php 2008-09-29 13:39:49 UTC (rev 394) +++ website/library/Ostacium/Db/CrudTable.php 2008-09-29 13:39:57 UTC (rev 395) @@ -31,25 +31,47 @@ return self::$perpage; } - public function getSelect($table, $columns) + public function getSelect($table, $columns, $where = null, $notIn = null) { - $index = md5(serialize($table) . serialize($columns)); + $index = md5(serialize($table) . serialize($columns) . serialize($where) . serialize($notIn)); if (isset($_select[$index])) { return $_select[$index]; } $select = $this->select()->setIntegrityCheck(false)->from($table, $columns); + + if ($where) + $select = $select->where($where); + + if ($notIn) + $select = $select->where($this->notIn($notIn['table'], $notIn['column1'], $notIn['column2'])); + $_select[$index] = $this->fetchAll($select)->toArray(); return $_select[$index]; } + + public function notIn($table, $column1, $column2) + { + return ($column1 . ' NOT IN (SELECT ' . $column2 . ' FROM ' . $table . ')'); + } public function createData($values) { - $values = $this->_cleanInput($values, array_keys($this->_options['createFields'])); + try + { + $values = $this->_cleanInput($values, array_keys($this->_options['createFields'])); - return $this->insert($values); + return $this->insert($values); + } + catch(Exception $e) + { + if (stripos($e->getMessage(), 'Duplicate entry')) + return false; + else + throw $e; + } } public function getData($id) @@ -62,8 +84,13 @@ public function updateData($values, $id) { $db_values = $this->_cleanInput($this->get($id), array_keys($this->_options['updateFields'])); + $values = $this->_cleanInput($values, array_keys($db_values)); + $values = array_diff_assoc($values, $db_values); + + if (count($values) < 1) return true; + try { return (bool)$this->update($values, $this->getAdapter()->quoteInto(current($this->_primary) . ' = ?', $id)); @@ -92,6 +119,11 @@ throw $e; } } + + public function markDelete($id) + { + return (bool)$this->update(array('deleted' => 1), $this->getAdapter()->quoteInto(current($this->_primary) . ' = ?', $id)); + } public function retrieve($page, $sort) { @@ -108,9 +140,20 @@ $data = $this->fetchAll($select, key($sort).' '.current($sort), self::$perpage, self::$perpage * $page); - return $data->toArray(); + return $data->toArray(true); } + public function getCountries() + { + $locale = new Zend_Locale(Zend_Registry::get('Zend_Translate')->getAdapter()->getLocale()); + + $list = $locale->getTranslationList('Territory', null, 2); + + unset($list['ZZ']); + + return $list; + } + public function up($id) { $position = $this->select()->from($this->_name, 'position')->where(current($this->_primary) . ' = ?', $id)->query()->fetchColumn(); @@ -146,15 +189,16 @@ } } - protected function _cleanInput($data, $fields) + protected function _cleanInput($data, $fields, $flip = true) { if (!$fields || !is_array($fields)) return $data; if (!$data || !is_array($data) ) return $data; - $data = array_intersect_key($data, array_flip($fields)); + if ($flip) + $data = array_intersect_key($data, array_flip($fields)); + else + $data = array_intersect_key($data, $fields); return $data; } -} - -?> \ No newline at end of file +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <vl...@us...> - 2008-09-28 18:32:27
|
Revision: 393 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=393&view=rev Author: vladykx Date: 2008-09-28 18:32:15 +0000 (Sun, 28 Sep 2008) Log Message: ----------- All langs as array in config.ini Modified Paths: -------------- website/config/config.ini website/library/Application.php Modified: website/config/config.ini =================================================================== --- website/config/config.ini 2008-09-26 20:22:27 UTC (rev 392) +++ website/config/config.ini 2008-09-28 18:32:15 UTC (rev 393) @@ -8,7 +8,7 @@ truncate.length = "300" truncate.ending = "..." -truncate.exact' = "0" +truncate.exact = "0" truncate.considerHtml = "1" table.perpage = "10" @@ -29,6 +29,8 @@ lang.path = "lang/"; lang.default = "uk"; +lang.langs[] = "uk"; +lang.langs[] = "en"; title = "ACM Contester" titlesep = " - " @@ -36,8 +38,11 @@ [development: general] db.adapter = "Mysqli" +db.params.host = "localhost" db.params.dbname = "acm" db.params.username = "acm" db.params.password = "c0nt3st3r" +db.params.profiler.enabled = true +db.params.profiler.class = Zend_Db_Profiler_Firebug [stable: genral] \ No newline at end of file Modified: website/library/Application.php =================================================================== --- website/library/Application.php 2008-09-26 20:22:27 UTC (rev 392) +++ website/library/Application.php 2008-09-28 18:32:15 UTC (rev 393) @@ -204,7 +204,11 @@ $_db = Zend_Registry::get('db'); $translate = new Zend_Translate('csv', $this->_docroot.'/'.$_config->lang->path . $_config->lang->default . '.csv', $_config->lang->default); - $translate->addTranslation($this->_docroot.'/'.$_config->lang->path . 'en.csv', 'en'); + foreach($_config->lang->langs as $lang) + { + if ($lang != $_config->lang->default) + $translate->addTranslation($this->_docroot.'/'.$_config->lang->path . $lang .'.csv', 'en'); + } $translate->setLocale($_config->lang->default); Zend_Registry::set('Zend_Translate', $translate); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pan...@us...> - 2008-09-26 20:22:33
|
Revision: 392 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=392&view=rev Author: panzaboi Date: 2008-09-26 20:22:27 +0000 (Fri, 26 Sep 2008) Log Message: ----------- problem Property Changed: ---------------- website/library/ Property changes on: website/library ___________________________________________________________________ Added: svn:ignore + Zend This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pan...@us...> - 2008-09-26 20:06:21
|
Revision: 391 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=391&view=rev Author: panzaboi Date: 2008-09-26 20:06:11 +0000 (Fri, 26 Sep 2008) Log Message: ----------- removed Removed Paths: ------------- website/library/Zend/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2008-09-25 23:11:07
|
Revision: 389 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=389&view=rev Author: brus07 Date: 2008-09-25 21:49:54 +0000 (Thu, 25 Sep 2008) Log Message: ----------- System commit. Added logminsize property to this folder. Now, smallest log message can be 5 symbols. Property Changed: ---------------- website/ website/application/ website/application/default/ website/application/default/controllers/ website/application/default/layouts/ website/application/default/models/ website/application/default/views/ website/application/default/views/helpers/ website/application/default/views/scripts/ website/application/default/views/scripts/archieve/ website/application/default/views/scripts/error/ website/application/default/views/scripts/index/ website/config/ website/httpdocs/ website/httpdocs/images/ website/httpdocs/scripts/ website/httpdocs/styles/ website/lang/ website/library/ website/library/Ostacium/ website/library/Ostacium/Controller/ website/library/Ostacium/Controller/Plugin/ website/library/Ostacium/Db/ website/library/Ostacium/Db/Table/ website/library/Ostacium/Form/ website/library/Ostacium/Form/Decorator/ website/library/Ostacium/Form/Element/ website/library/Ostacium/Validate/ website/library/Ostacium/View/ website/library/Ostacium/View/Helper/ website/library/Zend/ website/other/ Property changes on: website ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/application ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/application/default ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/application/default/controllers ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/application/default/layouts ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/application/default/models ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/application/default/views ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/application/default/views/helpers ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/application/default/views/scripts ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/application/default/views/scripts/archieve ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/application/default/views/scripts/error ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/application/default/views/scripts/index ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/config ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/httpdocs ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/httpdocs/images ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/httpdocs/scripts ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/httpdocs/styles ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/lang ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/library ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/library/Ostacium ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/library/Ostacium/Controller ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/library/Ostacium/Controller/Plugin ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/library/Ostacium/Db ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/library/Ostacium/Db/Table ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/library/Ostacium/Form ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/library/Ostacium/Form/Decorator ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/library/Ostacium/Form/Element ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/library/Ostacium/Validate ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/library/Ostacium/View ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/library/Ostacium/View/Helper ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/library/Zend ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/other ___________________________________________________________________ Added: tsvn:logminsize + 5 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2008-09-25 22:05:14
|
Revision: 390 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=390&view=rev Author: brus07 Date: 2008-09-25 22:05:07 +0000 (Thu, 25 Sep 2008) Log Message: ----------- Updating dll tester modules. Fix bug with output usedTime and usedMemory when return WA. Modified Paths: -------------- ACMServer/trunk/ACMServer/Runner/Checker.dll ACMServer/trunk/ACMServer/Runner/Class1.cs ACMServer/trunk/ACMServer/Runner/Main.dll ACMServer/trunk/ACMServer/Runner/Plugin.dll ACMServer/trunk/ACMServer/Runner/Runner.csproj ACMServer/trunk/ACMServer/Runner/Test.dll Modified: ACMServer/trunk/ACMServer/Runner/Class1.cs =================================================================== --- ACMServer/trunk/ACMServer/Runner/Class1.cs 2008-09-25 21:49:54 UTC (rev 389) +++ ACMServer/trunk/ACMServer/Runner/Class1.cs 2008-09-25 22:05:07 UTC (rev 390) @@ -80,19 +80,19 @@ else { result.res = test.run.results[i].res.ToString(); + usedTime = test.run.results[i].UsedTime; + usedMemory = test.run.results[i].UsedMemory; break; } } - if (result.res == TestResult.Accepted.ToString()) - { - result.usedMemory = usedTime; - result.usedTime = usedMemory; - } + result.usedMemory = usedTime; + result.usedTime = usedMemory; } } catch (Exception tex) { log.Loging("Runner:GetResult - Exception (" + tex.ToString() + ": " + tex.Message, Log.Priority.INFO); + log.Loging(tex.StackTrace, Log.Priority.INFO); result.res = "Exception"; } return result.ToStringX(); Modified: ACMServer/trunk/ACMServer/Runner/Runner.csproj =================================================================== --- ACMServer/trunk/ACMServer/Runner/Runner.csproj 2008-09-25 21:49:54 UTC (rev 389) +++ ACMServer/trunk/ACMServer/Runner/Runner.csproj 2008-09-25 22:05:07 UTC (rev 390) @@ -32,7 +32,7 @@ <Reference Include="System" /> <Reference Include="System.Data" /> <Reference Include="System.Xml" /> - <Reference Include="Test, Version=1.0.3187.73, Culture=neutral, processorArchitecture=x86" /> + <Reference Include="Test, Version=1.0.3190.20622, Culture=neutral, processorArchitecture=x86" /> </ItemGroup> <ItemGroup> <Compile Include="Class1.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |