Summary description for SyncForm.
Inheritance: System.Windows.Forms.Form, ISyncProgressVisualizer, ITaskIndicatorProvider, ISyncErrorInformer
Ejemplo n.º 1
0
        private IStatisticsContainer PerformSyncSession(
            Action <ISyncContext> syncProc,
            bool activateUI)
        {
            var stats = new StatisticsContainer();

            if (!InitStartSync())
            {
                return(stats);
            }

            var       svcManager    = new ServiceManager(_provider);
            SyncForm  syncForm      = null;
            var       result        = SyncResult.Failed;
            Exception failException = null;

            try
            {
                var context = new SyncContext(
                    svcManager,
                    stats,
                    // ReSharper disable AccessToModifiedClosure
                    () => syncForm != null && syncForm.IsCancelled);
                // ReSharper restore AccessToModifiedClosure

                if (_lastSyncFormInstance != null)
                {
                    _uiAsyncOp.Send(_lastSyncFormInstance.Dispose);
                }
                if (Config.Instance.ShowSyncWindow)
                {
                    _uiAsyncOp.Send(
                        () =>
                    {
                        syncForm =
                            new SyncForm(context)
                        {
                            WindowState = activateUI
                                                                                ? FormWindowState.Normal
                                                                                : FormWindowState.Minimized
                        };
                        syncForm.Show();
                    });
                    syncForm.Closed      += (sender, args) => _lastSyncFormInstance = null;
                    _lastSyncFormInstance = syncForm;
                    svcManager.Publish <ISyncProgressVisualizer>(syncForm);
                    svcManager.Publish <ITaskIndicatorProvider>(syncForm);
                    svcManager.Publish <ISyncErrorInformer>(syncForm);
                }

                syncProc(context);

                if (!stats.IsEmpty())
                {
                    _provider.LogInfo(stats.GetFormattedValues(_provider));
                }

                result = SyncResult.Finished;
            }
            catch (UserCancelledException ex)
            {
                _provider.LogWarning(SyncResources.SyncWarning.FormatStr(ex.Message));
                result = SyncResult.Aborted;
            }
            catch (Exception ex)
            {
                _provider.LogError(SyncResources.SyncError.FormatStr(ex.Message));
                result        = SyncResult.Failed;
                failException = ex;
            }
            finally
            {
                _isActive = false;
                OnEndSync(new EndSyncEventArgs(stats, result, failException));
                if (syncForm != null)
                {
                    _uiAsyncOp.Send(syncForm.TryClose);
                }
            }
            return(stats);
        }
Ejemplo n.º 2
0
        private IStatisticsContainer PerformSyncSession(
            Action<ISyncContext> syncProc,
            bool activateUI)
        {
            var stats = new StatisticsContainer();

            if (!InitStartSync())
                return stats;

            var svcManager = new ServiceManager(_provider);
            SyncForm syncForm = null;
            var result = SyncResult.Failed;
            Exception failException = null;
            try
            {
                var context = new SyncContext(
                    svcManager,
                    stats,
                    // ReSharper disable AccessToModifiedClosure
                    () => syncForm != null && syncForm.IsCancelled);
                    // ReSharper restore AccessToModifiedClosure

                if (_lastSyncFormInstance != null)
                    _uiAsyncOp.Send(_lastSyncFormInstance.Dispose);
                if (Config.Instance.ShowSyncWindow)
                {
                    _uiAsyncOp.Send(
                        () =>
                        {
                            syncForm =
                                new SyncForm(context)
                                {
                                    WindowState = activateUI
                                        ? FormWindowState.Normal
                                        : FormWindowState.Minimized
                                };
                            syncForm.Show();
                        });
                    syncForm.Closed += (sender, args) => _lastSyncFormInstance = null;
                    _lastSyncFormInstance = syncForm;
                    svcManager.Publish<ISyncProgressVisualizer>(syncForm);
                    svcManager.Publish<ITaskIndicatorProvider>(syncForm);
                    svcManager.Publish<ISyncErrorInformer>(syncForm);
                }

                syncProc(context);

                if (!stats.IsEmpty())
                    _provider.LogInfo(stats.GetFormattedValues(_provider));

                result = SyncResult.Finished;
            }
            catch (UserCancelledException ex)
            {
                _provider.LogWarning(SyncResources.SyncWarning.FormatStr(ex.Message));
                result = SyncResult.Aborted;
            }
            catch (Exception ex)
            {
                _provider.LogError(SyncResources.SyncError.FormatStr(ex.Message));
                result = SyncResult.Failed;
                failException = ex;
            }
            finally
            {
                _isActive = false;
                OnEndSync(new EndSyncEventArgs(stats, result, failException));
                if (syncForm != null)
                    _uiAsyncOp.Send(syncForm.TryClose);
            }
            return stats;
        }