Exemplo n.º 1
0
        public static void UpdateDirectories()
        {
            var pictDirs = new List <string>
            {
                FoldersHelper.GetPathAbsolut(FolderType.Product),
                FoldersHelper.GetPathAbsolut(FolderType.News),
                FoldersHelper.GetPathAbsolut(FolderType.Category),
                FoldersHelper.GetPathAbsolut(FolderType.BrandLogo),
                FoldersHelper.GetPathAbsolut(FolderType.Carousel),
                FoldersHelper.GetPathAbsolut(FolderType.Color),
            };

            pictDirs.AddRange(FoldersHelper.ProductPhotoPrefix.Select(kvp => FoldersHelper.GetImageProductPathAbsolut(kvp.Key, string.Empty)));
            pictDirs.AddRange(FoldersHelper.CategoryPhotoPrefix.Select(kvp => FoldersHelper.GetImageCategoryPathAbsolut(kvp.Key, string.Empty)));
            pictDirs.AddRange(FoldersHelper.ColorPhotoPrefix.Select(kvp => FoldersHelper.GetImageColorPathAbsolut(kvp.Key, string.Empty)));
            foreach (var directory in pictDirs.Where(dir => (!Directory.Exists(dir) && dir.Trim().Length != 0)))
            {
                Directory.CreateDirectory(directory);
            }
        }
Exemplo n.º 2
0
        protected void btnCleanUpPictureFolder_Click(object sender, EventArgs e)
        {
            var fileNames = new List<string>();

            foreach (var photo in PhotoService.GetNamePhotos(0, PhotoType.Product, true))
            {
                fileNames.Add(FoldersHelper.GetImageProductPathAbsolut(ProductImageType.Big, photo));
                fileNames.Add(FoldersHelper.GetImageProductPathAbsolut(ProductImageType.Middle, photo));
                fileNames.Add(FoldersHelper.GetImageProductPathAbsolut(ProductImageType.Small, photo));
                fileNames.Add(FoldersHelper.GetImageProductPathAbsolut(ProductImageType.XSmall, photo));
            }

            foreach (string photo in PhotoService.GetNamePhotos(0, PhotoType.CategoryBig, true))
            {
                fileNames.Add(FoldersHelper.GetImageCategoryPathAbsolut(CategoryImageType.Big, photo));
            }

            foreach (string photo in PhotoService.GetNamePhotos(0, PhotoType.CategorySmall, true))
            {
                fileNames.Add(FoldersHelper.GetImageCategoryPathAbsolut(CategoryImageType.Small, photo));
            }

            foreach (string photo in PhotoService.GetNamePhotos(0, PhotoType.Color, true))
            {
                fileNames.Add(FoldersHelper.GetImageColorPathAbsolut(ColorImageType.Catalog, photo));
                fileNames.Add(FoldersHelper.GetImageColorPathAbsolut(ColorImageType.Details, photo));
            }

            foreach (string photo in PhotoService.GetNamePhotos(0, PhotoType.Brand, true))
            {
                fileNames.Add(FoldersHelper.GetPathAbsolut(FolderType.BrandLogo, photo));
            }
            foreach (string photo in PhotoService.GetNamePhotos(0, PhotoType.Carousel, true))
            {
                fileNames.Add(FoldersHelper.GetPathAbsolut(FolderType.Carousel, photo));
            }

            foreach (string photo in PhotoService.GetNamePhotos(0, PhotoType.MenuIcon, true))
            {
                fileNames.Add(FoldersHelper.GetPathAbsolut(FolderType.MenuIcons, photo));
            }
            foreach (string photo in PhotoService.GetNamePhotos(0, PhotoType.News, true))
            {
                fileNames.Add(FoldersHelper.GetPathAbsolut(FolderType.News, photo));
            }


            //Add Logo image in exceptions
            fileNames.Add(SettingsMain.LogoImageName);

            var files = new List<string>();
            files.AddRange(Directory.GetFiles(FoldersHelper.GetImageProductPathAbsolut(ProductImageType.Big, string.Empty)));
            files.AddRange(Directory.GetFiles(FoldersHelper.GetImageProductPathAbsolut(ProductImageType.Middle, string.Empty)));
            files.AddRange(Directory.GetFiles(FoldersHelper.GetImageProductPathAbsolut(ProductImageType.Small, string.Empty)));
            files.AddRange(Directory.GetFiles(FoldersHelper.GetImageProductPathAbsolut(ProductImageType.XSmall, string.Empty)));

            // CategoryImageType ------------------------

            files.AddRange(Directory.GetFiles(FoldersHelper.GetImageCategoryPathAbsolut(CategoryImageType.Big, string.Empty)));

            if (Directory.Exists(FoldersHelper.GetImageCategoryPathAbsolut(CategoryImageType.Small, string.Empty)))
            {
                files.AddRange(Directory.GetFiles(FoldersHelper.GetImageCategoryPathAbsolut(CategoryImageType.Small, string.Empty)));
            }

            // ColorImageType Check exist ----------------

            if (Directory.Exists(FoldersHelper.GetImageColorPathAbsolut(ColorImageType.Catalog, string.Empty)))
            {
                files.AddRange(Directory.GetFiles(FoldersHelper.GetImageColorPathAbsolut(ColorImageType.Catalog, string.Empty)));
            }
            if (Directory.Exists(FoldersHelper.GetImageColorPathAbsolut(ColorImageType.Details, string.Empty)))
            {
                files.AddRange(Directory.GetFiles(FoldersHelper.GetImageColorPathAbsolut(ColorImageType.Details, string.Empty)));
            }

            // FolderType --------------------------------

            files.AddRange(Directory.GetFiles(FoldersHelper.GetPathAbsolut(FolderType.BrandLogo, string.Empty)));
            files.AddRange(Directory.GetFiles(FoldersHelper.GetPathAbsolut(FolderType.Carousel, string.Empty)));
            files.AddRange(Directory.GetFiles(FoldersHelper.GetPathAbsolut(FolderType.MenuIcons, string.Empty)));
            files.AddRange(Directory.GetFiles(FoldersHelper.GetPathAbsolut(FolderType.News, string.Empty)));


            var deleted = new List<string>();

            foreach (string file in files)
            {
                if (!fileNames.Contains(file) || (file.Trim().Length == 0))
                {
                    if (chboxDeleteFiles.Checked)
                    {
                        File.Delete(file);
                    }
                    deleted.Add(file);
                }
            }

            if (!chboxDeleteFiles.Checked)
            {
                lCompleted.Text = @"Analysis successfully completed";
            }

            lCompleted.Visible = true;

            var res = new StringBuilder();

            foreach (string del in deleted)
            {
                res.Append(del);
                res.Append("<br />");
            }

            if (deleted.Count > 0)
            {
                if (!chboxDeleteFiles.Checked)
                {
                    lResultHeader.Text = @"Files to delete";
                }
                lResultHeader.Visible = true;
                lResult.Text = res.ToString();
            }
            else
            {
                lResultHeader.Text = @"No unnecessary files";
                lResultHeader.Visible = true;
            }
        }
Exemplo n.º 3
0
        private static void DeleteFile(PhotoType type, string photoName)
        {
            bool backup = SettingProvider.GetConfigSettingValue <bool>("BackupPhotosBeforeDeleting");

            switch (type)
            {
            case PhotoType.Product:

                if (backup)
                {
                    FileHelpers.BackupFhoto(FoldersHelper.GetImageProductPathAbsolut(ProductImageType.Original, photoName));
                    FileHelpers.BackupFhoto(FoldersHelper.GetImageProductPathAbsolut(ProductImageType.Big, photoName));
                    FileHelpers.BackupFhoto(FoldersHelper.GetImageProductPathAbsolut(ProductImageType.Middle, photoName));
                    FileHelpers.BackupFhoto(FoldersHelper.GetImageProductPathAbsolut(ProductImageType.Small, photoName));
                    FileHelpers.BackupFhoto(FoldersHelper.GetImageProductPathAbsolut(ProductImageType.XSmall, photoName));
                }
                else
                {
                    FileHelpers.DeleteFile(FoldersHelper.GetImageProductPathAbsolut(ProductImageType.Original, photoName));
                    FileHelpers.DeleteFile(FoldersHelper.GetImageProductPathAbsolut(ProductImageType.Big, photoName));
                    FileHelpers.DeleteFile(FoldersHelper.GetImageProductPathAbsolut(ProductImageType.Middle, photoName));
                    FileHelpers.DeleteFile(FoldersHelper.GetImageProductPathAbsolut(ProductImageType.Small, photoName));
                    FileHelpers.DeleteFile(FoldersHelper.GetImageProductPathAbsolut(ProductImageType.XSmall, photoName));
                }
                break;

            case PhotoType.Brand:
                if (backup)
                {
                    FileHelpers.BackupFhoto(FoldersHelper.GetPathAbsolut(FolderType.BrandLogo, photoName));
                }
                else
                {
                    FileHelpers.DeleteFile(FoldersHelper.GetPathAbsolut(FolderType.BrandLogo, photoName));
                }
                break;

            case PhotoType.CategoryBig:
                if (backup)
                {
                    FileHelpers.BackupFhoto(FoldersHelper.GetImageCategoryPathAbsolut(CategoryImageType.Big, photoName));
                }
                else
                {
                    FileHelpers.DeleteFile(FoldersHelper.GetImageCategoryPathAbsolut(CategoryImageType.Big, photoName));
                }
                break;

            case PhotoType.CategorySmall:
                if (backup)
                {
                    FileHelpers.BackupFhoto(FoldersHelper.GetImageCategoryPathAbsolut(CategoryImageType.Small, photoName));
                }
                else
                {
                    FileHelpers.DeleteFile(FoldersHelper.GetImageCategoryPathAbsolut(CategoryImageType.Small, photoName));
                }
                break;

            case PhotoType.CategoryIcon:
                if (backup)
                {
                    FileHelpers.BackupFhoto(FoldersHelper.GetImageCategoryPathAbsolut(CategoryImageType.Icon, photoName));
                }
                else
                {
                    FileHelpers.DeleteFile(FoldersHelper.GetImageCategoryPathAbsolut(CategoryImageType.Icon, photoName));
                }
                break;

            case PhotoType.Carousel:
                if (backup)
                {
                    FileHelpers.BackupFhoto(FoldersHelper.GetPathAbsolut(FolderType.Carousel, photoName));
                }
                else
                {
                    FileHelpers.DeleteFile(FoldersHelper.GetPathAbsolut(FolderType.Carousel, photoName));
                }
                break;

            case PhotoType.News:
                if (backup)
                {
                    FileHelpers.BackupFhoto(FoldersHelper.GetPathAbsolut(FolderType.News, photoName));
                }
                else
                {
                    FileHelpers.DeleteFile(FoldersHelper.GetPathAbsolut(FolderType.News, photoName));
                }
                break;

            case PhotoType.StaticPage:
                if (backup)
                {
                    FileHelpers.BackupFhoto(FoldersHelper.GetPathAbsolut(FolderType.StaticPage, photoName));
                }
                else
                {
                    FileHelpers.DeleteFile(FoldersHelper.GetPathAbsolut(FolderType.StaticPage, photoName));
                }
                break;

            case PhotoType.Shipping:
                if (backup)
                {
                    FileHelpers.BackupFhoto(FoldersHelper.GetPathAbsolut(FolderType.ShippingLogo, photoName));
                }
                else
                {
                    FileHelpers.DeleteFile(FoldersHelper.GetPathAbsolut(FolderType.ShippingLogo, photoName));
                }
                break;

            case PhotoType.Payment:
                if (backup)
                {
                    FileHelpers.BackupFhoto(FoldersHelper.GetPathAbsolut(FolderType.PaymentLogo, photoName));
                }
                else
                {
                    FileHelpers.DeleteFile(FoldersHelper.GetPathAbsolut(FolderType.PaymentLogo, photoName));
                }
                break;

            case PhotoType.MenuIcon:
                if (backup)
                {
                    FileHelpers.BackupFhoto(FoldersHelper.GetPathAbsolut(FolderType.MenuIcons, photoName));
                }
                else
                {
                    FileHelpers.DeleteFile(FoldersHelper.GetPathAbsolut(FolderType.MenuIcons, photoName));
                }
                break;

            case PhotoType.Color:
                if (backup)
                {
                    FileHelpers.BackupFhoto(FoldersHelper.GetImageColorPathAbsolut(ColorImageType.Catalog, photoName));
                    FileHelpers.BackupFhoto(FoldersHelper.GetImageColorPathAbsolut(ColorImageType.Details, photoName));
                }
                else
                {
                    FileHelpers.DeleteFile(FoldersHelper.GetImageColorPathAbsolut(ColorImageType.Catalog, photoName));
                    FileHelpers.DeleteFile(FoldersHelper.GetImageColorPathAbsolut(ColorImageType.Details, photoName));
                }
                break;

            default:
                throw new NotImplementedException();
            }
        }
Exemplo n.º 4
0
        protected void btnCleanUpBD_Click(object sender, EventArgs e)
        {
            var res = new StringBuilder();

            try
            {
                foreach (var photoName in PhotoService.GetNamePhotos(0, PhotoType.Product, true))
                {
                    res.Append(CheckExistingFile(PhotoType.Product, photoName, FoldersHelper.GetImageProductPathAbsolut(ProductImageType.Big, photoName)));
                    res.Append(CheckExistingFile(PhotoType.Product, photoName, FoldersHelper.GetImageProductPathAbsolut(ProductImageType.Middle, photoName)));
                    res.Append(CheckExistingFile(PhotoType.Product, photoName, FoldersHelper.GetImageProductPathAbsolut(ProductImageType.Small, photoName)));
                    res.Append(CheckExistingFile(PhotoType.Product, photoName, FoldersHelper.GetImageProductPathAbsolut(ProductImageType.XSmall, photoName)));
                }

                foreach (var photoName in PhotoService.GetNamePhotos(0, PhotoType.CategoryBig, true))
                {
                    res.Append(CheckExistingFile(PhotoType.CategoryBig, photoName, FoldersHelper.GetImageCategoryPathAbsolut(CategoryImageType.Big, photoName)));
                }

                foreach (var photoName in PhotoService.GetNamePhotos(0, PhotoType.CategorySmall, true))
                {
                    res.Append(CheckExistingFile(PhotoType.CategorySmall,photoName, FoldersHelper.GetImageCategoryPathAbsolut(CategoryImageType.Small, photoName)));
                }


                foreach (var photoName in PhotoService.GetNamePhotos(0, PhotoType.Color, true))
                {
                    res.Append(CheckExistingFile(PhotoType.Color, photoName, FoldersHelper.GetImageColorPathAbsolut(ColorImageType.Catalog, photoName)));
                }


                foreach (var photoName in PhotoService.GetNamePhotos(0, PhotoType.Color, true))
                {
                    res.Append(CheckExistingFile(PhotoType.Color, photoName, FoldersHelper.GetImageColorPathAbsolut(ColorImageType.Details, photoName)));
                }

                foreach (var photoName in PhotoService.GetNamePhotos(0, PhotoType.Brand, true))
                {
                    res.Append(CheckExistingFile(PhotoType.Brand, photoName, FoldersHelper.GetPathAbsolut(FolderType.BrandLogo, photoName)));
                }
                foreach (var photoName in PhotoService.GetNamePhotos(0, PhotoType.Carousel, true))
                {
                    res.Append(CheckExistingFile(PhotoType.Carousel, photoName, FoldersHelper.GetPathAbsolut(FolderType.Carousel, photoName)));
                }
                foreach (var photoName in PhotoService.GetNamePhotos(0, PhotoType.MenuIcon, true))
                {
                    res.Append(CheckExistingFile(PhotoType.MenuIcon, photoName, FoldersHelper.GetPathAbsolut(FolderType.MenuIcons, photoName)));
                }
                foreach (var photoName in PhotoService.GetNamePhotos(0, PhotoType.News, true))
                {
                    res.Append(CheckExistingFile(PhotoType.News, photoName, FoldersHelper.GetPathAbsolut(FolderType.News, photoName)));
                }
                foreach (var photoName in PhotoService.GetNamePhotos(0, PhotoType.Payment, true))
                {
                    res.Append(CheckExistingFile(PhotoType.Payment, photoName, FoldersHelper.GetPathAbsolut(FolderType.PaymentLogo, photoName)));
                }
                foreach (var photoName in PhotoService.GetNamePhotos(0, PhotoType.Shipping, true))
                {
                    res.Append(CheckExistingFile(PhotoType.Shipping, photoName, FoldersHelper.GetPathAbsolut(FolderType.ShippingLogo, photoName)));
                }
            }
            catch (Exception ex)
            {
                Debug.LogError(ex);
            }

            if (!chboxMakeNull.Checked)
            {
                lDBCleanupCompleted.Text = @"Analysis successfully completed";
            }

            lDBCleanupCompleted.Visible = true;

            lDBResult.Text = string.IsNullOrEmpty(res.ToString()) ? @"No items to correct" : res.ToString();
        }