Пример #1
0
        public UploadResult UploadData(IGenericUploaderService service, Stream stream, string fileName)
        {
            if (!service.CheckConfig(Program.UploadersConfig))
            {
                return(GetInvalidConfigResult(service));
            }

            uploader = service.CreateUploader(Program.UploadersConfig, taskReferenceHelper);

            if (uploader != null)
            {
                uploader.BufferSize       = (int)Math.Pow(2, Program.Settings.BufferSizePower) * 1024;
                uploader.ProgressChanged += uploader_ProgressChanged;

                if (Info.TaskSettings.AfterUploadJob.HasFlag(AfterUploadTasks.CopyURLToClipboard) && Info.TaskSettings.AdvancedSettings.EarlyCopyURL)
                {
                    uploader.EarlyURLCopyRequested += url => ClipboardHelpers.CopyText(url);
                }

                Info.UploadDuration = Stopwatch.StartNew();

                UploadResult result = uploader.Upload(stream, fileName);

                Info.UploadDuration.Stop();

                return(result);
            }

            return(null);
        }
Пример #2
0
        public UploadResult UploadData(IGenericUploaderService service, Stream stream, string fileName)
        {
            if (!service.CheckConfig(App.UploadersConfig))
            {
                return(GetInvalidConfigResult(service));
            }

            uploader = service.CreateUploader(App.UploadersConfig, new TaskReferenceHelper());

            if (uploader != null)
            {
                uploader.BufferSize       = (int)Math.Pow(2, App.Settings.BufferSizePower) * 1024;
                uploader.ProgressChanged += uploader_ProgressChanged;

                Info.UploadDuration = Stopwatch.StartNew();

                UploadResult result = uploader.Upload(stream, fileName);

                Info.UploadDuration.Stop();

                return(result);
            }

            return(null);
        }
Пример #3
0
        public UploadResult UploadData(IGenericUploaderService service, Stream stream, string fileName)
        {
            if (!service.CheckConfig(Program.UploadersConfig))
            {
                return(GetInvalidConfigResult(service));
            }

            uploader = service.CreateUploader(Program.UploadersConfig, taskReferenceHelper);

            if (uploader != null)
            {
                uploader.BufferSize = (int)Math.Pow(2, Program.Settings.BufferSizePower) * 1024;

                if (Program.Settings.VerboseRequestLogs)
                {
                    uploader.VerboseLogs     = true;
                    uploader.VerboseLogsPath = Program.RequestLogsFilePath;
                }

                uploader.ProgressChanged += uploader_ProgressChanged;

                if (Info.TaskSettings.AfterUploadJob.HasFlag(AfterUploadTasks.CopyURLToClipboard) && Info.TaskSettings.AdvancedSettings.EarlyCopyURL)
                {
                    uploader.EarlyURLCopyRequested += url => ClipboardHelpers.CopyText(url);
                }

                if (Info.TaskSettings.UploadSettings.FileUploadReplaceProblematicCharacters)
                {
                    // http://www.ietf.org/rfc/rfc3986.txt
                    // Section 2.3:
                    //   Characters that are allowed in a URI but do not have a reserved
                    //   purpose are called unreserved.  These include uppercase and lowercase
                    //   letters, decimal digits, hyphen, period, underscore, and tilde.
                    //      unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
                    //
                    // \w takes care of alpha, digit and _ for us
                    fileName = Regex.Replace(fileName, @"[^\w-.~]", "_");
                }

                Info.UploadDuration = Stopwatch.StartNew();

                UploadResult result = uploader.Upload(stream, fileName);

                Info.UploadDuration.Stop();

                return(result);
            }

            return(null);
        }
Пример #4
0
        public UploadResult UploadData(IGenericUploaderService service, Stream stream, string fileName)
        {
            if (!service.CheckConfig(Program.UploadersConfig))
            {
                return(GetInvalidConfigResult(service));
            }

            uploader = service.CreateUploader(Program.UploadersConfig, taskReferenceHelper);

            if (uploader != null)
            {
                uploader.BufferSize = (int)Math.Pow(2, Program.Settings.BufferSizePower) * 1024;

                if (Program.Settings.VerboseRequestLogs)
                {
                    uploader.VerboseLogs     = true;
                    uploader.VerboseLogsPath = Program.RequestLogsFilePath;
                }

                uploader.ProgressChanged += uploader_ProgressChanged;

                if (Info.TaskSettings.AfterUploadJob.HasFlag(AfterUploadTasks.CopyURLToClipboard) && Info.TaskSettings.AdvancedSettings.EarlyCopyURL)
                {
                    uploader.EarlyURLCopyRequested += url => ClipboardHelpers.CopyText(url);
                }

                fileName = URLHelpers.RemoveBidiControlCharacters(fileName);

                if (Info.TaskSettings.UploadSettings.FileUploadReplaceProblematicCharacters)
                {
                    fileName = URLHelpers.ReplaceReservedCharacters(fileName, "_");
                }

                Info.UploadDuration = Stopwatch.StartNew();

                UploadResult result = uploader.Upload(stream, fileName);

                Info.UploadDuration.Stop();

                return(result);
            }

            return(null);
        }