public void StopPlugin(PluginAssemblyType PluginTypeToStop)
        {
            init();
            switch (PluginTypeToStop)
            {
            case PluginAssemblyType.Command:
            {
                if (controller_command != null)
                {
                    controller_command.IsShuttingDown = true;
                    controller_command.StopPluginType(PluginTypeToStop);
                }
                return;
            }

            case PluginAssemblyType.Plugin:
            {
                if (controller_plugin != null)
                {
                    controller_plugin.IsShuttingDown = true;
                    controller_plugin.StopPluginType(PluginTypeToStop);
                }
                return;
            }
            }
        }
Example #2
0
        public void LoadDomain(PluginAssemblyType controllerToLoad) {
            Initialise();

            switch (controllerToLoad) {
                case PluginAssemblyType.PrePlugin:
                    _prePluginController =
                        (PluginController)
                            _domainPrePlugins.CreateInstanceAndUnwrap(typeof(PluginController).Assembly.FullName,
                                typeof(PluginController).FullName);
                    _prePluginController.Callback += PluginCallback;
                    _prePluginController.LoadPlugins(PluginAssemblyType.PrePlugin);
                    return;
                case PluginAssemblyType.Plugin:
                    _pluginController =
                        (PluginController)
                            _domainPlugins.CreateInstanceAndUnwrap(typeof(PluginController).Assembly.FullName,
                                typeof(PluginController).FullName);
                    _pluginController.Callback += PluginCallback;
                    _pluginController.LoadPlugins(PluginAssemblyType.Plugin);
                    ChannelMessageCallback += _pluginController.OnChannelMessageCallback;
                    break;
                case PluginAssemblyType.None:
                    break;
                default:
                    throw new ArgumentOutOfRangeException(nameof(controllerToLoad), controllerToLoad, null);
            }
        }
 public void RemovePluginFromList(PluginAssemblyType UnloadType)
 {
     for (int i = Plugins.Count - 1; i > -1; i--)
     {
         if (Plugins[i].PluginType == UnloadType)
         {
             Plugins.RemoveAt(i);
         }
     }
 }
 public void StartPluginType(PluginAssemblyType StartType)
 {
     for (int i = Plugins.Count - 1; i > -1; i--)
     {
         if (Plugins[i].PluginType == StartType)
         {
             Plugins[i].Instance.Start();
         }
     }
 }
 public void AddPlugin(IPlugin Plugin, PluginAssemblyType PluginType, bool AutoStart)
 {
     try
     {
         PluginInstance pInstance = new PluginInstance();
         pInstance.Instance   = (IPlugin)Plugin;
         pInstance.PluginType = PluginType;
         pInstance.Status     = PluginStatus.Stopped;
         Plugins.Add(pInstance);
     }
     catch (Exception ex)
     {
         EventLogger.LogEvent("Error adding plugin: " + ex.Message, EventLogEntryType.Error);
     }
 }
        public void LoadDomainPlugin(PluginAssemblyType LoadType)
        {
            switch (LoadType)
            {
            case PluginAssemblyType.Command:
            {
                LoadDomain(PluginAssemblyType.Command);
                return;
            }

            case PluginAssemblyType.Plugin:
            {
                LoadDomain(PluginAssemblyType.Plugin);
                return;
            }
            }
        }
        public void LoadDomain(PluginAssemblyType controllerToLoad)
        {
            init();
            switch (controllerToLoad)
            {
            case PluginAssemblyType.Command:
            {
                controller_command           = (PluginController)domainCommand.CreateInstanceAndUnwrap((typeof(PluginController)).Assembly.FullName, (typeof(PluginController)).FullName);
                controller_command.Callback += Plugins_Callback;
                controller_command.LoadPlugin(PluginAssemblyType.Command);
                return;
            }

            case PluginAssemblyType.Plugin:
            {
                controller_plugin           = (PluginController)domainPlugins.CreateInstanceAndUnwrap((typeof(PluginController)).Assembly.FullName, (typeof(PluginController)).FullName);
                controller_plugin.Callback += Plugins_Callback;
                controller_plugin.LoadPlugin(PluginAssemblyType.Plugin);
                return;
            }
            }
        }
        public void UnLoadDomain(PluginAssemblyType domainToUnLoad)
        {
            init();
            try
            {
                switch (domainToUnLoad)
                {
                case PluginAssemblyType.Command:
                {
                    if (domainCommand != null)
                    {
                        AppDomain.Unload(domainCommand);
                        domainCommand = null;
                        //controller_command = null;
                    }
                    break;
                }

                case PluginAssemblyType.Plugin:
                {
                    if (domainPlugins != null)
                    {
                        AppDomain.Unload(domainPlugins);
                        domainPlugins = null;
                        //controller_plugin = null;
                    }
                    break;
                }
                }
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            catch (Exception ex)
            {
                var s = ex.Message;
                EventLogger.LogEvent("Error: " + ex.Message, EventLogEntryType.Error);
            }
        }
        public void LoadPlugin(PluginAssemblyType PluginType)
        {
            switch (PluginType)
            {
            case PluginAssemblyType.Command:
            {
                AppDomain.CurrentDomain.Load(_assemblyNameCommand);
                AddPlugin(Load(_assemblyNameCommand, ProxyLoader_RaiseCallbackEvent), PluginAssemblyType.Command, false);
                return;
            }

            case PluginAssemblyType.Plugin:
            {
                try
                {
                    string[] FileList = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, _genericPluginMask);
                    foreach (var plugin in FileList)
                    {
                        string _plugin = Path.GetFileNameWithoutExtension(plugin);
                        AppDomain.CurrentDomain.Load(_plugin);
                        AddPlugin(Load(_plugin, ProxyLoader_RaiseCallbackEvent), PluginAssemblyType.Plugin, false);
                    }
                    return;
                }
                catch (Exception ex)
                {
                    EventLogger.LogEvent("Error loading plugin: " + ex.Message, EventLogEntryType.Error);
                    break;
                }
            }

            default:
            {
                break;
            }
            }
        }
        public void StartPlugin(PluginAssemblyType PluginTypeToStart)
        {
            init();
            switch (PluginTypeToStart)
            {
            case PluginAssemblyType.Command:
            {
                if (controller_command != null)
                {
                    controller_command.StartPluginType(PluginTypeToStart);
                }
                return;
            }

            case PluginAssemblyType.Plugin:
            {
                if (controller_plugin != null)
                {
                    controller_plugin.StartPluginType(PluginTypeToStart);
                }
                return;
            }
            }
        }
Example #11
0
 public void RemovePluginFromList(PluginAssemblyType unloadType) {
     for (int i = Plugins.Count - 1; i > -1; i--) {
         if (Plugins[i].PluginType == unloadType) Plugins.RemoveAt(i);
     }
 }
Example #12
0
 public void StopPluginType(PluginAssemblyType stopType) {
     for (int i = Plugins.Count - 1; i > -1; i--) {
         if (Plugins[i].PluginType == stopType) Plugins[i].Instance.Stop();
     }
 }
Example #13
0
 public void AddPlugin(List<IPlugin> plugin, PluginAssemblyType pluginType, bool autoStart) {
     try {
         foreach (IPlugin instance in plugin) {
             Plugins.Add(new PluginInstance {
                 Instance = instance,
                 PluginType = pluginType,
                 Status = PluginStatus.Stopped
             });
         }
     } catch (Exception ex) {
         Writer.Log($"Error adding plugin: {ex.Message}", EventLogEntryType.Error);
     }
 }
Example #14
0
        public void LoadPlugins(PluginAssemblyType type) {
            try {
                string[] fileList = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, PLUGIN_MASK,
                    SearchOption.AllDirectories);

                if (fileList.Length == 0) {
                    Writer.Log("No plugins to load.", EventLogEntryType.Information);
                    return;
                }

                foreach (string plugin in fileList) {
                    AppDomain.CurrentDomain.Load(AssemblyName.GetAssemblyName(plugin));
                    AddPlugin(Load(plugin, ProxyLoader_RaiseCallbackEvent), PluginAssemblyType.Plugin, false);
                }
            } catch (ReflectionTypeLoadException ex) {
                foreach (Exception loaderException in ex.LoaderExceptions) {
                    Writer.Log($"{loaderException.Message}\n{loaderException.StackTrace}", EventLogEntryType.Error);
                }
            } catch (Exception ex) {
                if (ex is ArgumentException ||
                    ex is FormatException) {
                    Writer.Log($"Error loading json file.", EventLogEntryType.Error);
                    return;
                }

                Writer.Log($"Error loading plugin: {ex.Message}\n{ex.StackTrace}", EventLogEntryType.Error);
            }
        }
Example #15
0
        public void StopPlugins(PluginAssemblyType typeToStop) {
            switch (typeToStop) {
                case PluginAssemblyType.None:
                    break;
                case PluginAssemblyType.PrePlugin: {
                    if (_prePluginController == null) return;

                    _prePluginController.IsShuttingDown = true;
                    _prePluginController.StopPluginType(typeToStop);
                    return;
                }
                case PluginAssemblyType.Plugin: {
                    if (_pluginController == null) return;

                    _pluginController.IsShuttingDown = true;
                    _pluginController.StopPluginType(typeToStop);
                    return;
                }
                default:
                    throw new ArgumentOutOfRangeException(nameof(typeToStop), typeToStop, null);
            }
        }
Example #16
0
 public void StartPlugins(PluginAssemblyType typeToStart) {
     switch (typeToStart) {
         case PluginAssemblyType.None:
             break;
         case PluginAssemblyType.PrePlugin:
             _prePluginController?.StartPluginType(typeToStart);
             break;
         case PluginAssemblyType.Plugin:
             _pluginController?.StartPluginType(typeToStart);
             break;
         default:
             throw new ArgumentOutOfRangeException(nameof(typeToStart), typeToStart, null);
     }
 }
Example #17
0
        public void UnloadDomain(PluginAssemblyType typeToUnload) {
            Initialise();

            switch (typeToUnload) {
                case PluginAssemblyType.None:
                    break;
                case PluginAssemblyType.PrePlugin:
                    if (_domainPrePlugins == null) break;

                    AppDomain.Unload(_domainPrePlugins);
                    _domainPrePlugins = null;
                    break;
                case PluginAssemblyType.Plugin:
                    if (_domainPlugins == null) break;

                    AppDomain.Unload(_domainPlugins);
                    _domainPlugins = null;
                    break;
                default:
                    throw new ArgumentOutOfRangeException(nameof(typeToUnload), typeToUnload, null);
            }
        }
 public PluginAssemblyAttribute(string tenant, PluginAssemblyType assemblyType)
 {
     Tenant       = tenant;
     AssemblyType = assemblyType;
 }