public EmailWatcher(GoogleServiceHelper googleServiceHelper, ViewModel viewModel) : base(nameof(EmailWatcher))
 {
     GoogleServiceHelper       = googleServiceHelper ?? throw new ArgumentNullException(nameof(googleServiceHelper));
     ViewModel                 = viewModel ?? throw new ArgumentNullException(nameof(viewModel));
     _emailCheckTimer          = new DispatcherTimer();
     _payloadParser            = new DispatcherTimer();
     _emailCheckTimer.Interval = TimeSpan.FromSeconds(1);
     _payloadParser.Interval   = TimeSpan.FromSeconds(1);
     InitializeTimers();
 }
        /// <summary>
        /// Checks for new Email timer.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="ElapsedEventArgs"/> instance containing the event data.</param>
        private async void CheckForNewEmailTimer_Elapsed(object sender, EventArgs e)
        {
            try
            {
                _emailCheckTimer.Stop();

                await CheckForNewEmails("Kindle");
            }
            catch (Exception exc)
            {
                LogError(exc);

                // If something goes wrong try Initializing G-mail service again in the next timer tick
                // If This happens show UI Indication
                await GoogleServiceHelper.InitializeGmailServiceAsync();
            }
            finally
            {
                _emailCheckTimer.Start();
            }
        }
        protected override void OnStartup(StartupEventArgs e)
        {
            try
            {
                base.OnStartup(e);
                string currentDirectoryWithNlog = Path.Combine(Directory.GetCurrentDirectory(), "nlog.config");;
                var    pathWithFileName         = Path.Combine(Directory.GetCurrentDirectory(), "BooksRead.json");

                if (File.Exists(currentDirectoryWithNlog) is false)
                {
                    throw new Exception($"Path to configuration files do not exist does not exist{currentDirectoryWithNlog}");
                }

                LogFactory.Initialize(currentDirectoryWithNlog);


                var viewModel     = new ViewModel(pathWithFileName);
                var googleService = new GoogleServiceHelper();
                googleService.InitializeGmailServiceAsync();
                EmailWatcher emailWatcher = new EmailWatcher(googleService, viewModel);


                var noteViewerWindow = new NoteViewer(viewModel);
                noteViewerWindow.Show();
                noteViewerWindow.Focus();
            }
            catch (Exception exc)
            {
                var errorWindowViewModel = new ErrorWindowViewModel()
                {
                    ErrorMessage = exc.StackTrace + Environment.NewLine + exc.Message
                };
                var errorWindow = new ErrorWindow(errorWindowViewModel);
                errorWindow.Show();
                errorWindow.Focus();
            }
        }