private static void ValidateNode(OrganizationNodeReader nodeReader) { if (nodeReader == null) { return; } ValidateCollection(nodeReader.Activities); // caught BadProperties2 ValidateNode(nodeReader.Sequencing); // Issue: not sure how to trap this ValidateProperty(nodeReader.Id); // Issue: errors here are thrown in the parent collection ValidateProperty(nodeReader.Metadata); // caught BadProperties3 ValidateProperty(nodeReader.ObjectivesGlobalToSystem); // caught BadProperties3 ValidateProperty(nodeReader.Structure); // derived value, doesn't throw an exception ValidateProperty(nodeReader.Title); // caught BadProperties4 ValidateProperty(nodeReader.Instructions); ValidateProperty(nodeReader.Description); ValidateProperty(nodeReader.PointsPossible); }
/// <summary>Sets the location of the package.</summary> /// <remarks>Security checks:Fails if the user doesn't have access to the package/file</remarks> /// <param name="location">The MLC SharePoint location string that refers to the e-learning /// package or non-e-learning document to assign. Use /// <c>SharePointPackageStore.GetLocation</c> to construct this string.</param> /// <param name="organizationIndex">The zero-based index of the organization within the /// e-learning content to assign; this is the value that's used as an index to /// <c>ManifestReader.Organizations</c>. If the content being assigned is a non-e-learning /// document, use <c>null</c> for <paramref name="organizationIndex"/>.</param> /// <param name="title">Any title that has been passed in.</param> public void SetLocation(SharePointFileLocation location, Nullable <int> organizationIndex, string title) { if (location == null) { throw new ArgumentNullException("location"); } if (location.ToString() == Package.NoPackageLocation.ToString()) { MakeNoPackageAssignment(title); return; } // Access the properties of the file to verify that the user has access to the file SPFile file = location.LoadFile(); System.Collections.Hashtable fileProperties = file.Properties; // set <rootActivityId> to the ID of the organization, or null if a non-e-learning document is being assigned if (organizationIndex != null) { using (Package package = new Package(Store, file, location)) { package.Register(); RootActivityId = package.FindRootActivity(organizationIndex.Value); bool existingTitle = (string.IsNullOrEmpty(Title) == false); if (existingTitle == false) { Title = package.Title; } if (string.IsNullOrEmpty(Description)) { Description = package.Description; } // validate <organizationIndex> if ((organizationIndex.Value < 0) || (organizationIndex.Value >= package.Organizations.Count)) { throw new SafeToDisplayException(SlkCulture.GetResources().InvalidOrganizationIndex); } PackageFormat = package.PackageFormat; // set <organizationNodeReader> to refer to the organization OrganizationNodeReader organizationNodeReader = package.Organizations[organizationIndex.Value]; // if there is more than one organization, append the organization title, if any if (existingTitle == false && package.Organizations.Count > 1) { if (!String.IsNullOrEmpty(organizationNodeReader.Title)) { SlkCulture culture = new SlkCulture(); Title = culture.Format(culture.Resources.SlkPackageAndOrganizationTitle, Title, organizationNodeReader.Title); } } // set <pointsPossible> to the points-possible value stored in the manifest, or null if none switch (PackageFormat) { case Microsoft.LearningComponents.PackageFormat.Lrm: PointsPossible = organizationNodeReader.PointsPossible; break; case Microsoft.LearningComponents.PackageFormat.V1p3: PointsPossible = 100; break; default: PointsPossible = null; break; } } } else // Non-elearning content { RootActivityId = null; Location = location.ToString(); if (string.IsNullOrEmpty(Title)) { Title = file.Title; if (String.IsNullOrEmpty(Title)) { Title = System.IO.Path.GetFileNameWithoutExtension(file.Name); } } if (string.IsNullOrEmpty(Description)) { Description = string.Empty; } if (PointsPossible == null) { PointsPossible = null; // "Points Possible" defaults to null for non-e-learning content PackageWarnings = null; // no package warnings PackageFormat = null; // non-e-learning package } } }