Beispiel #1
0
        private void LoadWinLogger()
        {
            ImageComboBoxItem item;
            XmlSettingsItem   logger = Logger.ModuleManager.GetLibrary(typeof(WinLogger).Name);

            foreach (Logger.LogLevel level in Enum.GetValues(typeof(Logger.LogLevel)))
            {
                item             = new ImageComboBoxItem();
                item.Description = level.ToString();
                item.Value       = level;
                item.ImageIndex  = (int)level;
                cboLogWindowsLevel.Properties.Items.Add(item);

                if (logger != null && level == Logger.StringToLogLevel(logger.GetString(Logger.SETTING_LOG_LEVEL)))
                {
                    cboLogWindowsLevel.SelectedItem = item;
                }
            }

            if (cboLogWindowsLevel.SelectedItem == null)
            {
                cboLogWindowsLevel.SelectedItem = cboLogWindowsLevel.Properties.Items[0];
            }
            else
            {
                txtLogWindowsName.Text   = logger.GetString(WinLogger.SETTING_LOG_NAME);
                txtLogWindowsSource.Text = logger.GetString(WinLogger.SETTING_LOG_SOURCE);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Install new plug-in package into current instance.
        /// </summary>
        /// <param name="package">Plug-in package to install.</param>
        /// <param name="path">Path (with filename) to the assembly file containing the plugin.</param>
        public void Add(IPluginPackage package)
        {
            Logger.LogDebug(this, "[CLASS].Add([{0}])", package);

            if (package == null)
            {
                return;
            }

            try
            {
                XmlSettingsItem xmlPlugin = new XmlSettingsItem();
                xmlPlugin.Key   = package.ID;
                xmlPlugin.Value = package.GetType().Assembly.Location;

                XmlSettingsItem pluginSection = this.GetPluginsSection();
                pluginSection.AddSetting(xmlPlugin);

                OTCContext.Settings.SaveSettings();

                // Add to current instance
                this.InstalledPackages.Add(package);
            }
            catch (Exception ex)
            {
                Logger.LogError(this, ex);
                throw ex;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Sets the theme used to render the switchboard panels.
        /// </summary>
        public DigitalSystem GetSystem()
        {
            XmlSettingsItem item   = null;
            DigitalSystem   system = null;

            Logger.LogDebug(this, "[CLASS].GetSystem()");

            try
            {
                item = this.Settings.GetItem(SystemManager.SETTINGS_SYSTEMS_KEY);
                if (item != null)
                {
                    Assembly assembly = Assembly.LoadFrom(item.GetString(SystemManager.SETTINGS_SYSTEM_PATH));
                    if (assembly == null)
                    {
                        return(null);
                    }

                    Type type = assembly.GetType(item.GetString(SystemManager.SETTINGS_SYSTEM_CLASS));
                    if (type == null)
                    {
                        return(null);
                    }

                    system = (DigitalSystem)Activator.CreateInstance(type);
                }

                return(system);
            }
            catch (Exception ex)
            {
                Logger.LogError(this, ex);
                throw ex;
            }
        }
Beispiel #4
0
        public List <Plugin> GetAll()
        {
            List <Plugin> plugins = new List <Plugin>();

            Logger.LogDebug(this, "[CLASS].GetAll()");

            try
            {
                XmlSettingsItem pluginSection = this.Settings.GetItem(PluginManager.SETTINGS_KEY_PLUGINS);
                if (pluginSection != null)
                {
                    foreach (XmlSettingsItem item in pluginSection.Items.Values)
                    {
                        XmlSettingsItem xmlPlugin = pluginSection.GetItem(item.Key);
                        Plugin          plugin    = new Plugin();
                        plugin.ID   = xmlPlugin.Key;
                        plugin.Name = xmlPlugin.Value;
                        plugin.File = xmlPlugin.GetString("assembly-file");

                        plugins.Add(plugin);
                    }

                    return(plugins);
                }

                return(null);
            }
            catch (Exception ex)
            {
                Logger.LogError(this, ex);

                throw;
            }
        }
Beispiel #5
0
        public Plugin Get(string pluginId)
        {
            Logger.LogDebug(this, "[CLASS].Get('{0}')", pluginId);

            try
            {
                XmlSettingsItem pluginSection = this.Settings.GetItem(PluginManager.SETTINGS_KEY_PLUGINS);
                if (pluginSection != null)
                {
                    XmlSettingsItem xmlPlugin = pluginSection.GetItem(pluginId);
                    Plugin          plugin    = new Plugin();
                    plugin.ID   = xmlPlugin.Key;
                    plugin.Name = xmlPlugin.Value;
                    plugin.File = xmlPlugin.GetString("assembly-file");

                    return(plugin);
                }

                return(null);
            }
            catch (Exception ex)
            {
                Logger.LogError(this, ex);

                throw;
            }
        }
Beispiel #6
0
        /// <summary>
        /// Initialize the instance data.
        /// </summary>
        private void Initialize()
        {
            XmlSettingsItem systems = OTCContext.Settings.GetItem(SystemManager.SETTINGS_SYSTEMS_KEY, true);

            this.SystemSettingsNode = systems.GetItem(this.ID, true);
            this.Status             = SystemStatus.Disconnected;
        }
Beispiel #7
0
        /// <summary>
        /// returns a new instance of <see cref="Plugin"/>.
        /// </summary>
        /// <param name="node">An instance of <see cref="XmlSettingsItem"/> containing all plugin settings.</param>
        public Plugin(XmlSettingsItem node)
        {
            this.ID   = node.Key;
            this.Name = node.Value;

            this.SetAssemblyFile(node.GetString(Plugin.SETTING_KEY_FILE));
        }
Beispiel #8
0
        /// <summary>
        /// Initialize the logger with the settings loaded.
        /// </summary>
        /// <param name="settings">Settings for the corresponding plugin module.</param>
        public void Initialize(XmlSettingsItem settings)
        {
            this.Settings = settings;

            // Get the service name
            string name = this.Settings.GetString(SETTING_LOG_NAME, Application.ProductName);

            // Get the service source
            string source = this.Settings.GetString(SETTING_LOG_SOURCE, string.Empty);

            if (string.IsNullOrEmpty(source))
            {
                source = "RWM";
            }

            try
            {
                // Ensure that the log source exists
                if (!EventLog.SourceExists(source))
                {
                    EventLog.CreateEventSource(source, name);
                }
            }
            catch
            {
                Application.DoEvents();
            }

            // Generate log instance
            this.Log        = new EventLog();
            this.Log.Log    = name;
            this.Log.Source = source;
        }
Beispiel #9
0
        /// <summary>
        /// Load all installed packages.
        /// </summary>
        public void LoadPackages()
        {
            Logger.LogDebug(this, "[CLASS].LoadPackages()");

            try
            {
                this.InstalledPackages = new List <IPluginPackage>();

                XmlSettingsItem pluginSection = this.GetPluginsSection();
                if (pluginSection != null)
                {
                    foreach (XmlSettingsItem item in pluginSection.Items.Values)
                    {
                        string assemblyFile = this.FindAssemblyFile(item.Value);
                        if (assemblyFile != null)
                        {
                            // Find the package descriptor type
                            Assembly assembly = Assembly.LoadFile(assemblyFile);
                            foreach (Type type in assembly.GetExportedTypes())
                            {
                                if (typeof(IPluginPackage).IsAssignableFrom(type) && type.IsClass)
                                {
                                    IPluginPackage package = Activator.CreateInstance(type) as IPluginPackage;
                                    package.LoadModules(type);

                                    this.InstalledPackages.Add(package);

                                    break;
                                }
                            }
                        }
                        else
                        {
                            Logger.LogWarning(this, "Cannot load plug-in package: file not found : {0}", assemblyFile);
                        }
                    }
                }

                // Add the RaiilwayStudio Common Tools plug-in
                foreach (Type type in this.GetType().Assembly.GetExportedTypes())
                {
                    if (typeof(IPluginPackage).IsAssignableFrom(type) && type.IsClass)
                    {
                        IPluginPackage package = Activator.CreateInstance(type) as IPluginPackage;
                        package.LoadModules(type);

                        this.InstalledPackages.Add(package);

                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(this, ex);
                throw ex;
            }
        }
Beispiel #10
0
        private void CmdAccept_Click(object sender, EventArgs e)
        {
            if (cboSkin.SelectedItem == null)
            {
                MessageBox.Show("You must select the visual skin.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                cboSkin.Focus();
                return;
            }

            // Change the current skin
            SkinContainer skin = ((ImageComboBoxItem)cboSkin.SelectedItem).Value as SkinContainer;

            SkinManager.EnableFormSkins();
            DevExpress.LookAndFeel.UserLookAndFeel.Default.Style    = DevExpress.LookAndFeel.LookAndFeelStyle.Skin;
            DevExpress.LookAndFeel.UserLookAndFeel.Default.SkinName = skin.SkinName;

            // General settings
            StudioContext.SkinName        = skin.SkinName;
            StudioContext.OpenLastProject = chkProjectsLoadLast.Checked;

            // LOGs settings
            Logger.LogLevel level = this.GetLoggerLevel(cboLogFileLevel);
            if (level == Logger.LogLevel.Disabled)
            {
                Logger.ModuleManager.RemoveLibrary(typeof(FileLogger).Name);
            }
            else
            {
                XmlSettingsItem library = new XmlSettingsItem(typeof(FileLogger).Name, typeof(FileLogger).FullName);
                library.AddSetting(Logger.SETTING_LOG_LEVEL, level.ToString().ToLower());
                Logger.ModuleManager.AddLibrary(library);
            }

            level = this.GetLoggerLevel(cboLogWindowsLevel);
            if (level == Logger.LogLevel.Disabled)
            {
                Logger.ModuleManager.RemoveLibrary(typeof(WinLogger).Name);
            }
            else
            {
                XmlSettingsItem library = new XmlSettingsItem(typeof(WinLogger).Name, typeof(WinLogger).FullName);
                library.AddSetting(Logger.SETTING_LOG_LEVEL, level.ToString().ToLower());
                library.AddSetting(WinLogger.SETTING_LOG_NAME, txtLogWindowsName.Text);
                library.AddSetting(WinLogger.SETTING_LOG_SOURCE, txtLogWindowsSource.Text);
                Logger.ModuleManager.AddLibrary(library);
            }

            OTCContext.Settings.SaveSettings();

            this.RefreshPluginsBar = this.PluginsControl.PluginsChanged;

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Beispiel #11
0
        private XmlSettingsItem GetPluginsSection()
        {
            XmlSettingsItem section = this.Settings.GetItem(PluginManager.SETTINGS_KEY_PLUGINS);

            if (section == null)
            {
                section     = new XmlSettingsItem();
                section.Key = PluginManager.SETTINGS_KEY_PLUGINS;
            }

            return(section);
        }
Beispiel #12
0
        /// <summary>
        /// Add or update a DLL library.
        /// </summary>
        /// <param name="module">Library to store.</param>
        /// <param name="setAsDefault">If <c>true</c> if the library must set as default library.</param>
        public void AddLibrary(XmlSettingsItem module)
        {
            if (module == null)
            {
                return;
            }

            this.LoggerPlugin.AddSetting(module);

            if (this.AutoStore)
            {
                OTCContext.Settings.SaveSettings();
            }
        }
Beispiel #13
0
        static Logger()
        {
            Assembly assembly;
            ILogger  logger;

            Logger.Loggers = new List <ILogger>();

            try
            {
                // Load modules from settings
                Logger.ModuleManager = new LoggerSettingsManager(); // OTCContext.Settings);

                // If no loggers are appended, a FileLogger with ERROR level will be appended to ensure LOG all application exceptions
                if (Logger.ModuleManager.LoggerModules.Count <= 0)
                {
                    XmlSettingsItem module = new XmlSettingsItem("FileLogger", typeof(FileLogger).FullName);
                    module.AddSetting(Logger.SETTING_LOG_LEVEL, LogLevel.Error.ToString());
                    Logger.ModuleManager.LoggerModules.Add(module);
                }

                // Generate the logger instances
                foreach (XmlSettingsItem module in Logger.ModuleManager.LoggerModules)
                {
                    assembly = Assembly.GetExecutingAssembly();
                    logger   = (ILogger)assembly.CreateInstance(module.Value);

                    if (logger != null)
                    {
                        logger.Initialize(module);

                        Logger.Loggers.Add(logger);
                    }
                }

                // To minimize the memory usage
                assembly = null;
                logger   = null;
            }
            catch
            {
                // Empty settings
            }
        }
Beispiel #14
0
        public void Remove(string key)
        {
            Logger.LogDebug(this, "[CLASS].Remove('{0}')", key);

            try
            {
                XmlSettingsItem pluginSection = this.Settings.GetItem(PluginManager.SETTINGS_KEY_PLUGINS);
                if (pluginSection != null)
                {
                    pluginSection.Remove(key);
                    this.Settings.SaveSettings();
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(this, ex);

                throw;
            }
        }
Beispiel #15
0
        /// <summary>
        /// Remove the specified plug-in package from the settings and also unload the package from the current application instance.
        /// </summary>
        /// <param name="packageId">Plug-in package unique identifier.</param>
        public void Remove(string packageId)
        {
            Logger.LogDebug(this, "[CLASS].Remove('{0}')", packageId);

            try
            {
                // Remove from the settings
                XmlSettingsItem pluginSection = this.GetPluginsSection();
                pluginSection.Remove(packageId);
                OTCContext.Settings.SaveSettings();

                // Remove from current instance
                this.InstalledPackages.Remove(this.GetPluguinPackage(packageId));
            }
            catch (Exception ex)
            {
                Logger.LogError(this, ex);
                throw ex;
            }
        }
Beispiel #16
0
        /// <summary>
        /// Sets the theme used to render the switchboard panels.
        /// </summary>
        public void SetTheme(Type type)
        {
            Logger.LogDebug(this, "[CLASS].SetTheme([{0}])", type.FullName);

            try
            {
                XmlSettingsItem item = new XmlSettingsItem(ThemeManager.SETTINGS_THEMES_KEY, string.Empty);
                item.AddSetting(ThemeManager.SETTINGS_THEME_PATH, ReflectionUtils.GetAssemblyFile(type));
                item.AddSetting(ThemeManager.SETTINGS_THEME_CLASS, type.FullName);

                this.Settings.AddSetting(item);
                this.Settings.SaveSettings();
            }
            catch (Exception ex)
            {
                Logger.LogError(this, ex);

                throw;
            }
        }
Beispiel #17
0
        /// <summary>
        /// Sets the theme used to render the switchboard panels.
        /// </summary>
        public void SetSystem(Type type)
        {
            Logger.LogDebug(this, "[CLASS].SetSystem([{0}])", type.FullName);

            try
            {
                XmlSettingsItem item = new XmlSettingsItem(SystemManager.SETTINGS_SYSTEMS_KEY, string.Empty);
                item.AddSetting(SystemManager.SETTINGS_SYSTEM_PATH, ReflectionUtils.GetAssemblyFile(type));
                item.AddSetting(SystemManager.SETTINGS_SYSTEM_CLASS, type.FullName);

                this.Settings.AddSetting(item);
                this.Settings.SaveSettings();

                // Force ti reload the digital system according to the selection
                OTCContext.Project.LoadSystem();
            }
            catch (Exception ex)
            {
                Logger.LogError(this, ex);
                throw ex;
            }
        }
Beispiel #18
0
        public DataTable GetAllAsDataTable()
        {
            Logger.LogDebug(this, "[CLASS].GetAllAsDataTable()");

            try
            {
                DataRow row;

                DataTable dt = new DataTable();
                dt.TableName = "Plugins";
                dt.Columns.Add("ID", typeof(string));
                dt.Columns.Add("Name", typeof(string));
                dt.Columns.Add("File", typeof(string));
                dt.Columns.Add("Driver", typeof(string));

                XmlSettingsItem pluginSection = this.Settings.GetItem(PluginManager.SETTINGS_KEY_PLUGINS);
                if (pluginSection != null)
                {
                    foreach (XmlSettingsItem xmlPlugin in pluginSection.Items.Values)
                    {
                        row           = dt.NewRow();
                        row["ID"]     = xmlPlugin.Key;
                        row["Name"]   = xmlPlugin.Value;
                        row["File"]   = xmlPlugin.GetString("assembly-file");
                        row["Driver"] = xmlPlugin.GetString("class");
                        dt.Rows.Add(row);
                    }
                }

                return(dt);
            }
            catch (Exception ex)
            {
                Logger.LogError(this, ex);

                throw;
            }
        }
Beispiel #19
0
        /// <summary>
        /// Sets the theme used to render the switchboard panels.
        /// </summary>
        public ITheme GetTheme()
        {
            XmlSettingsItem item  = null;
            ITheme          theme = null;

            Logger.LogDebug(this, "[CLASS].GetTheme()");

            try
            {
                if (this.Themes == null || this.Themes.Count <= 0)
                {
                    this.GetAll();
                }

                item = this.Settings.GetItem(ThemeManager.SETTINGS_THEMES_KEY);
                if (item != null && !string.IsNullOrWhiteSpace(item.Value))
                {
                    Assembly assembly = Assembly.LoadFrom(item.GetString(ThemeManager.SETTINGS_THEME_PATH));
                    Type     type     = assembly.GetType(item.GetString(ThemeManager.SETTINGS_THEME_CLASS));

                    theme = (ITheme)Activator.CreateInstance(type);
                }

                if (theme == null && this.Themes.Count > 0)
                {
                    theme = this.Themes[0];
                }

                return(theme);
            }
            catch (Exception ex)
            {
                Logger.LogError(this, ex);

                throw;
            }
        }
Beispiel #20
0
        public void Add(Plugin plugin)
        {
            Logger.LogDebug(this, "[CLASS].Add([{0}])", plugin);

            try
            {
                XmlSettingsItem xmlPlugin = new XmlSettingsItem();
                xmlPlugin.Key   = plugin.ID;
                xmlPlugin.Value = plugin.Name;
                xmlPlugin.AddSetting("assembly-file", plugin.File);

                XmlSettingsItem pluginSection = GetPluginsSection();
                pluginSection.AddSetting(xmlPlugin);

                this.Settings.AddSetting(pluginSection);
                this.Settings.SaveSettings();
            }
            catch (Exception ex)
            {
                Logger.LogError(this, ex);

                throw;
            }
        }
Beispiel #21
0
 /// <summary>
 /// Remove a DLL library.
 /// </summary>
 /// <param name="library">Library to remove.</param>
 public void RemoveLibrary(XmlSettingsItem library)
 {
     this.RemoveLibrary(ConvertNameToID(library.Value));
 }
Beispiel #22
0
 public void Initialize(XmlSettingsItem settings)
 {
     this.Settings = settings;
 }