public static TicketCounter Build(TicketCounterMode mode, IEnumerable <Ticket> tickets) { TicketCounter ticketCounter; switch (mode) { case TicketCounterMode.Moscow: { ticketCounter = new MoscowTicketCounter(tickets); break; } case TicketCounterMode.Piter: { ticketCounter = new PiterTicketCounter(tickets); break; } case TicketCounterMode.None: default: { throw new ArgumentOutOfRangeException("mode", "No such method of counting"); } } return(ticketCounter); }
public void Run() { string message = string.Empty; try { TicketGeneratorDTO generatorDTO = _ticketView.GetTicketGenerator(); TicketGenerator ticketGenerator = TicketGenerator.Build(generatorDTO); TicketCounterMode mode = GetTicketCounterMode(); TicketCounter ticketCounter = TicketCounterFactory.Build(mode, ticketGenerator); int luckyTickets = ticketCounter.CountLuckyTickets(); message = string.Format("Lucky tickets count: {0}", luckyTickets); Log.Information("LuckyTickets count: {luckyTickets}", luckyTickets); } catch (FormatException ex) { _ticketView.DisplayInstruction(); Log.Error(ex, "Exception thrown"); } catch (ArgumentOutOfRangeException ex) { _ticketView.DisplayInstruction(); Log.Error(ex, "Exception thrown"); } catch (OverflowException ex) { _ticketView.DisplayInstruction(); Log.Error(ex, "Exception thrown"); } catch (FileNotFoundException ex) { _ticketView.DisplayInstruction(); Log.Error(ex, "Exception thrown"); } _ticketView.Display(message); }