/// <summary> /// Starts the update library process in a background thread. /// </summary> /// <param name='mode'>Update library mode</param> /// <param name='filePaths'>Audio file paths to add to the database</param> /// <param name='folderPath'>Folder path to add to the database</param> public void UpdateLibrary(UpdateLibraryMode mode, List<string> filePaths, string folderPath) { UpdateLibraryArgument arg = new UpdateLibraryArgument(); arg.Mode = mode; arg.FilePaths = filePaths; arg.FolderPath = folderPath; cancelUpdateLibrary = false; if (mode == UpdateLibraryMode.SpecificFolder) libraryService.AddFolder(folderPath, true); else if(mode == UpdateLibraryMode.SpecificFiles) libraryService.AddFiles(filePaths); // Start the background process //workerUpdateLibrary.RunWorkerAsync(arg); // TODO: Add time elapsed/time remaining // // // Set start time when the process has finished finding the files and is ready to add files into library // // if (startTimeAddFiles == DateTime.MinValue) // // { // // startTimeAddFiles = DateTime.Now; // // } // // // Calculate time elapsed // // TimeSpan timeElapsed = DateTime.Now.Subtract(startTimeAddFiles); // // // Update title // // lblTitle.Text = data.Title + " (file " + data.CurrentFilePosition.ToString() + " of " + data.TotalNumberOfFiles.ToString() + ")"; // // // Calculate time remaining // // double msPerFile = timeElapsed.TotalMilliseconds / data.CurrentFilePosition; // // double remainingTime = (data.TotalNumberOfFiles - data.CurrentFilePosition) * msPerFile; // // TimeSpan timeRemaining = new TimeSpan(0, 0, 0, 0, (int)remainingTime); // // // Update estimated time left (from more precise to more vague) // // if (timeRemaining.TotalSeconds == 0) // // { // // lblEstimatedTimeLeft.Text = "Estimated time left : N/A"; // // } // // else if (timeRemaining.Minutes == 1) // // { // // lblEstimatedTimeLeft.Text = "Estimated time left : 1 minute"; // // } // // else if (timeRemaining.TotalSeconds <= 10) // // { // // lblEstimatedTimeLeft.Text = "Estimated time left : A few seconds"; // // } // // else if (timeRemaining.TotalSeconds <= 30) // // { // // lblEstimatedTimeLeft.Text = "Estimated time left : Less than 30 seconds"; // // } // // else if (timeRemaining.TotalSeconds <= 60) // // { // // lblEstimatedTimeLeft.Text = "Estimated time left : Less than a minute"; // // } // // else // // { // // lblEstimatedTimeLeft.Text = "Estimated time left : " + timeRemaining.Minutes.ToString() + " minutes"; // // } }
public void StartProcess(UpdateLibraryMode mode, List<string> filePaths, string folderPath) { presenter.UpdateLibrary(mode, filePaths, folderPath); }
void StartUpdateLibrary(UpdateLibraryMode mode, List<string> filePaths, string folderPath) { // Create window and start process if(updateLibraryWindowController != null) { updateLibraryWindowController.Dispose(); } updateLibraryWindowController = new UpdateLibraryWindowController(this, null); updateLibraryWindowController.Window.MakeKeyAndOrderFront(this); updateLibraryWindowController.StartProcess(mode, filePaths, folderPath); }