From: <br...@us...> - 2008-10-14 21:53:07
|
Revision: 417 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=417&view=rev Author: brus07 Date: 2008-10-14 21:52:59 +0000 (Tue, 14 Oct 2008) Log Message: ----------- MediatorKernel moved to PluginsFramework Modified Paths: -------------- ACMServer/trunk/ACMServer/Mediator/Form1.cs ACMServer/trunk/ACMServer/Mediator/Mediator.csproj ACMServer/trunk/ACMServer/Plugins/PluginsFramework/PluginsFramework.csproj ACMServer/trunk/ACMServer/Plugins/PluginsFramework/PluginsLoader.cs Added Paths: ----------- ACMServer/trunk/ACMServer/Plugins/PluginsFramework/MediatorKernel.cs Modified: ACMServer/trunk/ACMServer/Mediator/Form1.cs =================================================================== --- ACMServer/trunk/ACMServer/Mediator/Form1.cs 2008-10-14 20:29:04 UTC (rev 416) +++ ACMServer/trunk/ACMServer/Mediator/Form1.cs 2008-10-14 21:52:59 UTC (rev 417) @@ -9,6 +9,7 @@ using System.Net.Sockets; using System.IO; using AcmContester.Library.LibraryExtention; +using AcmContester.Plugins.PluginsFramework; namespace Mediator { @@ -22,22 +23,22 @@ textBox2.Text = s; } - AcmContester.Mediator.Library.MediatorKernel kernel; + MediatorKernel kernel; private void button2_Click(object sender, EventArgs e) { - kernel = new AcmContester.Mediator.Library.MediatorKernel(); + kernel = new MediatorKernel(); System.Threading.ThreadPool.QueueUserWorkItem(RunLoadDll); } void RunLoadDll(Object ob) { - kernel.AddControl += new EventHandler<AcmContester.Mediator.Library.MediatorKernel.ControlEventArgs>(kernel_AddControl); - kernel.LoadLists(); + kernel.AddControl += new EventHandler<AcmContester.Plugins.PluginsFramework.MediatorKernel.ControlEventArgs>(kernel_AddControl); + kernel.LoadLists("Dll_Tester", "Dll_Web"); } - delegate void AddControlCallback(object sender, AcmContester.Mediator.Library.MediatorKernel.ControlEventArgs e); - void kernel_AddControl(object sender, AcmContester.Mediator.Library.MediatorKernel.ControlEventArgs e) + delegate void AddControlCallback(object sender, AcmContester.Plugins.PluginsFramework.MediatorKernel.ControlEventArgs e); + void kernel_AddControl(object sender, AcmContester.Plugins.PluginsFramework.MediatorKernel.ControlEventArgs e) { if (this.tabControl1.InvokeRequired) { Modified: ACMServer/trunk/ACMServer/Mediator/Mediator.csproj =================================================================== --- ACMServer/trunk/ACMServer/Mediator/Mediator.csproj 2008-10-14 20:29:04 UTC (rev 416) +++ ACMServer/trunk/ACMServer/Mediator/Mediator.csproj 2008-10-14 21:52:59 UTC (rev 417) @@ -42,7 +42,6 @@ <Compile Include="Form1.Designer.cs"> <DependentUpon>Form1.cs</DependentUpon> </Compile> - <Compile Include="Library\MediatorKernel.cs" /> <Compile Include="Program.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <EmbeddedResource Include="Form1.resx"> @@ -83,6 +82,9 @@ <Name>PluginsFramework</Name> </ProjectReference> </ItemGroup> + <ItemGroup> + <Folder Include="Library\" /> + </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. Copied: ACMServer/trunk/ACMServer/Plugins/PluginsFramework/MediatorKernel.cs (from rev 414, ACMServer/trunk/ACMServer/Mediator/Library/MediatorKernel.cs) =================================================================== --- ACMServer/trunk/ACMServer/Plugins/PluginsFramework/MediatorKernel.cs (rev 0) +++ ACMServer/trunk/ACMServer/Plugins/PluginsFramework/MediatorKernel.cs 2008-10-14 21:52:59 UTC (rev 417) @@ -0,0 +1,108 @@ +using System; +using System.Collections; +using AcmContester.Plugins.PluginsFramework; +using System.Collections.Generic; +using System.Windows.Forms; +using AcmContester.Library.LibraryExtention; + +namespace AcmContester.Plugins.PluginsFramework +{ + public class MediatorKernel + { + List<BaseMediatorPlugin> clientSideList; + List<BaseMediatorPlugin> testerSideList; + + public sealed class ControlEventArgs : EventArgs + { + Control control; + string name; + public ControlEventArgs(Control in_Control, string in_Name) + { + control = in_Control; + name = in_Name; + } + public Control Control + { + get + { + return control; + } + } + public string Name + { + get + { + return name; + } + } + + } + + public event EventHandler<ControlEventArgs> AddControl; + + public void LoadLists(string testerFolderPath, string clientFolderPath) + { + LoadAllTesterList(testerFolderPath); + LoadAllClientList(clientFolderPath); + } + + public void LoadAllTesterList(string folderPath) + { + testerSideList = PluginsLoader<BaseMediatorPlugin>.Load(folderPath); + foreach (BaseMediatorPlugin plugin in testerSideList) + { + plugin.onDataArrived += DataArrivedFromTesterList; + if (plugin.Control != null) + { + this.OnAddControl(new ControlEventArgs(plugin.Control, plugin.GetType().Name)); + } + } + } + public void LoadAllClientList(string folderPath) + { + clientSideList = PluginsLoader<BaseMediatorPlugin>.Load(folderPath); + foreach (BaseMediatorPlugin plugin in clientSideList) + { + plugin.onDataArrived += DataArrivedFromClientList; + if (plugin.Control != null) + { + this.OnAddControl(new ControlEventArgs(plugin.Control, plugin.GetType().Name)); + } + } + } + + private void OnAddControl(ControlEventArgs e) + { + EventHandler<ControlEventArgs> temp = AddControl; + if (temp != null) + temp(this, e); + } + + private void DataArrivedFromClientList(SystemMessage message) + { + if (testerSideList != null) + { + for (int index = 0; index < testerSideList.Count; index++) + { + ((BaseMediatorPlugin)testerSideList[index]).Send(message); + } + } + } + private void DataArrivedFromTesterList(SystemMessage message) + { + if (clientSideList != null) + { + for (int index = 0; index < clientSideList.Count; index++) + { + ((BaseMediatorPlugin)clientSideList[index]).Send(message); + } + } + } + + public void SendToAll(SystemMessage message) + { + DataArrivedFromClientList(message); + DataArrivedFromTesterList(message); + } + } +} Property changes on: ACMServer/trunk/ACMServer/Plugins/PluginsFramework/MediatorKernel.cs ___________________________________________________________________ Added: svn:mergeinfo + Modified: ACMServer/trunk/ACMServer/Plugins/PluginsFramework/PluginsFramework.csproj =================================================================== --- ACMServer/trunk/ACMServer/Plugins/PluginsFramework/PluginsFramework.csproj 2008-10-14 20:29:04 UTC (rev 416) +++ ACMServer/trunk/ACMServer/Plugins/PluginsFramework/PluginsFramework.csproj 2008-10-14 21:52:59 UTC (rev 417) @@ -33,6 +33,7 @@ </ItemGroup> <ItemGroup> <Compile Include="BaseMediatorPlugin.cs" /> + <Compile Include="MediatorKernel.cs" /> <Compile Include="PluginsLoader.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> </ItemGroup> Modified: ACMServer/trunk/ACMServer/Plugins/PluginsFramework/PluginsLoader.cs =================================================================== --- ACMServer/trunk/ACMServer/Plugins/PluginsFramework/PluginsLoader.cs 2008-10-14 20:29:04 UTC (rev 416) +++ ACMServer/trunk/ACMServer/Plugins/PluginsFramework/PluginsLoader.cs 2008-10-14 21:52:59 UTC (rev 417) @@ -43,7 +43,11 @@ ///\xE3\xE5\xED\xE5\xF0\xF3\xBA\xF2\xFC\xF1\xFF \xEF\xEE\xF2\xF0\xB3\xE1\xED\xE8\xE9 \xF8\xEB\xFF\xF5 \xE4\xEE dll \xF3 \xE4\xE8\xF0\xE5\xEA\xF2\xEE\xF0\xB3\xBF directory string fileName = directory.Substring(directory.LastIndexOf('\\')+1) + ".dll"; string fileFullName = directory + "\\" + fileName; - ScanAndLoad(fileFullName, ref plugins); + List<T> lst = ScanAndLoad(fileFullName); + foreach(T t in lst) + { + plugins.Add(t); + } } return plugins; } @@ -54,11 +58,12 @@ /// </summary> /// <param name="filename">Which file to scan.</param> /// <param name="lst">Where to add found objects.</param> - private static void ScanAndLoad(string filename, ref List<T> lst) + public static List<T> ScanAndLoad(string filename) { + List<T> lst = new List<T>(); if (File.Exists(filename) == false) { - return; + return lst; } Assembly assembly; @@ -68,7 +73,7 @@ } catch { - return; + return lst; } if (assembly != null) { @@ -99,6 +104,7 @@ } } } + return lst; } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |