예제 #1
0
        private Task UploadSingleFile(Stream stream, string relativeUrl)
        {
            try
            {
                return(Task.Run(
                           async() =>
                {
                    await _fileUploader.SendStreamToHosts(Config.Urls, relativeUrl, 1, stream, doLogContent: true, doCompress: false);
                }));
            }
            catch (AggregateException ae)
            {
                ae.Handle((x) =>
                {
                    //if (x is UnauthorizedAccessException) // This we know how to handle.
                    //{
                    //    Console.WriteLine("You do not have permission to access all folders in this path.");
                    //    Console.WriteLine("See your network administrator or try another path.");
                    //    return true;
                    //}
                    MyLogger.Error(x);
                    return(false);
                });

                throw;
            }
        }
        private void UploadFile(FileUploadQueueItem wt)
        {
            try
            {
                Task.Run(async() =>
                {
                    await _fileUploader.SendStreamToHosts(Config.Urls, _relativeUrlForPosting,
                                                          wt.BatchNumber, wt.Stream, doLogContent: false, doCompress: Config.CompressFiles);
                })
                .Wait();

                MyLogger.Trace($"Uploaded batch: {wt.BatchNumber} ");
            }
            catch (AggregateException ae)
            {
                ae.Handle((x) =>
                {
                    //if (x is UnauthorizedAccessException) // This we know how to handle.
                    //{
                    //    Console.WriteLine("You do not have permission to access all folders in this path.");
                    //    Console.WriteLine("See your network administrator or try another path.");
                    //    return true;
                    //}
                    MyLogger.Error(x);
                    return(false); // Let anything else stop the application.
                });
            }
        }