Beispiel #1
0
		//TODO: commands to delete pumps or reactors
			
        #endregion


        public Inventory()
        {
            Current = this;
            ImportPumpCommand = new RelayCommand(delegate
            {
                OpenFileDialog ofd = new OpenFileDialog() { Filter = "Pump Calibration Files|*.pump" };
                DialogResult result = ofd.ShowDialog();
                if (result == DialogResult.OK)
                {
                    FileInfo fi = new FileInfo(ofd.FileName);
                    try
                    {
                        File.Copy(ofd.FileName, Path.Combine(pumpDirectory, fi.Name));
                    }
                    catch (Exception ex)
                    {
                        Task mb = CustomMessageBox.ShowAsync("Can't import", "There was an error:\r\n\r\n" + ex.Message, System.Windows.MessageBoxImage.Error, 0, "Ok");
                    }
                }
            });
            ImportSensorCommand = new RelayCommand(delegate
            {
                OpenFileDialog ofd = new OpenFileDialog() { Filter = "Sensor Calibration Files|*.biomass;*.sensor" };
                DialogResult result = ofd.ShowDialog();
                if (result == DialogResult.OK)
                {
                    FileInfo fi = new FileInfo(ofd.FileName);
                    try
                    {
                        File.Copy(ofd.FileName, Path.Combine(sensorDirectory, fi.Name));
                    }
                    catch (Exception ex)
                    {
                        Task mb = CustomMessageBox.ShowAsync("Can't import", "There was an error:\r\n\r\n" + ex.Message, System.Windows.MessageBoxImage.Error, 0, "Ok");
                    }
                }
            });
            AddReactorCommand = new RelayCommand(async delegate
            {
                ReactorInformation newReactor = new ReactorInformation();
                ReactorInformationWindow piw = new ReactorInformationWindow("Add New Reactor", true, Pumps.Values, BiomassSensors.Values, GasSensors.Values) { DataContext = newReactor };
                piw.Show();
                await piw.WaitTask;
                if (piw.Confirmed)
                {
                    newReactor.SaveTo(reactorDirectory);
                }
            });
            ImportReactorCommand = new RelayCommand(delegate
            {
                OpenFileDialog ofd = new OpenFileDialog() { Filter = "Reactor Files|*.reactor" };
                DialogResult result = ofd.ShowDialog();
                if (result == DialogResult.OK)
                {
                    FileInfo fi = new FileInfo(ofd.FileName);
                    try
                    {
                        File.Copy(ofd.FileName, Path.Combine(reactorDirectory, fi.Name));
                    }
                    catch (Exception ex)
                    {
                        Task mb = CustomMessageBox.ShowAsync("Can't import", "There was an error:\r\n\r\n" + ex.Message, System.Windows.MessageBoxImage.Error, 0, "Ok");
                    }
                }
            });
        }
Beispiel #2
0
 private void ScanReactorDirectory()
 {
     Dictionary<ParticipantID, ReactorInformation> newReactors = new Dictionary<ParticipantID, ReactorInformation>();
     foreach (string file in Directory.EnumerateFiles(reactorDirectory, "*.reactor"))
     {
         ReactorInformation reactor = ReactorInformation.LoadFromFile(file);
         if (reactor != null)
         {
             reactor.EditReactorCommand = new RelayCommand(async delegate
             {
                 ReactorInformation newReactor = new ReactorInformation()
                 {
                     ParticipantID = reactor.ParticipantID,
                     FeedPumpID = reactor.FeedPumpID,
                     AerationPumpID = reactor.AerationPumpID,
                     HarvestPumpID = reactor.HarvestPumpID,
                     BiomassSensorID = reactor.BiomassSensorID,
                     OxygenSensorID = reactor.OxygenSensorID,
                     CarbonDioxideSensorID = reactor.CarbonDioxideSensorID,
                     CHxSensorID = reactor.CHxSensorID
                 };
                 ReactorInformationWindow riw = new ReactorInformationWindow("Edit Reactor", false, Pumps.Values, BiomassSensors.Values, GasSensors.Values) { DataContext = newReactor };
                 riw.Show();
                 await riw.WaitTask;
                 if (riw.Confirmed)
                 {
                     reactor.FeedPumpID = newReactor.FeedPumpID;
                     reactor.AerationPumpID = newReactor.AerationPumpID;
                     reactor.HarvestPumpID = newReactor.HarvestPumpID;
                     reactor.BiomassSensorID = newReactor.BiomassSensorID;
                     reactor.OxygenSensorID = newReactor.OxygenSensorID;
                     reactor.CarbonDioxideSensorID = newReactor.CarbonDioxideSensorID;
                     reactor.CHxSensorID = newReactor.CHxSensorID;
                     reactor.SaveTo(reactorDirectory);
                 }
             });
             newReactors.Add(reactor.ParticipantID, reactor);
         }
     }
     Reactors = newReactors;
 }