/// <summary> /// Registers a class to handle its specified file types /// </summary> /// <param name="Viewer">The class to act as the handler</param> /// <param name="ID">The ID of the viewer</param> public static void RegisterMediaViewer(string ID, IMediaViewer Viewer) { if (string.IsNullOrWhiteSpace(ID)) { throw new ArgumentNullException(nameof(ID), "The ID had no valid content"); } try { Viewers.Add(ID, Viewer); Logging.Write($"Registered Media Viewer \"{ID}\"", "Registry"); } catch (Exception e) { Logging.Write(e, "Registry"); throw; } }
private void load(string path) { current = path; IMedia media = Data.Media[path]; IMediaViewer viewer = Registry.Viewers[Registry.SupportedDataTypes[media.FileType]]; viewer.LoadMedia(path, true); frmViewer.Content = viewer.Display; stkTags.Children.Clear(); foreach (int i in media.GetTags()) { ToggleButton tb = new ToggleButton() { Content = Data.Tags[Data.TagLocations[i]].Name, Style = (Style)Application.Current.Resources["Tag Button"], Tag = i }; tb.Checked += handleTagClick; stkTags.Children.Add(tb); } }
private void renderIndex() { if (Editing != null) { IMedia media = Data.Media[Editing]; string fileType = media.FileType; if (Registry.SupportedDataTypes.ContainsKey(fileType)) { string toLoad = Registry.SupportedDataTypes[fileType]; IMediaViewer viewer = Registry.Viewers[toLoad]; viewer.LoadMedia(Editing, true); if (currentViewer != toLoad) { frmPreview.Content = viewer.Display; } } lblIndex.Content = ""; checkTags(editTags.ToArray()); } else { string path = toImport[index]; string ext = Path.GetExtension(path).ToLower(); if (Registry.SupportedDataTypes.ContainsKey(ext)) { try { string toLoad = Registry.SupportedDataTypes[ext]; IMediaViewer viewer = Registry.Viewers[toLoad]; viewer.LoadMedia(path, false); if (currentViewer != toLoad) { Dispatcher.Invoke(() => frmPreview.Content = viewer.Display); } lblIndex.Content = $"{toImport.Count - index}/{toImport.Count}"; checkTags(checkedTags[index].ToArray()); } catch (Exception) { if (Debugger.IsAttached) { throw; } //TODO - HANDLE APPROPRIATE ERRORS AND LOG THEM MessageBox.Show($"The file at \"{path}\" could not be read. Please check if it's still there, and if it can be opened"); toImport.RemoveAt(index); checkedTags.RemoveAt(index); if (index > 0) { index--; } if (toImport.Count == 0) { frmPreview.Content = null; Paging.LoadPreviousPage(); return; } renderIndex(); } } else { //TODO - HANDLE INVALID FILE TYPE //Announce "Do not have a handler for that file type! ({ext}) } } }