// Get and display the episode text if various conditions are met public void RefreshEpisodeInfo(FileTable fileTable, int fileIndex) { if (Keyboard.IsKeyDown(Key.H)) { this.EpisodeTextBlock.Visibility = Visibility.Hidden; this.FileNameTextBlock.Visibility = Visibility.Hidden; this.TimeTextBlock.Visibility = Visibility.Hidden; return; } if (Episodes.ShowEpisodes) { // Episode number if (Episodes.EpisodesDictionary.ContainsKey(fileIndex) == false) { Episodes.EpisodeGetEpisodesInRange(fileTable, fileIndex); } Tuple <int, int> episode = Episodes.EpisodesDictionary.ContainsKey(fileIndex) == true ? Episodes.EpisodesDictionary[fileIndex] : new Tuple <int, int>(1, 1); // This is the (rare) error case that happened once ot a user - if for some reason the fileIndex is not in range. Could probably indicate this in the UI (which currently just marks it as single) but not sure why this error happens, so what to put there is unclear if (episode.Item1 == int.MaxValue) { this.EpisodeTextBlock.Text = "\u221E"; } else { this.EpisodeTextBlock.Text = (episode.Item2 == 1) ? "Single" : String.Format("{0}/{1}", episode.Item1, episode.Item2); } this.EpisodeTextBlock.Foreground = (episode.Item1 == 1) ? Brushes.Red : Brushes.Black; this.EpisodeTextBlock.FontWeight = (episode.Item1 == 1 && episode.Item2 != 1) ? FontWeights.Bold : FontWeights.Normal;; // Filename without the extention and Time in HH: MM // This was on request from a user, who needed to scan for the first/last image in a timelapse capture sequence this.FileNameTextBlock.Text = System.IO.Path.GetFileNameWithoutExtension(this.ImageRow.File); string timeInHHMM = (this.ImageRow.Time.Length > 3) ? this.ImageRow.Time.Remove(this.ImageRow.Time.Length - 3) : String.Empty; this.TimeTextBlock.Text = " (" + timeInHHMM + ")"; } this.EpisodeTextBlock.Visibility = Episodes.ShowEpisodes ? Visibility.Visible : Visibility.Hidden; this.FileNameTextBlock.Visibility = this.EpisodeTextBlock.Visibility; this.TimeTextBlock.Visibility = this.EpisodeTextBlock.Visibility; }
// Get and display the episode text if various conditions are met public void RefreshEpisodeInfo(FileTable fileTable, int fileIndex) { if (Keyboard.IsKeyDown(Key.H)) { this.EpisodeTextBlock.Visibility = Visibility.Hidden; this.FileNameTextBlock.Visibility = Visibility.Hidden; this.TimeTextBlock.Visibility = Visibility.Hidden; return; } if (Episodes.ShowEpisodes) { // Episode number if (Episodes.EpisodesDictionary.ContainsKey(fileIndex) == false) { Episodes.EpisodeGetEpisodesInRange(fileTable, fileIndex); } Tuple <int, int> episode = Episodes.EpisodesDictionary[fileIndex]; if (episode.Item1 == int.MaxValue) { this.EpisodeTextBlock.Text = "\u221E"; } else { this.EpisodeTextBlock.Text = (episode.Item2 == 1) ? "Single" : String.Format("{0}/{1}", episode.Item1, episode.Item2); } this.EpisodeTextBlock.Foreground = (episode.Item1 == 1) ? Brushes.Red : Brushes.Black; this.EpisodeTextBlock.FontWeight = (episode.Item1 == 1 && episode.Item2 != 1) ? FontWeights.Bold : FontWeights.Normal;; // Filename without the extention and Time in HH: MM // This was on request from a user, who needed to scan for the first/last image in a timelapse capture sequence this.FileNameTextBlock.Text = System.IO.Path.GetFileNameWithoutExtension(this.ImageRow.File); string timeInHHMM = (this.ImageRow.Time.Length > 3) ? this.ImageRow.Time.Remove(this.ImageRow.Time.Length - 3) : String.Empty; this.TimeTextBlock.Text = " (" + timeInHHMM + ")"; } this.EpisodeTextBlock.Visibility = Episodes.ShowEpisodes ? Visibility.Visible : Visibility.Hidden; this.FileNameTextBlock.Visibility = this.EpisodeTextBlock.Visibility; this.TimeTextBlock.Visibility = this.EpisodeTextBlock.Visibility; }
private async Task <bool> PopulateAsync() { return(await Task.Run(() => { string dataLabelToUpdate = this.dataLabelByLabel[this.dataFieldLabel]; this.TotalImages = this.fileDatabase.CountAllCurrentlySelectedFiles; int percentDone = 0; ObservableCollection <KeyValuePair <string, string> > keyValueList = new ObservableCollection <KeyValuePair <string, string> >(); List <ColumnTuplesWithWhere> imagesToUpdate = new List <ColumnTuplesWithWhere>(); //for (int imageIndex = 0; imageIndex < totalImages; ++imageIndex) int imageIndex = 0; string singletonData; while (imageIndex < TotalImages) { Episodes.Reset(); Episodes.EpisodeGetEpisodesInRange(this.fileDatabase.FileTable, imageIndex, Int32.MaxValue); // Provide feedback if the operation was cancelled during the database update if (Token.IsCancellationRequested == true) { keyValueList.Clear(); keyValueList.Add(new KeyValuePair <string, string>("Cancelled", "No changes were made")); return false; } // Provide feedback to the busy indicator every now and then if (this.ReadyToRefresh()) { percentDone = Convert.ToInt32(imageIndex / TotalImages * 100.0); this.Progress.Report(new ProgressBarArguments(percentDone, String.Format("Processing {0}/{1} images. ", imageIndex, TotalImages), true, false)); Thread.Sleep(Constant.ThrottleValues.RenderingBackoffTime); // Allows the UI thread to update every now and then } // Distinguish between single files vs and episode of files if (Episodes.EpisodesDictionary.Count <= 1) { if (this.SingletonAsSingle) { singletonData = "Single"; } else if (this.SingletonAsZero) { singletonData = "0:1|1"; } else { this.EpisodeCount++; singletonData = String.Format("{0}1|1", this.IncludeAnEpisodeIDNumber ? this.EpisodeCount + ":" : String.Empty); } List <ColumnTuple> ctl = new List <ColumnTuple>() { new ColumnTuple(this.dataLabelByLabel[this.dataFieldLabel], singletonData) }; imagesToUpdate.Add(new ColumnTuplesWithWhere(ctl, this.fileDatabase.FileTable[imageIndex].ID)); this.SingleCount++; imageIndex++; } else { this.EpisodeCount++; this.EpisodeNoSingletonsCount++; foreach (KeyValuePair <int, Tuple <int, int> > episode in Episodes.EpisodesDictionary) { List <ColumnTuple> ctl = new List <ColumnTuple>() { new ColumnTuple(this.dataLabelByLabel[this.dataFieldLabel], String.Format("{0}{1}|{2}", this.IncludeAnEpisodeIDNumber ? this.EpisodeCount + ":" : String.Empty, episode.Value.Item1, episode.Value.Item2)) }; imagesToUpdate.Add(new ColumnTuplesWithWhere(ctl, this.fileDatabase.FileTable[imageIndex].ID)); imageIndex++; } } } this.IsAnyDataUpdated = true; this.Progress.Report(new ProgressBarArguments(100, String.Format("Writing Episode data for {0} files. Please wait...", TotalImages), false, true)); Thread.Sleep(Constant.ThrottleValues.RenderingBackoffTime); // Allows the UI thread to update every now and then this.fileDatabase.UpdateFiles(imagesToUpdate); return true;//keyValueList; }, this.Token).ConfigureAwait(true)); }