예제 #1
0
        private async void OnWriteFlash()
        {
            if (!ConnectionVm.IsConnected)
            {
                return;
            }

            if (!ValidateConfig())
            {
                return;
            }

            VerifyConfigVersion();

            var res = await ConnectionVm.GetConnection().WriteConfiguration(ConfigVm.GetConfig(), TimeSpan.FromSeconds(5));

            if (!res.Timeout)
            {
                if (res.Result)
                {
                    MessageBox.Show("Configuration Written!", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    MessageBox.Show("Failed to write configuration to flash, try again.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show("Failed to write configuration to flash, timeout occured.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
예제 #2
0
        private void OnSaveConfig()
        {
            if (!ValidateConfig())
            {
                return;
            }

            var dialog = new SaveFileDialog();

            dialog.Filter   = "XML File|*.xml";
            dialog.Title    = "Save Configuration";
            dialog.FileName = "bbsfw.xml";

            var result = dialog.ShowDialog();

            if (result.HasValue && result.Value)
            {
                try
                {
                    ConfigVm.WriteConfiguration(dialog.FileName);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
예제 #3
0
        private bool ValidateConfig()
        {
            try
            {
                ConfigVm.GetConfig().Validate();
                return(true);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Validation Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            return(false);
        }
예제 #4
0
        private async void OnReadFlash()
        {
            if (!ConnectionVm.IsConnected)
            {
                return;
            }

            VerifyConfigVersion();

            var res = await ConnectionVm.GetConnection().ReadConfiguration(TimeSpan.FromSeconds(5));

            if (!res.Timeout && res.Result != null)
            {
                ConfigVm.UpdateFrom(res.Result);
            }
            else
            {
                MessageBox.Show("Failed to read configuration from flash, timeout occured.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
예제 #5
0
        private void OnOpenConfig()
        {
            var dialog = new OpenFileDialog();

            dialog.Filter = "XML File|*.xml";
            dialog.Title  = "Open Configuration";

            var result = dialog.ShowDialog();

            if (result.HasValue && result.Value)
            {
                try
                {
                    ConfigVm.ReadConfiguration(dialog.FileName);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
예제 #6
0
        public static void Save(ConfigVm config)
        {
            var configContent = JsonConvert.SerializeObject(config, Formatting.Indented);

            File.WriteAllText(_configPath, configContent);
        }