예제 #1
0
        public async Task RemoveAsync(LocationBase dst, RemoveOption option, CancellationToken ct = default)
        {
            // Lcations must be in quotes. It could have spaces in the name and the CLI would interpret as separate parameters.
            option.OutputType = "json";
            var args = $"rm \"{dst}\" {option} --cancel-from-stdin";

            await this.StartAZCopyAsync(args, ct);
        }
예제 #2
0
        public async Task Upload_local_file_to_remote_dir_with_dir_name_include_space_async()
        {
            var hasInitMessage     = false;
            var hasInfoMessage     = false;
            var hasProgressMessage = false;
            var hasEndOfJobMessage = false;
            var jobCompleted       = false;
            var copyOption         = new CopyOption();
            var fileName           = this.GetRandomFileName();
            var localFile          = new LocalLocation()
            {
                UseWildCard = false,
            };

            // create random file
            using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write))
            {
                fs.SetLength(1024 * 1024); // 1MB
                await fs.FlushAsync();

                localFile.Path = fileName;
            }

            var remoteLocation = new RemoteSasLocation()
            {
                ResourceUri = this.resourceUri,
                Container   = this.container,
                Path        = "directory with space/",
                SasToken    = this.sasToken,
            };

            var client = new AZCopyClient();

            client.OutputMessageHandler += (object sender, JsonOutputTemplate e) =>
            {
                this.output.WriteLine(e.MessageContent);
                if (e.MessageType == MessageType.Info)
                {
                    hasInfoMessage = true;
                }

                if (e.MessageType == MessageType.Init)
                {
                    hasInitMessage = true;
                }

                if (e.MessageType == MessageType.Progress)
                {
                    hasProgressMessage = true;
                }

                if (e.MessageType == MessageType.EndOfJob)
                {
                    hasEndOfJobMessage = true;
                }
            };

            client.JobStatusMessageHandler += (object sender, ListJobSummaryResponse e) =>
            {
                jobCompleted = e.JobStatus == JobStatus.Completed;
            };

            await client.CopyAsync(localFile, remoteLocation, copyOption);

            var deleteOption = new RemoveOption();
            await client.RemoveAsync(remoteLocation, deleteOption);

            Assert.True(hasInitMessage);
            Assert.True(hasProgressMessage);
            Assert.True(hasEndOfJobMessage);
            Assert.True(jobCompleted);
        }
예제 #3
0
        public async Task TestUploadAndDeleteExistingLocalFile()
        {
            var isSkip    = false;
            var localFile = new LocalLocation()
            {
                UseWildCard = false,
            };

            var fileName = this.GetRandomFileName();

            var sasLocation = new RemoteSasLocation()
            {
                ResourceUri = this.resourceUri,
                Container   = this.container,
                Path        = fileName,
                SasToken    = this.sasToken,
            };

            var option = new CopyOption();

            option.Overwrite = "ifSourceNewer";
            option.CapMbps   = 4;

            var client = new AZCopyClient();

            client.OutputMessageHandler += (object sender, JsonOutputTemplate e) =>
            {
                this.output.WriteLine(e.MessageContent);
            };

            client.JobStatusMessageHandler += (object sender, ListJobSummaryResponse e) =>
            {
                if (e.JobStatus == JobStatus.CompletedWithSkipped)
                {
                    isSkip = true;
                }
            };

            // create random file
            using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write))
            {
                fs.SetLength(1024 * 1024); // 1MB
                await fs.FlushAsync();

                localFile.Path = fileName;
            }

            await client.CopyAsync(localFile, sasLocation, option);

            await Task.Delay(3 * 1000); // delay 3 s

            // upload again
            await client.CopyAsync(localFile, sasLocation, option);

            var deleteOption = new RemoveOption()
            {
                Recursive = true,
            };
            await client.RemoveAsync(sasLocation, deleteOption);

            Assert.True(isSkip);
        }
예제 #4
0
        public async Task TestUploadAndDeleteLocalFolderWithPatternToSASAsync()
        {
            var hasInfoMessage     = false;
            var hasInitMessage     = false;
            var hasProgressMessage = false;
            var hasEndOfJobMessage = false;
            var jobCompleted       = false;
            var totalFiles         = 0;

            var localFile = new LocalLocation()
            {
                UseWildCard = true,
                Path        = @"TestData/fruits",
            };

            var sasLocation = new RemoteSasLocation()
            {
                ResourceUri = this.resourceUri,
                Container   = this.container,
                Path        = @"fruits",
                SasToken    = this.sasToken,
            };

            var option = new CopyOption()
            {
                Recursive      = true,
                IncludePattern = "*.jpg;*.png",
            };

            var client = new AZCopyClient();

            client.OutputMessageHandler += (object sender, JsonOutputTemplate e) =>
            {
                Console.WriteLine(e.MessageContent);
                if (e.MessageType == MessageType.Info)
                {
                    hasInfoMessage = true;
                }

                if (e.MessageType == MessageType.Init)
                {
                    hasInitMessage = true;
                }

                if (e.MessageType == MessageType.Progress)
                {
                    hasProgressMessage = true;
                }

                if (e.MessageType == MessageType.EndOfJob)
                {
                    hasEndOfJobMessage = true;
                }
            };

            client.JobStatusMessageHandler += (object sender, ListJobSummaryResponse e) =>
            {
                jobCompleted = e.JobStatus == JobStatus.Completed;
                totalFiles   = e.TotalTransfers;
            };

            await client.CopyAsync(localFile, sasLocation, option);

            Assert.True(hasInfoMessage);
            Assert.True(hasInitMessage);
            Assert.True(hasProgressMessage);
            Assert.True(hasEndOfJobMessage);
            Assert.True(jobCompleted);
            Assert.Equal(6, totalFiles);

            hasInitMessage     = false;
            hasProgressMessage = false;
            hasEndOfJobMessage = false;
            jobCompleted       = false;

            var deleteOption = new RemoveOption()
            {
                Recursive = true,
            };
            await client.RemoveAsync(sasLocation, deleteOption);

            Assert.True(hasInitMessage);
            Assert.True(hasProgressMessage);
            Assert.True(hasEndOfJobMessage);
            Assert.True(jobCompleted);
        }
예제 #5
0
 /// <summary>
 /// Remove the item(s) with the given key and value.
 /// </summary>
 public bool Remove(TKey key, TValue value, RemoveOption para)
 {
     return(Remove(key, value, (RemoveParameter)para));
 }
예제 #6
0
 /// <summary>
 /// Remove the item(s) with the given key.
 /// </summary>
 public bool Remove(TKey key, RemoveOption para)
 {
     return(Remove(key, default(TValue), (RemoveParameter)(-((int)para))));
 }