Esempio n. 1
0
        public override void OnFinish()
        {
            base.OnFinish();

            Models.Synchronization sync = Model as Models.Synchronization;

            Console.WriteLine("Status = {0}", sync.Status);
            Console.WriteLine("StorageAccount = {0}", sync.StorageAccount.DisplayName);
            Console.WriteLine("StorageAccountType = {0}", sync.StorageAccountType.ToString());
            foreach (Models.BackupedFile entry in sync.Files)
            {
                Console.WriteLine("SyncedFile => #{0}, {1}, {2}", entry.Id, entry.File.Path, entry.Version);
            }

            //try
            //{
            //	if (IsEditingModel)
            //	{
            //		_dao.Update(sync);
            //	}
            //	else
            //	{
            //		_dao.Insert(sync);
            //	}
            //}
            //catch (Exception ex)
            //{
            //	MessageBox.Show(ex.Message, "Error");
            //}
        }
Esempio n. 2
0
        public override void OnCancel()
        {
            base.OnCancel();

            Models.Synchronization sync = Model as Models.Synchronization;
            if (sync.Id.HasValue)
            {
                _dao.Refresh(sync);
            }
        }
Esempio n. 3
0
 private void cbAmazonS3_SelectionChangeCommitted(object sender, EventArgs e)
 {
     if (cbAmazonS3.SelectedIndex == 0)
     {
         MessageBox.Show("Show <Create new account> window.");
     }
     else
     {
         Models.Synchronization sync = Model as Models.Synchronization;
         sync.StorageAccountType = Models.EStorageAccountType.AmazonS3;
         sync.StorageAccount     = _s3dao.Get((int)cbAmazonS3.SelectedValue);
     }
 }
Esempio n. 4
0
        public SyncPresenter(Models.Synchronization sync)
        {
            IsEditingModel = true;
            Model          = sync;

            WizardFormOptions options = new WizardFormOptions {
                DoValidate = true
            };

            RegisterFormClass(typeof(SyncSelectAccountForm), options);
            RegisterFormClass(typeof(SyncProgressForm), options);
            //RegisterFormClass(typeof(SyncFinishedForm), options);
        }
Esempio n. 5
0
        protected void RegisterEventHandlers(Models.Synchronization sync)
        {
            TransferAgent.ListingStarted += (object sender, ListingProgressArgs e) =>
            {
                // ...
            };
            TransferAgent.ListingCompleted += (object sender, ListingProgressArgs e) =>
            {
                // ...
            };
            TransferAgent.ListingProgress += (object sender, ListingProgressArgs e) =>
            {
                RemoteObjects.AddRange(e.Objects);

#if DEBUG
                foreach (var obj in e.Objects)
                {
                    Info("Found {0}", obj.Key);
                }
#endif

                int  filesCount = e.Objects.Count;
                long filesSize  = e.Objects.Sum(x => x.Size);

                SyncAgent.Results.Stats.FileCount += filesCount;
                SyncAgent.Results.Stats.TotalSize += filesSize;

                var message = string.Format("Found {0} files ({1} bytes)", filesCount, filesSize);
                OnUpdate(new SyncOperationEvent {
                    Status = SyncOperationStatus.ListingUpdated, Message = message
                });
            };
            TransferAgent.ListingCanceled += (object sender, ListingProgressArgs e) =>
            {
                var message = string.Format("Canceled: {0}", e.Exception != null ? e.Exception.Message : "Unknown reason");
                Info(message);
                //StatusInfo.Update(SyncStatusLevel.INFO, message);
                OnUpdate(new SyncOperationEvent {
                    Status = SyncOperationStatus.ListingUpdated, Message = message
                });
            };
            TransferAgent.ListingFailed += (object sender, ListingProgressArgs e) =>
            {
                var message = string.Format("Failed: {0}", e.Exception != null ? e.Exception.Message : "Unknown reason");
                Warn(message);
                //StatusInfo.Update(SyncStatusLevel.ERROR, message);
                OnUpdate(new SyncOperationEvent {
                    Status = SyncOperationStatus.ListingUpdated, Message = message
                });
            };
        }
Esempio n. 6
0
 private void cbFileSystem_SelectionChangeCommitted(object sender, EventArgs e)
 {
     if (cbFileSystem.SelectedIndex == 0)
     {
         MessageBox.Show("Show <Create new account> window.");
     }
     else
     {
         Models.Synchronization sync = Model as Models.Synchronization;
         sync.StorageAccountType = Models.EStorageAccountType.FileSystem;
         //sync.StorageAccount = new CloudStorageAccount { Id = (int)cbFileSystem.SelectedValue };
         throw new NotImplementedException();
     }
 }
Esempio n. 7
0
        // ...

        #endregion

        #region Event handlers

        public override void OnStart(CustomSynchronizationAgent agent, Models.Synchronization sync)
        {
            base.OnStart(agent, sync);

            _daoSynchronization.Insert(sync);

            var message = string.Format("Synchronization started at {0}", StartedAt);

            Info(message);
            //StatusInfo.Update(SyncStatusLevel.OK, message);

            OnUpdate(new SyncOperationEvent {
                Status = SyncOperationStatus.Started, Message = message
            });
        }
Esempio n. 8
0
        public void OnFailure(CustomSynchronizationAgent agent, Models.Synchronization sync, Exception exception)
        {
            IsRunning = false;

            var message = string.Format("Synchronization failed: {0}", exception != null ? exception.Message : "Exception not informed");

            Error(message);
            //StatusInfo.Update(SyncStatusLevel.ERROR, message);

            sync.DidFail();
            _daoSynchronization.Update(sync);

            OnUpdate(new SyncOperationEvent {
                Status = SyncOperationStatus.Failed, Message = message
            });
        }
Esempio n. 9
0
        private void NewSyncOperation(Models.Synchronization sync)
        {
            // Create new sync operation.
            SyncOperation obj = new NewSyncOperation(sync) as SyncOperation;

            obj.Updated += (sender2, e2) => UpdateStatsInfo(e2.Status);
            //obj.EventLog = ...
            //obj.TransferListControl = ...

            // IMPORTANT: Dispose before assigning.
            if (RunningOperation != null)
            {
                RunningOperation.Dispose();
            }

            RunningOperation = obj;

            UpdateStatsInfo(SyncOperationStatus.Unknown);
        }
Esempio n. 10
0
        public SyncProgressForm()
        {
            InitializeComponent();

            this.ModelChangedEvent += (sender, args) =>
            {
                this.Sync = args.Model as Models.Synchronization;

                switch (this.Sync.StorageAccountType)
                {
                case Models.EStorageAccountType.AmazonS3:
                    break;

                case Models.EStorageAccountType.FileSystem:
                    break;
                }

                NewSyncOperation(this.Model as Models.Synchronization);
            };
        }
Esempio n. 11
0
        private void llblRunNow_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
        {
            if (RunningOperation.IsRunning)
            {
                this.llblRunNow.Enabled = false;
                RunningOperation.Cancel();
                this.llblRunNow.Enabled = true;
            }
            else
            {
                this.llblRunNow.Enabled = false;

                this.btnPrevious.Enabled = false;
                this.btnNext.Enabled     = false;
                this.btnFinish.Enabled   = false;

                Models.Synchronization sync = Model as Models.Synchronization;
                if (sync.Id.HasValue)
                {
                    _daoSynchronization.Update(sync);
                }
                else
                {
                    _daoSynchronization.Insert(sync);
                }

                // Create new sync operation for every 'Run' click.
                NewSyncOperation(this.Model as Models.Synchronization);

                // FIXME: Re-enable before starting the backup because it's not an async task.
                this.llblRunNow.Enabled = true;

                RunningOperation.Start();

                OperationResults = RunningOperation.Report.SyncResults;
            }
        }
Esempio n. 12
0
        public SyncSelectAccountForm()
        {
            InitializeComponent();

            this.ModelChangedEvent += (sender, args) =>
            {
                this.Sync = args.Model as Models.Synchronization;

                switch (this.Sync.StorageAccountType)
                {
                case Models.EStorageAccountType.AmazonS3:
                    rbtnAmazonS3.Checked = true;
                    break;

                case Models.EStorageAccountType.FileSystem:
                    rbtnFileSystem.Checked = true;
                    break;
                }

                if (this.Sync.StorageAccountType != Models.EStorageAccountType.Unknown)
                {
                    LoadAccounts(this.Sync.StorageAccountType);

                    if (this.Sync.StorageAccount != null)
                    {
                        SelectExistingAccount(this.Sync.StorageAccountType, this.Sync.StorageAccount.Id);
                    }
                }
            };

            // Setup data bindings
            cbAmazonS3.DataBindings.Add(new Binding("Enabled", rbtnAmazonS3,
                                                    this.GetPropertyName((RadioButton x) => x.Checked)));
            cbFileSystem.DataBindings.Add(new Binding("Enabled", rbtnFileSystem,
                                                      this.GetPropertyName((RadioButton x) => x.Checked)));
        }
Esempio n. 13
0
 public NewSyncOperation(Models.Synchronization sync)
     : this(sync, new SyncOperationOptions())
 {
 }
Esempio n. 14
0
        protected async void DoSynchronization(CustomSynchronizationAgent agent, Models.Synchronization sync, SyncOperationOptions options)
        {
            try
            {
                CurrentState = SyncOperationState.STARTING;
                OnStart(agent, sync);

                //
                // Synchronization
                //

                CurrentState = SyncOperationState.SYNCHRONIZING_FILES;
                {
                    Task syncTask = agent.Start(TransferAgent.RemoteRootDir, true);

                    {
                        var message = string.Format("Synchronizing files started.");
                        Info(message);
                        //StatusInfo.Update(SyncStatusLevel.INFO, message);
                        OnUpdate(new SyncOperationEvent {
                            Status = SyncOperationStatus.Started, Message = message
                        });
                    }

                    try
                    {
                        await syncTask;
                    }
                    catch (Exception ex)
                    {
                        if (ex.IsCancellation())
                        {
                            logger.Warn("Synchronizing files was canceled.");
                        }
                        else
                        {
                            logger.Log(LogLevel.Error, ex, "Caught exception during synchronizing files");
                        }

                        if (syncTask.IsFaulted || syncTask.IsCanceled)
                        {
                            if (syncTask.IsCanceled)
                            {
                                OnCancelation(agent, sync, ex);                                 // syncTask.Exception
                            }
                            else
                            {
                                OnFailure(agent, sync, ex);                                 // syncTask.Exception
                            }
                            return;
                        }
                    }

                    {
                        var message = string.Format("Synchronizing files finished.");
                        Info(message);
                        //StatusInfo.Update(SyncStatusLevel.INFO, message);
                        //OnUpdate(new SyncOperationEvent { Status = SyncOperationStatus.Finished, Message = message });
                    }

                    {
                        var message = string.Format("Estimated synchronization size: {0} files, {1}",
                                                    RemoteObjects.Count(), FileSizeUtils.FileSizeToString(agent.Results.Stats.TotalSize));
                        Info(message);
                    }
                }

                //
                // Database files saving
                //

                CurrentState = SyncOperationState.SAVING_TO_DATABASE;
                {
                    Task saveTask = ExecuteOnBackround(() =>
                    {
                        // Save everything.
                        Save(CancellationTokenSource.Token);
                    }, CancellationTokenSource.Token);

                    {
                        var message = string.Format("Database files saving started.");
                        Info(message);
                    }

                    try
                    {
                        await saveTask;
                    }
                    catch (Exception ex)
                    {
                        if (ex.IsCancellation())
                        {
                            logger.Warn("Database files saving was canceled.");
                        }
                        else
                        {
                            logger.Log(LogLevel.Error, ex, "Caught exception during database files saving");
                        }

                        if (saveTask.IsFaulted || saveTask.IsCanceled)
                        {
                            if (saveTask.IsCanceled)
                            {
                                OnCancelation(agent, sync, ex);                                 // saveTask.Exception
                            }
                            else
                            {
                                OnFailure(agent, sync, ex);                                 // saveTask.Exception
                            }
                            return;
                        }
                    }

                    {
                        var message = string.Format("Database files saving finished.");
                        Info(message);
                    }
                }

                CurrentState = SyncOperationState.FINISHING;
                OnFinish(agent, sync);
            }
            catch (Exception ex)
            {
                OnFinish(agent, sync, ex);
            }
        }
Esempio n. 15
0
        private void UpdateStatsInfo(SyncOperationStatus status, bool runningRemotely = false)
        {
            if (RunningOperation == null)
            {
                return;
            }

            switch (status)
            {
            default: throw new ArgumentException("Unhandled status", "status");

            case SyncOperationStatus.Unknown:
            {
                this.lblRemoteDirectory.Text = RunningOperation.RemoteRootDirectory;
                this.lblStatus.Text          = LBL_STATUS_STOPPED;
                this.llblRunNow.Text         = LBL_RUNNOW_STOPPED;
                this.lblTotalFiles.Text      = LBL_TOTALFILES_STOPPED;
                this.lblFilesSynced.Text     = LBL_FILESSYNCED_STOPPED;
                this.lblDuration.Text        = LBL_DURATION_INITIAL;
                this.btnPrevious.Enabled     = false;
                this.btnNext.Enabled         = false;
                this.btnFinish.Enabled       = false;
                break;
            }

            case SyncOperationStatus.Started:
                //case SyncOperationStatus.Resumed:
            {
                Assert.IsNotNull(OperationResults);
                this.lblRemoteDirectory.Text = RunningOperation.RemoteRootDirectory;
                this.llblRunNow.Text         = LBL_RUNNOW_RUNNING;
                this.lblStatus.Text          = LBL_STATUS_STARTED;
                this.lblDuration.Text        = LBL_DURATION_STARTED;
                this.lblTotalFiles.Text      = LBL_TOTALFILES_STARTED;
                this.lblFilesSynced.Text     = LBL_FILESSYNCED_STARTED;

                timer1.Enabled = true;
                timer1.Start();
                break;
            }

            case SyncOperationStatus.ListingUpdated:
            {
                long   totalSize      = OperationResults.Stats.TotalSize;
                string totalSizeAsStr = totalSize == 0 ? "Completed" : FileSizeUtils.FileSizeToString(totalSize);

                this.lblTotalFiles.Text = string.Format("{0} files ({1})",
                                                        OperationResults.Stats.FileCount, totalSizeAsStr);
                break;
            }

            case SyncOperationStatus.SavingUpdated:
            {
                Dispatcher.Invoke(() =>
                    {
                        this.lblFilesSynced.Text = string.Format("{0} of {1}",
                                                                 OperationResults.Stats.SavedFileCount,
                                                                 OperationResults.Stats.FileCount);
                    });
                break;
            }

            case SyncOperationStatus.Canceled:
            case SyncOperationStatus.Failed:
            {
                UpdateDuration(status);

                this.lblRemoteDirectory.Text = RunningOperation.RemoteRootDirectory;
                this.llblRunNow.Text         = LBL_RUNNOW_STOPPED;
                this.lblStatus.Text          = status == SyncOperationStatus.Canceled ? LBL_STATUS_CANCELED : LBL_STATUS_FAILED;
                this.lblFilesSynced.Text     = LBL_FILESSYNCED_STOPPED;

                timer1.Stop();
                timer1.Enabled = false;

                this.btnPrevious.Enabled = true;
                this.btnNext.Enabled     = true;
                this.btnFinish.Enabled   = true;

                if (!runningRemotely)
                {
                    // Update timestamps.
                    Models.Synchronization sync = Model as Models.Synchronization;
                    //sync.LastRunAt = DateTime.UtcNow;
                    _daoSynchronization.Update(sync);
                }
                break;
            }

            case SyncOperationStatus.Finished:
            {
                UpdateDuration(status);
                this.lblRemoteDirectory.Text = RunningOperation.RemoteRootDirectory;
                this.llblRunNow.Text         = LBL_RUNNOW_STOPPED;
                this.lblStatus.Text          = LBL_STATUS_COMPLETED;

                timer1.Stop();
                timer1.Enabled = false;

                this.btnPrevious.Enabled = true;
                this.btnNext.Enabled     = true;
                this.btnFinish.Enabled   = true;

                if (!runningRemotely)
                {
                    // Update timestamps.
                    Models.Synchronization sync = Model as Models.Synchronization;
                    //sync.LastRunAt = sync.LastSuccessfulRunAt = DateTime.UtcNow;
                    _daoSynchronization.Update(sync);
                }
                break;
            }
            }
        }
Esempio n. 16
0
        public void OnFinish(CustomSynchronizationAgent agent, Models.Synchronization sync, Exception ex = null)
        {
            IsRunning = false;

            switch (CurrentState)
            {
            default:
            {
                var message = string.Format("Synchronization failed: {0}", ex.Message);
                Warn(message);
                //StatusInfo.Update(SyncStatusLevel.WARN, message);
                Report.AddErrorMessage(ex.Message);

                Report.OperationStatus = OperationStatus.FAILED;
                sync.DidFail();
                _daoSynchronization.Update(sync);
                OnUpdate(new SyncOperationEvent {
                        Status = SyncOperationStatus.Failed, Message = message
                    });

                break;
            }

            case SyncOperationState.FINISHING:
            {
                SyncResults.Statistics stats = agent.Results.Stats;
                var message = string.Format("Synchronization finished! Stats: {0} files", stats.FileCount);
                Info(message);
                //StatusInfo.Update(SyncStatusLevel.OK, message);

                // TODO(jweyrich): Handle overall failure and cancelation during Sync?
                sync.DidComplete();
                _daoSynchronization.Update(sync);
                OnUpdate(new SyncOperationEvent {
                        Status = SyncOperationStatus.Finished, Message = message
                    });

                /*
                 * switch (agent.Results.OverallStatus)
                 * //switch (sync.Status)
                 * {
                 *      default: throw new InvalidOperationException("Unexpected TransferStatus");
                 *      case TransferStatus.CANCELED:
                 *              Report.OperationStatus = OperationStatus.CANCELED;
                 *              sync.WasCanceled();
                 *              _daoSynchronization.Update(sync);
                 *              OnUpdate(new SyncOperationEvent { Status = SyncOperationStatus.Canceled, Message = message });
                 *              break;
                 *      case TransferStatus.FAILED:
                 *              Report.OperationStatus = OperationStatus.FAILED;
                 *              sync.DidFail();
                 *              _daoSynchronization.Update(sync);
                 *              OnUpdate(new SyncOperationEvent { Status = SyncOperationStatus.Failed, Message = message });
                 *              break;
                 *      case TransferStatus.COMPLETED:
                 *              Report.OperationStatus = OperationStatus.COMPLETED;
                 *              sync.DidComplete();
                 *              _daoSynchronization.Update(sync);
                 *              OnUpdate(new SyncOperationEvent { Status = SyncOperationStatus.Finished, Message = message });
                 *              break;
                 * }
                 */

                break;
            }
            }
        }
Esempio n. 17
0
 public NewSyncOperation(Models.Synchronization sync, SyncOperationOptions options)
     : base(options)
 {
     Synchronization = sync;
 }
Esempio n. 18
0
        public virtual void OnStart(CustomSynchronizationAgent agent, Models.Synchronization sync)
        {
            IsRunning = true;

            sync.DidStart();
        }