本文整理汇总了C#中ShareX.UploadTask类的典型用法代码示例。如果您正苦于以下问题:C# UploadTask类的具体用法?C# UploadTask怎么用?C# UploadTask使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UploadTask类属于ShareX命名空间,在下文中一共展示了UploadTask类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDataUploaderTask
public static UploadTask CreateDataUploaderTask(EDataType dataType, Stream stream, string fileName, TaskSettings taskSettings)
{
UploadTask task = new UploadTask(taskSettings);
task.Info.Job = TaskJob.DataUpload;
task.Info.DataType = dataType;
task.Info.FileName = fileName;
task.Data = stream;
return task;
}
示例2: Start
public static void Start(UploadTask task)
{
Tasks.Add(task);
task.StatusChanged += task_StatusChanged;
task.UploadStarted += new UploadTask.TaskEventHandler(task_UploadStarted);
task.UploadProgressChanged += new UploadTask.TaskEventHandler(task_UploadProgressChanged);
task.UploadCompleted += new UploadTask.TaskEventHandler(task_UploadCompleted);
CreateListViewItem(task);
StartTasks();
}
示例3: PrepareFileImage
public static void PrepareFileImage(UploadTask task)
{
int sizeLimit = task.Info.TaskSettings.ImageSettings.ImageSizeLimit * 1000;
if (sizeLimit > 0 && task.Data.Length > sizeLimit)
{
using (Stream stream = task.Data)
using (Image img = Image.FromStream(stream))
{
task.Data = SaveImage(task.Info.TaskSettings, img, task.Info.TaskSettings.ImageSettings.ImageFormat2);
task.Info.FileName = Path.ChangeExtension(task.Info.FileName, task.Info.TaskSettings.ImageSettings.ImageFormat2.GetDescription());
}
}
}
示例4: Remove
public static void Remove(UploadTask task)
{
if (task != null)
{
task.Stop();
Tasks.Remove(task);
ListViewItem lvi = FindListViewItem(task);
if (lvi != null)
{
ListViewControl.Items.Remove(lvi);
}
task.Dispose();
}
}
示例5: task_UploadProgressChanged
private static void task_UploadProgressChanged(UploadTask task)
{
if (task.Status == TaskStatus.Working && ListViewControl != null)
{
TaskInfo info = task.Info;
ListViewItem lvi = FindListViewItem(task);
if (lvi != null)
{
lvi.SubItems[1].Text = string.Format("{0:0.0}%", info.Progress.Percentage);
lvi.SubItems[2].Text = string.Format("{0} / {1}", Helpers.ProperFileSize(info.Progress.Position), Helpers.ProperFileSize(info.Progress.Length));
if (info.Progress.Speed > 0)
{
lvi.SubItems[3].Text = Helpers.ProperFileSize((long)info.Progress.Speed, "/s");
}
lvi.SubItems[4].Text = Helpers.ProperTimeSpan(info.Progress.Elapsed);
lvi.SubItems[5].Text = Helpers.ProperTimeSpan(info.Progress.Remaining);
}
UpdateProgressUI();
}
}
示例6: task_UploadStarted
private static void task_UploadStarted(UploadTask task)
{
TaskInfo info = task.Info;
string status = string.Format("Upload started. Filename: {0}", info.FileName);
if (!string.IsNullOrEmpty(info.FilePath)) status += ", Filepath: " + info.FilePath;
DebugHelper.WriteLine(status);
ListViewItem lvi = FindListViewItem(task);
if (lvi != null)
{
lvi.Text = info.FileName;
lvi.SubItems[1].Text = info.Status;
lvi.ImageIndex = 0;
}
}
示例7: task_StatusChanged
private static void task_StatusChanged(UploadTask task)
{
DebugHelper.WriteLine("Task status: " + task.Status);
ChangeListViewItemStatus(task);
UpdateProgressUI();
}
示例8: CreateListViewItem
private static void CreateListViewItem(UploadTask task)
{
if (ListViewControl != null)
{
TaskInfo info = task.Info;
DebugHelper.WriteLine("Task in queue. Job: {0}, Type: {1}, Host: {2}", info.Job, info.UploadDestination, info.UploaderHost);
ListViewItem lvi = new ListViewItem();
lvi.Tag = task;
lvi.Text = info.FileName;
lvi.SubItems.Add("In queue");
lvi.SubItems.Add(string.Empty);
lvi.SubItems.Add(string.Empty);
lvi.SubItems.Add(string.Empty);
lvi.SubItems.Add(string.Empty);
lvi.SubItems.Add(info.DataType.ToString());
lvi.SubItems.Add(info.IsUploadJob ? info.UploaderHost : string.Empty);
lvi.SubItems.Add(string.Empty);
lvi.ImageIndex = 3;
ListViewControl.Items.Add(lvi);
lvi.EnsureVisible();
ListViewControl.FillLastColumn();
}
}
示例9: CreateDownloadUploadTask
public static UploadTask CreateDownloadUploadTask(string url, TaskSettings taskSettings)
{
UploadTask task = new UploadTask(taskSettings);
task.Info.Job = TaskJob.DownloadUpload;
task.Info.DataType = TaskHelpers.FindDataType(url, taskSettings);
task.Info.FileName = URLHelpers.GetFileName(url, true);
if (string.IsNullOrEmpty(task.Info.FileName))
{
return null;
}
task.Info.Result.URL = url;
return task;
}
示例10: CreateTextUploaderTask
public static UploadTask CreateTextUploaderTask(string text, TaskSettings taskSettings)
{
UploadTask task = new UploadTask(taskSettings);
task.Info.Job = TaskJob.TextUpload;
task.Info.DataType = EDataType.Text;
task.Info.FileName = TaskHelpers.GetFilename(taskSettings, taskSettings.AdvancedSettings.TextFileExtension);
task.tempText = text;
return task;
}
示例11: CreateFileJobTask
public static UploadTask CreateFileJobTask(string filePath, TaskSettings taskSettings)
{
UploadTask task = new UploadTask(taskSettings);
task.Info.FilePath = filePath;
task.Info.DataType = TaskHelpers.FindDataType(task.Info.FilePath, taskSettings);
if (task.Info.TaskSettings.UploadSettings.FileUploadUseNamePattern)
{
string ext = Path.GetExtension(task.Info.FilePath);
task.Info.FileName = TaskHelpers.GetFilename(task.Info.TaskSettings, ext);
}
task.Info.Job = TaskJob.Job;
if (task.Info.IsUploadJob && !task.LoadFileStream())
{
return null;
}
return task;
}
示例12: CreateURLShortenerTask
public static UploadTask CreateURLShortenerTask(string url, TaskSettings taskSettings)
{
UploadTask task = new UploadTask(taskSettings);
task.Info.Job = TaskJob.ShortenURL;
task.Info.DataType = EDataType.URL;
task.Info.FileName = string.Format(Resources.UploadTask_CreateURLShortenerTask_Shorten_URL___0__, taskSettings.URLShortenerDestination.GetLocalizedDescription());
task.Info.Result.URL = url;
return task;
}
示例13: task_UploadCompleted
private static void task_UploadCompleted(UploadTask task)
{
try
{
if (ListViewControl != null && task != null)
{
if (task.RequestSettingUpdate)
{
Program.MainForm.UpdateMainFormSettings();
}
TaskInfo info = task.Info;
if (info != null && info.Result != null)
{
ListViewItem lvi = FindListViewItem(task);
if (info.Result.IsError)
{
string errors = string.Join("\r\n\r\n", info.Result.Errors.ToArray());
DebugHelper.WriteLine("Task failed. Filename: {0}, Errors:\r\n{1}", info.FileName, errors);
if (lvi != null)
{
lvi.SubItems[1].Text = Resources.TaskManager_task_UploadCompleted_Error;
lvi.SubItems[6].Text = string.Empty;
lvi.ImageIndex = 1;
}
if (!info.TaskSettings.AdvancedSettings.DisableNotifications)
{
if (info.TaskSettings.GeneralSettings.PlaySoundAfterUpload)
{
TaskHelpers.PlayErrorSound(info.TaskSettings);
}
if (info.TaskSettings.GeneralSettings.PopUpNotification != PopUpNotificationType.None && Program.MainForm.niTray.Visible && !string.IsNullOrEmpty(errors))
{
Program.MainForm.niTray.Tag = null;
Program.MainForm.niTray.ShowBalloonTip(5000, "ShareX - " + Resources.TaskManager_task_UploadCompleted_Error, errors, ToolTipIcon.Error);
}
}
}
else
{
DebugHelper.WriteLine("Task completed. Filename: {0}, URL: {1}, Duration: {2} ms", info.FileName, info.Result.ToString(), (int)info.UploadDuration.TotalMilliseconds);
string result = info.Result.ToString();
if (string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(info.FilePath))
{
result = info.FilePath;
}
if (lvi != null)
{
lvi.Text = info.FileName;
lvi.SubItems[1].Text = info.Status;
lvi.ImageIndex = 2;
if (!string.IsNullOrEmpty(result))
{
lvi.SubItems[6].Text = result;
}
}
if (!task.StopRequested && !string.IsNullOrEmpty(result))
{
if (info.TaskSettings.GeneralSettings.SaveHistory && (!info.TaskSettings.AdvancedSettings.HistorySaveOnlyURL ||
(!string.IsNullOrEmpty(info.Result.URL) || !string.IsNullOrEmpty(info.Result.ShortenedURL))))
{
HistoryManager.AddHistoryItemAsync(Program.HistoryFilePath, info.GetHistoryItem());
}
RecentManager.Add(result);
if (Program.Settings.RecentLinksRemember)
{
Program.Settings.RecentLinks = RecentManager.Items.ToArray();
}
else
{
Program.Settings.RecentLinks = null;
}
if (!info.TaskSettings.AdvancedSettings.DisableNotifications && info.Job != TaskJob.ShareURL)
{
if (info.TaskSettings.GeneralSettings.PlaySoundAfterUpload)
{
TaskHelpers.PlayTaskCompleteSound(info.TaskSettings);
}
if (!string.IsNullOrEmpty(info.TaskSettings.AdvancedSettings.BalloonTipContentFormat))
{
result = new UploadInfoParser().Parse(info, info.TaskSettings.AdvancedSettings.BalloonTipContentFormat);
}
if (!string.IsNullOrEmpty(result))
{
//.........这里部分代码省略.........
示例14: Start
public static void Start(UploadTask task)
{
if (task != null)
{
Tasks.Add(task);
UpdateMainFormTip();
task.StatusChanged += task_StatusChanged;
task.UploadStarted += task_UploadStarted;
task.UploadProgressChanged += task_UploadProgressChanged;
task.UploadCompleted += task_UploadCompleted;
CreateListViewItem(task);
StartTasks();
}
}
示例15: CreateListViewItem
private static void CreateListViewItem(UploadTask task)
{
if (ListViewControl != null)
{
TaskInfo info = task.Info;
DebugHelper.WriteLine("Task in queue. Job: {0}, Type: {1}, Host: {2}", info.Job, info.UploadDestination, info.UploaderHost);
ListViewItem lvi = new ListViewItem();
lvi.Tag = task;
lvi.Text = info.FileName;
lvi.SubItems.Add(Resources.TaskManager_CreateListViewItem_In_queue);
lvi.SubItems.Add(string.Empty);
lvi.SubItems.Add(string.Empty);
lvi.SubItems.Add(string.Empty);
lvi.SubItems.Add(string.Empty);
lvi.SubItems.Add(string.Empty);
lvi.ImageIndex = 3;
if (Program.Settings.ShowMostRecentTaskFirst)
{
ListViewControl.Items.Insert(0, lvi);
}
else
{
ListViewControl.Items.Add(lvi);
}
lvi.EnsureVisible();
ListViewControl.FillLastColumn();
}
}