Beispiel #1
0
        public bool _OnRun()
        {
            _CheckInitialized();

            var runNext = true;

            if (PluginState == PluginState.Started || PluginState == PluginState.Paused)
            {
                var typeTitle = TypeTitle;

                try
                {
                    ICEController.WriteICEEventInfo("(" + typeTitle + ") Running '" + Name + "' ...");

                    runNext = _Plugin.OnRun();

                    ICEController.WriteICEEventInfo("(" + typeTitle + ") '" + Name + "' completed.");
                }
                catch (Exception ex)
                {
                    SetErrorMessage(ex, "Error running ", typeTitle.ToLower(), " '", Name, "' on channel '", Channel.Name, "'.");
                    runNext = false;
                }
            }

            return(runNext);
        }
Beispiel #2
0
        /// <summary>
        /// Attempts to load the assembly for this plugin library. Returns true on success, and false otherwise.
        /// </summary>
        /// <param name="throwErrors">If true, then an exception is thrown instead of returning false.</param>
        public bool Load(bool throwErrors = false)
        {
            if (_Assembly == null || _Assembly.ReflectionOnly)
            {
                if (string.IsNullOrEmpty(_Filename))
                {
                    var _ex = ICEController.WriteICEEventError("Cannot load this library: No valid filename was given.");
                    if (throwErrors)
                    {
                        throw _ex;
                    }
                    return(false);
                }

                string libFileToLoad = AppDomain.CurrentDomain.BaseDirectory + _Filename;

                ICEController.WriteICEEventInfo("Loading library '" + libFileToLoad + "'...");

                try
                {
                    _Assembly = Assembly.LoadFile(libFileToLoad);
                }
                catch (Exception ex)
                {
                    var _ex = ICEController.WriteICEEventError("An error occurred trying to load plugin '" + libFileToLoad + "'.", ex);
                    if (throwErrors)
                    {
                        throw _ex;
                    }
                    return(false);
                }
            }

            return(IsLoaded);
        }
Beispiel #3
0
        public void _OnStart()
        {
            if (!_CheckInitialized(false))
            {
                _Timer.Dispose();
            }

            if (PluginState == PluginState.Ready || PluginState == PluginState.Paused || PluginState == PluginState.Stopped)
            {
                var typeTitle = TypeTitle;

                try
                {
                    ICEController.WriteICEEventInfo("(" + typeTitle + ") Starting '" + Name + "' ...");

                    _Plugin.OnStart();
                    PluginState = PluginState.Started;

                    ICEController.WriteICEEventInfo("(" + typeTitle + ") '" + Name + "' started.");
                }
                catch (Exception ex)
                {
                    SetErrorMessage(ex, "Error starting ", typeTitle.ToLower(), " '", Name, "' on channel '", Channel.Name, "'.");
                }
            }
        }
Beispiel #4
0
        // -------------------------------------------------------------------------------------------------------

        public Channel CreateChannel(string name, string guid = null)
        {
            ICEController.WriteICEEventInfo("Creating channel '" + name + "'...");
            Channel channel = new Channel(this, name, guid);

            _Channels.Add(channel);
            return(channel);
        }
Beispiel #5
0
        // -------------------------------------------------------------------------------------------------------

        /// <summary>
        /// Creates and returns a plugin instance to run on the channel.
        /// </summary>
        /// <param name="name">The case-sensitive type name, or full type name (i.e. [Namespace].[Type]), of the plugin to create.  Full type names are
        /// searched first before type-only names.</param>
        public Plugin <IPlugin> CreateInstance(string name, string guid)
        {
            ICEController.WriteICEEventInfo("Creating instance for plugin '" + name + "' on channel '" + Name + "'...");

            Plugin <IPlugin> plugin = PluginManager.CreateInstance(this, name, guid);

            if (plugin != null)
            {
                _PluginInstances.Add(plugin);
            }

            return(plugin);
        }
Beispiel #6
0
        // -------------------------------------------------------------------------------------------------------

        /// <summary>
        /// Creates and returns a plugin instance to run on a given channel.
        /// </summary>
        /// <param name="channel">The channel instance to create the plugin in (required).</param>
        /// <param name="name">The case-sensitive type name, or full type name (i.e. [Namespace].[Type]), of the plugin to create.  Full type names are
        /// searched first before type-only names.</param>
        /// <param name="guid">A globally unique ID for this plugin instance (system wide, across all channels). If null or empty, a new GUID will be created automatically.</param>
        public Plugin <IPlugin> CreateInstance(Channel channel, string instanceName, string guid = null)
        {
            if (channel == null)
            {
                throw new ArgumentNullException("A channel reference is required for plugin instances.");
            }

            if (string.IsNullOrEmpty(guid))
            {
                guid = Guid.NewGuid().ToString("N");
            }

            if (channel.GetPluginInstance(instanceName) != null)
            {
                throw new InvalidOperationException("There is already an existing plugin instance with the name '" + instanceName + "'.");
            }

            Plugin <IPlugin> pluginController = null;

            try
            {
                ICEController.WriteICEEventInfo("Creating instance for plugin '" + PluginType.FullName + "' on channel '" + channel.Name + "'...");

                var pluginInstance = PluginType.Assembly.CreateInstance(PluginType.FullName) as IPlugin;

                pluginController = pluginInstance as Plugin <IPlugin>;

                if (pluginInstance != null && pluginController == null)
                {
                    // ... this plugin instance does not derive from the plugin<T> controller class, so we need to wrap it in one ...
                    pluginController         = new Plugin <IPlugin>();
                    pluginController._Plugin = pluginInstance;
                }

                if (pluginController != null)
                {
                    pluginController._Configure(channel, Library, instanceName, pluginController.ActualPlugin, guid);
                }
            }
            catch (Exception ex)
            {
                throw ICEController.WriteICEEventError("Error creating plugin type '" + PluginType.FullName + "'.", ex);
            }

            return(pluginController);
        }
Beispiel #7
0
        public void _OnClosing()
        {
            _CheckInitialized();

            var typeTitle = TypeTitle;

            try
            {
                ICEController.WriteICEEventInfo("(" + typeTitle + ") Closing '" + Name + "' ...");

                _Plugin.OnClosing();
                PluginState = PluginState.Uninitialized;

                ICEController.WriteICEEventInfo("(" + typeTitle + ") '" + Name + "' ready for termination.");
            }
            catch (Exception ex)
            {
                SetErrorMessage(ex, "Error closing ", typeTitle.ToLower(), " '", Name, "' on channel '", Channel.Name, "'.");
            }
        }
Beispiel #8
0
        public void _OnTick()
        {
            _CheckInitialized();

            if (PluginState == PluginState.Started)
            {
                var typeTitle = TypeTitle;

                try
                {
                    ICEController.WriteICEEventInfo("(" + typeTitle + ") Timer elapsed for '" + Name + "' ...");

                    _Plugin.OnTick();

                    ICEController.WriteICEEventInfo("(" + typeTitle + ") '" + Name + "' completed.");
                }
                catch (Exception ex)
                {
                    SetErrorMessage(ex, "Error in timer method for ", typeTitle.ToLower(), " '", Name, "' on channel '", Channel.Name, "'.");
                }
            }
        }
Beispiel #9
0
        public void _OnPause()
        {
            _CheckInitialized();

            if (PluginState == PluginState.Started)
            {
                var typeTitle = TypeTitle;

                try
                {
                    ICEController.WriteICEEventInfo("(" + typeTitle + ") Pausing '" + Name + "' ...");

                    _Plugin.OnPause();
                    PluginState = PluginState.Paused;

                    ICEController.WriteICEEventInfo("(" + typeTitle + ") '" + Name + "' paused.");
                }
                catch (Exception ex)
                {
                    SetErrorMessage(ex, "Error pausing ", typeTitle.ToLower(), " '", Name, "' on channel '", Channel.Name, "'.");
                }
            }
        }
Beispiel #10
0
        // -------------------------------------------------------------------------------------------------------

        public void Initialize()
        {
            if (!IsInitialized)
            {
                var typeTitle = TypeTitle;

                try
                {
                    ICEController.WriteICEEventInfo("(" + typeTitle + ") '" + Name + "' startup properties:", GetNameValues(), "Initializing ...");

                    LoadData();

                    _Plugin.Initialize(Channel.Controller, this);
                    PluginState = PluginState.Ready;

                    ICEController.WriteICEEventInfo("(" + typeTitle + ") '" + Name + "' initialized.", "Properties after initialization:", GetNameValues());
                }
                catch (Exception ex)
                {
                    SetErrorMessage(ex, "Error initializing ", typeTitle.ToLower(), " '", Name, "' on channel '", Channel.Name, "'.");
                }
            }
        }
Beispiel #11
0
        public virtual void Stop()
        {
            _CheckInitialized();

            if (_PluginState == PluginState.Started || _PluginState == PluginState.Paused)
            {
                var typeTitle = TypeTitle;

                try
                {
                    ICEController.WriteICEEventInfo("(" + typeTitle + ") Stopping '" + _Name + "' ...");

                    _Plugin.OnStop();
                    _PluginState = PluginState.Stopped;

                    ICEController.WriteICEEventInfo("(" + typeTitle + ") '" + _Name + "' stopped.");
                }
                catch (Exception ex)
                {
                    SetErrorMessage(ex, "Error stopping ", typeTitle.ToLower(), " '", _Name, "' on channel '", _Channel.Name, "'.");
                }
            }
        }