コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
 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.");
     }
 }
コード例 #4
0
        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);
        }
コード例 #5
0
ファイル: Bee.cs プロジェクト: MarkPThomas/HeadFirst-CSharp
        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!");
            }
        }
コード例 #6
0
        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!");
            }
        }
コード例 #7
0
 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.");
     }
 }
コード例 #8
0
 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.");
     }
 }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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);
        }