private void bnImportTrackingMissing_Click(object sender, RoutedEventArgs e) { if (LoadTrackingWorker.IsBusy) { return; } Properties.Settings settings = new Properties.Settings(); String path = settings.TrackingPathRemote; path = Configuration.FileDialogs.SelectFolder(path); if (path == null) { return; } LoggingStatus.PostMessage(Severity.Info, String.Format("Scanning directory {0} and all subdirectories for missing tracking data...", path)); List <LoadFilesArgument> args = new List <LoadFilesArgument>(); ScanForMissingTracking(path, args); int numTests = args.Count; int numFiles = args.Sum(a => a.fileNames.Count); if (numFiles > 0) { LoggingStatus.PostMessage(Severity.Info, String.Format("Found total of {0} files related to {1} different tests.", numFiles, numTests)); LoadTrackingWorker.RunWorkerAsync(args); } else { LoggingStatus.PostMessage(Severity.Info, "No suitable tracking files identified."); } }
private void bnImportTrackingCurrent_Click(object sender, RoutedEventArgs e) { if (LoadTrackingWorker.IsBusy) { return; } Test test = (Test)gridTests.SelectedItem; if (test == null) { return; } if (test.LastStep < test.Test_Definition.EyeTrackerStep) { LoggingStatus.PostMessage(Severity.Warning, "Cannot load tracking data, eyetracker experiment not executed yet"); return; } bool mergeReplace = false; if (test.HasTracking) { if (MessageBox.Show("Test already contains tracking data. Do you want to merge/replace existing data?", "Confirmation", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { mergeReplace = true; } else { return; } } Properties.Settings settings = new Properties.Settings(); String fullPattern = String.Format(EyeTracking.PresentationWindow.TrackingFilePattern, settings.TrackingPathRemote, test.Candidate.personal_code, test.id, "*"); String initialDirectory = Path.GetDirectoryName(fullPattern); String filter = Path.GetFileName(fullPattern); filter = "idf tracking for " + test.Candidate.personal_code + "|" + filter + "|" + "txt tracking for " + test.Candidate.personal_code + "|" + filter.Replace(".idf", ".txt"); String[] fileNames = Configuration.FileDialogs.SelectFiles(initialDirectory, filter); if (fileNames != null) { LoggingStatus.PostMessage(Severity.Info, String.Format("Examining {0} tracking files...", fileNames.Count())); LoadFilesArgument arg = new LoadFilesArgument() { test = test, mergeReplace = mergeReplace }; arg.fileNames.AddRange(fileNames); List <LoadFilesArgument> args = new List <LoadFilesArgument>(); args.Add(arg); LoadTrackingWorker.RunWorkerAsync(args); } }
public MainWindow() { InitializeComponent(); LoadTrackingWorker.DoWork += LoadTracking; LoadTrackingWorker.RunWorkerCompleted += LoadTrackingCompleted; db = EyetrackerEntities.EyeTrackerDB; LoadData(); DataContext = db; LoggingStatus.PostMessage(Severity.Info, String.Format("Total of {0} tests loaded from database.", db.Tests.Count)); }
private void ScanForMissingTracking(String path, List <LoadFilesArgument> args) { LoggingStatus.PostMessage(Severity.Info, String.Format("Scanning files in {0}...", path)); try { foreach (String filePath in Directory.GetFiles(path)) { String fileName = Path.GetFileNameWithoutExtension(filePath); String extension = Path.GetExtension(filePath); if (!extension.ToUpper().Equals(".TXT") && !extension.ToUpper().Equals(".IDF")) { continue; } String[] nameParts = fileName.Split('-'); if (nameParts.Count() != 3) { continue; } if (nameParts[0].Length != 10) { continue; } int slideNum = -1; int testId = -1; if (!int.TryParse(nameParts[1], out testId) || !int.TryParse(nameParts[2], out slideNum)) { continue; } Test test = db.Tests.FirstOrDefault(t => t.id == testId); if (test == null) { LoggingStatus.PostMessage(Severity.Warning, String.Format("Encountered file {0} but could not find corresponding test.", fileName + extension)); continue; } Slide_Answer slideAnswer = test.Slide_Answer.FirstOrDefault(sa => sa.Slide.num == slideNum); if (slideAnswer == null) { LoggingStatus.PostMessage(Severity.Warning, String.Format("Encountered file {0} but could not find corresponding answer for slide {1} in test.", fileName + extension, slideNum)); continue; } LoadFilesArgument arg = args.FirstOrDefault(a => a.test.id == test.id); if (arg == null) { arg = new LoadFilesArgument() { test = test, mergeReplace = false }; args.Add(arg); } arg.fileNames.Add(filePath); } } catch (System.UnauthorizedAccessException) { } try { foreach (String subDir in Directory.GetDirectories(path)) { ScanForMissingTracking(subDir, args); } } catch (System.UnauthorizedAccessException) { } }