Exemple #1
0
        private List <CommandAzCopy> ExtractAzCopyCommandsFromIni()
        {
            List <CommandAzCopy> r = null;

            try
            {
                string iniFilePath = CraftSynth.BuildingBlocks.Common.Misc.ApplicationRootFolderPath + "AzCopyBatch.ini";
                var    lines       = File.ReadLines(iniFilePath);
                foreach (string line in lines)
                {
                    if (line.Trim().StartsWith("[Tasks]"))
                    {
                        r = new List <CommandAzCopy>();
                    }
                    else if (r != null && line.Trim().Length > 0)                    // && !line.StartsWith("--"))
                    {
                        var newCommand = CommandAzCopy.Parse(line, true, new CustomTraceLog());
                        if (newCommand != null)
                        {
                            r.Add(newCommand);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                AzCopyGui.HandlerForLoging.LogException(exception, this._appLog);
            }

            return(r);
        }
Exemple #2
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.");
                        }
                    }
                }
            }
        }