コード例 #1
0
        public AddPackageResult AddPackage(PackageReader packageReader, PackageEnforcement packageEnforcement)
        {
            Utilities.ValidateParameterNonNull("packageReader", packageReader);
            Utilities.ValidateParameterNonNull("packageEnforcement", packageEnforcement);

            AddPackageReferenceResult refResult;
            string packageLocation = null;

            try
            {
                TransactionOptions options = new TransactionOptions();
                options.IsolationLevel = System.Transactions.IsolationLevel.RepeatableRead;
                using (LearningStoreTransactionScope scope = new LearningStoreTransactionScope(options))
                {
                    // Add the reference to the package
                    refResult = AddPackageReference(packageReader, "$Invalid Value$", packageEnforcement);

                    // Add the resource files and determine the location of them. The location is derived from the packageId.
                    packageLocation = ImportFiles(refResult.PackageId, packageReader);

                    // Update the package location in LearningStore
                    UpdatePackageLocation(refResult.PackageId, packageLocation);

                    scope.Complete();
                }
            }
            catch (Exception)
            {
                try
                {
                    // Delete files if necessary
                    if (!String.IsNullOrEmpty(packageLocation))
                    {
                        DeleteFiles(packageLocation);
                    }
                }
                catch
                {
                    // If the deletion failed, make sure the original exception is thrown to the caller
                }
                throw;
            }
            return(new AddPackageResult(refResult));
        }
コード例 #2
0
        /// <summary>
        /// Registers a package with the SharePointLibraryPackageStore. Any changes to the original file after the package is
        /// registered are not reflected in the store.
        /// </summary>
        /// <param name="packageReader">A reader positioned on the package.</param>
        /// <param name="packageEnforcement">The settings to determine whether the package should be modified to
        /// allow it to be added to the store.</param>
        /// <returns>The results of adding the package, including a log of any warnings or errors that occurred in the process.
        /// </returns>
        /// <exception cref="PackageImportException">Thrown if the package could not be registered with the store. The exception may
        /// include a log indicating a cause for the failure.</exception>
        /// <remarks>The package is read from SharePoint under elevated privileges. The current user does not need access to the
        /// package in order to register it. However, the current user does need to have permission to add a package to
        /// LearningStore in order to register it.</remarks>
        public RegisterPackageResult RegisterPackage(FileSystemBasedSharePointPackageReader packageReader, PackageEnforcement packageEnforcement)
        {
            Utilities.ValidateParameterNonNull("packageEnforcement", packageEnforcement);
            Utilities.ValidateParameterNonNull("packageReader", packageReader);

            // Add the reference to the package. The process of importing the package will cause the package reader to cache
            // the package in the file system.
            AddPackageReferenceResult refResult = AddPackageReference(packageReader, packageReader.Location.ToString(), packageEnforcement);

            return(new RegisterPackageResult(refResult));
        }