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


C# IFileInfo.CreateReadStream方法代码示例

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


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

示例1: CompileCore

        private async Task<CompilationResult> CompileCore(IFileInfo file)
        {
            var host = new MvcRazorHost();
            var engine = new RazorTemplateEngine(host);
            GeneratorResults results;
            using (TextReader rdr = new StreamReader(file.CreateReadStream()))
            {
                results = engine.GenerateCode(rdr, '_' + Path.GetFileNameWithoutExtension(file.Name), "Asp", file.PhysicalPath ?? file.Name);
            }

            string generatedCode;

            using (var writer = new StringWriter())
            using (var codeProvider = new CSharpCodeProvider())
            {
                codeProvider.GenerateCodeFromCompileUnit(results.GeneratedCode, writer, new CodeGeneratorOptions());
                generatedCode = writer.ToString();
            }

            if (!results.Success) 
            {
                return CompilationResult.Failed(generatedCode, results.ParserErrors.Select(e => new CompilationMessage(e.Message)));
            }

            Directory.CreateDirectory(_tempPath);
            string tempFile = Path.Combine(_tempPath, Path.GetRandomFileName() + ".cs");

            File.WriteAllText(tempFile, generatedCode);

            _tempFileSystem.TryGetFileInfo(tempFile, out file);
            return await _baseCompilationService.Compile(file);
        }
开发者ID:464884492,项目名称:Mvc,代码行数:32,代码来源:RazorCompilationService.cs

示例2: GetHashForFile

 private string GetHashForFile(IFileInfo fileInfo)
 {
     using (var sha256 = SHA256.Create())
     {
         using (var readStream = fileInfo.CreateReadStream())
         {
             var hash = sha256.ComputeHash(readStream);
             return WebEncoders.Base64UrlEncode(hash);
         }
     }
 }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:11,代码来源:FileVersionProvider.cs

示例3: Parse

        public PlacementFile Parse(IFileInfo fileInfo)
        {
            if (!fileInfo.Exists)
            {
                return null;
            }

            var element = XElement.Load(fileInfo.CreateReadStream());
            return new PlacementFile
            {
                Nodes = Accept(element).ToList()
            };
        }
开发者ID:jimitndiaye,项目名称:Orchard2,代码行数:13,代码来源:PlacementFileParser.cs

示例4: CompileCore

        // TODO: Make this internal
        public CompilationResult CompileCore(IFileInfo file)
        {
            GeneratorResults results;
            using (var inputStream = file.CreateReadStream())
            {
                Contract.Assert(file.PhysicalPath.StartsWith(_appRoot, StringComparison.OrdinalIgnoreCase));
                var rootRelativePath = file.PhysicalPath.Substring(_appRoot.Length);
                results = _razorHost.GenerateCode(rootRelativePath, inputStream);
            }

            if (!results.Success)
            {
                var messages = results.ParserErrors.Select(e => new CompilationMessage(e.Message));
                throw new CompilationFailedException(messages, results.GeneratedCode);
            }

            return _baseCompilationService.Compile(results.GeneratedCode);
        }
开发者ID:Nakro,项目名称:Mvc,代码行数:19,代码来源:RazorCompilationService.cs

示例5: Compile

        public Task<CompilationResult> Compile(IFileInfo file)
        {
            string className = MakeClassName(file.Name);
            var engine = new RazorTemplateEngine(new RazorEngineHost(new CSharpRazorCodeLanguage())
            {
                DefaultBaseClass = "Microsoft.AspNet.Razor.Owin.PageBase",
                GeneratedClassContext = new GeneratedClassContext(
                    executeMethodName: "Execute",
                    writeMethodName: "Write",
                    writeLiteralMethodName: "WriteLiteral",
                    writeToMethodName: "WriteTo",
                    writeLiteralToMethodName: "WriteLiteralTo",
                    templateTypeName: "Template",
                    defineSectionMethodName: "DefineSection")
                {
                    ResolveUrlMethodName = "Href"
                }
            });
            engine.Host.NamespaceImports.Add("System");
            engine.Host.NamespaceImports.Add("System.Linq");
            engine.Host.NamespaceImports.Add("System.Collections.Generic");

            GeneratorResults results;
            using (TextReader rdr = new StreamReader(file.CreateReadStream()))
            {
                results = engine.GenerateCode(rdr, className, "RazorCompiled", file.PhysicalPath ?? file.Name);
            }

            var messages = new List<CompilationMessage>();
            if (!results.Success)
            {
                foreach (var error in results.ParserErrors)
                {
                    messages.Add(new CompilationMessage(
                        MessageLevel.Error,
                        error.Message,
                        new FileLocation(file.PhysicalPath ?? file.Name, error.Location.LineIndex, error.Location.CharacterIndex)));
                }
            }

            // Regardless of success or failure, we're going to try and compile
            return Task.FromResult(CompileCSharp("RazorCompiled." + className, file, results.Success, messages, results.GeneratedCode));
        }
开发者ID:Kstal,项目名称:Microsoft.Owin,代码行数:43,代码来源:RazorCompiler.cs

示例6: ReadContent

        private IPublishedContent ReadContent(IFileInfo fileInfo)
        {
            using (var file = fileInfo.CreateReadStream())
            using (var reader = new StreamReader(file))
            {
                var serializer = new JsonSerializer
                {
                    ContractResolver = new CamelCasePropertyNamesContractResolver()
                };

                var content = (IPublishedContent)serializer.Deserialize(reader, typeof(PublishedContent));
                return content;
            }
        }
开发者ID:vnbaaij,项目名称:Umbraco9,代码行数:14,代码来源:FileSystemPublishedContentCache.cs

示例7: ParseViewFile

        private static ChunkTree ParseViewFile(
            RazorTemplateEngine engine,
            IFileInfo fileInfo,
            string viewImportsPath)
        {
            using (var stream = fileInfo.CreateReadStream())
            {
                using (var streamReader = new StreamReader(stream))
                {
                    var parseResults = engine.ParseTemplate(streamReader, viewImportsPath);
                    var className = ParserHelpers.SanitizeClassName(fileInfo.Name);
                    var language = engine.Host.CodeLanguage;
                    var chunkGenerator = language.CreateChunkGenerator(
                        className,
                        engine.Host.DefaultNamespace,
                        viewImportsPath,
                        engine.Host);
                    chunkGenerator.Visit(parseResults);

                    // Rewrite the location of inherited chunks so they point to the global import file.
                    var chunkTree = chunkGenerator.Context.ChunkTreeBuilder.ChunkTree;
                    foreach (var chunk in chunkTree.Chunks)
                    {
                        chunk.Start = new SourceLocation(
                            viewImportsPath,
                            chunk.Start.AbsoluteIndex,
                            chunk.Start.LineIndex,
                            chunk.Start.CharacterIndex);
                    }

                    return chunkTree;
                }
            }
        }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:34,代码来源:ChunkInheritanceUtility.cs

示例8: GetFileStream

        /// <summary>
        /// Returns <see cref="Stream"/> for the specified <paramref name="fileInfo"/>.
        /// </summary>
        /// <param name="fileInfo">The <see cref="IFileInfo"/> for which the stream is needed.</param>
        /// <returns><see cref="Stream"/> for the specified <paramref name="fileInfo"/>.</returns>
        protected virtual Stream GetFileStream(IFileInfo fileInfo)
        {
            if (fileInfo == null)
            {
                throw new ArgumentNullException(nameof(fileInfo));
            }

            return fileInfo.CreateReadStream();
        }
开发者ID:phinq19,项目名称:git_example,代码行数:14,代码来源:VirtualFileResult.cs

示例9: ReadFileContentsSafely

 private static string ReadFileContentsSafely(IFileInfo fileInfo)
 {
     try
     {
         using (var reader = new StreamReader(fileInfo.CreateReadStream()))
         {
             return reader.ReadToEnd();
         }
     }
     catch
     {
         // Ignore any failures
         return null;
     }
 }
开发者ID:AndersBillLinden,项目名称:Mvc,代码行数:15,代码来源:RoslynCompilationService.cs

示例10: ReadLines

 private static IEnumerable<string> ReadLines(IFileInfo fileInfo)
 {
     using (var reader = new StreamReader(fileInfo.CreateReadStream()))
     {
         string line;
         while ((line = reader.ReadLine()) != null)
         {
             yield return line;
         }
     }
 }
开发者ID:leloulight,项目名称:Diagnostics,代码行数:11,代码来源:DeveloperExceptionPageMiddleware.cs

示例11: ParseViewFile

        private static CodeTree ParseViewFile(RazorTemplateEngine engine,
                                              IFileInfo fileInfo,
                                              string viewStartPath)
        {
            using (var stream = fileInfo.CreateReadStream())
            {
                using (var streamReader = new StreamReader(stream))
                {
                    var parseResults = engine.ParseTemplate(streamReader, viewStartPath);
                    var className = ParserHelpers.SanitizeClassName(fileInfo.Name);
                    var language = engine.Host.CodeLanguage;
                    var codeGenerator = language.CreateCodeGenerator(className,
                                                                     engine.Host.DefaultNamespace,
                                                                     viewStartPath,
                                                                     engine.Host);
                    codeGenerator.Visit(parseResults);

                    return codeGenerator.Context.CodeTreeBuilder.CodeTree;
                }
            }
        }
开发者ID:AndersBillLinden,项目名称:Mvc,代码行数:21,代码来源:ChunkInheritanceUtility.cs

示例12: GetFileStream

 protected virtual Stream GetFileStream(IFileInfo fileInfo)
 {
     return fileInfo.CreateReadStream();
 }
开发者ID:xuchrist,项目名称:Mvc,代码行数:4,代码来源:VirtualFileResultExecutor.cs

示例13: ReadAllText

		private string ReadAllText(IFileInfo fileInfo)
		{
			using (var stream = fileInfo.CreateReadStream())
			using (var reader = new StreamReader(stream))
			{
				return reader.ReadToEnd();
			}
		}
开发者ID:mrahhal,项目名称:MR.AspNet.Deps,代码行数:8,代码来源:DepsManager.cs

示例14: ReadLines

        private static IEnumerable<string> ReadLines(IFileInfo fileInfo)
        {
            var result = new List<string>();

            using (var reader = new StreamReader(fileInfo.CreateReadStream()))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    result.Add(line);
                }
            }

            return result;
        }
开发者ID:mike-kaufman,项目名称:Glimpse.Prototype,代码行数:15,代码来源:ExceptionProcessor.cs


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