public void Dispose()
        {
            _billValidator?.Dispose();
            _billValidator = null;

            GC.SuppressFinalize(this);
        }
Exemplo n.º 2
0
        private void CreateBillValidator()
        {
            var con = new ConnectionRs232
            {
                PortName   = GetCom(),
                RemoveEcho = true                                         // if we are connected to USB-COM echo is present otherwise set to false
            };

            Dictionary <byte, BillTypeInfo> notes;

            if (!BillValidator.TryParseConfigWord(configWord.Text, out notes))
            {
                MessageBox.Show("Wrong config word, using defaults");

                notes           = BillValidator.DefaultConfig;
                configWord.Text = BillValidator.ConfigWord(BillValidator.DefaultConfig);
            }

            _billValidator = new BillValidator(Convert.ToByte(deviceNumber.Value), con, notes, null);

            _billValidator.NotesAccepted        += BillValidatorNotesAccepted;
            _billValidator.ErrorMessageAccepted += BillValidatorErrorMessageAccepted;

            _billValidator.Init();

            groupBox1.Enabled = true;
            panel1.Enabled    = true;

            initCoinButton.Enabled = false;
            resetButton.Enabled    = true;
            configWord.Enabled     = false;
        }
        public ValidatorObject(ChromiumWebBrowser chromiumWebBrowser, BillValidator billValidator)
        {
            _chromiumWebBrowser = chromiumWebBrowser;

            this._billValidator = billValidator;

            this._billValidator.BillCassetteStatusEvent += _billValidator_BillCassetteStatusEvent;
            this._billValidator.BillReceived            += _billValidator_BillReceived;
            this._billValidator.BillStacking            += _billValidator_BillStacking;
        }
Exemplo n.º 4
0
        Decimal _notesCounter;        // counts accepted money amount in bills

        public Form1()
        {
            InitializeComponent();

            // Showing message about current config for defices
            var configMessage = String.Format("Coin config:{0}{1}{0}Bill config:{0}{2}",
                                              Environment.NewLine,
                                              CoinAcceptor.ConfigWord(CoinAcceptor.DefaultConfig),
                                              BillValidator.ConfigWord(BillValidator.DefaultConfig));

            configWord.Text = configMessage;
        }
Exemplo n.º 5
0
        public (bool isValid, IEnumerable <ValidationResult> errors) Validate()
        {
            var validator = new BillValidator();
            var result    = validator.Validate(this);

            if (result.IsValid)
            {
                return(true, null);
            }

            return(false, result.Errors.Select(item => new ValidationResult(item.ErrorMessage, new [] { item.PropertyName })));
        }
Exemplo n.º 6
0
        public AddBillResponse AddBill([FromBody] AddBillRequest billRequest)
        {
            var response = new AddBillResponse();

            try
            {
                if (_userService.AuthenticateSession(Request.Headers["Authorization"].ToString()) == false)
                {
                    response.AddError("The authorization credentails were invalid", ErrorCode.SESSION_INVALID);
                    return(response);
                }

                ActiveUser user = _userService.GetUserInformationFromAuthHeader(Request.Headers["Authorization"].ToString());
                if (user.HouseId == 0)
                {
                    response.AddError("You must belong to a household to add bills", ErrorCode.USER_NOT_IN_HOUSEHOLD);
                    return(response);
                }

                AddBill bill = new AddBill
                {
                    Name          = billRequest.Name,
                    Due           = billRequest.Due,
                    PeopleIds     = billRequest.PeopleIds,
                    RecurringType = billRequest.RecurringType,
                    TotalAmount   = billRequest.TotalAmount,
                    HouseId       = user.HouseId
                };
                BillValidator.CheckIfValidBill(bill);
                response.Id = _billRepository.AddBill(bill);

                if (user.HouseId == 1)
                {
                    _discordService.AddBillNotification(billRequest.Name, billRequest.Due, billRequest.TotalAmount);
                }

                response.Notifications = new List <string>
                {
                    $"The bill '{billRequest.Name}' has been added"
                };
            }
            catch (ErrorCodeException exception)
            {
                response.AddError($"An unexpected exception occured: {exception}", billRequest, exception.Code);
            }
            catch (Exception exception)
            {
                response.AddError($"An unexpected exception occured: {exception}", billRequest);
            }

            return(response);
        }
Exemplo n.º 7
0
        //public TelegramManager _telegramManager;

        /// <summary>
        /// Main form
        /// </summary>
        public BrowserForm()
        {
            InitializeComponent();

            Text = Assembly.GetExecutingAssembly().GetName().Name;

            this.FormClosing += BrowserForm_FormClosing;

            // A system tray initialization
            _trayMenu = new ContextMenu();
            _trayMenu.MenuItems.Add("Exit", new EventHandler(delegate(Object obj, EventArgs e)
            {
                this.Close();
            }));
            _trayIcon             = new NotifyIcon();
            _trayIcon.Text        = $"{Text} {Assembly.GetExecutingAssembly().GetName().Version}";
            _trayIcon.Icon        = Utils.GetIconFromUrl($"{_defaultUrlAddress}/images/brand48x48.png");
            _trayIcon.ContextMenu = _trayMenu;
            _trayIcon.Visible     = true;

            // Adding the handler to show log messages (ILoggerHandler)
            Logger.LoggerHandlerManager.AddHandler(new FileLoggerHandler(_defaultLogFileName, string.Format("{0}\\logs", Directory.GetCurrentDirectory())));
            Logger.Log(Logger.Level.Info, string.Format("{0} has been started at {1}", Text, DateTime.Now.ToString("dddd, MMMM dd, yyyy h:mm:ss tt")));

            if (!File.Exists(_defaultIniPath))
            {
                Logger.Log <BrowserForm>(Logger.Level.Warning, ".ini file being used doesn't exist!");
            }
            _baseAddress = new Uri(INI.ReadFile(_defaultIniPath).Get("App", "Source"));

            // Checking for a bill validator existence
            _billValidator = new BillValidator(
                INI.ReadFile(_defaultIniPath).Get("BillAcceptor", "PortName"),
                Int32.Parse(INI.ReadFile(_defaultIniPath).Get("BillAcceptor", "BaudRate"))
                );
            _billValidator.BillReceived            += _billValidator_BillReceived;
            _billValidator.BillStacking            += _billValidator_BillStacking;
            _billValidator.BillCassetteStatusEvent += _billValidator_BillCassetteStatusEvent;

            _billValidator.PowerUp();

            _credentialManager = new CredentialManager(null);
            _terminal          = _credentialManager.Configure();

            // Initializes Chromium (3.2883.1552)
            InitializeChromiumWebBrowser();

            //OldUpdateManager.Start();
            //InitializeTelegram();
            //Mailer.Send("IPTS", _baseAddress.OriginalString, new string[] { "*****@*****.**" });
        }
Exemplo n.º 8
0
        private void DisposeBillValidator()
        {
            if (_billValidator == null)
            {
                return;
            }

            if (_billValidator.IsInitialized)
            {
                _billValidator.IsInhibiting = true;
                _billValidator.UnInit();
            }

            _billValidator.Dispose();

            _billValidator = null;

            groupBox1.Enabled      = false;
            panel1.Enabled         = false;
            initCoinButton.Enabled = true;
            resetButton.Enabled    = false;
            configWord.Enabled     = true;
        }
 public ValidatorTest()
 {
     _billValidator = new BillValidator();
 }
Exemplo n.º 10
0
 public BillInformationTest()
 {
     _billValidator = new BillValidator();
 }