public void SyncError(List <Tuple <string, Exception> > errors)
        {
            if (errors.Count == 0)
            {
                return;
            }

            if (_lastSynchronized != null)
            {
                LastSynchronizedText = _lastSynchronized.Value.ToLocalTime().ToString("HH:mm:ss");
            }
            else
            {
                LastSynchronizedText = "[ERROR]";
            }

            SynchronizationState = SynchronizationState.Error;

            App.Logger.Error("Sync", string.Join(Environment.NewLine, errors.Select(p => p.Item1)), string.Join("\r\n\r\n\r\n", errors.Select(p => p.Item2.ToString())));

            if (Settings.SuppressAllSyncProblemsPopup)
            {
                App.Logger.Info("Sync", "Suppress error display due to config [[SuppressAllSyncProblemsPopup]]");
            }
            else if (Settings.SuppressConnectionProblemPopup && errors.All(e => (e.Item2 as RestException)?.IsConnectionProblem == true))
            {
                App.Logger.Info("Sync", "Suppress error display due to config [[SuppressConnectionProblemPopup]]");
            }
            else
            {
                if (Owner.Visibility == Visibility.Hidden)
                {
                    Owner.TrayIcon.ShowBalloonTip(
                        "Synchronization failed",
                        string.Join(Environment.NewLine, errors.Select(p => p.Item1)),
                        BalloonIcon.Error);
                }
                else
                {
                    SyncErrorDialog.Show(Owner, errors.Select(p => p.Item1).ToList(), errors.Select(p => p.Item2).ToList());
                }
            }
        }
Exemple #2
0
        public void StartSync()
        {
            if (SelectedProvider == null)
            {
                return;
            }
            if (Account == null)
            {
                return;
            }

            if (_syncThread != null && _syncThread.IsAlive)
            {
                _syncThread.Abort();
            }
            if (_progressThread != null && _progressThread.IsAlive)
            {
                _progressThread.Abort();
            }

            SyncInfoText = "Starting Synchronization";
            var acc = new RemoteStorageAccount(Account.ID, Account.Plugin, Account.Config);

            _syncThread = new Thread(() =>
            {
                try
                {
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        IsValidating = true;

                        ConfigurationValidated = false;
                        ValidationResultData   = null;
                        ValidationResultNotes  = null;

                        SyncProgress = 0;
                        SyncInfoText = string.Empty;

                        CanAbort = true;
                    });

                    var r = DoSync(acc, App.Logger);
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        ConfigurationValidated = true;
                        ValidationResultData   = r.Item1;
                        ValidationResultNotes  = r.Item2;
                        SyncProgress           = r.Item3 == 0 ? -100 : -66;
                        SyncInfoText           = r.Item3 == 0 ? string.Empty : $"({r.Item3}/{r.Item4} notes had download errors)";
                    });
                }
                catch (ThreadAbortException)
                {
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        ConfigurationValidated = false;
                        ValidationResultData   = null;
                        ValidationResultNotes  = null;
                        SyncProgress           = 0;
                        SyncInfoText           = string.Empty;
                    });
                    return;
                }
                catch (Exception e)
                {
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        ConfigurationValidated = false;
                        ValidationResultData   = null;
                        ValidationResultNotes  = null;
                        SyncProgress           = -66;
                        SyncInfoText           = string.Empty;
                    });
                    Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        SyncProgress = -66;
                        SyncErrorDialog.Show(_owner, e);
                    }));
                }
                finally
                {
                    Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        IsValidating = false;
                        SyncInfoText = string.Empty;
                    }));
                }
            });
            _progressThread = new Thread(() =>
            {
                Thread.Sleep(350);
                for (;;)
                {
                    if (!_syncThread.IsAlive)
                    {
                        break;
                    }
                    Thread.Sleep(150);
                    Application.Current.Dispatcher.Invoke(() => { SyncProgress++; });
                }
                Application.Current.Dispatcher.Invoke(() =>
                {
                    if (ConfigurationValidated)
                    {
                        SyncProgress = -100;
                    }
                    else
                    {
                        SyncProgress = -66;
                    }
                    SyncInfoText = string.Empty;
                });
            });

            _syncThread.Start();
            _progressThread.Start();
        }