protected ImageModel(string filePath, Guid uniqueId) { UniqueId = uniqueId; FilePath = filePath; // Create FileInfo object FileInfo fi = new FileInfo(filePath); FileName = fi.Name; CreationTime = fi.CreationTime; Extension = fi.Extension; DirectoryName = fi.DirectoryName; FileSize = fi.Length; Size = FileNameParser.GetFileSizeWithPrefix(fi.Length); }
/// <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); }