/// <summary> /// Loads all connectors into the UI and Form /// </summary> /// <returns></returns> private async Task LoadConnectorsAsync(ILoadProgress P = null) { await Task.Run(() => { P?.Report((0, "Loading connectors")); // Load connectors ConnectorCollection = ConnectorsManager.GetAll( ); // Sort connectors P?.Report((50, "Sorting connectors")); Array.Sort(ConnectorCollection, (MangaConnector x, MangaConnector y) => x.Website.CompareTo(y.Website)); // Populate connectors combobox P?.Report((75, "Populating UI with connectors")); cbConnectors.InvokeEx(cb => { if (ConnectorCollection.Count( ) < 1) { return; } foreach (var connector in ConnectorCollection) { cb.Items.Add(connector.Website); } cb.SelectedIndex = 0; }); P?.Report((100, "Connectors loaded")); }); }
/// <summary> /// Initializes a new instance of the /// <see cref="FileProcessor" /> class. /// </summary> /// <param name="fileNames">The file names.</param> /// <param name="progress">The progress.</param> /// <param name="field">The field.</param> /// <param name="script">The script.</param> /// TODO Edit XML Comment Template for #ctor internal FileProcessor( IList <string> fileNames, Progress progress, Field field = null, Script script = null) { FileNames = fileNames; Progress = progress; Field = field; Script = script; Directory.CreateDirectory(OutputFolderPath); Directory.CreateDirectory(ProcessingFolderPath); }
public static async Task <string> CopyFileAsync( string sourceFilePath, string destinationFolderPath, IFileCopyProgress progress, CancellationToken token) { var fileName = Path.GetFileName(sourceFilePath); var copiedFilePath = Path.Combine(destinationFolderPath, fileName); var tempFilePath = copiedFilePath + ".tmp"; var fileInfo = new FileInfo(sourceFilePath); var fileLength = fileInfo.Length; var buffer = new byte[4096 * 16]; using (var sourceStream = File.OpenRead(sourceFilePath)) using (var destinationStream = File.Create(tempFilePath)) { try { int bytesRead; var alreadyReadCount = 0; var cummulatedProgressPercentage = 0m; while ((bytesRead = await sourceStream.ReadAsync(buffer, 0, buffer.Length, token)) > 0) { alreadyReadCount += bytesRead; var progressPercentageIncrement = (decimal)bytesRead / fileLength * 100; cummulatedProgressPercentage += progressPercentageIncrement; var isFinished = alreadyReadCount == fileLength; var reportedPercentage = isFinished ? 100 - cummulatedProgressPercentage : progressPercentageIncrement; progress.Report((fileInfo, reportedPercentage, isFinished)); await destinationStream.WriteAsync(buffer, 0, buffer.Length, token); } } catch (OperationCanceledException) { sourceStream.Close(); destinationStream.Close(); File.Delete(tempFilePath); throw; } } File.Move(tempFilePath, copiedFilePath); return(copiedFilePath); }