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


C# FileHelperEngine.ReadStream方法代码示例

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


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

示例1: GetMSWSReportsFromURL_AsStream_20060709_28Records

        public void GetMSWSReportsFromURL_AsStream_20060709_28Records()
        {
            DateTime date = new DateTime(2006, 7, 20);
                string url = string.Format(MSWSDataUrl_Format, date.ToString(MSWSDataURL_DateFormat));
                MSWSDailyReportRecord[] res = null;
                FileHelperEngine engine = new FileHelperEngine(typeof(MSWSDailyReportRecord));

                    // make request
                    HttpWebRequest webReq = null;
                HttpWebResponse webResp = null;
                StreamReader reader = null;
                try
                {
                    webReq = (HttpWebRequest)HttpWebRequest.Create(url);
                    webResp = (HttpWebResponse)webReq.GetResponse();
                    Encoding encode = Encoding.GetEncoding("utf-8");
                    reader = new StreamReader(webResp.GetResponseStream(), encode);
                    res = (MSWSDailyReportRecord[]) engine.ReadStream(reader);
                }
                catch
                {
                    throw;
                }
                finally
                {
                    if (webReq != null) webReq = null;
                    if (webResp != null) webResp.Close();
                    if (reader != null) reader.Close();
                }

                Assert.AreEqual(res.Length, 32);
        }
开发者ID:hoffmanc,项目名称:FileHelpers,代码行数:32,代码来源:EncodingAdv.cs

示例2: ReadOperationShouldBeQuick

        public void ReadOperationShouldBeQuick()
        {
            Benchmark.This("FileHelperEngine.ReadStream", () =>
            {
                var engine = new FileHelperEngine<FixedSampleRecord>();
                using (var stream = new StringReader(FixedFileSample))
                {
                    var records = engine.ReadStream(stream);
                    records.Should().HaveCount(19);
                }
            })
                .Against.This("FlatFileEngine.Read", () =>
                {
                    var layout = new FixedSampleRecordLayout();
                    using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(FixedFileSample)))
                    {
                        var factory = new FixedLengthFileEngineFactory();

                        var flatFile = factory.GetEngine(layout);

                        var records = flatFile.Read<FixedSampleRecord>(stream).ToArray();

                        records.Should().HaveCount(19);
                    }
                })
                .WithWarmup(1000)
                .For(10000)
                .Iterations()
                .PrintComparison();
        }
开发者ID:mtherien,项目名称:FlatFile,代码行数:30,代码来源:FlatFileVsFileHelpersBenchmark.cs

示例3: EncodingAdvanced5

        public void EncodingAdvanced5()
        {
            var engine = new FileHelperEngine(typeof(EncodingRecord));

            var encode = Encoding.GetEncoding("utf-8");
            var reader = new StreamReader(FileTest.Good.EncodingAdv3.Path, encode);
            var res = (EncodingRecord[])engine.ReadStream(reader);

            Assert.AreEqual(res.Length, 18);
        }
开发者ID:hoffmanc,项目名称:FileHelpers,代码行数:10,代码来源:FileEncodingAdvanced.cs

示例4: ProcessFile

        private void ProcessFile(IDAO dao, string fullPath, string fileName, CancellationToken token)
        {
            Log.Trace($"Thread [{Thread.CurrentThread.ManagedThreadId}] - Start processing file [{fileName}]");

            token.ThrowIfCancellationRequested();
            string managerSecondName = GetManagerSecondNameFromFileName(fileName);
            var manager = dao.ManagerRepository.FindBySecondName(managerSecondName) ??
                          dao.ManagerRepository.Add(new Manager(managerSecondName));

            token.ThrowIfCancellationRequested();
            // parsing .csv
            using (var textReader = File.OpenText(fullPath))
            {
                var engine = new FileHelperEngine<SaleRecord>();
                var records = engine.ReadStream(textReader);

                foreach (var record in records)
                {
                    token.ThrowIfCancellationRequested();
                    ProcessRecord(dao, record, manager, fileName, token);
                }
            }
        }
开发者ID:SergeyKononovich,项目名称:EpamTraining,代码行数:23,代码来源:FolderMonitor.cs

示例5: loadSessions

        /// <summary>
        /// Import the sessions in this providers type
        /// This may throw an exception if there are File I/O issues
        /// </summary>
        /// <param name="location">The location of the csv file</param>
        /// <returns>The list of sessions</returns>
        public List<Session> loadSessions(string location)
        {
            Uri uri = null;
            try
            {
                uri = new Uri(location);
            }
            catch (Exception e)
            {
                throw new Exception("Unable to parse location: " + e.Message);
            }

            FileHelperEngine<CsvRecord> engine = new FileHelperEngine<CsvRecord>();
            List<CsvRecord> csvList = null;
            List<Session> sessionList = null;

            if (uri.Scheme == Uri.UriSchemeFile)
            {
                try
                {
                    csvList = new List<CsvRecord>(engine.ReadFile(uri.LocalPath));
                }
                catch
                {
                    throw new Exception("Unable to parse sessions file." + Environment.NewLine +
                                        "The file may be corrupted or from" + Environment.NewLine +
                                        "a previous version of PuTTY Session Manager.");
                }

            }
            else if (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps)
            {
                Stream s = getRemoteCsvFile(uri);
                if (s != null)
                {
                    try
                    {
                        csvList = new List<CsvRecord>(engine.ReadStream(new StreamReader(s)));
                    }
                    catch
                    {
                        throw new Exception("Unable to parse sessions file." + Environment.NewLine +
                                            "The file may be corrupted or from" + Environment.NewLine +
                                            "a previous version of PuTTY Session Manager.");
                    }
                    finally
                    {
                        if ( s != null )
                            s.Close();
                    }
                }
            }
            else
            {
                throw new Exception("Unable to parse location: unsupported protocol");
            }

            if (csvList != null)
            {
                sessionList = csvList.ConvertAll(new Converter<CsvRecord, Session>(CsvToSessionConvertor));
            }

            return sessionList;
        }
开发者ID:verbitan,项目名称:PuTTY-Session-Manager,代码行数:70,代码来源:CsvSessionImportImpl.cs

示例6: ReadStream

        public void ReadStream()
        {
            string data = "11121314901234" + Environment.NewLine +
                "10111314012345" + Environment.NewLine +
                "11101314123456" + Environment.NewLine +
                "10101314234567" + Environment.NewLine;

            var engine = new FileHelperEngine<SampleType>();

            SampleType[] res;
            res = engine.ReadStream(new StringReader(data));

            Assert.AreEqual(4, res.Length);
            Assert.AreEqual(4, engine.TotalRecords);
            Assert.AreEqual(0, engine.ErrorManager.ErrorCount);

            Assert.AreEqual(new DateTime(1314, 12, 11), res[0].Field1);
            Assert.AreEqual("901", res[0].Field2);
            Assert.AreEqual(234, res[0].Field3);

            Assert.AreEqual(new DateTime(1314, 11, 10), res[1].Field1);
            Assert.AreEqual("012", res[1].Field2);
            Assert.AreEqual(345, res[1].Field3);
        }
开发者ID:rohancragg,项目名称:FileHelpers,代码行数:24,代码来源:ReadersGeneric.cs

示例7: ReadEmpty

        public void ReadEmpty()
        {
            string data = "";

            var engine = new FileHelperEngine<SampleType>();

            SampleType[] res;
            res = engine.ReadStream(new StringReader(data));

            Assert.AreEqual(0, res.Length);
            Assert.AreEqual(0, engine.TotalRecords);
            Assert.AreEqual(0, engine.ErrorManager.ErrorCount);
        }
开发者ID:rohancragg,项目名称:FileHelpers,代码行数:13,代码来源:ReadersGeneric.cs

示例8: GetRecords

 private static IEnumerable<FixedSampleRecord> GetRecords()
 {
     var engine = new FileHelperEngine<FixedSampleRecord>();
     using (var stream = new StringReader(FixedFileSample))
     {
         var records = engine.ReadStream(stream);
         return records;
     }
 }
开发者ID:mtherien,项目名称:FlatFile,代码行数:9,代码来源:FlatFileVsFileHelpersBenchmark.cs

示例9: ReadStream

        public void ReadStream()
        {
            string data = "11121314901234\n"+
                "10111314012345\n" +
                "11101314123456\n" +
                "10101314234567\n" ;

            engine = new FileHelperEngine(typeof(SampleType));

            SampleType[] res;
            res = (SampleType[])engine.ReadStream(new StringReader(data));

            Assert.AreEqual(4, res.Length);
            Assert.AreEqual(4, engine.TotalRecords);
            Assert.AreEqual(0, engine.ErrorManager.ErrorCount);

            Assert.AreEqual(new DateTime(1314, 12, 11), res[0].Field1);
            Assert.AreEqual("901", res[0].Field2);
            Assert.AreEqual(234, res[0].Field3);

            Assert.AreEqual(new DateTime(1314, 11, 10), res[1].Field1);
            Assert.AreEqual("012", res[1].Field2);
            Assert.AreEqual(345, res[1].Field3);
        }
开发者ID:TheJeremyGray,项目名称:FileWatcherService,代码行数:24,代码来源:Readers.cs

示例10: NullReader

		public void NullReader()
		{
			engine = new FileHelperEngine(typeof (SampleType));
			engine.ReadStream(null);
		}
开发者ID:BD-GitHub,项目名称:filehelpers,代码行数:5,代码来源:OtherErrors.cs

示例11: NullReader

 public void NullReader()
 {
     engine = new FileHelperEngine(typeof (SampleType));
     Assert.Throws<ArgumentNullException>(()
         => engine.ReadStream(null));
 }
开发者ID:hoffmanc,项目名称:FileHelpers,代码行数:6,代码来源:OtherErrors.cs

示例12: ReadFile

        public IList<FeederSystemFixedLengthRecord> ReadFile(Stream stream)
        {
            var engine = new FileHelperEngine<FeederSystemFixedLengthRecord>();
            var streamReader = new StreamReader(stream);

            var result = engine.ReadStream(streamReader);
            return result.ToList();
        }
开发者ID:ucdavis,项目名称:BenefitsAllocationUpload,代码行数:8,代码来源:FileService.cs

示例13: DownloadAsExcel

        public ActionResult DownloadAsExcel(string id)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                TempData["Message"] = "Unable to download file.  No file was selected. Please select a file and try again.";
                return RedirectToAction("Index");
            }

            try
            {
                var file = GetNamedFile(id);
                var created = file.TimeStamp;
                var filePathAndFilename = file.FilePath;
                var filename = file.FileNameLessExtension;

                var streamReader = new StreamReader(filePathAndFilename);

                var engine = new FileHelperEngine<FeederSystemFixedLengthRecord>();

                var result = engine.ReadStream(streamReader);

                var transactions = result.ToList();

                // Opening the Excel template...
                var templateFileStream = new FileStream(Server.MapPath(@"~\Files\RevisedScrubberWithoutData.xlsx"),
                    FileMode.Open, FileAccess.Read);

                // Getting the complete workbook...
                var templateWorkbook = new XSSFWorkbook(templateFileStream);

                // Getting the worksheet by its name...
                var sheet = templateWorkbook.GetSheet("Sheet1");

                // We need this so the date will be formatted correctly; otherwise, the date format gets all messed up.
                var dateCellStyle = templateWorkbook.CreateCellStyle();
                var format = templateWorkbook.CreateDataFormat();
                dateCellStyle.DataFormat = format.GetFormat("[$-809]m/d/yyyy;@");

                // Here's another to ensure we get a number with 2 decimal places:
                var twoDecimalPlacesCellStyle = templateWorkbook.CreateCellStyle();
                format = templateWorkbook.CreateDataFormat();
                twoDecimalPlacesCellStyle.DataFormat = format.GetFormat("#0.00");

                var boldFont = templateWorkbook.CreateFont();
                    boldFont.FontHeightInPoints = 11;
                    boldFont.FontName = "Calibri";
                    boldFont.Boldweight = (short)FontBoldWeight.Bold;

                var boldCellStyle = templateWorkbook.CreateCellStyle();
                boldCellStyle.SetFont(boldFont);

                var boldTotalAmountStyle = templateWorkbook.CreateCellStyle();
                boldTotalAmountStyle.DataFormat = twoDecimalPlacesCellStyle.DataFormat;
                boldTotalAmountStyle.SetFont(boldFont);

                var grandTotal = 0.0;
                var i = 0;
                foreach (var transaction in transactions)
                {
                    i++;
                    // Getting the row... 0 is the first row.
                    var dataRow = sheet.GetRow(i);
                    dataRow.CreateCell(0).SetCellValue(transaction.FiscalYear);
                    dataRow.CreateCell(1).SetCellValue(transaction.ChartNum);
                    dataRow.CreateCell(2).SetCellValue(transaction.Account);
                    dataRow.CreateCell(3).SetCellValue(transaction.SubAccount);
                    dataRow.CreateCell(4).SetCellValue(transaction.ObjectCode);
                    dataRow.CreateCell(5).SetCellValue(transaction.SubObjectCode);
                    dataRow.CreateCell(6).SetCellValue(transaction.BalanceType);
                    dataRow.CreateCell(7).SetCellValue(transaction.ObjectType.Trim());
                    dataRow.CreateCell(8).SetCellValue(transaction.FiscalPeriod);
                    dataRow.CreateCell(9).SetCellValue(transaction.DocumentType);
                    dataRow.CreateCell(10).SetCellValue(transaction.OriginCode);
                    dataRow.CreateCell(11).SetCellValue(transaction.DocumentNumber);
                    dataRow.CreateCell(12).SetCellValue(transaction.LineSequenceNumber);
                    dataRow.CreateCell(13).SetCellValue(transaction.TransactionDescription);

                    var transactionAmount = Convert.ToDouble(transaction.Amount.Trim());
                    grandTotal += transactionAmount;
                    var cell = dataRow.CreateCell(14);
                    cell.CellStyle = twoDecimalPlacesCellStyle;
                    cell.SetCellValue(transactionAmount);

                    dataRow.CreateCell(15).SetCellValue(transaction.DebitCreditCode.Trim());

                    cell = dataRow.CreateCell(16);
                    cell.CellStyle = dateCellStyle;
                    cell.SetCellValue(Convert.ToDateTime(transaction.TransactionDate));

                    dataRow.CreateCell(17).SetCellValue(transaction.OrganizationTrackingNumber);
                    dataRow.CreateCell(18).SetCellValue(transaction.ProjectCode);
                    dataRow.CreateCell(19).SetCellValue(transaction.OrganizationReferenceId.Trim());
                    dataRow.CreateCell(20).SetCellValue(transaction.ReferenceTypeCode.Trim());
                    dataRow.CreateCell(21).SetCellValue(transaction.ReferenceOriginCode.Trim());
                    dataRow.CreateCell(22).SetCellValue(transaction.ReferenceNumber.Trim());
                    dataRow.CreateCell(23).SetCellValue(transaction.ReversalDate.Trim());
                    dataRow.CreateCell(24).SetCellValue(transaction.TransactionEncumbranceUpdateCode.Trim());
                }

                if (transactions.Any())
//.........这里部分代码省略.........
开发者ID:ucdavis,项目名称:BenefitsAllocationUpload,代码行数:101,代码来源:ReportsController.cs

示例14: Display

        public ActionResult Display(string id)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                TempData["Message"] = "Unable to display file.  No file was selected. Please select a file and try again.";
                return RedirectToAction("Index");
            }

            var file = GetNamedFile(id);

            var engine = new FileHelperEngine<FeederSystemFixedLengthRecord>();

            var streamReader = new StreamReader(file.FilePath);

            var result = engine.ReadStream(streamReader);

            var transactions = result.ToList();

            TempData["Message"] = String.Format("Now viewing \"{0}\".", file.FileName);
            TempData["Filename"] = file.FileNameLessExtension;
            return View(transactions);
        }
开发者ID:ucdavis,项目名称:BenefitsAllocationUpload,代码行数:22,代码来源:ReportsController.cs


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