Esempio n. 1
0
        /// <summary>
        /// accesses the document library at the path provided,
        /// loops through the learning packages
        /// located the library and reads the package Id from package manifest
        /// </summary>
        /// <param name="siteURL">web site url</param>
        /// <param name="documentLibraryName">document library name</param>
        /// <returns></returns>
        public Hashtable GetAllLearningResources(string siteURL, string documentLibraryName)
        {
            Hashtable         resources      = new Hashtable();
            SharePointV3      sharepoint     = new SharePointV3();
            SPWeb             documentLibWeb = sharepoint.OpenWeb(siteURL);
            SPDocumentLibrary docLibrary     = sharepoint.GetDocumentLibrary(documentLibraryName, documentLibWeb);

            Microsoft.SharePointLearningKit.SlkStore store = SlkStore.GetStore(documentLibWeb);
            foreach (SPListItem item in docLibrary.Items)
            {
                //if this list item is a file
                if (item.File != null)
                {
                    SharePointFileLocation fileLocation = new SharePointFileLocation(documentLibWeb, item.UniqueId, item.File.UIVersion);
                    string location = fileLocation.ToString();
                    try
                    {
                        PackageInformation info = store.GetPackageInformation(location);
                        XPathNavigator     manifestNavigator = info.ManifestReader.CreateNavigator();
                        Guid packageIdentifier = ManifestParser.ParseIndexXml(manifestNavigator);
                        if (packageIdentifier == Guid.Empty)
                        {
                            packageIdentifier = ManifestParser.ParseImsManifestXml(manifestNavigator);
                        }
                        if (packageIdentifier != Guid.Empty)
                        {
                            resources.Add(packageIdentifier.ToString(), location);
                        }
                    }
                    catch
                    {
                        //not a valid learning package, do nothing
                    }
                }
            }
            return(resources);
        }
        string AssignmentSiteUrl(string webUrl)
        {
            string urlFormat  = "{0}{1}AssignmentProperties.aspx?Location={2}{3}{4}";
            string orgIndex   = null;
            string titleValue = null;
            SharePointFileLocation location = null;
            string title = null;

            if (NoFileAssignment)
            {
                title    = Request.QueryString["title"];;
                location = Package.NoPackageLocation;
            }
            else
            {
                location = package.Location;
                if (NonELearning == false)
                {
                    orgIndex = String.Format(CultureInfo.InvariantCulture, "&OrgIndex={0}", OrganizationIndex);
                }
            }

            if (string.IsNullOrEmpty(title) == false)
            {
                titleValue = "&Title=" + title;
            }

            return(String.Format(CultureInfo.InvariantCulture, urlFormat, webUrl, Constants.SlkUrlPath, location.ToString(), orgIndex, titleValue));
        }
        /// <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
                }
            }
        }