コード例 #1
0
        /// <summary>
        /// Creates a package reader to read the specified package from SharePoint. This constructor
        /// optionally causes the file to be read from SharePoint using elevated permissions.
        /// </summary>
        /// <param name="cacheSettings">The settings to use for the caching of this package.
        /// A subdirectory will be created in the cacheSettings.CachePath location with a cached version of this package.</param>
        /// <param name="packageLocation">The location of the package to be read. Any changes to this SharePointFileLocation
        /// object after the SharePointPackageReader is created are not reflected in the behavior of this object.</param>
        /// <param name="runWithElevatedPrivileges">If true, files in SharePoint are accessed using elevated privileges.
        /// If false, the current user credentials are used to access SharePoint files.</param>
        /// <param name="file">The SPFile to read.</param>
        /// <remarks>
        /// <para>
        /// In addition to the exceptions listed below, this method may throw exceptions caused by the
        /// identity not having access to the <paramref name="cacheSettings"/> CachePath location.
        /// </para>
        /// <para>
        /// The contents of the package are not read in the constructor. The contents of the package are read
        /// only once when they are first needed.  If the referenced SharePoint file does not contain a
        /// valid e-learning package, accessing other methods and properties on this object will result
        /// in an <c>InvalidPackageException</c>.
        /// </para>
        /// <para>
        /// If the  <paramref name="cacheSettings"/> CacheInvalidPackageAsFile value is true,
        /// e-learning packages that do not contain basic package information are saved as
        /// files in the cache. In particular, this may increase performance in processing of zip files that do not contain
        /// e-learning content. If false, SharePointPackageReader will not cache zip files that are not e-learning
        /// content. In that case, an application that wants to cache this file would need to cache it as a
        /// CachedSharePointFile. Regardless of the value of this parameter, the SharePointPackageReader will not allow
        /// accessing files from within a package that is not e-learning content.
        /// </para>
        /// </remarks>
        /// <exception cref="ArgumentNullException">Thrown if any argument is null.</exception>
        /// <exception cref="DirectoryNotFoundException">Thrown if the CachePath property of <paramref name="cacheSettings"/>
        /// does not exist prior to calling this constructor.</exception>
        /// <exception cref="FileNotFoundException">Thrown if the requested file does not exist.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown if the identity doesn't have access to the CachePath provided in the
        /// cache settings.</exception>
        public SharePointPackageReader(SharePointCacheSettings cacheSettings, SharePointFileLocation packageLocation, SPFile file, bool runWithElevatedPrivileges) : base(packageLocation)
        {
            Resources.Culture = Thread.CurrentThread.CurrentCulture;
            Utilities.ValidateParameterNonNull("cacheSettings", cacheSettings);

            RunWithElevatedPrivileges useRequestedPrivileges;

            if (runWithElevatedPrivileges)
            {
                useRequestedPrivileges = SPSecurity.RunWithElevatedPrivileges;
            }
            else
            {
                useRequestedPrivileges = RunWithCurrentUserPrivileges;
            }

            CachedPackage.EnsureCache(cacheSettings);

            CheckFileExists(file, packageLocation);

            // Store variables.
            m_settings = cacheSettings.Clone();

            CachedPackage cachedPackage = null;

            useRequestedPrivileges(delegate
            {
                cachedPackage = new CachedPackage(m_settings, Location, true);
            });

            using (cachedPackage)
            {
                Initialize(new DirectoryInfo(cachedPackage.CacheDir), m_settings.ImpersonationBehavior);
            }
        }
コード例 #2
0
        /// <summary>
        /// Create the store.
        /// </summary>
        /// <param name="learningStore">The learning store to use.</param>
        /// <param name="cacheSettings">Cache settings, including the file system location where the packages in the store can be cached.
        /// </param>
        /// <remarks>
        /// </remarks>
        public SharePointLibraryPackageStore(LearningStore learningStore, SharePointCacheSettings cacheSettings) : base(learningStore)
        {
            Utilities.ValidateParameterNonNull("learningStore", learningStore);
            Utilities.ValidateParameterNonNull("cacheSettings", cacheSettings);

            CacheSettings = cacheSettings;
        }
        /// <summary>
        /// Creates a package reader to read the specified package from SharePoint. This constructor
        /// optionally causes the file to be read from SharePoint using elevated permissions.
        /// </summary>
        /// <param name="cacheSettings">The settings to use for the caching of this package.
        /// A subdirectory will be created in the cacheSettings.CachePath location with a cached version of this package.</param>
        /// <param name="packageLocation">The location of the package to be read. Any changes to this SharePointFileLocation
        /// object after the SharePointLibraryPackageReader is created are not reflected in the behavior of this object.</param>
        /// <param name="file">The file to create the reader for.</param>
        /// <remarks>
        /// <para>
        /// In addition to the exceptions listed below, this method may throw exceptions caused by the
        /// identity not having access to the <paramref name="cacheSettings"/> CachePath location.
        /// </para>
        /// <para>
        /// The contents of the package are not read in the constructor. The contents of the package are read
        /// only once when they are first needed.  If the referenced SharePoint file does not contain a
        /// valid e-learning package, accessing other methods and properties on this object will result
        /// in an <c>InvalidPackageException</c>.
        /// </para>
        /// </remarks>
        /// <exception cref="ArgumentNullException">Thrown if any argument is null.</exception>
        /// <exception cref="FileNotFoundException">Thrown if the requested file does not exist.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown if the identity doesn't have access to the CachePath provided in the
        /// cache settings.</exception>
        public SharePointLibraryPackageReader(SharePointCacheSettings cacheSettings, SharePointFileLocation packageLocation, SPFile file) : base(packageLocation)
        {
            Resources.Culture = Thread.CurrentThread.CurrentCulture;
            Utilities.ValidateParameterNonNull("cacheSettings", cacheSettings);

            SPWeb web = SPContext.Current.Web;

            cache = new SharePointLibraryCache(web, file, packageLocation, cacheSettings);
        }
コード例 #4
0
        /// <summary>
        /// Create a representation of a file in SharePoint, running with elevated privileges when
        /// accessing the SharePoint file.
        /// </summary>
        /// <param name="cacheSettings">The settings that determine how the file is cached.</param>
        /// <param name="location">The location of the file in SharePoint.</param>
        /// <param name="runWithElevatedPrivileges">If true, SharePoint file will be accessed using elevated privileges.</param>
        /// <remarks>
        /// This method does only verifies that the <c>settings.WindowsIdentity</c> has access to the
        /// <c>settings.CachePath</c>. It does not verify that the file exists in SharePoint.
        /// The contents of the package are read only once when they are first needed.
        /// </remarks>
        /// <exception cref="UnauthorizedAccessException">Thrown if the <c>settings.WindowsIdentity</c>
        /// does not have appropriate permissions to the <c>settings.CachePath</c> folder.</exception>
        public CachedSharePointFile(SharePointCacheSettings cacheSettings, SharePointFileLocation location, bool runWithElevatedPrivileges)
        {
            Resources.Culture = Thread.CurrentThread.CurrentCulture;
            Utilities.ValidateParameterNonNull("cacheSettings", cacheSettings);
            Utilities.ValidateParameterNonNull("location", location);

            m_settings = cacheSettings.Clone();
            m_location = location;

            if (runWithElevatedPrivileges)
            {
                m_useRequestedPrivileges = SPSecurity.RunWithElevatedPrivileges;
            }
            else
            {
                m_useRequestedPrivileges = RunWithCurrentUserPrivileges;
            }

            CachedPackage.EnsureCache(cacheSettings);
        }
コード例 #5
0
        public SharePointLibraryCache(SPWeb web, SPFile file, SharePointFileLocation packageLocation, SharePointCacheSettings cacheSettings)
        {
            Uri baseWebUri = new Uri(web.Url);
            Uri cacheUri   = new Uri(baseWebUri, cacheSettings.CachePath);

            cacheSite = new SPSite(cacheUri.ToString());
            cacheWeb  = cacheSite.OpenWeb();
            cacheWeb.AllowUnsafeUpdates = true;

            try
            {
                cacheList = cacheWeb.GetList(cacheSettings.CachePath);
            }
            catch (ArgumentException)
            {
                throw new CacheException(string.Format(CultureInfo.CurrentUICulture, Resources.InvalidLibraryCache, cacheSettings.CachePath));
            }

            int packageId = FindOrCreatePackageId(packageLocation);

            CacheFolderUrl = string.Concat(cacheWeb.Url, "/", cacheList.RootFolder.Url, "/", packageId.ToString(CultureInfo.InvariantCulture));
            cacheFolder    = cacheWeb.GetFolder(CacheFolderUrl);
            if (cacheFolder.Exists == false)
            {
                cacheFolder = CreateCacheFolder(packageId.ToString(CultureInfo.InvariantCulture));
                UnzipAndCachePackage(file);
            }
        }
コード例 #6
0
        private bool m_disposed;   // indicates this object has been disposed

        /// <summary>
        /// Create a cached copy of a file in SharePoint.
        /// </summary>
        /// <param name="cacheSettings">The settings that determine how the file is cached.</param>
        /// <param name="location">The location of the file in SharePoint.</param>
        /// <remarks>
        /// This method does only verifies that the <c>settings.WindowsIdentity</c> has access to the
        /// <c>settings.CachePath</c>. It does not verify that the file exists in SharePoint.
        /// The contents of the package are read only once when they are first needed.
        /// </remarks>
        public CachedSharePointFile(SharePointCacheSettings cacheSettings, SharePointFileLocation location)
            : this(cacheSettings, location, false)
        {
        }