public static async Task <(bool isValid, string explanation)> FileContentFileValidation(FileInfo fileContentFile, Guid?currentContentId) { if (fileContentFile == null) { return(false, "Please choose a file"); } fileContentFile.Refresh(); if (!fileContentFile.Exists) { return(false, "File does not Exist?"); } if (!FolderFileUtility.IsNoUrlEncodingNeeded(Path.GetFileNameWithoutExtension(fileContentFile.Name))) { return(false, "Limit File Names to A-Z a-z 0-9 - . _"); } if (await(await Db.Context()).ImageFilenameExistsInDatabase(fileContentFile.Name, currentContentId)) { return(false, "This filename already exists in the database - file names must be unique."); } return(true, "File is Valid"); }
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"); }
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")); }
public static (bool isValid, string explanation) ValidateFolder(string folder) { if (string.IsNullOrWhiteSpace(folder)) { return(false, "Folder can't be blank or only whitespace."); } if (!FolderFileUtility.IsNoUrlEncodingNeeded(folder)) { return(false, "Limit folder names to a-z A-Z 0-9 _ -"); } if (folder.ToLower() == "data") { return(false, "Folders can not be named 'Data' - this folder is reserved for use by the CMS"); } if (folder.ToLower() == "galleries") { return(false, "Folders can not be named 'Galleries' - this folder is reserved for use by the CMS"); } return(true, string.Empty); }