/// ------------------------------------------------------------------------------------ /// <summary> /// Creates a session which will "receive" the specified file. New /// session names are the name of the file without the extension. The Date of the /// session is the file's DateModified date. /// </summary> /// ------------------------------------------------------------------------------------ public void CreateSingleSession(string sourcePath) { var file = new NewSessionFile(sourcePath); var sessionId = Path.GetFileNameWithoutExtension(file.FileName); var session = Session.Create(MainWnd.CurrentProject, sessionId); //todo: remove static session.Date = File.GetLastWriteTime(file.FullFilePath); session.Save(); if (FirstNewSessionAdded == null) { FirstNewSessionAdded = sessionId; } }
public void GetSourceAndDestinationPairs_UnselectedFileIsIgnored() { using (var temp = new TempFile()) { //var path = _mainAppFldr.Combine("dog.wav"); //File.CreateText(path).Close(); var sessionFile = new NewSessionFile(temp.Path); sessionFile.Selected = false; using (var model = new NewSessionsFromFileDlgViewModel()) { model.Files.Add(sessionFile); Assert.AreEqual(0, model.GetSourceAndDestinationPairs().Count()); } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ void HandleFileLoaderDoWork(object sender, DoWorkEventArgs e) { var fileList = e.Argument as string[]; if (fileList == null) { return; } var validExtensions = (Settings.Default.AudioFileExtensions + Settings.Default.VideoFileExtensions).ToLower(); foreach (var file in fileList) { // If the file's path no longer exists, it probably means the user disconnected the // storage device (e.g. recorder) before reading all its contents. if (_fileLoaderWorker.CancellationPending || !Directory.Exists(Path.GetDirectoryName(file))) { e.Cancel = true; return; } _fileLoaderWorker.ReportProgress(0); try { if (validExtensions.Contains(Path.GetExtension(file.ToLower()))) { var sessionFile = new NewSessionFile(file); sessionFile.Selected = (new FileInfo(file).Attributes & FileAttributes.Archive) > 0; Files.Add(sessionFile); } } catch (Exception) { if (Directory.Exists(Path.GetDirectoryName(file))) { throw; } } } }