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


C# IFile.OpenRead方法代码示例

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


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

示例1: ReadLines

        private List<string> ReadLines(IFile file, out bool needsPatching)
        {
            var existing = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

            using (var stream = file.OpenRead())
            using (var reader = new StreamReader(stream, true))
            {
                var readLines = new List<string>();
                while (true)
                {
                    var line = reader.ReadLine();
                    if (line == null)
                    {
                        break;
                    }

                    if (!_content.Contains(line, StringComparer.Ordinal))
                    {
                        readLines.Add(line);
                    }
                    else
                    {
                        existing.Add(line);
                    }
                }

                needsPatching = existing.Count != _content.Length;
                return RemoveTrailingEmptyLines(readLines);
            }
        }
开发者ID:gep13,项目名称:bootstrapper,代码行数:30,代码来源:GitIgnorePatcher.cs

示例2: Read

 // TODO: Read-retry should be part of an extension method that can be reused for reading the index in indexed folder repositories.
 public IPackageDescriptor Read(IFile filePath)
 {
     if (!filePath.Exists)
         return null;
     IOException ioException = null;
     int tries = 0;
     while (tries < FILE_READ_RETRIES)
     {
         try
         {
             using (var fileStream = filePath.OpenRead())
             {
                 var descriptor = new PackageDescriptorReader().Read(fileStream);
                 if (descriptor.Name == null)
                     descriptor.Name = PackageNameUtility.GetName(filePath.NameWithoutExtension);
                 return descriptor;
             }
         }
         catch (InvalidPackageException ex)
         {
             throw new InvalidPackageException(String.Format("Invalid package for file '{0}'.", filePath.Path), ex);
         }
         catch (IOException ex)
         {
             ioException = ex;
             tries++;
             Thread.Sleep(FILE_READ_RETRIES_WAIT);
             continue;
         }
     }
     throw ioException;
 }
开发者ID:scrummyin,项目名称:openwrap,代码行数:33,代码来源:PackageDescriptorReaderWriter.cs

示例3: Copy

        private bool Copy(IFile source, IFile destination)
        {
            if (!source.Exists)
            {
                _log.Error("Could not find file {0}.", source.Path.FullPath);
                return false;
            }
            if (destination.Exists)
            {
                _log.Error("The file {0} already exist.", destination.Path.FullPath);
                return false;
            }

            using (var input = source.OpenRead())
            using (var output = destination.OpenWrite())
            {
                using (var reader = new StreamReader(input))
                using (var writer = new StreamWriter(output))
                {
                    while (true)
                    {
                        var line = reader.ReadLine();
                        if (line == null)
                        {
                            break;
                        }
                        writer.WriteLine(line);
                    }
                }
            }

            return true;
        }
开发者ID:gep13,项目名称:bootstrapper,代码行数:33,代码来源:FileCopier.cs

示例4: Read

 public PackageDescriptor Read(IFile filePath)
 {
     if (!filePath.Exists)
         return null;
     IOException ioException = null;
     int tries = 0;
     while (tries < FILE_READ_RETRIES)
     {
         try
         {
             using (var fileStream = filePath.OpenRead())
             {
                 var descriptor = Read(fileStream);
                 if (descriptor.Name == null)
                     descriptor.Name = PackageNameUtility.GetName(filePath.NameWithoutExtension);
                 return descriptor;
             }
         }
         catch (IOException ex)
         {
             ioException = ex;
             tries++;
             Thread.Sleep(FILE_READ_RETRIES_WAIT);
             continue;
         }
     }
     throw ioException;
 }
开发者ID:adymitruk,项目名称:openwrap,代码行数:28,代码来源:PackageDescriptorReaderWriter.cs

示例5: HashFileContents

 string HashFileContents(IFile file)
 {
     using (var fileStream = file.OpenRead())
     {
         return fileStream.ComputeSHA1Hash().ToHexString();
     }
 }
开发者ID:prabirshrestha,项目名称:cassette,代码行数:7,代码来源:ExpandCssUrlsAssetTransformer.cs

示例6: SendFile

 void SendFile(IFile file)
 {
     using (var stream = file.OpenRead())
     {
         response.Cache.SetExpires(DateTime.UtcNow.AddYears(1));
         stream.CopyTo(response.OutputStream);
     }
 }
开发者ID:pyttroll,项目名称:cassette,代码行数:8,代码来源:CachedFileRequestHandler.cs

示例7: SendFile

 void SendFile(IFile file)
 {
     using (var stream = file.OpenRead())
     {
         response.Cache.SetCacheability(HttpCacheability.Public);
         response.Cache.SetExpires(DateTime.UtcNow.AddYears(1));
         response.Cache.SetMaxAge(new TimeSpan(365, 0, 0, 0));
         stream.CopyTo(response.OutputStream);
     }
 }
开发者ID:TheCloudlessSky,项目名称:cassette,代码行数:10,代码来源:CachedFileRequestHandler.cs

示例8: SendFile

        void SendFile(IFile file)
        {
            //HttpResponseUtil.EncodeStreamAndAppendResponseHeaders(request, response);
            response.Cache.SetCacheability(HttpCacheability.Public);
            response.Cache.SetExpires(DateTime.UtcNow.AddYears(1));
            response.Cache.SetMaxAge(new TimeSpan(365, 0, 0, 0));

            using (var stream = file.OpenRead())
            {
                stream.CopyTo(response.OutputStream);
            }
        }
开发者ID:vinkhub,项目名称:cassette,代码行数:12,代码来源:CachedFileRequestHandler.cs

示例9: AddFile

        private void AddFile(IFile file)
        {
            using (var stream = file.OpenRead())
            using (var ms = new MemoryStream())
            {
                stream.CopyTo(ms);
                _messageBus.Publish(new AddTorrentMessage(ms.ToArray()));
            }

            // Add file to history
            var hist = new History {Path = file.Path.FullPath};
            _autoAddRepository.CreateHistory(hist);
        }
开发者ID:DNIDNL,项目名称:hadouken,代码行数:13,代码来源:FolderScanner.cs

示例10: TryGenerateAssemblyInfo

 public static IFile TryGenerateAssemblyInfo(IFile descriptorPath, SemanticVersion providedVersion = null)
 {
     IPackageDescriptor descriptor;
     using (var str = descriptorPath.OpenRead())
         descriptor = new PackageDescriptorReader().Read(str);
     var versionFile = descriptorPath.Parent.GetFile("version");
     var version = providedVersion ?? GenerateVersion(descriptor, versionFile);
     if (version == null) return null;
     var generator = new AssemblyInfoGenerator(descriptor) { Version = version };
     var projectAsmFile = descriptorPath.Parent.GetUniqueFile("SharedAssemblyInfo.cs");
     generator.Write(projectAsmFile);
     return projectAsmFile;
 }
开发者ID:modulexcite,项目名称:openwrap,代码行数:13,代码来源:BuildManagement.cs

示例11: LoadRunner

 ITestRunner LoadRunner(IFile tdnet)
 {
     using (var stream = tdnet.OpenRead())
     using (var reader = new XmlTextReader(stream))
     {
         var xmlDoc = XDocument.Load(reader);
         var friendlyName = GetChildNode(xmlDoc, "FriendlyName");
         var typeName = GetChildNode(xmlDoc, "TypeName");
         var assemblyPath = GetChildNode(xmlDoc, "AssemblyPath");
         if (typeName != null && assemblyPath != null)
             return new AppDomainTestRunner(tdnet.Parent.Path.Combine(assemblyPath), typeName);
     }
     return null;
 }
开发者ID:modulexcite,项目名称:openwrap,代码行数:14,代码来源:TdnetTestRunnerFactory.cs

示例12: ExtractPackage

 // TODO: Replace with clean OFS-based zip methods
 static void ExtractPackage(IFile wrapFile, IDirectory destinationDirectory)
 {
     var nt = new WindowsNameTransform(destinationDirectory.Path.FullPath);
     using (var zipFile = new ZipFile(wrapFile.OpenRead()))
     {
         foreach (ZipEntry zipEntry in zipFile)
         {
             if (zipEntry.IsFile)
             {
                 var filePath = nt.TransformFile(zipEntry.Name);
                 using (var targetFile = destinationDirectory.FileSystem.GetFile(filePath).MustExist().OpenWrite())
                 using (var sourceFile = zipFile.GetInputStream(zipEntry))
                     sourceFile.CopyTo(targetFile);
                 // TODO: restore last write time here by adding it to OFS
             }
         }
     }
 }
开发者ID:ryansroberts,项目名称:openwrap,代码行数:19,代码来源:CachedZipPackage.cs

示例13: Compile

        public Task<CompilationResult> Compile(IFile file)
        {
            string className = MakeClassName(file.Name);
            RazorTemplateEngine engine = new RazorTemplateEngine(new RazorEngineHost(new CSharpRazorCodeLanguage())
            {
                DefaultBaseClass = "Edge.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 = file.OpenRead())
            {
                results = engine.GenerateCode(rdr, className, "EdgeCompiled", file.FullPath);
            }

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

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

示例14: ParseFile

 public WrapDescriptor ParseFile(IFile filePath)
 {
     int tries = 0;
     while (tries < FILE_READ_RETRIES)
     {
         try
         {
             using (var fileStream = filePath.OpenRead())
             {
                 return ParseFile(filePath, fileStream);
             }
         }
         catch (IOException)
         {
             tries++;
             Thread.Sleep(FILE_READ_RETRIES_WAIT);
             continue;
         }
     }
     return null;
 }
开发者ID:bobthemighty,项目名称:openwrap,代码行数:21,代码来源:WrapDescriptorParser.cs

示例15: GetHash

 /// <summary>
 /// Gets the hash of a file
 /// </summary>
 /// <param name="file">The file to calculate the hash of</param>
 /// <returns>The hash of a file.</returns>
 public string GetHash(IFile file)
 {
     using (var md5 = MD5.Create())
     {
         using (var stream = file.OpenRead())
         {
             return BitConverter.ToString(md5.ComputeHash(stream)).Replace("-","").ToLower();
         }
     }
 }
开发者ID:SharpeRAD,项目名称:Cake.AWS.S3,代码行数:15,代码来源:S3Manager.cs


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