|
From: <br...@us...> - 2008-10-10 21:36:46
|
Revision: 414
http://acmcontester.svn.sourceforge.net/acmcontester/?rev=414&view=rev
Author: brus07
Date: 2008-10-10 21:36:40 +0000 (Fri, 10 Oct 2008)
Log Message:
-----------
Separate Socket and Work (Testing) into two different module and added Mediator module.
Modified Paths:
--------------
ACMServer/trunk/ACMServer/Tester/Form1.cs
ACMServer/trunk/ACMServer/Tester/Library/SocketClientGate.cs
ACMServer/trunk/ACMServer/Tester/Library/WorkRunner.cs
ACMServer/trunk/ACMServer/Tester/Tester.csproj
Added Paths:
-----------
ACMServer/trunk/ACMServer/Tester/Library/ISocketMediator.cs
ACMServer/trunk/ACMServer/Tester/Library/IWorkerMediator.cs
ACMServer/trunk/ACMServer/Tester/Library/WorkMediator.cs
Modified: ACMServer/trunk/ACMServer/Tester/Form1.cs
===================================================================
--- ACMServer/trunk/ACMServer/Tester/Form1.cs 2008-10-10 19:05:39 UTC (rev 413)
+++ ACMServer/trunk/ACMServer/Tester/Form1.cs 2008-10-10 21:36:40 UTC (rev 414)
@@ -14,6 +14,8 @@
public partial class Form1 : Form
{
static SocketClientGate socket;
+ static WorkRunner worker;
+ static WorkMediator mediator;
public Form1()
{
@@ -51,6 +53,12 @@
socket.onAddLogText += AddText;
}
socket.Connect();
+
+ if (worker == null)
+ {
+ worker = new WorkRunner();
+ }
+ mediator = WorkMediator.GetInstance(worker, socket);
}
private void button2_Click(object sender, EventArgs e)
@@ -65,6 +73,11 @@
socket.Disconnect();
socket = null;
}
+ if (worker != null)
+ {
+ worker.Stop();
+ worker = null;
+ }
}
delegate void AddTextCallback(string text);
Added: ACMServer/trunk/ACMServer/Tester/Library/ISocketMediator.cs
===================================================================
--- ACMServer/trunk/ACMServer/Tester/Library/ISocketMediator.cs (rev 0)
+++ ACMServer/trunk/ACMServer/Tester/Library/ISocketMediator.cs 2008-10-10 21:36:40 UTC (rev 414)
@@ -0,0 +1,12 @@
+using System;
+using AcmContester.Library.LibraryExtention;
+
+namespace AcmContester.Tester.Library
+{
+ interface ISocketMediator
+ {
+ bool Send(SystemMessage message);
+ bool Arrived(SystemMessage message);
+ bool IsBusy();
+ }
+}
Added: ACMServer/trunk/ACMServer/Tester/Library/IWorkerMediator.cs
===================================================================
--- ACMServer/trunk/ACMServer/Tester/Library/IWorkerMediator.cs (rev 0)
+++ ACMServer/trunk/ACMServer/Tester/Library/IWorkerMediator.cs 2008-10-10 21:36:40 UTC (rev 414)
@@ -0,0 +1,11 @@
+using System;
+using AcmContester.Library.LibraryExtention;
+
+namespace AcmContester.Tester.Library
+{
+ interface IWorkerMediator
+ {
+ bool Send(SystemMessage message);
+ bool Arrived(SystemMessage message);
+ }
+}
Modified: ACMServer/trunk/ACMServer/Tester/Library/SocketClientGate.cs
===================================================================
--- ACMServer/trunk/ACMServer/Tester/Library/SocketClientGate.cs 2008-10-10 19:05:39 UTC (rev 413)
+++ ACMServer/trunk/ACMServer/Tester/Library/SocketClientGate.cs 2008-10-10 21:36:40 UTC (rev 414)
@@ -7,23 +7,29 @@
{
class SocketClientGate: AbstractConnector
{
+ ISocketMediator mediator;
+
SocketClientTask client;
- //TODO: tut vin tymchasovo, potribno bude perenesty jogo kudys dali
- private WorkRunner workRunner = new WorkRunner();
-
public SocketClientGate(string IP)
{
client = new SocketClientTask(IP);
client.onDataArrived +=new SocketClient.DataArrivedDelegate(SocketClientGate_onDataArrived);
client.onAddLogText += OnAddLogText;
client.isBusy += IsBusy;
- workRunner.onDataArrived += Send;
}
+ public ISocketMediator Mediator
+ {
+ set
+ {
+ mediator = value;
+ }
+ }
+
bool IsBusy()
{
- return workRunner.IsBusy();
+ return mediator.IsBusy();
}
void SocketClientGate_onDataArrived(SystemMessage message)
@@ -32,7 +38,7 @@
if (message.IsType("TestingSubmit") == true)
{
- workRunner.AddWork(message.Message);
+ OnDataArrived(message);
}
}
@@ -64,7 +70,6 @@
public void Disconnect()
{
client.Disconnect();
- workRunner.Stop();
}
public bool IsConnected()
{
Added: ACMServer/trunk/ACMServer/Tester/Library/WorkMediator.cs
===================================================================
--- ACMServer/trunk/ACMServer/Tester/Library/WorkMediator.cs (rev 0)
+++ ACMServer/trunk/ACMServer/Tester/Library/WorkMediator.cs 2008-10-10 21:36:40 UTC (rev 414)
@@ -0,0 +1,93 @@
+using System;
+using AcmContester.Library.LibraryExtention;
+
+namespace AcmContester.Tester.Library
+{
+ sealed class WorkMediator: ISocketMediator, IWorkerMediator
+ {
+ private static WorkMediator instance = new WorkMediator();
+
+ WorkRunner runner;
+ SocketClientGate socketClient;
+
+ private WorkMediator()
+ {
+ }
+ void init(WorkRunner runner, SocketClientGate client)
+ {
+ if (this.runner == null)
+ {
+ this.runner = runner;
+
+ this.runner.onDataArrived += ((IWorkerMediator)this).Arrived;
+ }
+ if (this.socketClient == null)
+ {
+ this.socketClient = client;
+ this.socketClient.Mediator = (ISocketMediator)this;
+ this.socketClient.onDataArrived += SocketArrived;
+ }
+ }
+ public static WorkMediator GetInstance(WorkRunner runner, SocketClientGate client)
+ {
+ instance.init(runner, client);
+ return instance;
+ }
+ public static WorkMediator GetInstance()
+ {
+ return instance;
+ }
+
+
+ public bool Send(SystemMessage message)
+ {
+ throw new Exception("The method or operation is not implemented.");
+ }
+
+ public bool Arrived(SystemMessage message)
+ {
+ throw new Exception("The method or operation is not implemented.");
+ }
+
+ void SocketArrived(SystemMessage messsage)
+ {
+ ((ISocketMediator)this).Arrived(messsage);
+ }
+
+ #region ISocket Members
+
+ bool ISocketMediator.Send(SystemMessage message)
+ {
+ return socketClient.Send(message);
+ }
+
+ bool ISocketMediator.Arrived(SystemMessage message)
+ {
+ return ((IWorkerMediator)this).Send(message);
+ }
+
+ public bool IsBusy()
+ {
+ return runner.IsBusy();
+ }
+
+
+ #endregion
+
+ #region IWorker Members
+
+ bool IWorkerMediator.Send(SystemMessage message)
+ {
+ if (message.IsType("TestingSubmit") == true)
+ return runner.AddWork(message.Message);
+ return true;
+ }
+
+ bool IWorkerMediator.Arrived(SystemMessage message)
+ {
+ return ((ISocketMediator)this).Send(message);
+ }
+
+ #endregion
+ }
+}
Modified: ACMServer/trunk/ACMServer/Tester/Library/WorkRunner.cs
===================================================================
--- ACMServer/trunk/ACMServer/Tester/Library/WorkRunner.cs 2008-10-10 19:05:39 UTC (rev 413)
+++ ACMServer/trunk/ACMServer/Tester/Library/WorkRunner.cs 2008-10-10 21:36:40 UTC (rev 414)
@@ -27,11 +27,11 @@
return false;
}
- internal void AddWork(string message)
+ internal bool AddWork(string message)
{
if (IsBusy() == true)
{
- return;
+ return false;
}
//TODO: tut potribno stavyty lock
@@ -44,6 +44,7 @@
// tak shob ne potribno bulo stvorjuvaty novyj
thread = new Thread(new ParameterizedThreadStart(Go));
thread.Start(this);
+ return true;
}
static void Go(object data)
Modified: ACMServer/trunk/ACMServer/Tester/Tester.csproj
===================================================================
--- ACMServer/trunk/ACMServer/Tester/Tester.csproj 2008-10-10 19:05:39 UTC (rev 413)
+++ ACMServer/trunk/ACMServer/Tester/Tester.csproj 2008-10-10 21:36:40 UTC (rev 414)
@@ -46,7 +46,10 @@
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
+ <Compile Include="Library\ISocketMediator.cs" />
+ <Compile Include="Library\IWorkerMediator.cs" />
<Compile Include="Library\WorkRunner.cs" />
+ <Compile Include="Library\WorkMediator.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.
|