Пример #1
0
        private static BackupResult ToResult(IProgressItem task)
        {
            if (task == null)
            {
                return(null);
            }

            if (task.Error != null)
            {
                throw new FaultException(((Exception)task.Error).Message);
            }

            var result = new BackupResult
            {
                Id        = task.Id.ToString(),
                Completed = task.IsCompleted,
                Percent   = (int)task.Percentage,
            };

            var backupTask = task as BackupTask;

            if (backupTask != null)
            {
                result.Link       = task.Status as string;
                result.ExpireDate = backupTask.ExpireDate;
            }
            return(result);
        }
Пример #2
0
        private static BackupProgress ToBackupProgress(IProgressItem progressItem)
        {
            if (progressItem == null)
            {
                return(null);
            }

            var progress = new BackupProgress
            {
                IsCompleted = progressItem.IsCompleted,
                Progress    = (int)progressItem.Percentage,
                Error       = progressItem.Error != null ? ((Exception)progressItem.Error).Message : null
            };

            var backupProgressItem = progressItem as BackupProgressItem;

            if (backupProgressItem != null)
            {
                progress.Link = backupProgressItem.Link;
            }
            else
            {
                var transferProgressItem = progressItem as TransferProgressItem;
                if (transferProgressItem != null)
                {
                    progress.Link = transferProgressItem.Link;
                }
            }

            return(progress);
        }
 /// <summary>
 /// Determines whether <see cref="ActiveItems"/> contains the progress item.
 /// </summary>
 /// <param name="item">The progress item.</param>
 /// <returns><c>true</c> if <see cref="ActiveItems"/> contains the progress item; otherwise, <c>false</c>.</returns>
 public bool Contains(IProgressItem item)
 {
     lock (this.activeItems)
     {
         return(this.activeItems.Contains(item));
     }
 }
Пример #4
0
        /// <summary>
        /// Initializes the progress item view model.
        /// </summary>
        /// <param name="progItem">The progress item.</param>
        protected void Initialize(IProgressItem progItem)
        {
            this.ReleaseProgressItem();

            this.progressItem = progItem;

            if (this.progressItem == null)
            {
                this.Title      = string.Empty;
                this.Text       = string.Empty;
                this.Percentage = 0;
                this.cancelCommand.IsExecutable = false;

                this.IsBusy = false;
            }
            else
            {
                this.Title      = this.progressItem.Title;
                this.Text       = this.progressItem.Text;
                this.Percentage = this.progressItem.Percentage;
                this.cancelCommand.IsExecutable = this.progressItem.CancelEnabled;

                this.progressItem.Changed   += this.ProgressItemChangedHandler;
                this.progressItem.Canceled  += this.ProgressItemCanceledHandler;
                this.progressItem.Completed += this.ProgressItemCompletedHandler;

                this.IsBusy = true;
            }
        }
Пример #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProgressItemVm" /> class.
        /// </summary>
        /// <param name="progressItem">The progress item.</param>
        public ProgressItemVm(IProgressItem progressItem)
        {
            this.cancelCommand = new DelegateCommand(this.Cancel);

            this.progressItem = null;

            this.Initialize(progressItem);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ProgressBarVm" /> class.
        /// </summary>
        /// <param name="progressItem">The progress item.</param>
        public ProgressBarVm(IProgressItem progressItem)
        {
            this.CancelButtonVisibility = Visibility.Collapsed;
            this.cancelCommand          = new DelegateCommand(this.Cancel);

            this.progressItem = null;

            this.UpdateProgressItem(progressItem);
        }
        /// <summary>
        /// Releases the progress item.
        /// </summary>
        private void ReleaseProgressItem()
        {
            if (this.progressItem != null)
            {
                this.progressItem.Changed   -= this.ProgressItemChangedHandler;
                this.progressItem.Canceled  -= this.ProgressItemCanceledHandler;
                this.progressItem.Completed -= this.ProgressItemCompletedHandler;

                this.progressItem = null;
            }
        }
Пример #8
0
        /// <summary>
        /// Removes a progress item.
        /// </summary>
        /// <param name="progItem">The progress item.</param>
        public void Remove(IProgressItem progItem)
        {
            foreach (var progressItemViewModel in this.Items)
            {
                if (progressItemViewModel.ProgressItem == progItem)
                {
                    progressItemViewModel.Completed -= this.ProgressItemCompletedHandler;
                    this.Items.Remove(progressItemViewModel);

                    this.IsBusy = this.Items.Count > 0;

                    return;
                }
            }
        }
        /// <summary>
        /// Called when a progress item is removed.
        /// </summary>
        /// <param name="item">The progress item, which has been removed.</param>
        private void OnItemRemoved(IProgressItem item)
        {
            if (Logger.IsDebugEnabled)
            {
                var message = string.Format(CultureInfo.CurrentUICulture, Resources.ProgressItemWithTitle_HasBeenRemovedFromProgressList, item.Title);
                Logger.Debug(message);
            }

            var itemRemoved = this.ItemRemoved;

            if (itemRemoved != null)
            {
                itemRemoved(null, new ProgressEventArgs(item));
            }
        }
        /// <summary>
        /// Updates the progress item.
        /// </summary>
        /// <param name="progItem">The progress item.</param>
        public void UpdateProgressItem(IProgressItem progItem)
        {
            if (this.CheckAccess())
            {
                this.ReleaseProgressItem();

                this.progressItem = progItem;

                if (this.progressItem == null)
                {
                    this.Title      = string.Empty;
                    this.Subtitle   = string.Empty;
                    this.Percentage = 0;
                    this.cancelCommand.IsExecutable = false;
                    this.CancelButtonVisibility     = Visibility.Collapsed;

                    this.IsBusy = false;
                }
                else
                {
                    this.Title      = this.progressItem.Title;
                    this.Subtitle   = this.progressItem.Text;
                    this.Percentage = this.progressItem.Percentage;

                    if (this.disableCancelButton)
                    {
                        this.cancelCommand.IsExecutable = false;
                        this.CancelButtonVisibility     = Visibility.Collapsed;
                    }
                    else
                    {
                        this.CancelButtonVisibility     = Visibility.Visible;
                        this.cancelCommand.IsExecutable = this.progressItem.CancelEnabled;
                    }

                    this.progressItem.Changed   += this.ProgressItemChangedHandler;
                    this.progressItem.Canceled  += this.ProgressItemCanceledHandler;
                    this.progressItem.Completed += this.ProgressItemCompletedHandler;

                    this.IsBusy = true;
                }
            }
            else
            {
                // again, but in correct thread
                this.Dispatcher.Invoke(new Action <IProgressItem>(this.UpdateProgressItem), new[] { progItem });
            }
        }
Пример #11
0
        /// <summary>
        /// Add a progress item.
        /// </summary>
        /// <param name="progItem">The progress item.</param>
        public void Add(IProgressItem progItem)
        {
            var progressItemViewModel = new ProgressItemVm(progItem);

            this.Title      = progressItemViewModel.Title;
            this.Subtitle   = progressItemViewModel.Text;
            this.Percentage = progressItemViewModel.Percentage;

            progressItemViewModel.Completed += this.ProgressItemCompletedHandler;

            if (progressItemViewModel.IsBusy)
            {
                this.Items.Add(progressItemViewModel);
                this.IsBusy = true;
            }
            else
            {
                progressItemViewModel.Completed -= this.ProgressItemCompletedHandler;
            }
        }
        /// <summary>
        /// Called when a progress item has changed.
        /// </summary>
        /// <param name="item">The progress item, which has changed.</param>
        public void OnItemChanged(IProgressItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(@"item");
            }

            if (Logger.IsDebugEnabled)
            {
                var message = string.Format(CultureInfo.CurrentUICulture, Resources.ProgressItemWithTitle_HasChanged, item.Title);
                Logger.Debug(message);
            }

            var itemChanged = this.ItemChanged;

            if (itemChanged != null)
            {
                itemChanged(null, new ProgressEventArgs(item));
            }
        }
        /// <summary>
        /// Removes a progress item from <see cref="ActiveItems"/>.
        /// </summary>
        /// <param name="item">The item to be removed.</param>
        public void Remove(IProgressItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(@"item");
            }

            lock (this.activeItems)
            {
                if (this.activeItems.Contains(item))
                {
                    if (Logger.IsDebugEnabled)
                    {
                        var message = string.Format(CultureInfo.CurrentUICulture, Resources.RemovingProgressItemWithTitle_FromProgressList, item.Title);
                        Logger.Debug(message);
                    }

                    this.activeItems.Remove(item);
                    this.OnItemRemoved(item);
                }
            }
        }
        /// <summary>
        /// Dispose(bool disposing) executes in two distinct scenarios.
        /// If disposing equals true, the method has been called directly
        /// or indirectly by a user's code. Managed and unmanaged resources
        /// can be disposed.
        /// If disposing equals false, the method has been called by the
        /// runtime from inside the finalizer and you should not reference
        /// other objects. Only unmanaged resources can be disposed.
        /// </summary>
        /// <param name="disposing">If equals true, method is called directly or indirectly
        /// by a user's code. If equals to false, method is called by the runtime from inside
        /// a finalizer.</param>
        private void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!this.disposed)
            {
                // If disposing equals true, dispose all managed
                // and unmanaged resources.
                if (disposing)
                {
                }

                this.ProgressItem = null;
                this.host.DoEvents();

                // Call the appropriate methods to clean up
                // unmanaged resources here.
                // If disposing is false,
                // only the following code is executed.
            }

            this.disposed = true;
        }
Пример #15
0
 public BackupResult RestorePortal(int tenantID, string demoID)
 {
     lock (tasks.SynchRoot)
     {
         IProgressItem task = tasks.GetItems().FirstOrDefault(t => (int)t.Id == tenantID);
         if (task != null && task.IsCompleted)
         {
             tasks.Remove(task);
             task = null;
         }
         if (task == null)
         {
             var config     = BackupConfigurationSection.GetSection();
             var demoPortal = config.DemoPortals.GetDemoPortal(demoID) ?? config.DemoPortals.Default;
             if (demoPortal == null)
             {
                 throw new FaultException("Can't find demo portal with id = " + demoID);
             }
             task = new RestoreTask(tenantID, demoPortal.DataPath);
             tasks.Add(task);
         }
         return(ToResult(task));
     }
 }
Пример #16
0
        private static BackupResult ToResult(IProgressItem task)
        {
            if (task == null)
                return null;

            if (task.Error != null)
                throw new FaultException(((Exception)task.Error).Message);

            var result = new BackupResult
                {
                    Id = task.Id.ToString(),
                    Completed = task.IsCompleted,
                    Percent = (int)task.Percentage,
                };

            var backupTask = task as BackupTask;
            if (backupTask != null)
            {
                result.Link = task.Status as string;
                result.ExpireDate = backupTask.ExpireDate;
            }
            return result;
        }
Пример #17
0
 public ActionIndexMap(IProgressItem action)
 {
     this.Action = action;
     // index isn't known yet
     this.Index = -1;
 }
Пример #18
0
        /// <summary>
        /// Add an action to the collection
        /// </summary>
        /// <param name="action">action to be added</param>
        public void AddAction(IProgressItem action)
        {
            ActionIndexMap map = new ActionIndexMap(action);

            this.actions.Add(map);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ProgressEventArgs"/> class.
 /// </summary>
 /// <param name="item">The item.</param>
 public ProgressEventArgs(IProgressItem item)
 {
     this.Item = item;
 }