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 <(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 <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) ValidateTags(string tags) { if (string.IsNullOrWhiteSpace(tags)) { return(false, "At least one tag must be included."); } var tagList = Db.TagListParse(tags); if (tagList.Any(x => !FolderFileUtility.IsNoUrlEncodingNeededLowerCaseSpacesOk(x) || x.Length > 200)) { return(false, "Limit tags to a-z 0-9 _ - [space] and less than 200 characters per tag."); } return(true, string.Empty); }
public static (bool isValid, string explanation) ValidateSlugLocal(string slug) { if (string.IsNullOrWhiteSpace(slug)) { return(false, "Slug can't be blank or only whitespace."); } if (!FolderFileUtility.IsNoUrlEncodingNeededLowerCase(slug)) { return(false, "Slug should only contain a-z 0-9 _ -"); } if (slug.Length > 100) { return(false, "Limit slugs to 100 characters."); } return(true, string.Empty); }
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); }
/// <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()); }