示例#1
0
        /// <summary>
        /// Refreshs the update intervals for all indicators.
        /// </summary>
        private void RefreshUpdateIntervals()
        {
            Dictionary <string, TimeSpan> intervals = new Dictionary <string, TimeSpan>();

            List <string>       pluginNames = new List <string>();
            List <Core.IPlugin> plugins     = PluginManager.Instance.LoadAvailablePlugins();

            foreach (Core.IPlugin current in plugins)
            {
                pluginNames.Add(current.GetName());
            }

            List <Tuple <string, string, long?> > tmpUpdateIntervals = GetAllUpdateIntervals(pluginNames);
            string   ID;
            TimeSpan currentInterval;

            foreach (Tuple <string, string, long?> current in tmpUpdateIntervals)
            {
                WorkstationLogger.WriteLog("New intervals: " + current.Item1 + " " +
                                           current.Item2 + " " + current.Item3 / 10000000 + " seconds");
                ID = current.Item1 + "." + current.Item2;
                currentInterval = TimeSpan.FromTicks((long)current.Item3);
                intervals.Add(ID, currentInterval);
            }

            Scheduler.Instance.RefreshUpdateInterval(intervals);
        }
示例#2
0
        /// <summary>
        /// Store a plugin to the assembly folder
        /// </summary>
        /// <param name="plugin">Plugin to store</param>
        /// /// <returns>Result of this method</returns>
        private Boolean StorePlugin(PluginFile plugin)
        {
            // Convert the Base64 UUEncoded input into binary output.
            byte[] binaryData;
            try
            {
                binaryData = System.Convert.FromBase64String(plugin.FileAsBase64);
            }
            catch (System.ArgumentNullException)
            {
                //Logging "Base 64 string is null."
                var messageEx1 = new StringBuilder();
                messageEx1.Append(ServerConnection.GetWorkstationName() + "_PluginManager_StorePlugin: ");
                messageEx1.Append("Can't store the plugin. " + "Base 64 string is null.");
                ServerConnection.WriteLog(messageEx1.ToString(), LogType.Exception);
                return(false);
            }
            catch (System.FormatException)
            {
                //Logging "Base 64 string length is not 4 or is not an even multiple of 4."
                var messageEx2 = new StringBuilder();
                messageEx2.Append(
                    ServerConnection.GetWorkstationName() +
                    "Base 64 string length is not 4 or is not an even multiple of 4.");
                messageEx2.Append("Can't store the plugin. " + "Base 64 string is null.");
                ServerConnection.WriteLog(messageEx2.ToString(), LogType.Exception);
                return(false);
            }

            // Write out the decoded data.
            System.IO.FileStream outFile;
            string outputFileName =
                pluginPath +
                Path.DirectorySeparatorChar +
                plugin.FileName;

            WorkstationLogger.WriteLog("Storing plugin into: " + outputFileName);

            try
            {
                outFile = new System.IO.FileStream(outputFileName,
                                                   System.IO.FileMode.Create,
                                                   System.IO.FileAccess.Write);
                outFile.Write(binaryData, 0, binaryData.Length);
                outFile.Close();
            }
            catch (System.Exception exp)
            {
                //Logging
                //Logging "Base 64 string is null."
                var messageEx3 = new StringBuilder();
                messageEx3.Append(ServerConnection.GetWorkstationName() + "_PluginManager_StorePlugin: ");
                messageEx3.Append("Can't store the plugin. " + exp.ToString());
                ServerConnection.WriteLog(messageEx3.ToString(), LogType.Exception);
                return(false);
            }

            return(true);
        }
示例#3
0
        /// <summary>
        /// Check for new plugins on the MISD server, download of the new plugins and load them.
        /// </summary>
        /// <returns>Empty list if new plugins are loaded, otherwise all plugins.</returns>
        public List <IPlugin> UpdatePlugins()
        {
            List <string> pluginsToChange = new List <string>();

            //download plugin metadata
            var metadata = ServerConnection.GetPluginList();

            //check for changes and delete old plugins
            if (metadata == null)
            {
                ServerConnection.WriteLog(
                    ServerConnection.GetWorkstationName() +
                    "_PluginManager_UpdatePlugins: Error in GetPluginList, object was null.", LogType.Exception);
            }
            else
            {
                foreach (PluginMetadata data in metadata)
                {
                    WorkstationLogger.WriteLog("Received metadata for: " + data.Name);
                    if (!this.PluginIsUptodate(data))
                    {
                        pluginsToChange.Add(data.Name);
                    }
                }
            }

            // check if new plugins are loaded
            WorkstationLogger.WriteLog("Updating " + pluginsToChange.Count + " plugins");
            if (pluginsToChange.Count > 0)
            {
                this.ReleasePluginContainer();

                foreach (string pluginName in pluginsToChange)
                {
                    //delete plugin
                    this.DeletePlugin(this.plugins.FirstOrDefault(p => p.GetName() == pluginName));
                }

                //download new plugins
                WorkstationLogger.WriteLog("Downloading " + pluginsToChange.Count + " plugins");
                var pluginFiles = ServerConnection.DownloadPlugins(pluginsToChange.ToArray());

                //store new plugins
                Boolean result = true;
                foreach (PluginFile file in pluginFiles)
                {
                    result = result && this.StorePlugin(file);
                }

                //load all available plugins
                this.LoadAvailablePlugins();

                return(this.plugins.ToList());
            }
            else
            {
                return(new List <IPlugin>());
            }
        }
示例#4
0
        private PluginManager()
        {
            this.LoadAvailablePlugins();

            //create directory
            if (!Directory.Exists(pluginPath))
            {
                WorkstationLogger.WriteLog("Creating: " + pluginPath);
                Directory.CreateDirectory(pluginPath);
            }
        }
示例#5
0
        /// <summary>
        /// Method to aquire data with the plugin.
        /// </summary>
        /// <returns>A list containing IndicatorName | IndicatorValue | IndicatorValueDataType.</returns>
        private List <Tuple <string, object, MISD.Core.DataType> > GetValues()
        {
            List <string> indicatorName = new List <String>();

            indicatorName.Add(this.Indicator);
            try
            {
                List <Tuple <string, object, MISD.Core.DataType> > l = this.Plugin.AcquireData(indicatorName);
                WorkstationLogger.WriteLog("Indicator: " + this.Indicator + " Value: " + l.First().Item2.ToString());
                return(l);
            }
            catch (Exception e)
            {
                WorkstationLogger.WriteLog("Couldn't acquire value for: " + this.Indicator + ". Error: " + e.Message);
                ServerConnection.WriteLog(ServerConnection.GetWorkstationName() +
                                          " GetValues(): Couldn't acquire data for " + this.Indicator + " Error Message: " + e.Message, LogType.Exception);
            }
            return(new List <Tuple <string, object, MISD.Core.DataType> >());
        }
示例#6
0
        /// <summary>
        /// The method that gets the new update interval and start the refresh for all timerjobs.
        /// </summary>
        protected override void TimerTickAsync()
        {
            WorkstationLogger.WriteLog("Main update interval expired.");
            // Update its own interval
            TimeSpan oldInterval = this.Interval;

            this.Interval = ServerConnection.GetMainUpdateInterval(oldInterval);

            // Update plugins

            if (PluginManager.Instance.UpdatePlugins().Count > 0)
            {
                // PluginManager.Instance.UpdatePlugins() deletes all timerjobs, so the timerjobs have to be reinitialized
                Scheduler.Instance.RefreshJobs();
                RefreshUpdateIntervals();
            }
            else
            {
                // If no new plugins are loaded, the intervals need to be refreshed
                RefreshUpdateIntervals();
            }
        }
示例#7
0
        /// <summary>
        /// Initializes the scheduler.
        /// </summary>
        protected override void Initialize()
        {
            // Load plugins
            try
            {
                WorkstationLogger.WriteLog("Loading local plugins.");
                PluginManager.Instance.LoadAvailablePlugins();
                WorkstationLogger.WriteLog("Loaded plugins: " + PluginManager.Instance.GetLoadedPlugins().Count);
                WorkstationLogger.WriteLog("Updating plugins from remote computer...");
                PluginManager.Instance.UpdatePlugins();

                // Add the schedulers for all indicators
                foreach (IPlugin p in PluginManager.Instance.GetLoadedPlugins())
                {
                    foreach (IndicatorSettings indicatorSetting in p.GetIndicatorSettings())
                    {
                        WorkstationLogger.WriteLog("Registering " + p.GetName() + "." + indicatorSetting.IndicatorName +
                                                   " at: " + indicatorSetting.UpdateInterval.Ticks / 10000000 + " seconds");
                        TimeSpan updateInterval = new TimeSpan(indicatorSetting.UpdateInterval.Ticks);
                        Jobs.Add(new IndicatorTimerJob(p, indicatorSetting.IndicatorName, updateInterval));
                    }
                }

                // Add the main update scheduler
                Jobs.Add(new MainUpdateTimerJob());

                // Start all timerjobs
                foreach (TimerJobBase job in Jobs)
                {
                    job.Start();
                }
            }
            catch (Exception e)
            {
                WorkstationLogger.WriteLog("Error: " + e.Message);
            }
        }