Exemplo n.º 1
0
        public static async Task <(bool isValid, string explanation)> PhotoFileValidation(FileInfo photoFile,
                                                                                          Guid?currentContentId)
        {
            photoFile.Refresh();

            if (!photoFile.Exists)
            {
                return(false, "File does not Exist?");
            }

            if (!FolderFileUtility.IsNoUrlEncodingNeeded(Path.GetFileNameWithoutExtension(photoFile.Name)))
            {
                return(false, "Limit File Names to A-Z a-z 0-9 - . _");
            }

            if (!FolderFileUtility.PictureFileTypeIsSupported(photoFile))
            {
                return(false, "The file doesn't appear to be a supported file type.");
            }

            if (await(await Db.Context()).PhotoFilenameExistsInDatabase(photoFile.Name, currentContentId))
            {
                return(false, "This filename already exists in the database - photo file names must be unique.");
            }

            return(true, "File is Valid");
        }
Exemplo n.º 2
0
        public static async Task <GenerationReturn> Validate(ImageContent imageContent, FileInfo selectedFile)
        {
            var rootDirectoryCheck = UserSettingsUtilities.ValidateLocalSiteRootDirectory();

            if (!rootDirectoryCheck.Item1)
            {
                return(await GenerationReturn.Error($"Problem with Root Directory: {rootDirectoryCheck.Item2}",
                                                    imageContent.ContentId));
            }

            var mediaArchiveCheck = UserSettingsUtilities.ValidateLocalMediaArchive();

            if (!mediaArchiveCheck.Item1)
            {
                return(await GenerationReturn.Error($"Problem with Media Archive: {mediaArchiveCheck.Item2}",
                                                    imageContent.ContentId));
            }

            var commonContentCheck = await CommonContentValidation.ValidateContentCommon(imageContent);

            if (!commonContentCheck.valid)
            {
                return(await GenerationReturn.Error(commonContentCheck.explanation, imageContent.ContentId));
            }

            var updateFormatCheck = CommonContentValidation.ValidateUpdateContentFormat(imageContent.UpdateNotesFormat);

            if (!updateFormatCheck.isValid)
            {
                return(await GenerationReturn.Error(updateFormatCheck.explanation, imageContent.ContentId));
            }

            selectedFile.Refresh();

            if (!selectedFile.Exists)
            {
                return(await GenerationReturn.Error("Selected File doesn't exist?", imageContent.ContentId));
            }

            if (!FolderFileUtility.IsNoUrlEncodingNeeded(Path.GetFileNameWithoutExtension(selectedFile.Name)))
            {
                return(await GenerationReturn.Error("Limit File Names to A-Z a-z - . _", imageContent.ContentId));
            }

            if (!FolderFileUtility.PictureFileTypeIsSupported(selectedFile))
            {
                return(await GenerationReturn.Error("The file doesn't appear to be a supported file type.",
                                                    imageContent.ContentId));
            }

            if (await(await Db.Context()).ImageFilenameExistsInDatabase(selectedFile.Name, imageContent.ContentId))
            {
                return(await GenerationReturn.Error(
                           "This filename already exists in the database - image file names must be unique.",
                           imageContent.ContentId));
            }

            return(await GenerationReturn.Success("Image Content Validation Successful"));
        }
        /// <summary>
        ///     Deletes files from the local content directory of the dbEntry that are supported Photo file types but
        ///     don't match the original file name in the dbEntry. Use with caution and make sure that the PhotoContent
        ///     is current/has the intended values.
        /// </summary>
        /// <param name="dbEntry"></param>
        /// <param name="progress"></param>
        public static void DeleteSupportedPictureFilesInDirectoryOtherThanOriginalFile(ImageContent dbEntry,
                                                                                       IProgress <string> progress)
        {
            if (dbEntry == null || string.IsNullOrWhiteSpace(dbEntry.OriginalFileName))
            {
                progress?.Report("Nothing to delete.");
                return;
            }

            var baseFileNameList = dbEntry.OriginalFileName.Split(".").ToList();
            var baseFileName     = string.Join("", baseFileNameList.Take(baseFileNameList.Count - 1));

            var directoryInfo = UserSettingsSingleton.CurrentSettings().LocalSiteImageContentDirectory(dbEntry);

            var fileVariants = directoryInfo.GetFiles().Where(x =>
                                                              FolderFileUtility.PictureFileTypeIsSupported(x) && !x.Name.StartsWith($"{baseFileName}--")).ToList();

            progress?.Report(
                $"Found {fileVariants.Count} Supported Image File Type files in {directoryInfo.FullName} that don't match the " +
                $"original file name {dbEntry.OriginalFileName} from {dbEntry.Title}");

            fileVariants.ForEach(x => x.Delete());
        }