Inheritance: ObservableObject
        public ProgressOperationControl(ProgressOperationsManager manager, ProgressOperation operation)
        {
            this.Tag = operation;
            this.Operation = operation;
            this.manager = manager;
            this.Height = 2;
            messageAndOperationsPanel = Add(new StackPanel() { Orientation = Orientation.Vertical }).Fill();

            messageLabel = messageAndOperationsPanel.Add(new Label() { Mode = LabelRenderMode.ManualSizing }).FillHoriontally();
            messageLabel.CanFocus = true;

            messageLabel.KeyInputReceived.SubscribeForLifetime((k) =>
            {
                if (k.Key == ConsoleKey.Enter)
                {
                    var msg = operation.Message;
                    if (operation.Details != null)
                    {
                        msg += "\n" + operation.Details;
                    }
                    Dialog.ShowMessage(msg);
                }
                else if(k.Key == ConsoleKey.Delete)
                {
                    var app = Application;
                    manager.Operations.Remove(operation);
                    app.FocusManager.TryMoveFocus();
                }
            }, this.LifetimeManager);

            actionPanel = messageAndOperationsPanel.Add(new StackPanel() { Orientation = Orientation.Horizontal, Height = 1, Margin = 2 }).FillHoriontally(messageAndOperationsPanel);
            spinner = actionPanel.Add(new Spinner() { CanFocus=false});
            timeLabel = actionPanel.Add(new Label() { Mode = LabelRenderMode.SingleLineAutoSize, Text = operation.StartTime.ToFriendlyPastTimeStamp().ToConsoleString() });

            spinner.IsSpinning = operation.State == OperationState.InProgress;

            foreach (var action in operation.Actions)
            {
                BindActionToActionPanel(action);
            }

            AddedToVisualTree.SubscribeForLifetime(OnAddedToVisualTree, this.LifetimeManager);
        }
Example #2
0
        private void BeginDeleteSelectedEntityIfExists()
        {
            if (Grid.SelectedItem == null)
            {
                return;
            }

            var rowKey = (Grid.SelectedItem as ITableEntity).RowKey;

            Dialog.ConfirmYesOrNo("Are you sure you want to delete entity ".ToConsoleString() + rowKey.ToConsoleString(ConsoleColor.Yellow) + "?", () =>
             {
                 var entityToDelete = Grid.SelectedItem as ITableEntity;

                 ProgressOperation operation = new ProgressOperation()
                 {
                     State = OperationState.InProgress,
                     Message = "Deleting entity ".ToConsoleString() + rowKey.ToConsoleString(Application.Theme.H1Color) + " from table " + table.Name,
                 };

                 ProgressOperationManager.Operations.Add(operation);

                 var applicationRef = Application;
                 Application.QueueAsyncAction(table.ExecuteAsync(TableOperation.Delete(entityToDelete)), (t) =>
                 {
                      if (t.Exception != null)
                      {
                          operation.Message = "Failed to delete entity ".ToConsoleString(ConsoleColor.Red) + rowKey.ToConsoleString(applicationRef.Theme.H1Color) + " from table " + table.Name;
                          operation.Details = t.Exception.ToString().ToConsoleString();
                          operation.State = OperationState.Failed;
                      }
                      else
                      {
                          operation.Message = "Finished deleting entity ".ToConsoleString() + rowKey.ToConsoleString(applicationRef.Theme.H1Color) + " from table " + table.Name;
                          operation.State = OperationState.Completed;
                      }

                     Grid.NoVisibleColumnsMessage = "Loading...";
                     Grid.DataSource.ClearCachedData();
                     Grid.Refresh();
                  });
             });
        }
 private void Operations_Removed(ProgressOperation operation)
 {
     var toRemove = operationsStackPanel.Controls.Where(c => c.Tag == operation).Single();
     operationsStackPanel.Controls.Remove(toRemove);
 }
 private void Operations_Added(ProgressOperation operation)
 {
     operationsStackPanel.Controls.Insert(0, new ProgressOperationControl(manager, operation).FillHoriontally(operationsStackPanel));
 }
        private void DeleteSelectedBlob()
        {
            Dialog.ConfirmYesOrNo("Are you sure you want ot delete blob " + (Grid.SelectedItem as CloudBlob).Name + "?", () =>
            {
                var operation = new ProgressOperation()
                {
                    Message = "Deleting blob ".ToConsoleString() + (Grid.SelectedItem as CloudBlob).Name.ToConsoleString(ConsoleColor.Yellow),
                    State = OperationState.InProgress
                };

                Application.QueueAsyncAction((Grid.SelectedItem as CloudBlob).DeleteAsync(), (tp) =>
                {
                    if(tp.Exception != null)
                    {
                        operation.State = OperationState.Failed;
                        operation.Details = tp.Exception.ToString().ToConsoleString();
                        operation.Message = "Failed to delete blob ".ToConsoleString() + (Grid.SelectedItem as CloudBlob).Name.ToConsoleString(ConsoleColor.Yellow);

                    }
                    else
                    {
                        operation.State = OperationState.Completed;
                        operation.Message = "Finished deleting blob ".ToConsoleString() + (Grid.SelectedItem as CloudBlob).Name.ToConsoleString(ConsoleColor.Yellow);
                    }

                    if (Application != null && PageStack.CurrentPage == this)
                    {
                        PageStack.TryRefresh();
                    }
                });
            });
        }
        private void UploadBlob()
        {
            Dialog.ShowTextInput("Choose file".ToConsoleString(), (f) =>
            {
                var operation = new ProgressOperation()
                {
                    Message = "Uploading file ".ToConsoleString()+f.ToConsoleString(),
                    State = OperationState.Scheduled
                };

                ProgressOperationManager.Operations.Add(operation);

                if (File.Exists(f.ToString()) == false)
                {
                    operation.State = OperationState.Failed;
                    operation.Message = "File not found - ".ToConsoleString()+f;
                }
                else
                {
                    Dialog.ShowTextInput("Enter blob prefix".ToConsoleString(), (pre) =>
                    {
                        var blobPath = System.IO.Path.Combine(pre.ToString(), System.IO.Path.GetFileName(f.ToString()));
                        var blob = container.GetBlockBlobReference(blobPath);
                        Application.QueueAsyncAction(blob.UploadFromFileAsync(f.ToString(), FileMode.Open), (t) =>
                        {
                            if(t.Exception != null)
                            {
                                operation.State = OperationState.Failed;
                                operation.Message = operation.Message = "Failed to upload file ".ToConsoleString() + f.ToConsoleString();
                                operation.Details = t.Exception.ToString().ToConsoleString();
                            }
                            else
                            {
                                operation.State = OperationState.Completed;
                                operation.Message = operation.Message = "Finished uploading file ".ToConsoleString() + f.ToConsoleString();

                                if(Application != null && PageStack.CurrentPage == this)
                                {
                                    PageStack.TryRefresh();
                                }
                            }
                        });
                    },
                    ()=>
                    {
                        operation.State = OperationState.CompletedWithWarnings;
                        operation.Message = "Cancelled uploading file ".ToConsoleString() + f.ToConsoleString();
                    });
                }
            });
        }
        private void OpenSelectedBlob()
        {
            var blob = Grid.SelectedItem as CloudBlob;
            var tempFile = System.IO.Path.Combine(System.IO.Path.GetTempPath(), GetFileName(blob));

            var operation = new ProgressOperation()
            {
                State = OperationState.InProgress,
                Message = "Downloading blob ".ToConsoleString()+blob.Uri.ToString().ToConsoleString(ConsoleColor.Cyan)
            };

            ProgressOperationManager.Operations.Add(operation);

            Application.QueueAsyncAction(blob.DownloadToFileAsync(tempFile, FileMode.OpenOrCreate), (t) =>
            {
                if (t.Exception != null)
                {
                    operation.State = OperationState.Failed;
                    operation.Message = "Failed to delete blob ".ToConsoleString() + blob.Uri.ToString().ToConsoleString(ConsoleColor.Cyan);
                    operation.Details = t.Exception.ToString().ToConsoleString();
                }
                else
                {
                    operation.State = OperationState.Completed;
                    operation.Message = "Fiinished downloading blob ".ToConsoleString() + blob.Uri.ToString().ToConsoleString(ConsoleColor.Cyan);
                    operation.Details = "The downloaded file is located here: ".ToConsoleString() + tempFile.ToConsoleString(ConsoleColor.Cyan);
                    Process.Start(tempFile);
                }
            });
        }