/// <summary> /// Validate a package according to specific validation settings. /// </summary> /// <remarks> /// The <Typ>ValidationResults</Typ> log will contain the warnings and errors encountered during the package /// validation process, up to any <Typ>InvalidPackageException</Typ> that is thrown during the process, at /// which time the validation process ends. /// </remarks> /// <returns> /// A <Typ>ValidationResults</Typ> log that contains the warnings and errors encountered during the package /// validation process. /// </returns> /// <param name="packageValidatorSettings">The <c>PackageValidatorSettings</c> determining which /// validation rules should be applied during the validation process.</param> /// <param name="packageReader">The package to be valdated.</param> /// <exception cref="ArgumentNullException">Thrown if the <paramref name="packageReader"/> is null.</exception> /// <exception cref="InvalidPackageException">Thrown if the validation process encounters errors in the package /// for which the <paramref name="packageValidatorSettings"/> have a <Typ>ValidationBehavior</Typ> value /// of <c>ValidationBehavior.Enforce</c>.</exception> public static ValidationResults Validate(PackageReader packageReader, PackageValidatorSettings packageValidatorSettings) { ValidatorResources.Culture = LocalizationManager.GetCurrentCulture(); Utilities.ValidateParameterNonNull("packageReader", packageReader); Utilities.ValidateParameterNonNull("packageValidatorSettings", packageValidatorSettings); ValidationResults log = Validate(packageReader); if (log.HasErrors || (packageValidatorSettings.ScormRequirementValidation == ValidationBehavior.None && packageValidatorSettings.ScormRecommendationValidation == ValidationBehavior.None && packageValidatorSettings.LrmRequirementValidation == ValidationBehavior.None && packageValidatorSettings.MlcRequirementValidation == ValidationBehavior.None)) { return(log); } ManifestReaderSettings manifestSettings = new ManifestReaderSettings(true, true); LrmSettings lrmSettings = new LrmSettings(true); ManifestReader manifestReader; PackageValidator.Validate(packageValidatorSettings, packageReader, false, log, manifestSettings, lrmSettings, out manifestReader); return(log); }
/// <summary> /// Validate a package according to specific validation settings. /// </summary> /// <remarks> /// The <Typ>ValidationResults</Typ> log will contain the warnings and errors encountered during the package /// validation process, up to any <Typ>InvalidPackageException</Typ> that is thrown during the process, at /// which time the validation process ends. /// </remarks> /// <returns> /// A <Typ>ValidationResults</Typ> log that contains the warnings and errors encountered during the package /// validation process. /// </returns> /// <param name="packageValidatorSettings">The <c>PackageValidatorSettings</c> determining which /// validation rules should be applied during the validation process.</param> /// <param name="packageReader">The package to be valdated.</param> /// <exception cref="ArgumentNullException">Thrown if the <paramref name="packageReader"/> is null.</exception> /// <exception cref="InvalidPackageException">Thrown if the validation process encounters errors in the package /// for which the <paramref name="packageValidatorSettings"/> have a <Typ>ValidationBehavior</Typ> value /// of <c>ValidationBehavior.Enforce</c>.</exception> public static ValidationResults Validate(PackageReader packageReader, PackageValidatorSettings packageValidatorSettings) { ValidatorResources.Culture = Thread.CurrentThread.CurrentCulture;; Utilities.ValidateParameterNonNull("packageReader", packageReader); Utilities.ValidateParameterNonNull("packageValidatorSettings", packageValidatorSettings); ValidationResults log = ValidateIsELearning(packageReader); if (log.HasErrors || (packageValidatorSettings.ScormRequirementValidation == ValidationBehavior.None && packageValidatorSettings.ScormRecommendationValidation == ValidationBehavior.None && packageValidatorSettings.LrmRequirementValidation == ValidationBehavior.None && packageValidatorSettings.MlcRequirementValidation == ValidationBehavior.None)) { return(log); } ManifestReaderSettings manifestSettings = new ManifestReaderSettings(true, true); ManifestReader manifestReader; bool fixLrmViolations = true; PackageValidator.Validate(packageValidatorSettings, packageReader, false, log, manifestSettings, fixLrmViolations, out manifestReader); return(log); }
private static void CheckPackageFiles(ReadOnlyCollection <string> packageFilePaths, Dictionary <string, bool> manifestFilePaths, ValidationResults log, PackageValidatorSettings packageValidatorSettings) { ValidatorResources.Culture = LocalizationManager.GetCurrentCulture(); // Check all of the files in the package to make sure they are referenced in the manifest. foreach (string filePath in packageFilePaths) { string fileExtension = Path.GetExtension(filePath); if (filePath != "imsmanifest.xml" && string.Compare(fileExtension, ".xsd", StringComparison.OrdinalIgnoreCase) != 0 && string.Compare(fileExtension, ".dtd", StringComparison.OrdinalIgnoreCase) != 0 && !manifestFilePaths.ContainsKey(filePath)) { ProcessError(packageValidatorSettings.ScormRecommendationValidation, string.Format(CultureInfo.CurrentCulture, ValidatorResources.OrphanedFile, filePath), log); } } }
private static void CheckManifestFiles(ReadOnlyCollection <string> packageFilePaths, Dictionary <string, bool> manifestFilePaths, ValidationResults log, PackageValidatorSettings packageValidatorSettings) { ValidatorResources.Culture = LocalizationManager.GetCurrentCulture(); // Check all of the files in the manifest to make sure they are referenced in the package. Dictionary <string, bool> packageFileDictionary = new Dictionary <string, bool>(StringComparer.OrdinalIgnoreCase); foreach (string filePath in packageFilePaths) { packageFileDictionary.Add(filePath, true); } foreach (string filePath in manifestFilePaths.Keys) { if (!packageFileDictionary.ContainsKey(filePath)) { ProcessError(packageValidatorSettings.ScormRequirementValidation, string.Format(CultureInfo.CurrentCulture, ValidatorResources.FileMissing, filePath), log); } } }
internal static void Validate(PackageValidatorSettings packageValidatorSettings, PackageReader packageReader, bool logReplacement, ValidationResults log, ManifestReaderSettings manifestSettings, LrmSettings lrmSettings, out ManifestReader manifestReader) { ValidatorResources.Culture = LocalizationManager.GetCurrentCulture(); if (packageReader == null) { throw new ArgumentNullException("packageReader"); } ValidationResults manifestLog; XPathNavigator manifest; packageReader.CreateManifestNavigator(packageValidatorSettings.LrmRequirementValidation, lrmSettings.FixLrmViolations, out manifestLog, out manifest); if (manifestLog != null) { foreach (ValidationResult result in manifestLog.Results) { log.AddResult(result); } } manifestReader = new ManifestReader(packageReader, manifestSettings, packageValidatorSettings, logReplacement, log, manifest); if (packageValidatorSettings.MlcRequirementValidation != ValidationBehavior.None) { int activityCount = 0; if (manifestReader.Organizations.Count > 0) { foreach (OrganizationNodeReader nodeReader in manifestReader.Organizations) { activityCount += nodeReader.Activities.Count; } if (activityCount == 0) { ProcessError(packageValidatorSettings.MlcRequirementValidation, ValidatorResources.MlcViolationActivityMissing, log); } } else { ProcessError(packageValidatorSettings.MlcRequirementValidation, ValidatorResources.MlcViolationOrganizationMissing, log); } } ManifestValidator.Validate(manifestReader); // Add all files in the manifest to a Dictionary Dictionary <string, bool> manifestFilePaths = new Dictionary <string, bool>(StringComparer.OrdinalIgnoreCase); foreach (ResourceNodeReader r in manifestReader.Resources.Values) { foreach (FileNodeReader fileNode in r.Files) { if (!fileNode.Location.IsAbsoluteUri) { // get the path component of the Location property, and URL decode the string // so it is a proper file path. string path = System.Web.HttpUtility.UrlDecode(RemoveQueryAndAnchor(fileNode.Location.OriginalString)); if (!manifestFilePaths.ContainsKey(path)) { manifestFilePaths.Add(path, true); } } } } ReadOnlyCollection <string> packageFilePaths = packageReader.GetFilePaths(); CheckManifestFiles(packageFilePaths, manifestFilePaths, log, packageValidatorSettings); CheckPackageFiles(packageFilePaths, manifestFilePaths, log, packageValidatorSettings); }