private void processNectar_Click(object sender, RoutedEventArgs e) { NectarVat vat = new NectarVat(); Bee bee = new Bee(15); HiveLog log = new HiveLog(); ProcessNectar(vat, bee, log); }
private void processNectarIOProblem_Click(object sender, RoutedEventArgs e) { NectarVat vat = new NectarVat(); Bee bee = new Bee(15); HiveLog log = new HiveLog(); bee.UnitsExpected = 2; log.OpenNonExistingFile = true; ProcessNectar(vat, bee, log); }
private void ProcessNectar(NectarVat vat, Bee bee, HiveLog log) { try { queen.ProcessNectar(vat, bee, log); } catch (HiveLogException) { MessageBox.Show("There was a problem in the hive log."); } }
private void processNectarLogError_Click(object sender, RoutedEventArgs e) { NectarVat vat = new NectarVat(); Bee bee = new Bee(15); HiveLog log = new HiveLog(); bee.UnitsExpected = 2; log.ThrowHiveLogException = true; ProcessNectar(vat, bee, log); }
public NectarUnit[] EmptyVat(NectarVat vat) { NectarUnit[] vatUnits; if (vat.Units.Count > 0) { vatUnits = new NectarUnit[vat.Units.Count]; for (int i = 0; i < vatUnits.Length; i++) { vatUnits[i] = vat.Units[i]; } return vatUnits; } else { throw new VatEmptyException("The vat has been emptied!"); } }
public NectarUnit[] EmptyVat(NectarVat vat) { NectarUnit[] vatUnits; if (vat.Units.Count > 0) { vatUnits = new NectarUnit[vat.Units.Count]; for (int i = 0; i < vatUnits.Length; i++) { vatUnits[i] = vat.Units[i]; } return(vatUnits); } else { throw new VatEmptyException("The vat has been emptied!"); } }
public void ProcessNectar(NectarVat vat, Bee worker, HiveLog log) { try { NectarUnit[] units = worker.EmptyVat(vat); for (int i = 0; i < worker.UnitsExpected; i++) { Stream hiveLogFile = log.OpenLogFile(); worker.AddLogEntry(hiveLogFile); hiveLogFile.Close(); } } catch (VatEmptyException) { MessageBox.Show("The vat is empty."); vat.Emptied = true; } catch (HiveLogException ex) { MessageBox.Show("Throwing a HiveLogException: " + ex.Message); throw; } // It's fine for two blocks to use the same 'ex' for the exception as long as they aren't nested. catch (IOException ex) { worker.AlertQueen("An unspecified file error happened: " + "Message: " + ex.Message + "\r\n" + "Stack Trace: " + ex.StackTrace + "\r\n" + "Data: " + ex.Data + "\r\n"); } finally { vat.Seal(); worker.FinishedJob(); MessageBox.Show("Vat is sealed and the worker is finished."); } }