Ejemplo n.º 1
0
        public static WorkerTask CreateDownloadTask(string url, bool upload, TaskSettings taskSettings)
        {
            WorkerTask task = new WorkerTask(taskSettings);

            task.Info.Job      = upload ? TaskJob.DownloadUpload : TaskJob.Download;
            task.Info.DataType = TaskHelpers.FindDataType(url, taskSettings);

            string filename = URLHelpers.URLDecode(url, 10);

            filename = URLHelpers.GetFileName(filename);
            filename = Helpers.GetValidFileName(filename);

            if (task.Info.TaskSettings.UploadSettings.FileUploadUseNamePattern)
            {
                string ext = Path.GetExtension(filename);
                filename = TaskHelpers.GetFilename(task.Info.TaskSettings, ext);
            }

            if (string.IsNullOrEmpty(filename))
            {
                return(null);
            }

            task.Info.FileName   = filename;
            task.Info.Result.URL = url;
            return(task);
        }