public static GTReader Instance() { if (_instance == null) { _instance = new GTReader(); } return(_instance); }
private async void GeotagRead_Click(object sender, RoutedEventArgs e) { if (Utilities.directoryHasFiles(mInputPath)) { reader = GTReader.Instance(); startTimers(); BrowseInputRead.IsEnabled = false; BrowseOutputRead.IsEnabled = false; GeotagRead.IsEnabled = false; TabItemWrite.IsEnabled = false; manager = null; bool format = Utilities.isFileValid(mOutputPath); if (format) { var source = new CancellationTokenSource(); CancellationToken token = source.Token; Task worker = Task.Factory.StartNew(() => { showProgressBar(); progressIndeterminate(true); reader.photoReader(mInputPath, false); progressIndeterminate(false); TaskStatus result = reader.readGeotag().Result; if (result == TaskStatus.RanToCompletion) { } }); await Task.WhenAll(worker); ConcurrentQueue <Record> queue = reader.Queue; List <Record> list = queue.ToList(); Writer writer = new Writer(list); writer.WriteCSV(mOutputPath); } else { string message = "The output file path is not valid"; string caption = "Error in output path"; MessageBoxButtons buttons = MessageBoxButtons.OK; // Displays the MessageBox. System.Windows.Forms.MessageBox.Show(message, caption, buttons); } } }
/// <summary> /// Fired when user clicks geotag button. Starts geotagger writer /// </summary> /// <param name="sender">object - the geotag button</param> /// <param name="e">click event</param> private async void Geotag_Click(object sender, RoutedEventArgs e) { if (Utilities.directoryHasFiles(mInputPath) || mInputPath != null) { manager = GTWriter.Instance(50); manager.Initialise(); startTimers(); BrowseDB.IsEnabled = false; BrowseInput.IsEnabled = false; BrowseOutput.IsEnabled = false; Geotag.IsEnabled = false; TabItemRead.IsEnabled = false; Upload.IsEnabled = false; reader = null; var source = new CancellationTokenSource(); CancellationToken token = source.Token; Task worker = Task.Factory.StartNew(() => { showProgressBar(); progressIndeterminate(true); manager.photoReader(mInputPath, false); progressIndeterminate(false); TaskStatus result = manager.readDatabase(mDBPath, "").Result; Console.WriteLine(result); if (result == TaskStatus.RanToCompletion) { if (manager.updateDuplicateCount == 0) { TaskStatus consumerStatus = manager.writeGeotag(mOutputPath).Result; if (consumerStatus == TaskStatus.RanToCompletion) { Dispatcher.Invoke((Action)(() => { refreshUI(); })); } else { Console.WriteLine(consumerStatus); } } else { MessageBoxResult msgResult = System.Windows.MessageBox.Show("Duplicates detected in the record database", "Operation will be cancelled", MessageBoxButton.OK, MessageBoxImage.Error); source.Cancel(); } if (token.IsCancellationRequested) { timer = false; token.ThrowIfCancellationRequested(); } } else { Console.WriteLine(result); } }, token); try { await Task.WhenAll(worker); Dispatcher.Invoke((Action)(() => { refreshUI(); SpeedLabel.Content = "Items/sec: 0"; })); BrowseDB.IsEnabled = true; BrowseInput.IsEnabled = true; BrowseOutput.IsEnabled = true; Geotag.IsEnabled = true; Upload.IsEnabled = true; TabItemRead.IsEnabled = true; dispatcherTimer.Stop(); timer = false; TimeSpan ts = stopwatch.Elapsed; string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); LogWriter log = new LogWriter(manager); log.Write(mDBPath, elapsedTime); } catch (OperationCanceledException ex) { manager.updateProgessMessage = "Cancelled"; refreshUI(); } } }