Ejemplo n.º 1
0
        public void WriteInfo(string info, bool showDate = false)
        {
            if (string.IsNullOrWhiteSpace(info))
            {
                return;
            }

            string text;

            if (showDate)
            {
                text = $"{GetDateTime()} {info}{Environment.NewLine}";
            }
            else
            {
                text = $"[{info}]{Environment.NewLine}";
            }

            OnNewInfo.Invoke(this, text);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates thumbnails for the images, wich are stored in the given source
        /// </summary>
        /// <param name="imageFiles">The image files</param>
        /// <param name="source">The path of the source folder</param>
        /// <param name="width">The width of the thumbnail</param>
        /// <param name="height">The height of the thumbnail</param>
        /// <param name="keepRatio">true if the user wants to keep the ratio of the image, otherwise false</param>
        /// <returns>A dictionary with the image size for every image. The key is the name of the image</returns>
        /// <exception cref="ArgumentNullException"/>
        /// <exception cref="DirectoryNotFoundException"/>
        public static Dictionary <string, ImageSize> CreateThumbnails(List <ImageModel> imageFiles, string source, int width, int height, bool keepRatio)
        {
            // Step 1: Check the parameters
            if (!Directory.Exists(source))
            {
                throw new DirectoryNotFoundException("The specified source doesn't exist.");
            }

            var result = new Dictionary <string, ImageSize>();

            // Step 2: Create Thumbnail folder
            if (!CreateThumbnailFolder(source))
            {
                OnNewInfo?.Invoke(GlobalHelper.InfoType.Error, "Can't create thumbnail folder.");
                return(result);
            }

            // Step 4: Itterate through the image list and create for every image a thumbnail
            var count = 1;

            foreach (var image in imageFiles)
            {
                OnProgress?.Invoke(GlobalHelper.CalculateCurrentProgress(count++, imageFiles.Count), 100);
                OnNewInfo?.Invoke(GlobalHelper.InfoType.Info, $"Create thumbnail {count} of {imageFiles.Count}");

                var imageSize = new ImageSize(width, height);
                if (keepRatio || height == 0 && width != 0 || height != 0 && width == 0)
                {
                    imageSize = CalculateImageSize(image.File, width, height);
                }

                var newImage = GlobalHelper.ResizeImage(image.File, imageSize.Width, imageSize.Height);

                newImage.Save(Path.Combine(source, ThumbnailFolderName, image.File.Name));

                result.Add(image.File.Name, imageSize);
            }

            return(result);
        }