示例#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
        private void savePackageChangesToEATaggedValue(SQLRepository sqlRepository, String GUID)
        {
            SQLPackage sqlPackage = sqlRepository.GetPackageByGuid(GUID);
            EPackage   epackage   = new EPackage(sqlPackage, sqlRepository);
            String     packages   = addPackageName(epackage, "", sqlRepository);

            String previousName = sqlPackage.Name;

            SQLTaggedValue changesTreeTag = EAEcoreAddin.Util.EAUtil.findTaggedValue(sqlPackage, Main.MoflonChangesTreeTaggedValueName);

            if (changesTreeTag != null)
            {
                MocaNode eClassMocaNode = MocaTreeUtil.mocaNodeFromXmlString(changesTreeTag.Notes);
                previousName = eClassMocaNode.getAttribute("previousName").Value;
            }

            CachedPackage temp = new CachedPackage();

            temp.getPackage(GUID, sqlRepository);
            temp.name         = sqlPackage.Name;
            temp.previousName = previousName;
            temp.packageName  = packages;
            temp.projectName  = getTopLevelPackageName(sqlPackage, sqlRepository);
            temp.savePackageToEATaggedValue(true);
        }
示例#3
0
 /// <summary>
 /// Releases all resources used by this object
 /// </summary>
 /// <param name="disposing">True if this method was called from
 ///    <Typ>/System.IDisposable.Dispose</Typ></param>
 protected virtual void Dispose(bool disposing)
 {
     m_disposed = true;
     if (m_cachedPackage != null)
     {
         m_cachedPackage.Dispose();
         m_cachedPackage = null;
     }
 }
示例#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
 /// <summary>
 /// Gets the directory that the package (specified by site, web, file, etc)
 /// would be cached into.
 /// </summary>
 /// <param name="cachePath">The folder to use for a cache of all SharePoint files.</param>
 /// <param name="impersonationBehavior">The impersonation behaviour to use.</param>
 /// <param name="packageLocation">The location of the package in SharePoint.</param>
 /// <returns>The directory path to the cached package.</returns>
 internal static string GetCacheDirectory(string cachePath, ImpersonationBehavior impersonationBehavior, SharePointFileLocation packageLocation)
 {
     return(CachedPackage.GetCacheDirectory(cachePath, packageLocation, impersonationBehavior));
 }