- tcpwin_clientcmd.zip
- TCPWin_ClientCMD
- ICSharpCode.SharpZipLib.dll
- PluginInMannager.dll
- plugins
- FileSystemClient.dll
- RemoteDesktopClient.dll
- TCPClient.dll
- TCPClientCmd.exe
- tcp_client_server.zip
- TCP_client_server
- NET
- build.bat
- FileSystemClient
- FileSystemServer
- ICSharpCode.SharpZipLib.dll
- PluginInManager
- RemoteDesktopClient
- RemoteDesktopServer
- TCP_WIN_APP.sln
- TCPClient
- TCPClientCmd
- TCPClientWin
- TCPServer
- NETCF
- tcpwin_client.zip
- TCPWin_Client
- ICSharpCode.SharpZipLib.dll
- Interop.Shell32.dll
- Log
- PluginInMannager.dll
- plugins
- FileSystemClient.dll
- RemoteDesktopClient.dll
- TCPClient.dll
- TCPClientWin.exe
- tcpcf_server.zip
- TCPCF_Server
- ICSharpCode.SharpZipLib.dll
- PlugInManager.dll
- plugins
- FileSystemServer.dll
- RemoteDesktopServer.dll
- TCPServer.exe
- tcpwin_server.zip
- TCPWin_Server
- ICSharpCode.SharpZipLib.dll
- PluginInMannager.dll
- plugins
- FileSystemServer.dll
- SimpleRemoteDesktopServer.dll
- TCPServer.exe
|
//-----------------------------------------------------------------------
// <copyright file="PluginManager.cs" company="Matjazev.NET">
// Copyright (c) www.matjazev.net. All rights reserved.
// </copyright>
// <author>Matjaz Prtenjak</author>
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Matjazev.Tcp.Plugin.Interfaces;
namespace Matjazev.Tcp.Plugin
{
public class PluginsManager
{
private static PluginsManager inst = null;
private List<PluginData> serverPlugins = new List<PluginData>();
private List<PluginData> clientPlugins = new List<PluginData>();
private Dictionary<ExecuteTime, Dictionary<string, ExecuteAction>> functions = new Dictionary<ExecuteTime, Dictionary<string, ExecuteAction>>();
private string programPath = string.Empty;
private PluginData getPlugin(Dictionary<string, PluginData> dict, string action)
{
if (dict.ContainsKey(action))
return dict[action];
return null;
}
protected PluginsManager()
{
}
private bool addAssembly(string pluginFile, Assembly assembly)
{
bool found = false;
foreach (Type type in assembly.GetTypes())
{
if (type.IsAbstract) continue;
bool server = type.IsDefined(typeof(TCPServerPluginAttribute), true);
bool client = type.IsDefined(typeof(TCPClientPluginAttribute), true);
if (server || client)
{
PluginData data = new PluginData(Activator.CreateInstance(type) as IPlugin, pluginFile);
if (server)
this.serverPlugins.Add(data);
else
this.clientPlugins.Add(data);
foreach (string action in data.Plugin.Actions)
{
string uAction = action.ToUpper();
if (server)
this.functions[ExecuteTime.OnServer][uAction] = data.Plugin.GetExecuteFunction(ExecuteTime.OnServer, uAction);
else
{
this.functions[ExecuteTime.BeforeServer][uAction] = data.Plugin.GetExecuteFunction(ExecuteTime.BeforeServer, uAction);
this.functions[ExecuteTime.AfterServer][uAction] = data.Plugin.GetExecuteFunction(ExecuteTime.AfterServer, uAction);
}
}
found = true;
}
}
return found;
}
private bool addPlugin(string pluginFile)
{
if (!File.Exists(pluginFile))
return false;
Assembly assembly = Assembly.LoadFrom(pluginFile);
if (assembly == null)
return false;
return this.addAssembly(pluginFile, assembly);
}
public static PluginsManager Inst
{
get
{
if (inst == null)
inst = new PluginsManager();
return inst;
}
}
public void ReLoadPlugins()
{
this.LoadPlugins(this.programPath);
}
public void LoadPlugins(string programPath)
{
this.programPath = programPath;
string pluginsPath = Path.Combine(programPath, @"PlugIns");
pluginsPath = Path.GetFullPath(pluginsPath);
if (!Directory.Exists(pluginsPath))
{
pluginsPath = Path.Combine(programPath, @"..\..\PlugIns");
pluginsPath = Path.GetFullPath(pluginsPath);
}
this.Clear();
this.addAssembly(string.Empty, Assembly.GetExecutingAssembly());
if (!Directory.Exists(pluginsPath)) return;
foreach (string f in Directory.GetFiles(pluginsPath))
{
FileInfo fi = new FileInfo(f);
if (fi.Extension.Equals(".dll"))
this.addPlugin(f);
}
}
public void Clear()
{
this.serverPlugins.Clear();
this.clientPlugins.Clear();
this.functions.Clear();
this.functions[ExecuteTime.BeforeServer] = new Dictionary<string, ExecuteAction>();
this.functions[ExecuteTime.OnServer] = new Dictionary<string, ExecuteAction>();
this.functions[ExecuteTime.AfterServer] = new Dictionary<string, ExecuteAction>();
}
public IList<PluginData> ServerPlugins
{
get { return this.serverPlugins; }
}
public IList<PluginData> ClientPlugins
{
get { return this.clientPlugins; }
}
public ExecuteAction GetExecuteFunction(ExecuteTime executeTime, string action)
{
try
{
return this.functions[executeTime][action];
}
catch (Exception)
{
}
return null;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I am a software developer in one of the largest retailer in our country. My job is (beside else) also in setting some standards in SW development throughout our company.
I have a M.Sc. in computer science and 20 years of experience. I have written 2 books in Slovenian language and both are sold out (the first about C++ language and the second about VBA language)...