Exemple #1
0
        /// <summary>
        /// backup currnt image
        /// </summary>
        /// <param name="imagePath">image</param>
        /// <returns>if success or the reson of failuer</returns>
        public ExitCode BackupImage(string imagePath)
        {
            // make sure file aint lock
            ExitCode status;

            while (IsFileLocked(imagePath))
            {
                System.Threading.Thread.Sleep(500);
            }

            DateTime date = GetImageDate(imagePath, out status);

            if (status != ExitCode.Success)
            {
                return(ExitCode.F_Missing_Date);
            }

            string imageName      = Path.GetFileName(imagePath);
            string imageDest      = outputFolder + "\\" + date.Year + "\\" + date.Month;
            string imageThumbDest = outputFolder + "\\Thumbnails\\" + date.Year + "\\" + date.Month;

            status = fileHandler.CreateDir(imageDest);
            if (status != ExitCode.Success)
            {
                return(ExitCode.F_Create_Dir);
            }
            status = fileHandler.CreateDir(imageThumbDest);
            if (status != ExitCode.Success)
            {
                return(ExitCode.F_Create_Dir);
            }

            Image thumbImage = fileHandler.CreateThumbnail(imagePath, thumbnailSize, out status);

            if (status != ExitCode.Success)
            {
                return(ExitCode.F_Create_Thumb);
            }
            status = fileHandler.SaveImage(imageThumbDest + "\\" + imageName, thumbImage);
            if (status != ExitCode.Success)
            {
                return(ExitCode.F_Create_Thumb);
            }

            status = fileHandler.MoveFile(imagePath, imageDest);
            if (status != ExitCode.Success)
            {
                return(ExitCode.F_Move);
            }

            return(ExitCode.Success);
        }