示例#1
0
        private static void Main()
        {
            XmlConfigurator.Configure();
            Log.Debug("start");
            ILanguage languagePack = new LanguagePack("en-US");
            //ILanguage languagePack = new LanguagePack("ru-RU");

            Dictionary <AtmState, string> statesDictionary = new Dictionary <AtmState, string>()
            {
                { AtmState.Ok, languagePack.Ok },
                { AtmState.NotEnoughMoney, languagePack.NotEnoughMoney },
                { AtmState.ImpossibleToCollectMoney, languagePack.ImpossibleToCollectMoney },
                { AtmState.TooManyBanknotes, languagePack.TooManyBanknotes }
            };

            _atm = CashMachine.Deserialize(ConfigurationManager.AppSettings["SerializationFile"]) ?? new CashMachine();

            CommandPerformer commandPerformer = new CommandPerformer(ref _atm, ref languagePack);

            commandPerformer.TryPerform("help");

            while (true)
            {
                Console.WriteLine("\n" + _atm.TotalMoney);
                var readLine = Console.ReadLine();

                decimal requestedSum;

                if (decimal.TryParse(readLine, out requestedSum) && requestedSum > decimal.Zero)
                {
                    var money = _atm.WithdrawMoney(requestedSum);
                    switch (_atm.CurrentState)
                    {
                    case AtmState.Ok:
                    {
                        Console.WriteLine(MoneyConverter.ConvertToString(money));
                        break;
                    }

                    default:
                        Console.WriteLine(statesDictionary[_atm.CurrentState]);
                        break;
                    }
                    continue;
                }
                bool isCommand = readLine != null && commandPerformer.TryPerform(readLine.Trim().ToLower());

                if (!isCommand)
                {
                    Console.WriteLine(languagePack.WrongInput);
                }
            }
        }
示例#2
0
        private static void Main()
        {
            XmlConfigurator.Configure();
            Log.Info("start");
            try
            {
                _signalHandler += HandleConsoleSignal;
                ConsoleHelper.SetSignalHandler(_signalHandler, true);

                var errors = Configurator.Config();

                _atm = CashMachine.Deserialize(ConfigurationManager.AppSettings["SerializationAtm"]) ??
                       new CashMachine(new GreedyAlgorithm());
                _statistics = Statistics.Statistics.Deserialize(ConfigurationManager.AppSettings["SerializationStatistics"]) ??
                              new Statistics.Statistics();

                AtmEvent.InsertCassettesEvent += _statistics.InsertCassettes;
                AtmEvent.WithdrawMoneyEvent   += _statistics.WithdrawMoney;
                AtmEvent.RemoveCassettesEvent += _statistics.RemoveCassettes;

                var commandPerfomer = new Commands.CommandPerfomer(_atm, errors, _statistics);
                Console.WriteLine(ConsoleLanguagePack.MainMessage);

                while (true)
                {
                    var input = Console.ReadLine();
                    Log.Debug(input);
                    if (string.IsNullOrEmpty(input))
                    {
                        continue;
                    }
                    if (ConsoleLanguagePack.ExitFlags.Contains(input))
                    {
                        break;
                    }

                    if (!commandPerfomer.TryPerform(input))
                    {
                        Console.WriteLine(ConsoleLanguagePack.CommandNotFound);
                    }
                }
                _atm.Serialize(ConfigurationManager.AppSettings["SerializationAtm"]);
                _statistics.Serialize(ConfigurationManager.AppSettings["SerializationStatistics"]);
            }
            catch (Exception ex)
            {
                Log.Fatal(ex);
            }

            Log.Info("end");
        }
示例#3
0
        public AtmGui()
        {
            Log.Info("start");
            InitializeComponent();

            DisenableButtonSelection();

            XmlConfigurator.Configure();
            _errors = Configurator.Config();
            Atm     = CashMachine.Deserialize(ConfigurationManager.AppSettings["SerializationAtm"]) ??
                      new CashMachine(new GreedyAlgorithm());
            Stat = global::Statistics.Statistics.Deserialize(ConfigurationManager.AppSettings["SerializationStatistics"]) ??
                   new global::Statistics.Statistics();
            AtmEvent.InsertCassettesEvent += Stat.InsertCassettes;
            AtmEvent.WithdrawMoneyEvent   += Stat.WithdrawMoney;
            AtmEvent.RemoveCassettesEvent += Stat.RemoveCassettes;

            _operation = Operations.Withdraw;
            InitializeBanknotes();
        }
示例#4
0
 private void AtmMainForm_Load(object sender, EventArgs e)
 {
     Log.Debug("Start application");
     _atm = CashMachine.Deserialize(ConfigurationManager.AppSettings["SerializationFile"]) ?? new CashMachine();
     DisplayMoney(_atm.AllMoney);
 }