当前位置: 首页>>代码示例>>C#>>正文


C# IPackage.GetContentFiles方法代码示例

本文整理汇总了C#中IPackage.GetContentFiles方法的典型用法代码示例。如果您正苦于以下问题:C# IPackage.GetContentFiles方法的具体用法?C# IPackage.GetContentFiles怎么用?C# IPackage.GetContentFiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IPackage的用法示例。


在下文中一共展示了IPackage.GetContentFiles方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InstallPackage

        public void InstallPackage(IPackage package)
        {
            var directoryToExpandTo = Path.Combine(_localRepository.Source, package.Id);
            foreach (var file in package.GetContentFiles())
            {
                string pathWithoutContextPrefix = file.Path.Substring("content/".Length);
                var fullPath = Path.Combine(directoryToExpandTo, pathWithoutContextPrefix);
                Directory.CreateDirectory(Path.GetDirectoryName(fullPath));

                using (Stream writeStream = File.OpenWrite(fullPath),
                              readStream = file.GetStream())
                {
                    readStream.CopyTo(writeStream);
                }
            }

            // If there is no xdt file, generate a default one
            string xdtPath = Path.Combine(directoryToExpandTo, "applicationHost.xdt");
            if (!File.Exists(xdtPath))
            {
                var xdtTemplate = new XdtTemplate { Path = package.Id };
                File.WriteAllText(xdtPath, xdtTemplate.TransformText().Trim());
            }

            var packageFile = Path.Combine(
                directoryToExpandTo,
                String.Format("{0}.{1}.nupkg", package.Id, package.Version));
            using (Stream readStream = package.GetStream(),
                          writeStream = File.OpenWrite(packageFile))
            {
                readStream.CopyTo(writeStream);
            }
        }
开发者ID:projectkudu,项目名称:SiteExtensions.Admin,代码行数:33,代码来源:WebProjectManager.cs

示例2: ExtractPackageFilesToProject

        /// <summary>
        /// This method will be called first when a package is installed.  We're using
        /// this method to perform some pre processing of XDT files in the 
        /// </summary>
        /// <param name="package"></param>
        protected override void ExtractPackageFilesToProject( IPackage package )
        {
            List<IPackageFile> contentFiles = package.GetContentFiles().ToList();
            Dictionary<string, string> transformedFiles = new Dictionary<string, string>();
            string packageRestorePath = Path.Combine( Project.Root, "App_Data", "PackageRestore" );

            // go through each *.rock.xdt file and apply the transform first,
            foreach ( var xdtFile in contentFiles.Where( f => f.Path.EndsWith( TRANSFORM_FILE_PREFIX, StringComparison.OrdinalIgnoreCase ) ) )
            {
                using ( Stream stream = xdtFile.GetStream() )
                {
                    var fileName = xdtFile.EffectivePath;

                    // write the transform file out to the PackageRestore/xdt folder
                    var transformFilefullPath = Path.Combine( packageRestorePath, "xdt", fileName );
                    Directory.CreateDirectory( Path.GetDirectoryName( transformFilefullPath ) );
                    using ( var fileStream = File.Create( transformFilefullPath ) )
                    {
                        stream.CopyTo( fileStream );
                    }

                    var sourceFile = fileName.Remove( fileName.Length - TRANSFORM_FILE_PREFIX.Length );
                    var sourceFileFullPath = Path.Combine( Project.Root, sourceFile );
                    var tempPathOfTransformedFile = Path.Combine( packageRestorePath, "xdt", sourceFile );

                    // now transform the Rock file using the xdt file, but write it to the PackageRestore\xdt folder and we'll
                    // move it into place after the update is finished.
                    // If the transform fails, then we have to quit and inform the user.
                    if ( !ProcessXmlDocumentTransformation( transformFilefullPath, sourceFileFullPath, tempPathOfTransformedFile ) )
                    {
                        throw new System.Xml.XmlException( sourceFile );
                    }
                    transformedFiles.Add( tempPathOfTransformedFile, sourceFile );
                }
            }

            // now let the package installation proceed as normal
            base.ExtractPackageFilesToProject( package );

            // lastly, move the transformed xml files into place
            MoveTransformedFiles( transformedFiles );

            try
            {
                Directory.Delete( packageRestorePath, recursive: true );
            }
            catch ( Exception ex )
            {
                ExceptionLogService.LogException( ex, System.Web.HttpContext.Current );
                ExceptionLogService.LogException( new Exception( string.Format( "Unable to delete package restore folder ({0}) after a successful update.", packageRestorePath ) ), System.Web.HttpContext.Current );
            }
        }
开发者ID:tcavaletto,项目名称:Rock-CentralAZ,代码行数:57,代码来源:RockProjectManager.cs

示例3: InstallPackage

        public void InstallPackage(IPackage package)
        {
            var directoryToExpandTo = Path.Combine(_localRepository.Source, package.Id);
            foreach (var file in package.GetContentFiles())
            {
                string pathWithoutContextPrefix = file.Path.Substring("content/".Length);
                var fullPath = Path.Combine(directoryToExpandTo, pathWithoutContextPrefix);
                Directory.CreateDirectory(Path.GetDirectoryName(fullPath));

                using (Stream writeStream = File.OpenWrite(fullPath),
                              readStream = file.GetStream())
                {
                    readStream.CopyTo(writeStream);
                }
            }

            var packageFile = Path.Combine(directoryToExpandTo, package.GetFullName() + ".nupkg");
            using (Stream readStream = package.GetStream(),
                          writeStream = File.OpenWrite(packageFile))
            {
                readStream.CopyTo(writeStream);
            }
        }
开发者ID:pranavkm,项目名称:SiteExtensions.Admin,代码行数:23,代码来源:WebProjectManager.cs

示例4: GetTransformFiles

 private IEnumerable<IPackageFile> GetTransformFiles(IPackage package)
 {
     return package.GetContentFiles().Where(IsTransformFile);
 }
开发者ID:atheken,项目名称:nuget,代码行数:4,代码来源:ProjectFactory.cs

示例5: InstallExtension

        private IPackage InstallExtension(IPackage package, string installationDirectory)
        {
            try
            {
                if (FileSystemHelpers.DirectoryExists(installationDirectory))
                {
                    FileSystemHelpers.DeleteDirectorySafe(installationDirectory);
                }

                foreach (IPackageFile file in package.GetContentFiles())
                {
                    // It is necessary to place applicationHost.xdt under site extension root.
                    string contentFilePath = file.Path.Substring("content/".Length);
                    string fullPath = Path.Combine(installationDirectory, contentFilePath);
                    FileSystemHelpers.CreateDirectory(Path.GetDirectoryName(fullPath));
                    using (Stream writeStream = FileSystemHelpers.OpenWrite(fullPath), readStream = file.GetStream())
                    {
                        OperationManager.Attempt(() => readStream.CopyTo(writeStream));
                    }
                }

                // If there is no xdt file, generate default.
                GenerateApplicationHostXdt(installationDirectory, '/' + package.Id, isPreInstalled: false);

                OperationManager.Attempt(() => DeploySiteExtensionJobs(package.Id));

                var externalCommandFactory = new ExternalCommandFactory(_environment, _settings, installationDirectory);
                string installScript = Path.Combine(installationDirectory, _installScriptName);
                if (FileSystemHelpers.FileExists(installScript))
                {
                    OperationManager.Attempt(() =>
                    {
                        Executable exe = externalCommandFactory.BuildCommandExecutable(installScript,
                            installationDirectory,
                            _settings.GetCommandIdleTimeout(), NullLogger.Instance);
                        exe.ExecuteWithProgressWriter(NullLogger.Instance, _traceFactory.GetTracer(), String.Empty);
                    });
                }

                // Copy nupkg file for package list/lookup
                FileSystemHelpers.CreateDirectory(installationDirectory);
                string packageFilePath = GetNuGetPackageFile(package.Id, package.Version.ToString());
                using (
                    Stream readStream = package.GetStream(), writeStream = FileSystemHelpers.OpenWrite(packageFilePath))
                {
                    OperationManager.Attempt(() => readStream.CopyTo(writeStream));
                }
            }
            catch (Exception ex)
            {
                ITracer tracer = _traceFactory.GetTracer();
                tracer.TraceError(ex);
                FileSystemHelpers.DeleteDirectorySafe(installationDirectory);
                throw;
            }

            return _localRepository.FindPackage(package.Id);
        }
开发者ID:xt0rted,项目名称:kudu,代码行数:58,代码来源:SiteExtensionManager.cs

示例6: InstallExtension

        public bool InstallExtension(IPackage package, string installationDirectory)
        {
            try
            {
                if (FileSystemHelpers.DirectoryExists(installationDirectory))
                {
                    FileSystemHelpers.DeleteDirectorySafe(installationDirectory);
                }

                foreach (IPackageFile file in package.GetContentFiles())
                {
                    // It is necessary to place applicationHost.xdt under site extension root.
                    string contentFilePath = file.Path.Substring("content/".Length);
                    string fullPath = Path.Combine(installationDirectory, contentFilePath);
                    FileSystemHelpers.CreateDirectory(Path.GetDirectoryName(fullPath));
                    using (Stream writeStream = FileSystemHelpers.OpenWrite(fullPath), readStream = file.GetStream())
                    {
                        OperationManager.Attempt(() => readStream.CopyTo(writeStream));
                    }
                }

                // If there is no xdt file, generate default.
                string xdtPath = Path.Combine(installationDirectory, "applicationHost.xdt");
                if (!FileSystemHelpers.FileExists(xdtPath))
                {
                    string xdtContent = CreateDefaultXdtFile(package.Id);
                    OperationManager.Attempt(() => FileSystemHelpers.WriteAllText(xdtPath, xdtContent));
                }

                // Copy nupkg file for package list/lookup
                FileSystemHelpers.CreateDirectory(installationDirectory);
                string packageFilePath = Path.Combine(installationDirectory,
                    String.Format("{0}.{1}.nupkg", package.Id, package.Version));
                using (
                    Stream readStream = package.GetStream(), writeStream = FileSystemHelpers.OpenWrite(packageFilePath))
                {
                    OperationManager.Attempt(() => readStream.CopyTo(writeStream));
                }
            }
            catch (Exception ex)
            {
                ITracer tracer = _traceFactory.GetTracer();
                tracer.TraceError(ex);
                FileSystemHelpers.DeleteDirectorySafe(installationDirectory);
                return false;
            }

            return true;
        }
开发者ID:jeddawson,项目名称:kudu,代码行数:49,代码来源:SiteExtensionManager.cs

示例7: ShowMessageAndReadme

        private void ShowMessageAndReadme(IPackage package, string message)
        {
            var files = package.GetContentFiles();

            string filePath = null;

            if (files != null)
            {
                var readme = files.FirstOrDefault(
                                (file) => file.Path.Equals("ReadMe.txt", StringComparison.OrdinalIgnoreCase));

                if (readme == null)
                {
                    readme = files.FirstOrDefault(
                    (file) => file.Path.IndexOf("ReadMe.txt", StringComparison.OrdinalIgnoreCase) >= 0);
                }

                string text = null;

                if (readme != null)
                {
                    try
                    {
                        using (var stream = readme.GetStream())
                        {
                            using (var reader = new StreamReader(stream))
                            {
                                text = reader.ReadToEnd();
                            }
                        }

                        if (!string.IsNullOrWhiteSpace(text))
                        {
                            var tempFilePath = Path.GetTempFileName();

                            lock (_lock)
                            {
                                if (!_cleanupAdded)
                                {
                                    var dispatcher = TryGetDispatcher();

                                    if (dispatcher != null)
                                    {
                                        dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)AddExitCleanUp);
                                    }
                                }
                            }

                            File.WriteAllText(tempFilePath, text);

                            filePath = tempFilePath;

                            lock (_lock)
                            {
                                _tempFilesToDelete.Add(filePath);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.Fail(ex.ToString());
                    }
                }
            }

            if (filePath != null)
            {
                _webMatrixHost.ShowNotification(message, Resources.ClickForReadme, () => ShowReadMe(filePath, true));
            }
            else
            {
                _webMatrixHost.ShowNotification(message);
            }
        }
开发者ID:Newtopian,项目名称:nuget,代码行数:74,代码来源:NuGetModel.cs

示例8: GetFiles

 private static IEnumerable<Tuple<IPackageFile, string>> GetFiles(IPackage package)
 {
     if (package.GetLibFiles().IsEmpty() && package.GetContentFiles().IsEmpty()) {
         foreach (var packageFile in package.GetFiles()) {
             yield return new Tuple<IPackageFile, string>(packageFile, packageFile.Path);
         }
     } else {
         // TODO: net40 is hard-coded. Some day more frameworks should be supported
         foreach (var packageFile in package.GetLibFiles()) {
             yield return new Tuple<IPackageFile, string>(packageFile, packageFile.Path.Substring(@"lib\net40\".Length));
         }
         foreach (var packageFile in package.GetContentFiles()) {
             yield return new Tuple<IPackageFile, string>(packageFile, packageFile.Path.Substring(@"content\".Length));
         }
     }
 }
开发者ID:thoemmi,项目名称:NuUpdate,代码行数:16,代码来源:UpdateManager.cs


注:本文中的IPackage.GetContentFiles方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。