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


C# FileHelperEngine.ReadFile方法代码示例

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


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

示例1: Main

        static void Main()
        {
            Console.WriteLine("1. Clean old data.");

            OdbFactory.Delete("FileOut.ndb");
            OdbFactory.Delete("FileOut.txt");
            TimeSnapshot();

            Console.WriteLine("2. Read input file.");
            var engine = new FileHelperEngine(typeof(ExportData));
            var res = engine.ReadFile("FileIn.txt") as ExportData[];
            TimeSnapshot();

            Console.WriteLine("3. Prepare NDatabase db.");
            using (var odb = OdbFactory.Open("FileOut.ndb"))
            {
                Console.WriteLine("3a. Store items into NDatabase.");
                foreach (var exportData in res)
                    odb.Store(exportData);
                TimeSnapshot();

                Console.WriteLine("3b. Create index on NDatabase.");
                odb.IndexManagerFor<ExportData>().AddIndexOn("countryIndex", new[] { "CountryOrArea" });
            }
            TimeSnapshot();

            Console.WriteLine("4. Prepare final input file.");
            // To Write Use:
            engine.WriteFile("FileOut.txt", res);
            TimeSnapshot();

            Console.WriteLine("5. Start counting EGYPT by FileHelpers.");
            var stopwatch = new Stopwatch();
            stopwatch.Start();
            res = engine.ReadFile("FileOut.txt") as ExportData[];

            var count = res.Count(x => x.CountryOrArea.Equals("EGYPT"));
            stopwatch.Stop();
            Console.WriteLine("Egypt items: {0}", count);
            Console.WriteLine("Ellapsed: {0} ms", stopwatch.ElapsedMilliseconds);

            Console.WriteLine("5. Start counting EGYPT by NDatabase.");

            stopwatch.Reset();
            stopwatch.Start();
            long count2;
            using (var odb = OdbFactory.Open("FileOut.ndb"))
            {
                count2 = (from data in odb.AsQueryable<ExportData>()
                          where data.CountryOrArea.Equals("EGYPT")
                          select data).Count();
            }
            stopwatch.Stop();

            Console.WriteLine("Egypt items: {0}", count2);
            Console.WriteLine("Ellapsed: {0} ms", stopwatch.ElapsedMilliseconds);
            TimeSnapshot();
        }
开发者ID:danfma,项目名称:NDB,代码行数:58,代码来源:Program.cs

示例2: Import

        static void Import(string simAreasPath, DbConnection connection)
        {
            var simarea = new SimAreasContext(connection, false, new DropCreateDatabaseAlways<SimAreasContext>());
            var engine = new FileHelperEngine(typeof(SimAreas));
            var entries = (SimAreas[])engine.ReadFile(simAreasPath);

            foreach (var entry in entries)
            {
                var area = (from s in simarea.SimAreas
                            where s.SimAreaName == entry.SimAreaName
                            select s).FirstOrDefault();
                if (area == null)
                {
                    area = new SimArea
                    {
                        SimAreaName = entry.SimAreaName,
                        Latitude = entry.Latitude,
                        Longitude = entry.Longitude,
                        Height = entry.Height,
                        GeoidSeparation = entry.GeoidSeparation,
                        OpsLimitFile = entry.OpsLimitFile,
                        SimLimitFile = entry.SimLimitFile,
                    };
                    simarea.SimAreas.Add(area);
                    simarea.SaveChanges();
                }

            }
        }
开发者ID:AuditoryBiophysicsLab,项目名称:ESME-Workbench,代码行数:29,代码来源:Program.cs

示例3: ErrorHandling

        static void ErrorHandling()
        {
            Console.WriteLine("Testing error handling...");
            Console.WriteLine();

            // Estas dos lineas son el uso de la librería
            FileHelperEngine engine = new FileHelperEngine(typeof(Customer));

            engine.ErrorManager.ErrorMode = ErrorMode.SaveAndContinue;

            Customer[] customers = (Customer[]) engine.ReadFile(@"..\Data\CustomersWithErrors.txt");

            if (engine.ErrorManager.ErrorCount > 0)
            {
                Console.Write("Records: ");
                Console.WriteLine(engine.TotalRecords);

                Console.Write("Successful: ");
                Console.WriteLine(customers.Length);

                Console.Write("With Error: ");
                Console.WriteLine(engine.ErrorManager.ErrorCount);

                Console.Write("Error: ");
                Console.WriteLine(engine.ErrorManager.Errors[0].ExceptionInfo.Message);

            }

            engine.ErrorManager.SaveErrors("errors.txt");

            Console.ReadLine();

            if (File.Exists("errors.txt")) File.Delete("errors.txt");
        }
开发者ID:hoffmanc,项目名称:FileHelpers,代码行数:34,代码来源:Main.cs

示例4: WriteFile2

        public void WriteFile2()
        {
            var engine = new FileHelperEngine<SampleType>();

            var res = new SampleType[2];

            res[0] = new SampleType();
            res[1] = new SampleType();

            res[0].Field1 = DateTime.Now.AddDays(1);
            res[0].Field2 = "je";
            res[0].Field3 = 0;

            res[1].Field1 = DateTime.Now;
            res[1].Field2 = "ho";
            res[1].Field3 = 2;

            engine.WriteFile(@"miprueba.txt", res, -10);

            res = (SampleType[]) engine.ReadFile(@"miprueba.txt");

            if (File.Exists(@"miprueba.txt"))
                File.Delete(@"miprueba.txt");

            Assert.AreEqual(2, res.Length);
        }
开发者ID:rohancragg,项目名称:FileHelpers,代码行数:26,代码来源:WritersMaxRecords.cs

示例5: ReadFile

        public static ConcurrentDictionary<int, ILinie> ReadFile(String filePath)
        {
            FileHelperEngine<LinieRecord> engine = new FileHelperEngine<LinieRecord>();
            ConcurrentDictionary<int, ILinie> linien = new ConcurrentDictionary<int, ILinie>();

            try {
                engine.ErrorManager.ErrorMode = ErrorMode.SaveAndContinue;
                engine.Encoding = Encoding.UTF8;
                LinieRecord[] res = engine.ReadFile(filePath);

                foreach (LinieRecord linie in res) {
                    //Übernehmen der eingelesenen Daten in das Programm-Model:
                    ILinie transport = new Linie();
                    transport.Bezeichnung = linie.Bezeichnung;
                    transport.Echtzeit = linie.Echtzeit;
                    transport.Id = linie.Id;
                    transport.Reihenfolge = linie.Reihenfolge;
                    transport.Verkehrsmittel = Linie.VerkehrsmittelConverter(linie.Verkehrsmittel);

                    //Schreiben des Models in Collection für den Rückgabewert:
                    linien.AddOrUpdate(transport.Id, transport, (key, oldValue) => transport);
                }
            } catch (Exception ex) {
                //Dokument konnte nicht geparst werden (Nicht vorhanden/geöffnet)
                throw new VtmParsingException("Beim Versuch die Linien zu parsen ist ein Fehler aufgetreten!", filePath, ex);
            }

            return (linien);
        }
开发者ID:CodefoundryDE,项目名称:ViennaTrafficMonitor,代码行数:29,代码来源:LinienParser.cs

示例6: ReadFile

        public static ConcurrentDictionary<int, IHaltestelle> ReadFile(String filePath)
        {
            FileHelperEngine<HaltestelleRecord> engine = new FileHelperEngine<HaltestelleRecord>();
            ConcurrentDictionary<int, IHaltestelle> haltestellen = new ConcurrentDictionary<int, IHaltestelle>();

            try {
                engine.ErrorManager.ErrorMode = ErrorMode.SaveAndContinue;
                engine.Encoding = Encoding.UTF8;
                HaltestelleRecord[] res = engine.ReadFile(filePath);

                foreach (HaltestelleRecord haltestelle in res) {
                    //Übernehmen der eingelesenen Daten in das Programm-Model:
                    IHaltestelle transport = new Haltestelle();
                    Point HsLoc = new Point(haltestelle.XKoord, haltestelle.YKoord);

                    transport.Diva = haltestelle.Diva;
                    transport.Id = haltestelle.Id;
                    transport.Location = HsLoc;
                    transport.Name = haltestelle.Name;

                    //Schreiben des Models in Collection für den Rückgabewert:
                    haltestellen.AddOrUpdate(transport.Id, transport, (key, oldValue) => transport);
                }
            } catch (Exception ex) {
                //Dokument konnte nicht geparst werden (Nicht vorhanden/geöffnet)
                throw new VtmParsingException("Beim Versuch die Haltestellen zu parsen ist ein Fehler aufgetreten!", filePath, ex);
            }
            return (haltestellen);
        }
开发者ID:CodefoundryDE,项目名称:ViennaTrafficMonitor,代码行数:29,代码来源:HaltestellenParser.cs

示例7: AppendOneToFile

        public void AppendOneToFile()
        {
            engine = new FileHelperEngine(typeof (SampleType));

            SampleType[] res = new SampleType[2];

            res[0] = new SampleType();
            res[1] = new SampleType();

            res[0].Field1 = DateTime.Now.AddDays(1).Date;
            res[0].Field2 = "je";
            res[0].Field3 = 0;

            res[1].Field1 = DateTime.Now.Date;
            res[1].Field2 = "ho";
            res[1].Field3 = 2;

            engine.WriteFile(@"test.txt", res);

            SampleType record = new SampleType();

            record.Field1 = DateTime.Now.Date;
            record.Field2 = "h2";
            record.Field3 = 2;

            engine.AppendToFile(@"test.txt", record);

            SampleType[] res2 = (SampleType[]) engine.ReadFile(@"test.txt");

            Assert.AreEqual(3, res2.Length);
            Assert.AreEqual(res[0].Field1, res2[0].Field1);
            Assert.AreEqual(res[1].Field1, res2[1].Field1);
            Assert.AreEqual(DateTime.Now.Date, res2[2].Field1);
        }
开发者ID:hoffmanc,项目名称:FileHelpers,代码行数:34,代码来源:AppendWriters.cs

示例8: Main

        static void Main(string[] args)
        {
            //Creates new FileHelperEngine to parse csv file
            FileHelperEngine engine = new FileHelperEngine(typeof(XbrlUrl));
            XbrlUrl[] xbrlUrls = engine.ReadFile("XbrlInstanceDocs.csv") as XbrlUrl[];

            Reader reader = new Reader();
            string fileId = null;

            using (FileStream fs = File.Create("XbrlTextBlocks.csv"))
            using (StreamWriter writer = new StreamWriter(fs))
            {
                //Iterate through each xml url, strip out enclosing quotations and read xml file contents for tags
                //and writes contents to new xml file.
                foreach (var url in xbrlUrls)
                {
                    fileId = url.Id.Replace("\"", "").Replace("\\", "");
                    var bareUrl = url.XmlUrl.Replace("\"", "");
                    reader.ReadXml(bareUrl, fileId, fs, writer);
                }
            }

            Console.WriteLine("DONE");
            Console.ReadLine();
        }
开发者ID:theredchord,项目名称:XbrlTextBlock,代码行数:25,代码来源:Program.cs

示例9: Load

        public StartAndEndPair[] Load()
        {

            var fh = new FileHelperEngine<CommentedStartAndEndPair>();
            var values = fh.ReadFile(_fileName);

            var returnValues = new List<StartAndEndPair>();

            foreach (var value in values)
            {
                if (_matchRequiredTag)
                {
                    if (value.Comment.Contains(_requiredTag))
                    {
                        returnValues.Add(new StartAndEndPair(value.Start, value.End));
                    }
                }
                else
                {
                    returnValues.Add(new StartAndEndPair(value.Start, value.End));
                }
            }

            return returnValues.ToArray();
        }
开发者ID:timbarrass,项目名称:Alembic.Tools,代码行数:25,代码来源:Program.cs

示例10: ReadWrite

        /// <summary>
        /// Process the delimited file twice,
        /// once with the simple engine, once with Async
        /// </summary>
        /// <remarks>
        /// This is a simple sample of using the Normal engine and the Async engine
        /// </remarks>
        public void ReadWrite()
        {
            var engine = new FileHelperEngine<Orders>();

            // to Read use:
            Orders[] res = engine.ReadFile(@"C:\TestIn.txt");

            // to Write use:
            engine.WriteFile(@"C:\TestOut.txt", res);

            foreach (Orders order in res) {
                Console.WriteLine("Order Info:");
                Console.WriteLine(order.CustomerID + " - " +
                                  order.OrderDate.ToString("dd/MM/yy"));
            }

            var asyncEngine = new FileHelperAsyncEngine<Orders>();

            asyncEngine.BeginReadFile(@"C:\TestIn.txt");

            Orders ord;

            while (asyncEngine.ReadNext() != null) {
                ord = asyncEngine.LastRecord;
                // your code here
                Console.WriteLine(ord.CustomerID);
            }
        }
开发者ID:mgmccarthy,项目名称:FileHelpers,代码行数:35,代码来源:EasySample.cs

示例11: AppendToFile

        public void AppendToFile()
        {
            var engine = new FileHelperEngine<SampleType>();

            var res = new SampleType[2];

            res[0] = new SampleType();
            res[1] = new SampleType();

            res[0].Field1 = DateTime.Now.AddDays(1).Date;
            res[0].Field2 = "je";
            res[0].Field3 = 0;

            res[1].Field1 = DateTime.Now.Date;
            res[1].Field2 = "ho";
            res[1].Field3 = 2;

            engine.WriteFile(@"test.txt", res);
            engine.AppendToFile(@"test.txt", res);

            var res2 = (SampleType[]) engine.ReadFile(@"test.txt");

            Assert.AreEqual(4, res2.Length);
            Assert.AreEqual(res[0].Field1, res2[0].Field1);
            Assert.AreEqual(res[1].Field1, res2[1].Field1);
            Assert.AreEqual(res[0].Field1, res2[2].Field1);
            Assert.AreEqual(res[1].Field1, res2[3].Field1);
        }
开发者ID:calebillman,项目名称:FileHelpers,代码行数:28,代码来源:AppendWriters.cs

示例12: EncodingAdvanced4

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

            var res = (EncodingRecord[])engine.ReadFile(FileTest.Good.EncodingAdv3.Path);

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

示例13: GetFileHeader

        public void GetFileHeader()
        {
            var engine = new FileHelperEngine<CustomersVerticalBar>();
            var records = engine.ReadFile(FileTest.Good.CustomersVerticalBarDemo.Path);

            Check.That(engine.GetFileHeader())
                .IsEqualTo("CustomerID|CompanyName|ContactName|ContactTitle|Address|City|Country");
        }
开发者ID:rucila,项目名称:FileHelpers,代码行数:8,代码来源:HeaderText.cs

示例14: Main

        static void Main(string[] args)
        {
            var engine = new FileHelperEngine<Rvu2012Record>();
            var fsses = engine.ReadFile("Files\\PPRRVU12.csv");

            var store = new DocumentStore {Url = "http://localhost:8080"};
            store.Initialize();

            using (IDocumentSession session = store.OpenSession())
            {
                session.Advanced.MaxNumberOfRequestsPerSession = 999;

                var dels = new List<CmsRvu2012a>();
                do
                {
                    dels = session
                        .Query<CmsRvu2012a>()
                        .Customize(x => x.WaitForNonStaleResults())
                        .Take(1024)
                        .ToList();

                    dels.ForEach(session.Delete);
                    session.SaveChanges();
                } while (dels.Count > 0);
            }

            using (IDocumentSession session = store.OpenSession())
            {
                session.Advanced.MaxNumberOfRequestsPerSession = 999;

                var finals = fsses.Select(
                    rvu =>
                    new CmsRvu2012a
                    {
                        Hcpcs = rvu.Hcpcs,
                        Modifier = string.IsNullOrEmpty(rvu.Modifier) ? null : rvu.Modifier,
                        Work = rvu.WorkRvu ?? 0,
                        TransitionedFacilityPracticeExpense = rvu.TransitionedFacilityPracticeExpenseRvu ?? 0,
                        TransitionedFacilityPracticeExpenseIndicator = rvu.TransitionedFacilityNaIndicator == "NA" ? true : false,
                        TransitionedNonFacilityPracticeExpense = rvu.TransitionedNonFacilityPractiveExpenseRvu ?? 0,
                        TransitionedNonFacilityPracticeExpenseIndicator = rvu.TransitionedNonFacilityNaIndicator == "NA" ? true : false,
                        Malpractice = rvu.MalpracticeRvu ?? 0
                    })
                    .ToList();

                int i = 0;
                foreach (var final in finals)
                {
                    session.Store(final);
                    i++;

                    if (i%1024 == 0)
                        session.SaveChanges();
                }

                session.SaveChanges();
            }
        }
开发者ID:healthbus,项目名称:claimjutsu,代码行数:58,代码来源:Program.cs

示例15: Sort3

        public void Sort3()
        {
            engine = new FileHelperEngine(typeof (CustomersVerticalBar));

            object[] res = engine.ReadFile(FileTest.Good.Sort1.Path);

            Assert.Throws<BadUsageException>(()
                 => CommonEngine.SortRecords(res));
        }
开发者ID:hoffmanc,项目名称:FileHelpers,代码行数:9,代码来源:Sort.cs


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