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


C# FileInfoBase.OpenRead方法代码示例

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


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

示例1: ReadResultsFile

        private XDocument ReadResultsFile(FileInfoBase testResultsFile)
        {
            XDocument document;
            using (var stream = testResultsFile.OpenRead())
            {
                using (var streamReader = new System.IO.StreamReader(stream))
                {
                    string content = streamReader.ReadToEnd();

                    int begin = content.IndexOf("<!-- Pickles Begin", StringComparison.Ordinal);

                    content = content.Substring(begin);

                    content = content.Replace("<!-- Pickles Begin", string.Empty);

                    int end = content.IndexOf("Pickles End -->", System.StringComparison.Ordinal);

                    content = content.Substring(0, end);

                    content = content.Replace("&lt;", "<").Replace("&gt;", ">");

                    var xmlReader = XmlReader.Create(new System.IO.StringReader(content));
                    document = XDocument.Load(xmlReader);
                }
            }

            return document;
        }
开发者ID:picklesdoc,项目名称:pickles,代码行数:28,代码来源:SpecRunSingleResultLoader.cs

示例2: AddFile

 public static void AddFile(this ZipArchive zipArchive, FileInfoBase file, string directoryNameInArchive)
 {
     string fileName = Path.Combine(directoryNameInArchive, file.Name);
     ZipArchiveEntry entry = zipArchive.CreateEntry(fileName, CompressionLevel.Fastest);
     using (Stream zipStream = entry.Open(),
                   fileStream = file.OpenRead())
     {
         fileStream.CopyTo(zipStream);
     }
 }
开发者ID:GregPerez83,项目名称:kudu,代码行数:10,代码来源:ZipArchiveExtensions.cs

示例3: Load

        public XDocument Load(FileInfoBase fileInfo)
        {
            XDocument document;
            using (var stream = fileInfo.OpenRead())
            {
                document = this.Load(stream);
            }

            return document;
        }
开发者ID:picklesdoc,项目名称:pickles,代码行数:10,代码来源:XDocumentLoader.cs

示例4: Load

 public XDocument Load(FileInfoBase fileInfo)
 {
   XDocument document;
   using (var stream = fileInfo.OpenRead())
   {
     XmlReader xmlReader = XmlReader.Create(stream);
     document = XDocument.Load(xmlReader);
     stream.Close();
   }
   return document;
 }
开发者ID:Jaykul,项目名称:pickles,代码行数:11,代码来源:XDocumentLoader.cs

示例5: ReadResultsFile

 private List<Feature> ReadResultsFile(FileInfoBase testResultsFile)
 {
     List<Feature> result;
       using (var stream = testResultsFile.OpenRead())
       {
     using (var reader = new StreamReader(stream))
     {
       result = JsonConvert.DeserializeObject<List<Feature>>(reader.ReadToEnd());
     }
       }
       return result;
 }
开发者ID:pianovelty,项目名称:pickles,代码行数:12,代码来源:CucumberJsonSingleResults.cs

示例6: LoadFile

        /// <summary>
        /// Loads a file from the file name.
        /// </summary>
        /// <param name="fileInfo">The file info.</param>
        /// <returns>The file's content.</returns>
        protected string LoadFile(FileInfoBase fileInfo)
        {
            // Data validation
            if (null == fileInfo)
                throw new ArgumentNullException("fileInfo");

            // Load the file content
            MemoryStream memoryStream = new MemoryStream();
            using (StreamReader streamReader = new StreamReader(fileInfo.OpenRead()))
            using (var fileWriter = new StreamWriter(memoryStream))
            {
                fileWriter.Write(streamReader.ReadToEnd());
            }

            // Read the code snippet from the file
            return Encoding.UTF8.GetString(memoryStream.ToArray());
        }
开发者ID:defrancea,项目名称:Projbook,代码行数:22,代码来源:DefaultSnippetExtractor.cs

示例7: CreateFromFileName

        public static IFileReader CreateFromFileName(FileInfoBase fileInfoBase)
        {
            if (IsCsvFile(fileInfoBase.FullName))
            {
                var reader = new CsvHelper.CsvReader(new StreamReader(fileInfoBase.OpenRead()), new CsvConfiguration
                {
                    HasHeaderRecord = true,
                    Delimiter = ";"
                });

                return new CsvReader(reader);
            }

            if (IsExcelFile(fileInfoBase.FullName))
            {
                var excelReader = ExcelReaderFactory.CreateOpenXmlReader(fileInfoBase.Open(FileMode.Open, FileAccess.Read));
                excelReader.IsFirstRowAsColumnNames = true;
                return new ExcelReader(excelReader);
            }

            throw new InvalidOperationException();
        }
开发者ID:ArneD,项目名称:unique-file-records-comparer,代码行数:22,代码来源:FileReaderFactory.cs

示例8: HashDelivery

 private static string HashDelivery(FileInfoBase file)
 {
     using (var fs = file.OpenRead())
     using (var bs = new BufferedStream(fs))
     {
         using (var sha1 = new SHA1Managed())
         {
             var hash = sha1.ComputeHash(bs);
             var formatted = new StringBuilder(2 * hash.Length);
             foreach (var b in hash)
             {
                 formatted.AppendFormat("{0:X2}", b);
             }
             return formatted.ToString();
         }
     }
 }
开发者ID:KevinJump,项目名称:Chauffeur,代码行数:17,代码来源:DeliveryDeliverable.cs

示例9: ReadResultsFile

 private XDocument ReadResultsFile(FileInfoBase testResultsFile)
 {
     XDocument document;
       using (var stream = testResultsFile.OpenRead())
       {
     var xmlReader = XmlReader.Create(stream);
     document = XDocument.Load(xmlReader);
     stream.Close();
       }
       return document;
 }
开发者ID:pianovelty,项目名称:pickles,代码行数:11,代码来源:MsTestSingleResults.cs

示例10: GetHeightToWidthRatio

 public static double GetHeightToWidthRatio(FileInfoBase relativePath)
 {
     using (var stream = relativePath.OpenRead())
     {
         var image = Image.FromStream(stream);
         return ((double)image.Height) / ((double)image.Width);
     }
 }
开发者ID:orloffm,项目名称:OrlovMikhail.LiveJournalGrabber,代码行数:8,代码来源:ImageHelper.cs

示例11: GetScriptAsync

        /// <summary>
        /// Retrieves the build script contained in the given file.
        /// </summary>
        /// <param name="file">The file containing a build script</param>
        /// <returns>A build script.</returns>
        protected async Task<ScriptFile> GetScriptAsync(FileInfoBase file)
        {
            // Parse file name and path
            var typeName = file.Directory.Name;
            var schemaName = file.Directory.Parent.Name;
            var fileName = Path.GetFileNameWithoutExtension(file.FullName);
            if(!_objectTypes.ContainsKey(typeName))
            {
                return new ScriptFile(new DatabaseObject(ServerName, DatabaseName, schemaName.TrimObjectName(), fileName.TrimObjectName()), new UnexpectedObjectTypeError(typeName));
            }
            var objectType = _objectTypes[typeName];
            var dbObject = new TypedDatabaseObject(ServerName, DatabaseName, schemaName.TrimObjectName(), fileName.TrimObjectName(), objectType);

            // Read file contents
            string content;
            try
            {
                using (var fileInputStream = file.OpenRead())
                {
                    using (var fileReader = new StreamReader(fileInputStream))
                    {
                        content = await fileReader.ReadToEndAsync();
                    }
                }
            }
            catch (DirectoryNotFoundException)
            {
                return new ScriptFile(dbObject, GetDropScript(dbObject), _sqlParser);
            }
            catch (FileNotFoundException)
            {
                return new ScriptFile(dbObject, GetDropScript(dbObject), _sqlParser);
            }

            // Parse script file
            var script = new ScriptFile(dbObject, content, _sqlParser);

            return script;
        }
开发者ID:Zocdoc,项目名称:ZocBuild.Database,代码行数:44,代码来源:FileSystemScriptRepository.cs

示例12: BytesEqual

        private static bool BytesEqual(FileInfoBase file1, FileInfoBase file2)
        {
            if (file1.Length != file2.Length)
            {
                return false;
            }

            int bufferCount = (int)Math.Ceiling((double)file1.Length / BufferSize);
            using (Stream sourceStream = file1.OpenRead())
            using (Stream targetStream = file2.OpenRead())
            {
                byte[] sourceBuffer = new byte[BufferSize];
                byte[] targetBuffer = new byte[BufferSize];
                for (int i = 0; i < bufferCount; i++)
                {
                    sourceStream.Read(sourceBuffer, 0, BufferSize);
                    targetStream.Read(targetBuffer, 0, BufferSize);
                    if (BitConverter.ToInt64(sourceBuffer, 0) != BitConverter.ToInt64(targetBuffer, 0))
                    {
                        return false;
                    }
                }
            }
            return true;
        }
开发者ID:rwakelam,项目名称:Flow,代码行数:25,代码来源:Pusher.cs

示例13: AddFile

        public static void AddFile(this ZipArchive zipArchive, FileInfoBase file, ITracer tracer, string directoryNameInArchive)
        {
            Stream fileStream = null;
            try
            {
                fileStream = file.OpenRead();
            }
            catch (Exception ex)
            {
                // tolerate if file in use.
                // for simplicity, any exception.
                tracer.TraceError(String.Format("{0}, {1}", file.FullName, ex));
                return;
            }

            try
            {
                string fileName = ForwardSlashCombine(directoryNameInArchive, file.Name);
                ZipArchiveEntry entry = zipArchive.CreateEntry(fileName, CompressionLevel.Fastest);
                entry.LastWriteTime = file.LastWriteTime;

                using (Stream zipStream = entry.Open())
                {
                    fileStream.CopyTo(zipStream);
                }
            }
            finally
            {
                fileStream.Dispose();
            }
        }
开发者ID:40a,项目名称:kudu,代码行数:31,代码来源:ZipArchiveExtensions.cs


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