/// <summary> /// Adds the image to process queue. /// </summary> /// <param name="filePath">The file path.</param> /// <param name="eventMessageQueue">The event message queue.</param> /// <returns></returns> public bool AddImageToProcessQueue(string filePath, ref EventMessageQueue eventMessageQueue) { try { // Validate access and existence if (!File.Exists(filePath)) { eventMessageQueue.AddMessage($"{filePath} - A file with specified path does not exist"); return(false); } // Validate uniqueness if (_userConfig.ImageModels.Any(x => x.FilePath.Equals(filePath, StringComparison.CurrentCultureIgnoreCase))) { eventMessageQueue.AddMessage($"{filePath} - Is already added to the process queue."); return(false); } var model = ImageModel.CreateImageModel(filePath); var fi = new FileInfo(filePath); model.SortOrder = GetNextSortOrder(); model.FileName = fi.Name; model.CreationTime = fi.CreationTime; model.Extension = fi.Extension; model.DirectoryName = fi.DirectoryName; model.FileSize = fi.Length; model.Size = FileNameParser.GetFileSizeWithPrefix(model.FileSize); model.DisplayName = $"FileName: {model.FileName}, Size{model.Size}"; _userConfig.ImageModels.Add(model); RebuildSortIndex(); return(true); } catch (Exception ex) { Log.Error(ex, "AddImageToProcessQueue threw an exception", nameof(filePath)); eventMessageQueue.AddMessage(ex.Message); } return(false); }
/// <summary> /// Removes the image from process queue. /// </summary> /// <param name="imageGuid">The image unique identifier.</param> /// <param name="messageQueue">The message queue.</param> /// <returns></returns> public bool RemoveImageFromProcessQueue(Guid imageGuid, ref EventMessageQueue messageQueue) { if (_userConfig.ImageModels.All(x => x.UniqueId != imageGuid)) { messageQueue.AddMessage($"Could not remove item from list, list sync error?"); return(false); } var model = _userConfig.ImageModels.First(x => x.UniqueId == imageGuid); bool result = _userConfig.ImageModels.Remove(model); if (result) { RebuildSortIndex(); } return(result); }