Пример #1
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);
        }
Пример #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 TestUploadLocalSingleFileToSASCancellationAsync()
        {
            var hasInfoMessage     = false;
            var hasInitMessage     = false;
            var hasEndOfJobMessage = false;
            var jobCancelled       = 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();
            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.EndOfJob)
                {
                    hasEndOfJobMessage = true;
                }
            };

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

            // create cancellation Token
            var cts = new CancellationTokenSource();

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

                localFile.Path = fileName;
            }

            var stopWatch = new Stopwatch();

            stopWatch.Start();
            cts.CancelAfter(5);
            await client.CopyAsync(localFile, sasLocation, option, cts.Token);

            stopWatch.Stop();
            this.output.WriteLine("time elapes: " + stopWatch.ElapsedMilliseconds.ToString());

            Assert.True(hasInfoMessage);
            Assert.True(hasInitMessage);
            Assert.True(hasEndOfJobMessage);
            Assert.True(jobCancelled);
        }
Пример #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
        public async Task TestUploadToNonExistContainerAsync()
        {
            var hasInfoMessage     = false;
            var hasInitMessage     = false;
            var hasProgressMessage = false;
            var hasEndOfJobMessage = false;
            var jobCanceled        = false;
            var errorCode          = 0;

            var localFile = new LocalLocation()
            {
                UseWildCard = false,
            };

            var fileName = this.GetRandomFileName();

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

            var option = new CopyOption();
            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) =>
            {
                jobCanceled = e.JobStatus == JobStatus.Failed;
                if (jobCanceled)
                {
                    errorCode = e.FailedTransfers[0].ErrorCode;
                }
            };

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

                localFile.Path = fileName;
            }

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

            Assert.True(hasInfoMessage);
            Assert.True(hasInitMessage);
            Assert.True(hasProgressMessage);
            Assert.True(hasEndOfJobMessage);
            Assert.True(jobCanceled);
            Assert.Equal(404, errorCode);
        }
Пример #6
0
        public async Task TestUploadNonExistLocalFileAsync()
        {
            var hasInfoMessage     = false;
            var hasInitMessage     = false;
            var hasProgressMessage = false;
            var hasEndOfJobMessage = false;
            var jobCompleted       = false;
            var hitError           = false;

            var localFile = new LocalLocation()
            {
                UseWildCard = false,
                Path        = @"not/exist/file.bin",
            };

            var sasLocation = new RemoteSasLocation()
            {
                ResourceUri = this.resourceUri,
                Container   = this.container,
                Path        = @"some-random-file.bin",
                SasToken    = this.sasToken,
            };

            var option = new CopyOption();
            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;
                }

                if (e.MessageType == MessageType.Error)
                {
                    hitError = true;
                }
            };

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

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

            Assert.True(hasInfoMessage);
            Assert.False(hasInitMessage);
            Assert.False(hasProgressMessage);
            Assert.False(hasEndOfJobMessage);
            Assert.False(jobCompleted);
            Assert.True(hitError);
        }
Пример #7
0
        public async Task TestUploadAndDeleteLocalFileToSASAsync()
        {
            var hasInfoMessage     = false;
            var hasInitMessage     = false;
            var hasProgressMessage = false;
            var hasEndOfJobMessage = false;
            var jobCompleted       = 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 AZCopyOption();
            var client = new AZCopyClient();

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

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

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

                if (e.MessageType == "EndOfJob")
                {
                    hasEndOfJobMessage = true;
                    jobCompleted       = ((AZCopyEndOfJobMessage)e).JobStatus == "Completed";
                }
            };

            // 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);

            Assert.True(hasInfoMessage);
            Assert.True(hasInitMessage);
            Assert.True(hasProgressMessage);
            Assert.True(hasEndOfJobMessage);
            Assert.True(jobCompleted);

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

            var deleteOption = new AZDeleteOption();
            await client.DeleteAsync(sasLocation, deleteOption);

            Assert.True(hasInitMessage);
            Assert.True(hasProgressMessage);
            Assert.True(hasEndOfJobMessage);
            Assert.True(jobCompleted);
        }
Пример #8
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 AZCopyOption()
            {
                Recursive      = string.Empty,
                IncludePattern = "*.jpg;*.png",
            };

            var client = new AZCopyClient();

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

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

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

                if (e.MessageType == "EndOfJob")
                {
                    hasEndOfJobMessage = true;
                    jobCompleted       = ((AZCopyEndOfJobMessage)e).JobStatus == "Completed";
                    totalFiles         = ((AZCopyEndOfJobMessage)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 AZDeleteOption()
            {
                Recursive = string.Empty,
            };
            await client.DeleteAsync(sasLocation, deleteOption);

            Assert.True(hasInitMessage);
            Assert.True(hasProgressMessage);
            Assert.True(hasEndOfJobMessage);
            Assert.True(jobCompleted);
        }
Пример #9
0
        public async Task TestUploadNonExistLocalFileAsync()
        {
            var hasInfoMessage     = false;
            var hasInitMessage     = false;
            var hasProgressMessage = false;
            var hasEndOfJobMessage = false;
            var jobCompleted       = false;
            var hitError           = false;

            var localFile = new LocalLocation()
            {
                UseWildCard = false,
                Path        = @"not/exist/file.bin",
            };

            var sasLocation = new RemoteSasLocation()
            {
                ResourceUri = this.resourceUri,
                Container   = this.container,
                Path        = @"some-random-file.bin",
                SasToken    = this.sasToken,
            };

            var option = new AZCopyOption();
            var client = new AZCopyClient();

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

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

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

                if (e.MessageType == "EndOfJob")
                {
                    hasEndOfJobMessage = true;
                    jobCompleted       = ((AZCopyEndOfJobMessage)e).JobStatus == "Completed";
                }

                if (e.MessageType == "Error")
                {
                    hitError = true;
                }
            };

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

            Assert.True(hasInfoMessage);
            Assert.False(hasInitMessage);
            Assert.False(hasProgressMessage);
            Assert.False(hasEndOfJobMessage);
            Assert.False(jobCompleted);
            Assert.True(hitError);
        }