public void Add(string filename, Models.Metadata image) { if (string.IsNullOrWhiteSpace(filename)) { throw new ArgumentNullException(nameof(filename)); } _logService.TraceEnter(); try { _logService.Trace("Checking if a date and caption have been specified..."); if (string.IsNullOrWhiteSpace(image.DateTaken) || string.IsNullOrWhiteSpace(image.Caption)) { _logService.Trace(@"Either the date or caption has not been specified. Exiting..."); return; } _logService.Trace($@"Adding ""{filename}"" to dictionary of images with caches..."); _images[filename] = image; } finally { _logService.TraceExit(); } }
public void Remove(string filename) { _logService.TraceEnter(); try { _logService.Trace($@"Checking if there is quick caption information for ""{filename}""..."); if (!_images.ContainsKey(filename)) { _logService.Trace($@"There is no quick caption information for ""{filename}"". Exiting..."); return; } _logService.Trace($@"Removing quick caption information for ""{filename}""..."); _images.Remove(filename); _logService.Trace($@"Checking if ""{filename}"" is the cached file..."); if (_cachedFilename != filename) { return; } _logService.Trace($@"""{filename}"" is the cached file. Removing..."); _cachedFilename = null; _cachedImage = null; } finally { _logService.TraceExit(); } }
public void Save(Models.Metadata metadata, string filename) { using (var logger = _logger.Block()) { // validate that all of the properties have a value if (metadata.AppendDateTakenToCaption == null) { throw new InvalidOperationException(@"""AppendDateTakenToCaption"" property value not specified"); } if (metadata.BackgroundColour == null) { throw new InvalidOperationException(@"""BackgroundColour"" property value not specified"); } if (metadata.CaptionAlignment == null) { throw new InvalidOperationException(@"""CaptionAlignment"" property value not specified"); } if (metadata.Colour == null) { throw new InvalidOperationException(@"""Colour"" property value not specified"); } if (metadata.FontBold == null) { throw new InvalidOperationException(@"""FontBold"" property value not specified"); } if (metadata.FontSize == null) { throw new InvalidOperationException(@"""FontSize"" property value not specified"); } if (metadata.ImageFormat == null) { throw new InvalidOperationException(@"""ImageFormat"" property value not specified"); } if (metadata.Rotation == null) { throw new InvalidOperationException(@"""Rotation"" property value not specified"); } logger.Trace($"Saving metadata for \"{filename}\"..."); // get the name of the metadata file var metadataFilename = GetMetadataFilename(filename); logger.Trace($@"Saving metadata to ""{metadataFilename}""..."); _xmlFileSerialiser.Serialise(metadata, metadataFilename); } }
public Models.Metadata Populate(Models.Metadata metadata) { using (var logger = _logger.Block()) { logger.Trace("Populating any incomplete metadata values with defaults..."); metadata.AppendDateTakenToCaption = metadata.AppendDateTakenToCaption ?? false; metadata.BackgroundColour = metadata.BackgroundColour ?? System.Drawing.Color.Transparent.ToArgb(); metadata.CaptionAlignment = metadata.CaptionAlignment ?? CaptionAlignments.BottomRight; metadata.Colour = metadata.Colour ?? System.Drawing.Color.White.ToArgb(); metadata.FontBold = metadata.FontBold ?? false; metadata.FontFamily = metadata.FontFamily ?? System.Drawing.SystemFonts.DefaultFont.SystemFontName; metadata.FontSize = metadata.FontSize ?? 10; metadata.FontType = metadata.FontType ?? "pts"; metadata.ImageFormat = metadata.ImageFormat ?? ImageFormat.Jpeg; metadata.Rotation = metadata.Rotation ?? Rotations.Zero; return(metadata); } }
public void Clear() { _logService.TraceEnter(); try { _logService.Trace("Clearing list..."); _cachedImage = null; _images.Clear(); _logService.Trace($@"Notifying {_observers.Count} observers that list has been cleared..."); foreach (var observer in _observers) { observer.OnClear(); } } finally { _logService.TraceExit(); } }
public void Switch(string filename, Models.Metadata image) { _logService.TraceEnter(); try { _logService.Trace("Checking if filename has changed..."); if (_cachedFilename == filename) { _logService.Trace("Filename has not changed. Exiting..."); return; } _logService.Trace("Caching filename..."); _cachedFilename = filename; _cachedImage = image; _logService.Trace($@"Building caption list for ""{filename}""..."); var captions = GetQuickCaptions(); _logService.Trace($"Notifying {_observers.Count} observers of {captions.Count} captions..."); foreach (var observer in _observers) { Notify(observer, captions); } } catch (Exception ex) { _logService.Trace($@"Notifying {_observers.Count} observers of error..."); foreach (var observer in _observers) { observer.OnError(ex); } } finally { _logService.TraceExit(); } }