예제 #1
0
        /// <summary>
        /// Loads data into the data model from a XAML test file.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">Arguments describing the event.</param>
        private static void OnLoadDataCommand(object sender, ExecutedRoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog openDialog = new Microsoft.Win32.OpenFileDialog();
            openDialog.Filter           = "eXtensible Application Markup Language (XAML) files (*.xaml)|*.xaml|All files (*.*)|*.*";
            openDialog.InitialDirectory = Directory.GetCurrentDirectory();
            if (openDialog.ShowDialog() == true)
            {
                ServiceProvider.ViewModel.Locations.Clear();
                ServiceProvider.ViewModel.Devices.Clear();

                TestDataLoader dataLoader = TestDataLoader.Load(openDialog.FileName);

                foreach (var location in dataLoader.Locations)
                {
                    ServiceProvider.ViewModel.Locations.Add(location);
                }

                foreach (var device in dataLoader.Devices)
                {
                    ServiceProvider.ViewModel.Devices.Add(device);
                }

                MessageBox.Show("Data model has been successfully loaded from XAML file");
            }
        }
예제 #2
0
 /// <summary>
 /// Saves the data in the data model to a XAML test data file.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">Arguments describing the event.</param>
 private static void OnSaveDataCommand(object sender, ExecutedRoutedEventArgs e)
 {
     Microsoft.Win32.SaveFileDialog saveDialog = new Microsoft.Win32.SaveFileDialog()
     {
         AddExtension = true, ValidateNames = true
     };
     saveDialog.DefaultExt       = ".xaml";
     saveDialog.Filter           = "eXtensible Application Markup Language (XAML) files (*.xaml)|*.xaml|All files (*.*)|*.*";
     saveDialog.InitialDirectory = Directory.GetCurrentDirectory();
     if (saveDialog.ShowDialog() == true)
     {
         TestDataLoader dataLoader = new TestDataLoader();
         dataLoader.Locations.AddRange(ServiceProvider.ViewModel.Locations);
         dataLoader.Devices.AddRange(ServiceProvider.ViewModel.Devices);
         dataLoader.Save(saveDialog.FileName);
         MessageBox.Show("Data model has been successfully saved to XAML file");
     }
 }