Example #1
0
        private void LoadConfigButton_Click(object sender, EventArgs e)
        {
            if (OpenConfigFileDialog.ShowDialog() != DialogResult.OK)
                return;

            LastConfigName = OpenConfigFileDialog.FileName;
            SaveConfigToForm(Configuration.Load(LastConfigName));
        }
        private void LoadButtonClick(object sender, EventArgs e)
        {
            if (DialogResult.OK == OpenConfigFileDialog.ShowDialog())
            {
                _configFilename = OpenConfigFileDialog.FileName;

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

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

                ConfigurationTreeView.Nodes.Clear();
                ConfigurationTreeView.Nodes.Add(TreeNodeMapper.MapTransportAgentConfig(_config));
            }
        }
Example #3
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
                    );
            }
        }