public void LoadEditData()
        {
            if (SelectedEntry == null)
            {
                SelectedEntry = new SqlDatabaseNotifierConfig();
            }
            SqlDatabaseNotifierConfig currentConfig = (SqlDatabaseNotifierConfig)SelectedEntry;

            txtServer.Text           = currentConfig.SqlServer;
            txtDatabase.Text         = currentConfig.Database;
            chkIntegratedSec.Checked = currentConfig.IntegratedSec;
            txtUserName.Text         = currentConfig.UserName;
            txtPassword.Text         = currentConfig.Password;
            numericUpDownCmndTimeOut.SaveValueSet(currentConfig.CmndTimeOut);
            chkUseSP.Checked               = currentConfig.UseSP;
            txtCmndValue.Text              = currentConfig.CmndValue;
            txtAlertFieldName.Text         = currentConfig.AlertFieldName;
            txtCollectorFieldName.Text     = currentConfig.CollectorFieldName;
            txtPreviousStateFieldName.Text = currentConfig.PreviousStateFieldName;
            txtCurrentStateFieldName.Text  = currentConfig.CurrentStateFieldName;
            txtDetailsFieldName.Text       = currentConfig.DetailsFieldName;
            chkUseSP2.Checked              = currentConfig.UseSPForViewer;
            txtViewerName.Text             = currentConfig.ViewerName;
            txtDateTimeFieldName.Text      = currentConfig.DateTimeFieldName;
        }
        private void cmdOK_Click(object sender, EventArgs e)
        {
            if (SelectedEntry == null)
            {
                SelectedEntry = new SqlDatabaseNotifierConfig();
            }
            SqlDatabaseNotifierConfig currentConfig = (SqlDatabaseNotifierConfig)SelectedEntry;

            currentConfig.SqlServer              = txtServer.Text;
            currentConfig.Database               = txtDatabase.Text;
            currentConfig.IntegratedSec          = chkIntegratedSec.Checked;
            currentConfig.UserName               = txtUserName.Text;
            currentConfig.Password               = txtPassword.Text;
            currentConfig.CmndTimeOut            = (int)numericUpDownCmndTimeOut.Value;
            currentConfig.UseSP                  = chkUseSP.Checked;
            currentConfig.CmndValue              = txtCmndValue.Text;
            currentConfig.AlertFieldName         = txtAlertFieldName.Text;
            currentConfig.CollectorFieldName     = txtCollectorFieldName.Text;
            currentConfig.PreviousStateFieldName = txtPreviousStateFieldName.Text;
            currentConfig.CurrentStateFieldName  = txtCurrentStateFieldName.Text;
            currentConfig.DetailsFieldName       = txtDetailsFieldName.Text;
            currentConfig.UseSPForViewer         = chkUseSP2.Checked;
            currentConfig.ViewerName             = txtViewerName.Text;
            currentConfig.DateTimeFieldName      = txtDateTimeFieldName.Text;

            DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }
Example #3
0
        private void cmdOK_Click(object sender, EventArgs e)
        {
            if (txtMachine.Text.Trim().Length == 0)
            {
                MessageBox.Show("You must specify the computer name!", "Computer", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txtMachine.Focus();
            }
            else if (txtEventSource.Text.Trim().Length == 0)
            {
                MessageBox.Show("You must specify the event source!", "Event source", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txtEventSource.Focus();
            }
            else
            {
                EventLogNotifierConfig selectedEntry;
                if (SelectedEntry == null)
                {
                    SelectedEntry = new EventLogNotifierConfig();
                }
                selectedEntry = (EventLogNotifierConfig)SelectedEntry;

                selectedEntry.MachineName    = txtMachine.Text;
                selectedEntry.EventLogName   = txtEventLogName.Text;
                selectedEntry.EventSource    = txtEventSource.Text;
                selectedEntry.SuccessEventID = (int)successEventIDNumericUpDown.Value;
                selectedEntry.WarningEventID = (int)warningEventIDNumericUpDown.Value;
                selectedEntry.ErrorEventID   = (int)errorEventIDNumericUpDown.Value;
                DialogResult = System.Windows.Forms.DialogResult.OK;
                Close();
            }
        }
Example #4
0
        /// <summary>
        /// Adds a handler to the given agent configs list of events.
        /// </summary>
        /// <param name="agentConfig">Agent config instance on which the property (<see cref="eventPropertyInfo"/>) is declared.</param>
        /// <param name="eventPropertyInfo">PropertyInfo to get the list from the agent config.</param>
        /// <param name="handler">The actual handler instance to add.</param>
        public static void AddHandler([NotNull] this IAgentConfig agentConfig, [NotNull] PropertyInfo eventPropertyInfo,
                                      [NotNull] IHandler handler)
        {
            // now try to insert the handler into our collection
            // this needs to be done via reflection as users may use their own handlers
            var list = (IList)eventPropertyInfo.GetValue(agentConfig, new object[0]);
            // use .Insert instead of .Add to support IList
            var insertMethod = list.GetType().GetMethods().Single(x => x.Name == nameof(IList <IHandler> .Insert));

            insertMethod.Invoke(list, new object[] { list.Count, handler });
        }
Example #5
0
        private void cmdOK_Click(object sender, EventArgs e)
        {
            if (SelectedEntry == null)
            {
                SelectedEntry = new InMemoryNotifierConfig();
            }
            ((InMemoryNotifierConfig)SelectedEntry).MaxEntryCount = (int)maxCountNumericUpDown.Value;

            DialogResult = DialogResult.OK;
            Close();
        }
Example #6
0
        /// <summary>
        /// Replaces handler with a new one in the given event delegate.
        /// </summary>
        /// <param name="agentConfig">Agent on which the event list should exist.</param>
        /// <param name="eventPropertyInfo">Property info to the event list on the agent config.</param>
        /// <param name="oldHandler">Old handler to remove.</param>
        /// <param name="newHandler">New handler to add.</param>
        /// <returns>Whether the old could be removed (and the new could be added).</returns>
        public static bool ReplaceHandler([NotNull] this IAgentConfig agentConfig,
                                          [NotNull] PropertyInfo eventPropertyInfo,
                                          [NotNull] IHandler oldHandler, [NotNull] IHandler newHandler)
        {
            var result = agentConfig.RemoveHandler(eventPropertyInfo, oldHandler.GetType());

            if (result)
            {
                agentConfig.AddHandler(eventPropertyInfo, newHandler);
            }

            return(result);
        }
        public void LoadConfig(bool server)
        {
            IAgentConfig config = server ?
                                  (IAgentConfig)RawAgentConfig.Load() :
                                  (IAgentConfig)GetInstance <ClientAgentConfig>();

            OverseerAddress = config?.OverseerAddress ?? DEFAULT_OVERSEER_ADDRESS;
            OverseerTCPPort = (ushort)(config?.OverseerTCPPort ?? DEFAULT_OVERSEER_TCP_PORT);
            OverseerUDPPort = (ushort)(config?.OverseerUDPPort ?? DEFAULT_OVERSEER_UDP_PORT);

            if (config is null)
            {
                Logger.Info("Config not loaded! Using defaults.");
            }
        }
        public Entry(IAgentConfig agentConfig, string eventName, IHandler handler)
        {
            AgentConfig = agentConfig;
            EventName   = eventName;

            // don't use handler directly - use shallow copy instead to check whether it changed after editing in GUI
            var handlerType = handler.GetType();

            Handler = (IHandler)Activator.CreateInstance(handlerType);
            var props = handlerType.GetProperties().Where(x => x.CanWrite);

            foreach (var propertyInfo in props)
            {
                var parameters = propertyInfo.GetValue(handler, new object[0]);
                propertyInfo.SetValue(Handler, parameters, new object[0]);
            }
        }
Example #9
0
        public static IHandler GetHandler([NotNull] this IAgentConfig agentConfig, [CanBeNull] string eventName,
                                          [CanBeNull] string handlerName)
        {
            if (eventName == null || handlerName == null)
            {
                return(null);
            }

            var prop = agentConfig.GetType().GetProperty(eventName);

            if (prop == null)
            {
                return(null);
            }

            return(agentConfig.GetHandlers(prop).SingleOrDefault(x => x.GetType().Name == handlerName));
        }
Example #10
0
        private void cmdOK_Click(object sender, EventArgs e)
        {
            LogFileNotifierConfig currentConfig;

            if (SelectedEntry == null)
            {
                SelectedEntry = new LogFileNotifierConfig();
            }
            currentConfig = (LogFileNotifierConfig)SelectedEntry;

            if (currentConfig != null)
            {
                currentConfig.OutputPath          = txtLogFilePath.Text;
                currentConfig.CreateNewFileSizeKB = (long)numericUpDownCreateNewFileSizeKB.Value;
                DialogResult = DialogResult.OK;
                Close();
            }
        }
Example #11
0
        private void cmdQuickConfig_Click(object sender, EventArgs e)
        {
            switch (cboQuickConfig.SelectedIndex)
            {
            case 0:
                if (SelectedConfig != null)
                {
                    PerfCounterCollectorConfig currentConfig = (PerfCounterCollectorConfig)SelectedConfig;
                    if (currentConfig.Entries != null && currentConfig.Entries.Count > 0 && MessageBox.Show("Do you want to replace any existing config?", "Config", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No)
                    {
                        break;
                    }
                }
                SelectedConfig = new PerfCounterCollectorConfig();
                SelectedConfig.ReadConfiguration(Properties.Resources.PerfCounterCollectorQuickConfig1);
                LoadEntries();
                break;

            case 1:
                if (SelectedConfig != null)
                {
                    PerfCounterCollectorConfig currentConfig = (PerfCounterCollectorConfig)SelectedConfig;
                    if (currentConfig.Entries != null && currentConfig.Entries.Count > 0 && MessageBox.Show("Do you want to replace any existing config?", "Config", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No)
                    {
                        break;
                    }
                }
                SelectedConfig = new PerfCounterCollectorConfig();
                string customConfigString = Properties.Resources.PerfCounterCollectorQuickConfig2;
                string machineName        = QuickMon.Forms.InputBox.Show("Specify computer name", "Computer", "");
                if (machineName.Length > 0)
                {
                    customConfigString = customConfigString.Replace("[machineName]", machineName);
                    SelectedConfig.ReadConfiguration(customConfigString);
                    LoadEntries();
                }
                break;

            default:
                break;
            }
        }
Example #12
0
        private void cmdOK_Click(object sender, EventArgs e)
        {
            LogFileNotifierConfig currentConfig;

            if (SelectedEntry == null)
            {
                SelectedEntry = new LogFileNotifierConfig();
            }
            currentConfig = (LogFileNotifierConfig)SelectedEntry;

            if (currentConfig != null)
            {
                currentConfig.OutputPath          = txtLogFilePath.Text;
                currentConfig.CreateNewFileSizeKB = (long)numericUpDownCreateNewFileSizeKB.Value;
                currentConfig.AppendDate          = chkAppendDate.Checked;
                currentConfig.UseLocalTimeFormat  = chkUseLocalTimeFormat.Checked;
                currentConfig.CustomTimeFormat    = txtCustomTimeFormat.Text;
                DialogResult = DialogResult.OK;
                Close();
            }
        }
Example #13
0
        public static bool HasHandler(this IAgentConfig agentConfig, PropertyInfo eventPropertyInfo,
                                      [NotNull] Type handlerType)
        {
            // if no eventProperty exists the handler does not exist yet (probably).
            if (agentConfig == null || eventPropertyInfo == null)
            {
                return(false);
            }


            var list = (IList)eventPropertyInfo.GetValue(agentConfig, new object[0]);

            // get LINQ .Any method and make it generic
            var anyMethod = typeof(Enumerable).GetMethods()
                            .Single(x => x.Name == nameof(Enumerable.Any) && x.GetParameters().Length == 2);

            anyMethod = anyMethod.MakeGenericMethod(typeof(IHandler));

            // run something like list.Any(x => x.GetType() == handler.GetType()) to check whether the type has been added yet.
            return((bool)anyMethod.Invoke(null,
                                          new object[] { list, new Func <IHandler, bool>(x => x.GetType() == handlerType) }));
        }
Example #14
0
        public static IEnumerable <IHandler> GetHandlers([NotNull] this IAgentConfig agentConfig,
                                                         [NotNull] PropertyInfo propertyInfo)
        {
            if (agentConfig == null)
            {
                throw new ArgumentNullException(nameof(agentConfig));
            }
            if (propertyInfo == null)
            {
                throw new ArgumentNullException(nameof(propertyInfo));
            }

            if (!agentConfig.GetType().IsAssignableFrom(propertyInfo.DeclaringType))
            {
                throw new ArgumentException("PropertyInfo is not declared on the type of agent config.",
                                            nameof(propertyInfo));
            }

            var list = (IList)propertyInfo.GetValue(agentConfig, new object[0]);

            return(list.Cast <IHandler>());
        }
Example #15
0
        private void LoadEditData()
        {
            RSSNotifierConfig rssSettings;

            if (SelectedEntry == null)
            {
                SelectedEntry = new RSSNotifierConfig();
            }
            rssSettings = (RSSNotifierConfig)SelectedEntry;

            txtRSSFilePath.Text             = rssSettings.RSSFilePath;
            txtTitle.Text                   = rssSettings.Title;
            txtLink.Text                    = rssSettings.Link;
            txtLanguage.Text                = rssSettings.Language;
            txtGenerator.Text               = rssSettings.Generator;
            txtDescription.Text             = rssSettings.Description;
            keepDataDaysNumericUpDown.Value = rssSettings.KeepEntriesDays;
            txtLineTitle.Text               = rssSettings.LineTitle;
            txtLineCategory.Text            = rssSettings.LineCategory;
            txtLineDescription.Text         = rssSettings.LineDescription;
            txtLineLink.Text                = rssSettings.LineLink;
        }
Example #16
0
        private void LoadEditData()
        {
            SMTPNotifierConfig mailSettings;

            if (SelectedEntry == null)
            {
                SelectedEntry = new SMTPNotifierConfig();
            }
            mailSettings = (SMTPNotifierConfig)SelectedEntry;

            txtSMTPServer.Text = mailSettings.HostServer;
            chkUseDefaultCredentials.Checked = mailSettings.UseDefaultCredentials;
            txtDomain.Text                  = mailSettings.Domain;
            txtUserName.Text                = mailSettings.UserName;
            txtPassword.Text                = mailSettings.Password;
            txtFromAddress.Text             = mailSettings.FromAddress;
            txtToAddress.Text               = mailSettings.ToAddress;
            chkSplitToAddressOnSend.Checked = mailSettings.SplitToAddressOnSend;
            txtSender.Text                  = mailSettings.SenderAddress;
            txtReplyToAddress.Text          = mailSettings.ReplyToAddress;
            if (mailSettings.MailPriority == 1)
            {
                optPriorityLow.Checked = true;
            }
            else if (mailSettings.MailPriority == 2)
            {
                optPriorityHigh.Checked = true;
            }
            else
            {
                optPriorityNormal.Checked = true;
            }
            txtSubject.Text         = mailSettings.Subject;
            chkIsBodyHtml.Checked   = mailSettings.IsBodyHtml;
            txtBody.Text            = mailSettings.Body;
            chkTLS.Checked          = mailSettings.UseTLS;
            portNumericUpDown.Value = mailSettings.Port;
        }
Example #17
0
        /// <summary>
        /// Removes a handler from the given event in the given agent.
        /// </summary>
        /// <param name="agentConfig">Agent config on which the event property must be declared</param>
        /// <param name="eventPropertyInfo">Property info of the list where the handler shall exist.</param>
        /// <param name="handlerType">The type of the handler to remove. Should be unique</param>
        /// <returns>Whether the item could be removed (not found).</returns>
        /// <exception cref="InvalidOperationException">If more than one type given <see cref="handlerType"/> exist in the list. Usually should never happen.</exception>
        public static bool RemoveHandler([NotNull] this IAgentConfig agentConfig,
                                         [NotNull] PropertyInfo eventPropertyInfo,
                                         [NotNull] Type handlerType)
        {
            if (agentConfig == null)
            {
                throw new ArgumentNullException(nameof(agentConfig));
            }
            if (eventPropertyInfo == null)
            {
                throw new ArgumentNullException(nameof(eventPropertyInfo));
            }
            if (handlerType == null)
            {
                throw new ArgumentNullException(nameof(handlerType));
            }

            var      list         = (IList)eventPropertyInfo.GetValue(agentConfig, new object[0]);
            var      removeMethod = list.GetType().GetMethods().Single(x => x.Name == nameof(IList <IHandler> .Remove));
            IHandler handler      = null;

            foreach (var obj in list)
            {
                if (obj.GetType() == handlerType)
                {
                    handler = (IHandler)obj;
                }
            }

            if (handler == null)
            {
                return(false);
            }

            return((bool)removeMethod.Invoke(list, new object[] { handler }));
        }
Example #18
0
        private void cmdOK_Click(object sender, EventArgs e)
        {
            try
            {
                AudioNotifierConfig currentConfig;
                if (SelectedEntry == null)
                {
                    SelectedEntry = new AudioNotifierConfig();
                }
                currentConfig = (AudioNotifierConfig)SelectedEntry;

                if (chkGoodEnabled.Checked)
                {
                    if (chkGoodUseSystemSounds.Checked && cboGoodSystemSound.SelectedIndex < 0)
                    {
                        MessageBox.Show("You must specify a good system sound!");
                        cboGoodSystemSound.Focus();
                        return;
                    }
                    else if (!chkGoodUseSystemSounds.Checked && txtGoodAudioFilePath.Text.Trim().Length == 0)
                    {
                        MessageBox.Show("You must specify a good sound!");
                        txtGoodAudioFilePath.Focus();
                        return;
                    }
                }
                if (chkWarningEnabled.Checked)
                {
                    if (chkWarningUseSystemSounds.Checked && cboWarningSystemSound.SelectedIndex < 0)
                    {
                        MessageBox.Show("You must specify a warning system sound!");
                        cboWarningSystemSound.Focus();
                        return;
                    }
                    else if (!chkWarningUseSystemSounds.Checked && txtWarningAudioFilePath.Text.Trim().Length == 0)
                    {
                        MessageBox.Show("You must specify a warning sound!");
                        txtWarningAudioFilePath.Focus();
                        return;
                    }
                }
                if (chkErrorEnabled.Checked)
                {
                    if (chkErrorUseSystemSounds.Checked && cboErrorSystemSound.SelectedIndex < 0)
                    {
                        MessageBox.Show("You must specify an error system sound!");
                        cboErrorSystemSound.Focus();
                        return;
                    }
                    else if (!chkErrorUseSystemSounds.Checked && txtErrorAudioFilePath.Text.Trim().Length == 0)
                    {
                        MessageBox.Show("You must specify an error sound!");
                        txtErrorAudioFilePath.Focus();
                        return;
                    }
                }

                currentConfig.GoodSoundSettings.Enabled          = chkGoodEnabled.Checked;
                currentConfig.GoodSoundSettings.UseSystemSounds  = chkGoodUseSystemSounds.Checked;
                currentConfig.GoodSoundSettings.AudioFilePath    = txtGoodAudioFilePath.Text;
                currentConfig.GoodSoundSettings.SystemSound      = (SystemSounds)cboGoodSystemSound.SelectedIndex;
                currentConfig.GoodSoundSettings.SoundRepeatCount = (int)goodRepeatCountNumericUpDown.Value;
                currentConfig.GoodSoundSettings.SoundVolumePerc  = goodVolumePercTrackBar.Value;

                currentConfig.WarningSoundSettings.Enabled          = chkWarningEnabled.Checked;
                currentConfig.WarningSoundSettings.UseSystemSounds  = chkWarningUseSystemSounds.Checked;
                currentConfig.WarningSoundSettings.AudioFilePath    = txtWarningAudioFilePath.Text;
                currentConfig.WarningSoundSettings.SystemSound      = (SystemSounds)cboWarningSystemSound.SelectedIndex;
                currentConfig.WarningSoundSettings.SoundRepeatCount = (int)warningRepeatCountNumericUpDown.Value;
                currentConfig.WarningSoundSettings.SoundVolumePerc  = warningVolumePercTrackBar.Value;

                currentConfig.ErrorSoundSettings.Enabled          = chkErrorEnabled.Checked;
                currentConfig.ErrorSoundSettings.UseSystemSounds  = chkErrorUseSystemSounds.Checked;
                currentConfig.ErrorSoundSettings.AudioFilePath    = txtErrorAudioFilePath.Text;
                currentConfig.ErrorSoundSettings.SystemSound      = (SystemSounds)cboErrorSystemSound.SelectedIndex;
                currentConfig.ErrorSoundSettings.SoundRepeatCount = (int)errorRepeatCountNumericUpDown.Value;
                currentConfig.ErrorSoundSettings.SoundVolumePerc  = errorVolumePercTrackBar.Value;

                DialogResult = System.Windows.Forms.DialogResult.OK;
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #19
0
        /// <summary>
        /// Adds an entry to the tree view. Also adds it to the internal collection.
        /// </summary>
        /// <param name="eventProperty">Identifier for the event. Using the <see cref="PropertyInfo" /> we can review the type on which it's declared and the given property name for the event name.</param>
        /// <param name="handler">The actual handler for this tree node.</param>
        /// <exception cref="ArgumentException">When a handler already exist for the given event.</exception>
        public void AddEntry([NotNull] PropertyInfo eventProperty, [NotNull] IHandler handler)
        {
            Debug.Assert(eventProperty.DeclaringType != null, "Declaring type must never be null");
            Debug.Assert(eventProperty.IsValidHandlerPropertyType(),
                         $"Parameter {nameof(eventProperty)} must be of type IList<IAgentConfig>.");

            IAgentConfig agentConfig = null;
            TreeNode     groupNode   = null;
            TreeNode     eventNode   = null;
            TreeNode     handlerNode = null;

            // do group search / create
            // TODO Replace is dirty
            var groupName = eventProperty.DeclaringType.Name.Replace("AgentConfig", "");

            foreach (TreeNode node in treeViewEntries.Nodes)
            {
                if (node.Name == groupName)
                {
                    groupNode   = node;
                    agentConfig = _agentConfigs.Single(x => x.GetType() == eventProperty.DeclaringType);
                    break;
                }
            }

            if (groupNode == null)
            {
                groupNode = new TreeNode(groupName)
                {
                    Name = groupName
                };
                treeViewEntries.Nodes.Add(groupNode);
                agentConfig = _agentConfigs.SingleOrDefault(x => x.GetType() == eventProperty.DeclaringType);
                if (agentConfig == null)
                {
                    agentConfig = (IAgentConfig)Activator.CreateInstance(eventProperty.DeclaringType);
                    _agentConfigs.Add(agentConfig);
                }
            }

            // do event search / create
            var eventName = eventProperty.Name;

            if (groupNode.Nodes.Count > 0)
            {
                foreach (TreeNode node in groupNode.Nodes)
                {
                    if (node.Name == eventName)
                    {
                        eventNode = node;
                        break;
                    }
                }
            }

            if (eventNode == null)
            {
                eventNode = new TreeNode(eventName)
                {
                    Name = eventName
                };

                groupNode.Nodes.Add(eventNode);
            }


            // do handler search / create
            if (groupNode.Nodes.Count > 0)
            {
                foreach (TreeNode subNode in eventNode.Nodes)
                {
                    if (subNode.Name == handler.Name)
                    {
                        // as for now the GUI limits the usage of multiple handlers of the same type for an event.
                        throw new ArgumentException(
                                  $"Handler {handler.Name} is not allowed here. It's already been added.");
                    }
                }
            }

            // add new handler node if the type does not exist already
            handlerNode = new TreeNode(handler.GetType().Name)
            {
                Name = handler.GetType().Name
            };
            eventNode.Nodes.Add(handlerNode);

            agentConfig.AddHandler(eventProperty, handler);

            saveToolStripMenuItem.Enabled   = true;
            saveAsToolStripMenuItem.Enabled = true;
        }
Example #20
0
        private void LoadButtonClick(object sender, EventArgs e)
        {
            if (DialogResult.OK != OpenConfigFileDialog.ShowDialog())
            {
                return;
            }

            _configFilename = OpenConfigFileDialog.FileName;

            var serializer = new DataContractSerializer(typeof(TransportAgentConfig), _knownTypes);
            var settings   = new XmlReaderSettings {
                ConformanceLevel = ConformanceLevel.Auto,
            };

            try
            {
                using (var reader = XmlReader.Create(_configFilename, settings))
                {
                    _config = (TransportAgentConfig)serializer.ReadObject(reader, true);
                }

                // TODO make list flat
                treeViewEntries.Nodes.Clear();
                var agents = new IAgentConfig[]
                { _config.RoutingAgentConfig, _config.DeliveryAgentConfig, _config.SmtpReceiveAgentConfig }
                .Where(x => x != null);
                foreach (var agent in agents)
                {
                    var props = agent.GetType().GetProperties();
                    foreach (var prop in props)
                    {
                        var handlers = agent.GetHandlers(prop);
                        foreach (var handler in handlers)
                        {
                            var andAllSubHandlers = handler.GetAndAllSubHandlers();
                            foreach (var andAllSubHandler in andAllSubHandlers)
                            {
                                AddEntry(prop, andAllSubHandler);
                            }
                        }
                    }
                }
            } // TODO Logger
            catch (SerializationException ex)
            {
                Console.WriteLine(ex.Message);
                MessageBox.Show(
                    null,
                    "The file seems to be corrupt or invalid.",
                    "The file could not be read.",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error,
                    MessageBoxDefaultButton.Button1,
                    MessageBoxOptions.DefaultDesktopOnly
                    );
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
                MessageBox.Show(
                    null,
                    "The file has duplicate handlers for some events. Please fix this manually.",
                    "The file could not be read.",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error,
                    MessageBoxDefaultButton.Button1,
                    MessageBoxOptions.DefaultDesktopOnly
                    );
            }
        }