Example #1
0
        /// <exception cref="System.InvalidOperationException">
        ///   Thrown when the previous backup operation has not finished yet.
        /// </exception>
        /// <exception cref="System.NotImplementedException">
        ///   Thrown when the previous backup operation has not finished yet and it's marked to be resumed (`options.Resume` is `true`).
        ///   The restore operation doesn't support resume.
        /// </exception>
        private RestoreOperation CreateRestoreOperation(Models.RestorePlan plan)
        {
            var dao = new RestoreRepository();

            Models.Restore latest = dao.GetLatestByPlan(plan);
            MustResumeLastOperation = latest != null && latest.NeedsResume();

            if (MustResumeLastOperation && Options.Resume)
            {
                throw new NotImplementedException("The restore operation still does not support resuming.");
            }

            if (MustResumeLastOperation && !Options.Resume)
            {
                string message = string.Format("The restore (#{0}) has not finished yet."
                                               + " If it's still running, please, wait until it finishes,"
                                               + " otherwise you should resume it manually.",
                                               latest.Id);
                throw new InvalidOperationException(message);
            }

            // Create new restore or resume the last unfinished one.
            RestoreOperation obj = /* MustResumeLastOperation
                                    * ? new ResumeRestoreOperation(latest) as RestoreOperation
                                    * : */new NewRestoreOperation(plan) as RestoreOperation;

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

            RestoreUpdateStatsInfo(RestoreOperationStatus.Unknown, TransferStatus.STOPPED);

            return(obj);
        }
Example #2
0
        // Convert collection of `FileSystemTreeView.TreeNodeTag` to `RestorePlanSourceEntry`.
        public static List <Models.RestorePlanSourceEntry> ToRestorePlanSourceEntry(
            this Dictionary <string, BackupPlanTreeNodeData> dataDict, Models.RestorePlan plan, RestorePlanSourceEntryRepository dao)
        {
            List <Models.RestorePlanSourceEntry> sources = new List <Models.RestorePlanSourceEntry>(dataDict.Count);

            foreach (var entry in dataDict)
            {
                BackupPlanTreeNodeData        data   = entry.Value;
                Models.RestorePlanSourceEntry source = null;
                if (data.Id != null)
                {
                    source = dao.Get(data.Id as long?);
                }
                else
                {
                    source = new Models.RestorePlanSourceEntry();
                }
                source.RestorePlan = plan;
                source.Type        = data.ToEntryType();
                source.Path        = data.Path;
                source.PathNode    = data.UserObject as Models.BackupPlanPathNode;
                if (source.Type == Models.EntryType.FILE_VERSION)
                {
                    source.Version = data.Version.Version;
                }
                sources.Add(source);
            }
            return(sources);
        }
Example #3
0
        public RestorePlanViewControl()
        {
            InitializeComponent();

            AttachEventHandlers();

            /*
             * EventDispatcher dispatcher = new EventDispatcher();
             *
             * Watcher.Subscribe((RestoreUpdateMsg msg) =>
             * {
             *      if (this.Model == null)
             *              return;
             *
             *      Models.RestorePlan plan = this.Model as Models.RestorePlan;
             *
             *      // Only process messages that are related to the plan associated with this control.
             *      if (msg.PlanId != plan.Id.Value)
             *              return;
             *
             *      // IMPORTANT: Always invoke from Main thread!
             *      dispatcher.Invoke(() => { ProcessRemoteMessage(msg); });
             * });
             */

            this.ModelChangedEvent += (sender, args) =>
            {
                if (Model == null)
                {
                    return;
                }

                Models.RestorePlan plan = Model as Models.RestorePlan;

                if (CurrentOperation != null)
                {
                    CurrentOperation.Dispose();
                }
                CurrentOperation                     = new RemoteOperation(DurationTimer_Tick);
                CurrentOperation.Status              = Commands.OperationStatus.NOT_RUNNING;
                CurrentOperation.LastRunAt           = plan.LastRunAt;
                CurrentOperation.LastSuccessfulRunAt = plan.LastSuccessfulRunAt;

                this.lblSources.Text           = plan.SelectedSourcesAsDelimitedString(", ", 50, "...");       // Duplicate from RestoreOperation.cs - Sources property
                this.llblRunNow.Text           = LBL_RUNNOW_STOPPED;
                this.llblRunNow.Enabled        = false;
                this.lblStatus.Text            = "Querying status...";;
                this.lblDuration.Text          = "Unknown";;
                this.lblFilesTransferred.Text  = "Unknown";;
                this.llblEditPlan.Enabled      = false;
                this.llblDeletePlan.Enabled    = false;
                this.lblLastRun.Text           = PlanCommon.Format(CurrentOperation.LastRunAt);
                this.lblLastSuccessfulRun.Text = PlanCommon.Format(CurrentOperation.LastSuccessfulRunAt);
                this.lblTitle.Text             = PlanCommon.FormatTitle(plan.Name);
                this.lblSchedule.Text          = plan.ScheduleType.ToString();

                CurrentOperation.RequestedInitialInfo = true;
                Provider.Handler.Send(Commands.ServerQueryPlan("restore", plan.Id.Value));
            };
        }
Example #4
0
        public override void OnFormClosed()
        {
            base.OnFormClosed();

            Models.RestorePlan plan = Model as Models.RestorePlan;
            _dao.Refresh(plan);
        }
Example #5
0
        private void llblRunNow_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Models.RestorePlan plan = this.Model as Models.RestorePlan;

            if (OperationIsRunning)
            {
                // These buttons are re-enabled after the GUI receives the command `Commands.GUI_REPORT_PLAN_STATUS`
                // where the report status is one of these:
                //   Commands.OperationStatus.FAILED:
                //   Commands.OperationStatus.CANCELED:
                //   Commands.OperationStatus.FINISHED:
                this.llblRunNow.Enabled     = false;
                this.llblEditPlan.Enabled   = false;
                this.llblDeletePlan.Enabled = false;

                Provider.Handler.Send(Commands.ServerCancelPlan("restore", plan.Id.Value));
            }
            else
            {
                // These buttons are re-enabled after the GUI receives the command `Commands.GUI_REPORT_PLAN_STATUS`
                // where the report status is one of these:
                //   Commands.OperationStatus.FAILED:
                //   Commands.OperationStatus.CANCELED:
                //   Commands.OperationStatus.FINISHED:
                this.llblRunNow.Enabled     = false;
                this.llblEditPlan.Enabled   = false;
                this.llblDeletePlan.Enabled = false;

                string cmd = CurrentOperation.Status == Commands.OperationStatus.INTERRUPTED
                                        ? Commands.ServerResumePlan("restore", plan.Id.Value)
                                        : Commands.ServerRunPlan("restore", plan.Id.Value);
                Provider.Handler.Send(cmd);
            }
        }
Example #6
0
        public override void OnCancel()
        {
            base.OnCancel();

            Models.RestorePlan plan = Model as Models.RestorePlan;
            _dao.Refresh(plan);
        }
Example #7
0
        private void OnReportPlanProgress(object sender, GuiCommandEventArgs e)
        {
            if (this.Model == null || !CurrentOperation.GotInitialInfo)
            {
                return;
            }

            string planType = e.Command.GetArgumentValue <string>("planType");

            if (!planType.Equals("restore"))
            {
                return;
            }

            Models.RestorePlan plan = this.Model as Models.RestorePlan;

            Int32 planId = e.Command.GetArgumentValue <Int32>("planId");

            if (planId != plan.Id)
            {
                return;
            }

            Commands.GuiReportPlanProgress progress = e.Command.GetArgumentValue <Commands.GuiReportPlanProgress>("progress");
            UpdatePlanProgress(progress);
        }
Example #8
0
        public override void OnFinish()
        {
            base.OnFinish();

            Models.RestorePlan plan = Model as Models.RestorePlan;

            Console.WriteLine("Name = {0}", plan.Name);
            Console.WriteLine("StorageAccount = {0}", plan.StorageAccount.DisplayName);
            foreach (Models.RestorePlanSourceEntry entry in plan.SelectedSources)
            {
                Console.WriteLine("SelectedSource => #{0}, {1}, {2}, {3}",
                                  entry.Id, entry.Type.ToString(), entry.Path, entry.Version);
            }
            Console.WriteLine("ScheduleType = {0}", plan.ScheduleType.ToString());

            plan.UpdatedAt = DateTime.UtcNow;

            //try
            //{
            if (IsEditingModel)
            {
                _dao.Update(plan);
            }
            else
            {
                _dao.Insert(plan);
            }
            //}
            //catch (Exception ex)
            //{
            //	MessageBox.Show(ex.Message, "Error");
            //}
        }
Example #9
0
        protected override bool IsValid()
        {
            Models.RestorePlan plan = Model as Models.RestorePlan;
            bool didSelectSource    = plan.SelectedSources != null && plan.SelectedSources.Count > 0;

            return(didSelectSource);
        }
Example #10
0
        private Commands.GuiReportPlanStatus BuildGuiReportPlanStatus(Commands.OperationStatus status)
        {
            Commands.GuiReportPlanStatus data = null;

            if (RunningOperation is BackupOperation)
            {
                BackupOperation   op   = RunningOperation as BackupOperation;
                Models.BackupPlan plan = Model as Models.BackupPlan;
                data = new Commands.GuiReportPlanStatus
                {
                    Status              = status,
                    StartedAt           = op.StartedAt,
                    FinishedAt          = op.FinishedAt,
                    LastRunAt           = plan.LastRunAt,
                    LastSuccessfulRunAt = plan.LastSuccessfulRunAt,
                    //Sources = op.Sources,
                };

                // Sources
                if (status == Commands.OperationStatus.PROCESSING_FILES_FINISHED ||
                    status == Commands.OperationStatus.FINISHED ||
                    status == Commands.OperationStatus.FAILED ||
                    status == Commands.OperationStatus.CANCELED)
                {
                    data.Sources = op.Sources;
                }
            }
            else if (RunningOperation is RestoreOperation)
            {
                RestoreOperation   op   = RunningOperation as RestoreOperation;
                Models.RestorePlan plan = Model as Models.RestorePlan;
                data = new Commands.GuiReportPlanStatus
                {
                    Status              = status,
                    StartedAt           = op.StartedAt,
                    FinishedAt          = op.FinishedAt,
                    LastRunAt           = plan.LastRunAt,
                    LastSuccessfulRunAt = plan.LastSuccessfulRunAt,
                    //Sources = op.Sources,
                };

                // Sources
                if (status == Commands.OperationStatus.PROCESSING_FILES_FINISHED ||
                    status == Commands.OperationStatus.FINISHED ||
                    status == Commands.OperationStatus.FAILED ||
                    status == Commands.OperationStatus.CANCELED)
                {
                    data.Sources = op.Sources;
                }
            }
            else
            {
                string message = string.Format("Type {0} is not handled", RunningOperation.GetType().FullName);
                throw new NotImplementedException(message);
            }

            return(data);
        }
Example #11
0
        public RestorePlanGiveNameForm()
        {
            InitializeComponent();
            this.ModelChangedEvent += (sender, args) => {
                this.Plan = args.Model as Models.RestorePlan;

                // Setup data bindings
                textBox1.DataBindings.Clear();
                textBox1.DataBindings.Add(new Binding("Text", this.Plan,
                                                      this.GetPropertyName((Models.RestorePlan x) => x.Name)));
            };
        }
Example #12
0
 private void cbAmazonS3_SelectionChangeCommitted(object sender, EventArgs e)
 {
     if (cbAmazonS3.SelectedIndex == 0)
     {
         MessageBox.Show("Show <Create new account> window.");
     }
     else
     {
         Models.RestorePlan plan = Model as Models.RestorePlan;
         plan.StorageAccountType = Models.EStorageAccountType.AmazonS3;
         plan.StorageAccount     = _s3dao.Get((int)cbAmazonS3.SelectedValue);
     }
 }
Example #13
0
        private void llblEditPlan_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Models.RestorePlan plan = this.Model as Models.RestorePlan;

            using (var presenter = new NewRestorePlanPresenter(plan))
            {
                presenter.ShowDialog(this.ParentForm);
            }

            // Reload after edit is complete.
            //plan.InvalidateCachedSelectedSourcesAsDelimitedString();
            //UpdateStatusInfo(Commands.OperationStatus.QUERY);
            Provider.Handler.Send(Commands.ServerQueryPlan("restore", plan.Id.Value));
        }
Example #14
0
 private void cbFileSystem_SelectionChangeCommitted(object sender, EventArgs e)
 {
     if (cbFileSystem.SelectedIndex == 0)
     {
         MessageBox.Show("Show <Create new account> window.");
     }
     else
     {
         Models.RestorePlan plan = Model as Models.RestorePlan;
         plan.StorageAccountType = Models.EStorageAccountType.FileSystem;
         //plan.StorageAccount = new CloudStorageAccount { Id = (int)cbFileSystem.SelectedValue };
         throw new NotImplementedException();
     }
 }
Example #15
0
        protected override void OnBeforeNextOrFinish(object sender, CancelEventArgs e)
        {
            Models.RestorePlan plan = Model as Models.RestorePlan;

            ICollection <Models.RestorePlanSourceEntry> entries = tvFiles.GetCheckedTagData().ToRestorePlanSourceEntry(plan, _dao);

            plan.SelectedSources.Clear();
            plan.SelectedSources.AddRange(entries);

            if (DoValidate && !IsValid())
            {
                e.Cancel = true;
                this.ShowErrorMessage("Please, select a source.");
            }
            base.OnBeforeNextOrFinish(sender, e);
        }
Example #16
0
        private void llblDeletePlan_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Models.RestorePlan plan = Model as Models.RestorePlan;

            DialogResult result = MessageBox.Show(
                "Are you sure you want to delete this plan?",
                string.Format("Deleting {0}", plan.Name),
                MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                MessageBoxDefaultButton.Button1);

            if (result == DialogResult.Yes)
            {
                _daoRestorePlan.Delete(plan);
                Model = null;
                OnDelete(this, e);
            }
        }
Example #17
0
        public bool ControlsAlreadyContainControlForPlan(Models.RestorePlan plan)
        {
            foreach (Control ctrl in this.layoutPanel.Controls)
            {
                if (!(ctrl is RestorePlanViewControl))
                {
                    continue;
                }

                RestorePlanViewControl obj     = ctrl as RestorePlanViewControl;
                Models.RestorePlan     objPlan = obj.Model as Models.RestorePlan;

                if (objPlan.Id.Equals(plan.Id))
                {
                    return(true);
                }
            }
            return(false);
        }
Example #18
0
        public NewRestorePlanPresenter(Models.RestorePlan plan)
        {
            IsEditingModel = true;
            Model          = plan;

            WizardFormOptions options = new WizardFormOptions {
                DoValidate = true
            };

            // Only show `RestorePlanSelectAccountForm` if the `StorageAccount` is not already informed.
            if (plan.StorageAccount == null || !plan.StorageAccount.Id.HasValue)
            {
                RegisterFormClass(typeof(RestorePlanSelectAccountForm), options);
            }
            RegisterFormClass(typeof(RestorePlanGiveNameForm), options);
            RegisterFormClass(typeof(RestorePlanSelectSourceForm), options);
            RegisterFormClass(typeof(SchedulablePlanForm <Models.RestorePlan>), options);
            RegisterFormClass(typeof(NotificationOptionsForm <Models.RestorePlan>), options);
        }
Example #19
0
        private void OnReportPlanStatus(object sender, GuiCommandEventArgs e)
        {
            string planType = e.Command.GetArgumentValue <string>("planType");

            if (this.Model == null || !planType.Equals("restore"))
            {
                return;
            }

            Models.RestorePlan plan = this.Model as Models.RestorePlan;

            Int32 planId = e.Command.GetArgumentValue <Int32>("planId");

            if (planId != plan.Id)
            {
                return;
            }

            Commands.GuiReportPlanStatus report = e.Command.GetArgumentValue <Commands.GuiReportPlanStatus>("report");
            UpdatePlanInfo(report);
        }
Example #20
0
        public RestorePlanSelectSourceForm()
        {
            InitializeComponent();
            loadingPanel.Dock           = DockStyle.Fill;
            tvFiles.ExpandFetchStarted += (object sender, EventArgs e) =>
            {
                //loadingPanel.Visible = true;
            };
            tvFiles.ExpandFetchEnded += (object sender, EventArgs e) =>
            {
                //loadingPanel.Visible = false;
            };

            this.ModelChangedEvent += (object sender, Teltec.Forms.Wizard.WizardForm.ModelChangedEventArgs e) =>
            {
                Models.RestorePlan plan = e.Model as Models.RestorePlan;
                tvFiles.StorageAccount = plan.StorageAccount;
                // Lazily select nodes that match entries from `plan.SelectedSources`.
                tvFiles.CheckedDataSource = RestorePlanSelectedSourcesToCheckedDataSource(plan);
            };
        }
Example #21
0
        public RestorePlanSelectAccountForm()
        {
            InitializeComponent();

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

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

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

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

                    if (this.Plan.StorageAccount != null)
                    {
                        SelectExistingAccount(this.Plan.StorageAccountType, this.Plan.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)));
        }
Example #22
0
        //
        // Loads or creates `RestorePlanFile`s for each file in `files`.
        // Returns the complete list of `RestorePlanFile`s that are related to `files`.
        // NOTE: Does not save to the database because this method is run by a secondary thread.
        //
        private LinkedList <Models.RestorePlanFile> DoLoadOrCreateRestorePlanFiles(Models.RestorePlan plan, LinkedList <CustomVersionedFile> files)
        {
            Assert.IsNotNull(plan);
            Assert.IsNotNull(files);
            Assert.IsNotNull(AllFilesFromPlan);

            LinkedList <Models.RestorePlanFile> result      = new LinkedList <Models.RestorePlanFile>();
            BackupPlanPathNodeRepository        daoPathNode = new BackupPlanPathNodeRepository();

            // Check all files.
            foreach (CustomVersionedFile file in files)
            {
                // Throw if the operation was canceled.
                CancellationToken.ThrowIfCancellationRequested();

                //
                // Create or update `RestorePlanFile`.
                //
                Models.RestorePlanFile restorePlanFile = null;
                bool backupPlanFileAlreadyExists       = AllFilesFromPlan.TryGetValue(file.Path, out restorePlanFile);

                if (!backupPlanFileAlreadyExists)
                {
                    restorePlanFile           = new Models.RestorePlanFile(plan, file.Path);
                    restorePlanFile.CreatedAt = DateTime.UtcNow;
                }

                Models.BackupPlanPathNode pathNode = daoPathNode.GetByStorageAccountAndTypeAndPath(plan.StorageAccount, Models.EntryType.FILE, file.Path);
                Assert.IsNotNull(pathNode, string.Format("{0} has no corresponding {1}", file.Path, typeof(Models.BackupPlanPathNode).Name));
                restorePlanFile.PathNode      = pathNode;
                restorePlanFile.VersionedFile = file;
                result.AddLast(restorePlanFile);
            }

            return(result);
        }
Example #23
0
 public Restore(RestorePlan plan)
     : this()
 {
     _RestorePlan = plan;
     //StatusInfo = new RestoreStatusInfo();
 }
Example #24
0
        private void UpdatePlanInfo(Commands.GuiReportPlanStatus report)
        {
            CurrentOperation.Status = report.Status;

            switch (report.Status)
            {
            default: return;                     // TODO(jweyrich): Somehow report unexpected status?

            case Commands.OperationStatus.NOT_RUNNING:
            case Commands.OperationStatus.INTERRUPTED:
            {
                Models.RestorePlan plan = Model as Models.RestorePlan;

                //this.lblSources.Text = report.Sources;
                this.llblRunNow.Text = report.Status == Commands.OperationStatus.NOT_RUNNING
                                                        ? LBL_RUNNOW_STOPPED : LBL_RUNNOW_RESUME;
                this.llblRunNow.Enabled = true;
                this.lblStatus.Text     = report.Status == Commands.OperationStatus.NOT_RUNNING
                                                        ? LBL_STATUS_STOPPED : LBL_STATUS_INTERRUPTED;
                this.lblDuration.Text          = LBL_DURATION_INITIAL;
                this.lblFilesTransferred.Text  = LBL_FILES_TRANSFER_STOPPED;
                this.llblEditPlan.Enabled      = true;
                this.llblDeletePlan.Enabled    = true;
                this.lblLastRun.Text           = PlanCommon.Format(CurrentOperation.LastRunAt);
                this.lblLastSuccessfulRun.Text = PlanCommon.Format(CurrentOperation.LastSuccessfulRunAt);
                //this.lblTitle.Text = PlanCommon.FormatTitle(plan.Name);
                //this.lblSchedule.Text = plan.ScheduleType.ToString();

                break;
            }

            case Commands.OperationStatus.STARTED:
            case Commands.OperationStatus.RESUMED:
            {
                Models.RestorePlan plan = Model as Models.RestorePlan;

                CurrentOperation.StartedAt           = report.StartedAt;
                CurrentOperation.LastRunAt           = report.LastRunAt;
                CurrentOperation.LastSuccessfulRunAt = report.LastSuccessfulRunAt;

                this.lblSources.Text          = this.lblSources.Text = plan.SelectedSourcesAsDelimitedString(", ", 50, "...");                        // Duplicate from BackupOperation.cs - Sources property
                this.llblRunNow.Text          = LBL_RUNNOW_RUNNING;
                this.llblRunNow.Enabled       = true;
                this.lblStatus.Text           = LBL_STATUS_STARTED;
                this.lblDuration.Text         = LBL_DURATION_STARTED;
                this.lblFilesTransferred.Text = string.Format("{0} of {1} ({2} / {3})",
                                                              0, 0,
                                                              FileSizeUtils.FileSizeToString(0),
                                                              FileSizeUtils.FileSizeToString(0));
                this.llblEditPlan.Enabled      = false;
                this.llblDeletePlan.Enabled    = false;
                this.lblLastRun.Text           = PlanCommon.Format(CurrentOperation.LastRunAt);
                this.lblLastSuccessfulRun.Text = PlanCommon.Format(CurrentOperation.LastSuccessfulRunAt);
                //this.lblTitle.Text = PlanCommon.FormatTitle(plan.Name);
                //this.lblSchedule.Text = plan.ScheduleType.ToString();

                CurrentOperation.GotInitialInfo = true;
                CurrentOperation.StartTimer();
                break;
            }

            case Commands.OperationStatus.SCANNING_FILES_STARTED:
            {
                this.lblSources.Text = "Scanning files...";
                break;
            }

            case Commands.OperationStatus.SCANNING_FILES_FINISHED:
            {
                break;
            }

            case Commands.OperationStatus.PROCESSING_FILES_STARTED:
            {
                this.lblSources.Text        = "Processing files...";
                this.llblRunNow.Text        = LBL_RUNNOW_RUNNING;
                this.llblRunNow.Enabled     = true;
                this.lblStatus.Text         = LBL_STATUS_STARTED;
                this.llblEditPlan.Enabled   = false;
                this.llblDeletePlan.Enabled = false;
                break;
            }

            case Commands.OperationStatus.PROCESSING_FILES_FINISHED:
            {
                this.lblSources.Text        = report.Sources;
                this.llblRunNow.Text        = LBL_RUNNOW_RUNNING;
                this.llblRunNow.Enabled     = true;
                this.lblStatus.Text         = LBL_STATUS_STARTED;
                this.llblEditPlan.Enabled   = false;
                this.llblDeletePlan.Enabled = false;
                //this.lblFilesTransferred.Text = string.Format("{0} of {1} ({2} / {3})",
                //	progress.Completed, progress.Total,
                //	FileSizeUtils.FileSizeToString(progress.BytesCompleted),
                //	FileSizeUtils.FileSizeToString(progress.BytesTotal));
                break;
            }

            case Commands.OperationStatus.UPDATED:
            {
                // Should be handled by another command.
                break;
            }

            case Commands.OperationStatus.FINISHED:
            {
                CurrentOperation.FinishedAt          = report.FinishedAt;
                CurrentOperation.LastRunAt           = report.LastRunAt;
                CurrentOperation.LastSuccessfulRunAt = report.LastSuccessfulRunAt;
                UpdateDuration(report.Status);

                this.lblSources.Text    = report.Sources;
                this.llblRunNow.Text    = LBL_RUNNOW_STOPPED;
                this.llblRunNow.Enabled = true;
                this.lblStatus.Text     = LBL_STATUS_COMPLETED;
                //this.lblDuration.Text = LBL_DURATION_INITIAL;
                //this.lblFilesTransferred.Text = LBL_FILES_TRANSFER_STOPPED;
                this.llblEditPlan.Enabled      = true;
                this.llblDeletePlan.Enabled    = true;
                this.lblLastRun.Text           = PlanCommon.Format(CurrentOperation.LastRunAt);
                this.lblLastSuccessfulRun.Text = PlanCommon.Format(CurrentOperation.LastSuccessfulRunAt);
                //this.lblTitle.Text = PlanCommon.FormatTitle(plan.Name);
                //this.lblSchedule.Text = plan.ScheduleType.ToString();

                CurrentOperation.Reset();
                break;
            }

            case Commands.OperationStatus.FAILED:
            case Commands.OperationStatus.CANCELED:
            {
                CurrentOperation.FinishedAt = report.LastRunAt;
                CurrentOperation.LastRunAt  = report.LastRunAt;
                UpdateDuration(report.Status);

                this.lblSources.Text    = report.Sources;
                this.llblRunNow.Text    = LBL_RUNNOW_STOPPED;
                this.llblRunNow.Enabled = true;
                this.lblStatus.Text     = report.Status == Commands.OperationStatus.CANCELED ? LBL_STATUS_CANCELED : LBL_STATUS_FAILED;
                //this.lblDuration.Text = LBL_DURATION_INITIAL;
                //this.lblFilesTransferred.Text = LBL_FILES_TRANSFER_STOPPED;
                this.llblEditPlan.Enabled   = true;
                this.llblDeletePlan.Enabled = true;
                this.lblLastRun.Text        = PlanCommon.Format(CurrentOperation.LastRunAt);
                //this.lblLastSuccessfulRun.Text = PlanCommon.Format(CurrentOperation.LastSuccessfulRunAt);
                //this.lblTitle.Text = PlanCommon.FormatTitle(plan.Name);
                //this.lblSchedule.Text = plan.ScheduleType.ToString();

                CurrentOperation.Reset();
                break;
            }
            }
        }
Example #25
0
 public NewRestoreOperation(Models.RestorePlan plan, RestoreOperationOptions options)
     : base(options)
 {
     Restore = new Models.Restore(plan);
 }
Example #26
0
 private Dictionary <string, BackupPlanTreeNodeData> RestorePlanSelectedSourcesToCheckedDataSource(Models.RestorePlan plan)
 {
     return(plan.SelectedSources.ToDictionary(
                e => e.Path,
                e => new BackupPlanTreeNodeData
     {
         Id = e.Id,
         StorageAccount = plan.StorageAccount,
         Type = Models.EntryTypeExtensions.ToTypeEnum(e.Type),
         Path = e.Path,
         State = Teltec.Common.Controls.CheckState.Checked,
         InfoObject = new EntryInfo(Models.EntryTypeExtensions.ToTypeEnum(e.Type), e.PathNode.Name, e.Path, new FileVersion {
             Version = e.Version
         })
     }
                ));
 }
Example #27
0
 public RestorePlanFile(RestorePlan plan, string path)
     : this(plan)
 {
     _Path = path;
 }
Example #28
0
 public RestorePlanFile(RestorePlan plan)
     : this()
 {
     _RestorePlan = plan;
 }
Example #29
0
        private void RestoreUpdateStatsInfo(RestoreOperationStatus status, TransferStatus xferStatus)
        {
            if (RunningOperation == null)
            {
                return;
            }

            Models.RestorePlan     plan      = Model as Models.RestorePlan;
            RestoreOperation       operation = RunningOperation as RestoreOperation;
            RestoreOperationReport report    = operation.Report;

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

            case RestoreOperationStatus.Unknown:
            {
                break;
            }

            case RestoreOperationStatus.Started:
            case RestoreOperationStatus.Resumed:
            {
                logger.Info("{0} restore", status == RestoreOperationStatus.Resumed ? "Resuming" : "Starting");

                // Update timestamps.
                plan.LastRunAt = DateTime.UtcNow;
                _daoRestorePlan.Update(plan);

                // Report
                Commands.OperationStatus cmdStatus = status == RestoreOperationStatus.Started
                                                        ? Commands.OperationStatus.STARTED : Commands.OperationStatus.RESUMED;
                Commands.GuiReportPlanStatus cmdData = BuildGuiReportPlanStatus(cmdStatus);
                string cmd = Commands.GuiReportOperationStatus("restore", plan.Id.Value, cmdData);
                Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd);
                break;
            }

            case RestoreOperationStatus.ScanningFilesStarted:
            {
                logger.Info("Scanning files...");

                // Report
                Commands.OperationStatus     cmdStatus = Commands.OperationStatus.SCANNING_FILES_STARTED;
                Commands.GuiReportPlanStatus cmdData   = BuildGuiReportPlanStatus(cmdStatus);
                string cmd = Commands.GuiReportOperationStatus("restore", plan.Id.Value, cmdData);
                Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd);
                break;
            }

            case RestoreOperationStatus.ScanningFilesFinished:
            {
                logger.Info("Scanning files finished.");

                // Report
                Commands.OperationStatus     cmdStatus = Commands.OperationStatus.SCANNING_FILES_FINISHED;
                Commands.GuiReportPlanStatus cmdData   = BuildGuiReportPlanStatus(cmdStatus);
                string cmd = Commands.GuiReportOperationStatus("restore", plan.Id.Value, cmdData);
                Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd);
                break;
            }

            case RestoreOperationStatus.ProcessingFilesStarted:
            {
                logger.Info("Processing files...");

                // Report
                Commands.OperationStatus     cmdStatus = Commands.OperationStatus.PROCESSING_FILES_STARTED;
                Commands.GuiReportPlanStatus cmdData   = BuildGuiReportPlanStatus(cmdStatus);
                Handler.Send(Commands.GuiReportOperationStatus("restore", plan.Id.Value, cmdData));
                break;
            }

            case RestoreOperationStatus.ProcessingFilesFinished:
            {
                logger.Info("Processing files finished.");
                logger.Info("Completed: {0} of {1}", report.TransferResults.Stats.Completed, report.TransferResults.Stats.Total);

                // Report
                Commands.OperationStatus cmdStatus = Commands.OperationStatus.PROCESSING_FILES_FINISHED;
                // Report sources
                Commands.GuiReportPlanStatus cmdData1 = BuildGuiReportPlanStatus(cmdStatus);
                string cmd1 = Commands.GuiReportOperationStatus("restore", plan.Id.Value, cmdData1);
                Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd1);
                // Report counts
                Commands.GuiReportPlanProgress cmdData2 = BuildGuiReportPlanProgress(cmdStatus);
                string cmd2 = Commands.GuiReportOperationProgress("restore", plan.Id.Value, cmdData2);
                Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd2);
                break;
            }

            case RestoreOperationStatus.Finished:
            {
                //var message = string.Format(
                //	"Restore {0}! Stats: {1} completed, {2} failed, {3} canceled, {4} pending, {5} running",
                //	"finished",
                //	TransferResults.Stats.Completed, TransferResults.Stats.Failed,
                //	TransferResults.Stats.Canceled, TransferResults.Stats.Pending,
                //	TransferResults.Stats.Running);
                //logger.Info(message);

                // Update success timestamp.
                plan.LastSuccessfulRunAt = DateTime.UtcNow;
                _daoRestorePlan.Update(plan);

                // Signal to the other thread it may terminate.
                RunningOperationEndedEvent.Set();

                // Report
                Commands.OperationStatus     cmdStatus = Commands.OperationStatus.FINISHED;
                Commands.GuiReportPlanStatus cmdData   = BuildGuiReportPlanStatus(cmdStatus);
                string cmd = Commands.GuiReportOperationStatus("restore", plan.Id.Value, cmdData);
                Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd);
                break;
            }

            case RestoreOperationStatus.Updated:
            {
                if (xferStatus == TransferStatus.COMPLETED || xferStatus == TransferStatus.CANCELED || xferStatus == TransferStatus.FAILED)
                {
                    logger.Info("Completed: {0} of {1}", report.TransferResults.Stats.Completed, report.TransferResults.Stats.Total);
                }

                // Report
                Commands.OperationStatus       cmdStatus = Commands.OperationStatus.UPDATED;
                Commands.GuiReportPlanProgress cmdData   = BuildGuiReportPlanProgress(cmdStatus);
                string cmd = Commands.GuiReportOperationProgress("restore", plan.Id.Value, cmdData);
                Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd);
                break;
            }

            case RestoreOperationStatus.Failed:
            case RestoreOperationStatus.Canceled:
            {
                //var message = string.Format(
                //	"Restore {0}! Stats: {1} completed, {2} failed, {3} canceled, {4} pending, {5} running",
                //	status == RestoreOperationStatus.Failed ? "failed" : "was canceled",
                //	TransferResults.Stats.Completed, TransferResults.Stats.Failed,
                //	TransferResults.Stats.Canceled, TransferResults.Stats.Pending,
                //	TransferResults.Stats.Running);
                //logger.Info(message);

                // Signal to the other thread it may terminate.
                RunningOperationEndedEvent.Set();

                // Report
                Commands.OperationStatus cmdStatus = status == RestoreOperationStatus.Failed
                                                        ? Commands.OperationStatus.FAILED : Commands.OperationStatus.CANCELED;
                Commands.GuiReportPlanStatus cmdData = BuildGuiReportPlanStatus(cmdStatus);
                string cmd = Commands.GuiReportOperationStatus("restore", plan.Id.Value, cmdData);
                Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd);
                break;
            }
            }
        }
Example #30
0
 public NewRestoreOperation(Models.RestorePlan plan)
     : this(plan, new RestoreOperationOptions())
 {
 }