Пример #1
0
        private void btnOverwriteDestination_Click(object sender, EventArgs e)
        {
            CommandAzCopy commandAzCopy = null;

            try
            {
                commandAzCopy = CommandAzCopy.Parse(this.tbAzCopyCommand.Text, false, this._appLog);
            }
            catch (Exception ex)
            {
                HandlerForLoging.LogException(ex, this._appLog);
                //commandAzCopy = CommandAzCopy.Parse("azcopy {local-path-or-azure-storage-item-url}", null, true);
            }

            if (commandAzCopy != null)
            {
                if (commandAzCopy.SourceLocation.Contains("[T]"))
                {
                    MessageBox.Show("Source location can not contain wildcard [T]. Make sure that you selected date from dropdown box.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.tbSourceLocation.Focus();
                }
                else if ((!commandAzCopy.SourceLocation.ToLower().StartsWith("http://") &&
                          !commandAzCopy.SourceLocation.ToLower().StartsWith("https://")) &&
                         !Directory.Exists(commandAzCopy.SourceLocation))
                {
                    MessageBox.Show("Source location does not exist.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.tbSourceLocation.Focus();
                }
                else if (commandAzCopy.SourceLocation == "{local-path-or-azure-storage-item-url}")
                {
                    MessageBox.Show("Source location not specified.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.tbSourceLocation.Focus();
                }
                else if ((commandAzCopy.SourceLocation.ToLower().StartsWith("http://") ||
                          commandAzCopy.SourceLocation.ToLower().StartsWith("https://")) &&
                         (commandAzCopy.SourceKey == null || commandAzCopy.SourceKey == "{azure-storage-key}"))
                {
                    MessageBox.Show("Source key not specified.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.tbSourceKey.Focus();
                }
                else if ((!commandAzCopy.SourceLocation.ToLower().StartsWith("http://") &&
                          !commandAzCopy.SourceLocation.ToLower().StartsWith("https://")) &&
                         !string.IsNullOrEmpty(commandAzCopy.SourceKey))
                {
                    MessageBox.Show("Source key should not be specified for local folder.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.tbSourceKey.Focus();
                }
                else                 //-----------------
                if (commandAzCopy.DestinationLocation.Contains("[T]"))
                {
                    MessageBox.Show("Destination location can not contain wildcard [T].", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.tbDestinationLocation.Focus();
                }
                else if ((!commandAzCopy.DestinationLocation.ToLower().StartsWith("http://") &&
                          !commandAzCopy.DestinationLocation.ToLower().StartsWith("https://")) &&
                         !Directory.Exists(commandAzCopy.DestinationLocation))
                {
                    MessageBox.Show("Destination location does not exist.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.tbDestinationLocation.Focus();
                }
                else if (commandAzCopy.DestinationLocation == "{local-path-or-azure-storage-item-url}")
                {
                    MessageBox.Show("Destination location not specified.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.tbDestinationLocation.Focus();
                }
                else if ((commandAzCopy.DestinationLocation.ToLower().StartsWith("http://") ||
                          commandAzCopy.DestinationLocation.ToLower().StartsWith("https://")) &&
                         (commandAzCopy.DestinationKey == null || commandAzCopy.DestinationKey == "{azure-storage-key}"))
                {
                    MessageBox.Show("Destination key not specified.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.tbDestinationKey.Focus();
                }
                else if ((!commandAzCopy.DestinationLocation.ToLower().StartsWith("http://") &&
                          !commandAzCopy.DestinationLocation.ToLower().StartsWith("https://")) &&
                         !string.IsNullOrEmpty(commandAzCopy.DestinationKey))
                {
                    MessageBox.Show("Destination key should not be specified for local folder.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.tbDestinationKey.Focus();
                }
                else
                {
                    if (MessageBox.Show("This will overwrite '" + commandAzCopy.DestinationLocation + "'. Proceed?", "Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                    {
                        try
                        {
                            bool r = AzCopyBatch.HandlerForTask_AzCopy.Execute(this._appLog, 0, this.tbAzCopyCommand.Text, DateTime.Now.ToDateAndTimeInSortableFormatForAzureBlob() + "_Manual_", 30);
                            this._appLog.AddLine(r ? "Operation succeeded!" : "Operation failed!");
                        }
                        catch (Exception exx)
                        {
                            HandlerForLoging.LogException(exx, this._appLog);
                            this._appLog.AddLine("Operation failed.");
                        }
                    }
                }
            }
        }
Пример #2
0
        private void btnDeleteAllItemsAtDestination_Click(object sender, EventArgs e)
        {
            CommandDelete deleteCommand = null;

            try
            {
                deleteCommand = new CommandDelete(this.tbDestinationLocation.Text, string.IsNullOrWhiteSpace(this.tbDestinationKey.Text) ? null : this.tbDestinationKey.Text, true);
            }
            catch (Exception ex)
            {
                deleteCommand = new CommandDelete("{local-path-or-azure-storage-item-url}", null, true);
            }

            if (deleteCommand.DestinationLocation.Contains("[T]"))
            {
                MessageBox.Show("Destination location can not contain wildcard [T].", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.tbDestinationLocation.Focus();
            }
            else if ((!deleteCommand.DestinationLocation.ToLower().StartsWith("http://") &&
                      !deleteCommand.DestinationLocation.ToLower().StartsWith("https://")) &&
                     !Directory.Exists(deleteCommand.DestinationLocation))
            {
                MessageBox.Show("Destination location does not exist.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.tbDestinationLocation.Focus();
            }
            else if (deleteCommand.DestinationLocation == "{local-path-or-azure-storage-item-url}")
            {
                MessageBox.Show("Destination location not specified.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.tbDestinationLocation.Focus();
            }
            else if ((deleteCommand.DestinationLocation.ToLower().StartsWith("http://") ||
                      deleteCommand.DestinationLocation.ToLower().StartsWith("https://")) &&
                     (deleteCommand.DestinationKey == null || deleteCommand.DestinationKey == "{azure-storage-key}"))
            {
                MessageBox.Show("Destination key not specified.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.tbDestinationKey.Focus();
            }
            else if ((!deleteCommand.DestinationLocation.ToLower().StartsWith("http://") &&
                      !deleteCommand.DestinationLocation.ToLower().StartsWith("https://")) &&
                     (deleteCommand.DestinationKey != null && deleteCommand.DestinationKey.Length > 0))
            {
                MessageBox.Show("Destination key should not be specified for local folder.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.tbDestinationKey.Focus();
            }
            else
            {
                if (MessageBox.Show("This will empty '" + deleteCommand.DestinationLocation + "'. Proceed?", "Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                {
                    try
                    {
                        bool r = AzCopyBatch.HandlerForTask_Delete.Execute(0, this.tbDeleteDestinationCommand.Text, null, this._appLog);
                        this._appLog.AddLine(r ? "Operation succeeded!" : "Operation failed!");
                    }
                    catch (Exception exx)
                    {
                        HandlerForLoging.LogException(exx, this._appLog);
                        this._appLog.AddLine("Operation failed.");
                    }
                }
            }
        }