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


C# FileHelperAsyncEngine.BeginReadFile方法代码示例

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


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

示例1: Import

        internal void Import()
        {
            var repo = new AddressRepository();
            using (var engine = new FileHelperAsyncEngine<REDPostalAddressImport>())
            {
                engine.BeginReadFile(_fileName);

                var swWrite = Stopwatch.StartNew();
                var processed = 0L;

                var postalAddresses = new List<PostalAddress>();
                foreach (REDPostalAddressImport postalAddress in engine)
                {
                    postalAddresses.Add(Convert(postalAddress));
                    if (postalAddresses.Count == 100000)
                    {
                        processed += postalAddresses.Count;

                        repo.Write(postalAddresses);
                        postalAddresses.Clear();

                        Console.WriteLine("Processed {0} in {1}", processed, swWrite.Elapsed);
                        swWrite.Restart();
                    }
                }
                if (postalAddresses.Count > 0)
                {
                    repo.Write(postalAddresses);
                    processed += postalAddresses.Count;
                    Console.WriteLine("Processed {0} in {1}", processed, swWrite.Elapsed);
                }
            }
        }
开发者ID:kiwipiet,项目名称:AddressFinder,代码行数:33,代码来源:REDAddressImporter.cs

示例2: Run

        //-> /File
        //->  Instantiate a FileHelperAsyncEngine and read or write files:
        public override void Run()
        {
            //-> File:Example.cs
            var engine = new FileHelperAsyncEngine<Customer>();

            // Read
            using(engine.BeginReadFile("Input.txt"))
            {
                // The engine is IEnumerable
                foreach(Customer cust in engine)
                {
                    // your code here
                    Console.WriteLine(cust.Name);
                }
            }

            // Write

            var arrayCustomers = new Customer[] {
                new Customer { CustId = 1732, Name = "Juan Perez", Balance = 435.00m,
                               AddedDate = new DateTime (2020, 5, 11) },
                new Customer { CustId = 554, Name = "Pedro Gomez", Balance = 12342.30m,
                               AddedDate = new DateTime (2004, 2, 6) },
            };

            using(engine.BeginWriteFile("TestOut.txt"))
            {
                foreach(Customer cust in arrayCustomers)
                {
                    engine.WriteNext(cust);
                }
            }

            //-> /File
        }
开发者ID:luksio,项目名称:FileHelpers,代码行数:37,代码来源:60.ReadWriteRecordByRecord.cs

示例3: 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

示例4: ImportGeonamesFrom

        public void ImportGeonamesFrom(string fileName)
        {
            var geoNames = new FileHelperAsyncEngine(typeof(Geoname));
            geoNames.BeginReadFile(fileName);

            _geoDataStore.DeleteAll();

            long cnt = 0;
            foreach (Geoname geoName in geoNames)
            {
                //Store the name in a format suitable for case-insensitive searching:
                geoName.Name = geoName.Name.ToUpper();

                if (geoName.FeatureClass == "P")
                {
                    SaveCity(geoName, cnt);
                }

                // Parks: http://127.0.0.1:28017/local/geonames/?filter_FeatureClass=L&filter_FeatureCode=PRK
                if(geoName.FeatureClass.Equals("L") && geoName.FeatureCode.Equals("PRK"))
                {
                    SavePark(geoName);
                }

                cnt++;
            }

            _geoDataStore.DoIndexing();

            geoNames.Close();
        }
开发者ID:robertreppel,项目名称:Find-A-Park---Geospatial-searching-in-MongoDB,代码行数:31,代码来源:GeoDataImporter.cs

示例5: AsyncRead

        public void AsyncRead()
        {
            var asyncEngine = new FileHelperAsyncEngine<SampleType>();

            SampleType rec1, rec2;
            asyncEngine.BeginReadFile(FileTest.Good.Test1.Path);

            rec1 = asyncEngine.ReadNext();
            Assert.IsNotNull(rec1);
            rec2 = asyncEngine.ReadNext();
            Assert.IsNotNull(rec1);

            Assert.IsTrue(rec1 != rec2);

            rec1 = asyncEngine.ReadNext();
            Assert.IsNotNull(rec2);
            rec1 = asyncEngine.ReadNext();
            Assert.IsNotNull(rec2);

            Assert.IsTrue(rec1 != rec2);

            Assert.AreEqual(0, asyncEngine.ErrorManager.ErrorCount);

            asyncEngine.Close();
        }
开发者ID:rohancragg,项目名称:FileHelpers,代码行数:25,代码来源:ReadersGeneric.cs

示例6: AsyncRead

		public void AsyncRead()
		{

            FileHelperAsyncEngine<SampleType> asyncEngine = new FileHelperAsyncEngine<SampleType>();

			SampleType rec1, rec2;
            asyncEngine.BeginReadFile(Common.TestPath(@"Good\test1.txt"));

			rec1 = asyncEngine.ReadNext();
			Assert.IsNotNull(rec1);
			rec2 = asyncEngine.ReadNext();
			Assert.IsNotNull(rec1);

			Assert.IsTrue(rec1 != rec2);

			rec1 = asyncEngine.ReadNext();
			Assert.IsNotNull(rec2);
			rec1 = asyncEngine.ReadNext();
			Assert.IsNotNull(rec2);

			Assert.IsTrue(rec1 != rec2);

			Assert.AreEqual(0, asyncEngine.ErrorManager.ErrorCount);

            asyncEngine.Close();

		}
开发者ID:BD-GitHub,项目名称:filehelpers,代码行数:27,代码来源:ReadersGeneric.cs

示例7: WriteNullAsync

		public void WriteNullAsync()
		{
			asyncEngine = new FileHelperAsyncEngine(typeof (SampleType));

			asyncEngine.BeginWriteFile("tempNull.txt");

			asyncEngine.WriteNext(new SampleType());
			asyncEngine.WriteNext(new SampleType());
			asyncEngine.WriteNext(new SampleType());

			asyncEngine.Close();

			asyncEngine.BeginReadFile("tempNull.txt");
			SampleType[] res = (SampleType[]) asyncEngine.ReadNexts(5000);
			asyncEngine.Close();

			Assert.AreEqual(3, res.Length);
			Assert.AreEqual(3, asyncEngine.TotalRecords);
			Assert.AreEqual(0, asyncEngine.ErrorManager.ErrorCount);

			Assert.AreEqual(DateTime.MinValue, res[0].Field1);
			Assert.AreEqual("", res[0].Field2);
			Assert.AreEqual(0, res[0].Field3);

			if (File.Exists("tempNull.txt")) File.Delete("tempNull.txt");
		}
开发者ID:BD-GitHub,项目名称:filehelpers,代码行数:26,代码来源:NullValues.cs

示例8: ReadAllAsync

        public static object[] ReadAllAsync(FileHelperAsyncEngine engine, string fileName)
        {
            ArrayList arr = new ArrayList();
            engine.BeginReadFile(@"..\..\data\" + fileName);
            while(engine.ReadNext() != null)
                arr.Add(engine.LastRecord);
            engine.Close();

            return arr.ToArray();
        }
开发者ID:TheJeremyGray,项目名称:FileWatcherService,代码行数:10,代码来源:Common.cs

示例9: ReadAllAsync

        public static object[] ReadAllAsync(FileHelperAsyncEngine engine, params string[] pathElements)
        {
            ArrayList arr = new ArrayList();

            using (engine.BeginReadFile(GetPath(pathElements)))
            {
                while (engine.ReadNext() != null)
                    arr.Add(engine.LastRecord);
            }

            return arr.ToArray();
        }
开发者ID:hoffmanc,项目名称:FileHelpers,代码行数:12,代码来源:Common.cs

示例10: Main

		static void Main(string[] args)
		{
			FileHelperAsyncEngine engine = new FileHelperAsyncEngine (typeof(TestRecord));

			engine.BeginReadFile(@"E:\_SVN\FileHelpers\test2.csv");
			//string s;
			
			while(engine.ReadNext() != null)
			{
				
			}
			
			engine.Close();
		}
开发者ID:BD-GitHub,项目名称:filehelpers,代码行数:14,代码来源:BenchMark.cs

示例11: read

        public void read()
        {
            var engine = new FileHelperAsyncEngine<Racer>();
            engine.ErrorManager.ErrorMode = ErrorMode.IgnoreAndContinue;

            using (engine.BeginReadFile(FileName))
            {
                foreach (Racer r in engine)
                {
                    RaiseRacerParsed(r);
                }
            }

            RaiseEndOfFileReached();
        }
开发者ID:madlenerc,项目名称:TeamRace,代码行数:15,代码来源:InputFileController.cs

示例12: ReadIncomingTable

        /// <summary>
        /// Reads rows from the IncomingEncounterTable into the RowsToImport List.
        /// </summary>
        protected override void ReadIncomingTable()
        {
            try
            {
                try
                {
                    base.ReadIncomingTable();

                    // strip off any path saved in the database and look in the correct place
                    string fileToProcess = Path.Combine(SystemDataProvider.CurrentSettings.FileProcessingPath, Path.GetFileName(file.FileName));
                    log.DebugFormat("Looking for file {0}", fileToProcess);
                    if (!File.Exists(fileToProcess))
                    {
                        throw new FileNotFoundException(fileToProcess);
                    }

                    log.Debug("Loading File contents to Staging");
                    
                    // use the async engine so that we can save to the staging database a row at a time.                    
                    using (FileHelperAsyncEngine<PatientEncounter> engine = new FileHelperAsyncEngine<PatientEncounter>())
                    {
                        engine.ErrorMode = ErrorMode.SaveAndContinue;

                        engine.BeginReadFile(fileToProcess);
                        foreach (PatientEncounter row in engine)
                        {
                            row.SaveToStaging(job, engine.LineNumber, engine.Options.RecordToString(row), SystemDataProvider.ClientDataProvider);
                            if (engine.LineNumber % ProgressIndicator == 0)
                            {
                                log.DebugFormat("{0:#,#} rows loaded", engine.LineNumber);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    log.ErrorFormat("Error in ReadIncomingTable() with exception: {0}", e.Message);
                    throw;
                }
            }
            finally
            {
                log.InfoFormat("{0:#,#} Encounter rows loaded for processing from ImportedFileStatusID {1}.", RowsInFile, file.ImportedFileStatusID);
            }

        }
开发者ID:chuckfrazier,项目名称:DataPlatform,代码行数:49,代码来源:ProcessEncounterFile.cs

示例13: ReadEventsCancelAfter

        public void ReadEventsCancelAfter()
        {
            before = 0;
            after = 0;

            engine = new FileHelperAsyncEngine(typeof(SampleType));
            engine.AfterReadRecord += new AfterReadRecordHandler(AfterEvent2);

            engine.BeginReadFile(Common.TestPath(@"Good\test1.txt"));

            int count = 0;
            foreach (SampleType t in engine)
                count++;

            Assert.AreEqual(0, count);
            Assert.AreEqual(4, engine.TotalRecords);
            Assert.AreEqual(0, before);
            Assert.AreEqual(4, after);
        }
开发者ID:hoffmanc,项目名称:FileHelpers,代码行数:19,代码来源:EventsAsync.cs

示例14: AsyncReadMoreAndMore

        public void AsyncReadMoreAndMore()
        {
            var asyncEngine = new FileHelperAsyncEngine<SampleType>();
            SampleType rec1;
            asyncEngine.BeginReadFile(FileTest.Good.Test1.Path);

            rec1 = asyncEngine.ReadNext();
            rec1 = asyncEngine.ReadNext();
            rec1 = asyncEngine.ReadNext();
            rec1 = asyncEngine.ReadNext();
            rec1 = asyncEngine.ReadNext();

            Assert.IsTrue(rec1 == null);

            rec1 = (SampleType) asyncEngine.ReadNext();
            Assert.AreEqual(0, asyncEngine.ErrorManager.ErrorCount);

            asyncEngine.Close();
        }
开发者ID:mgmccarthy,项目名称:FileHelpers,代码行数:19,代码来源:ReadersGeneric.cs

示例15: AsyncReadEnumerable

        public void AsyncReadEnumerable()
        {
            var asyncEngine = new FileHelperAsyncEngine<SampleType>();
            asyncEngine.BeginReadFile(FileTest.Good.Test1.Path);

            int lineAnt = asyncEngine.LineNumber;

            foreach (var rec1 in asyncEngine)
            {
                Assert.IsNotNull(rec1);
                Assert.AreEqual(lineAnt + 1, asyncEngine.LineNumber);
                lineAnt = asyncEngine.LineNumber;
            }

            Assert.AreEqual(4, asyncEngine.TotalRecords);
            Assert.AreEqual(0, asyncEngine.ErrorManager.ErrorCount);

            asyncEngine.Close();
        }
开发者ID:rohancragg,项目名称:FileHelpers,代码行数:19,代码来源:ReadersGeneric.cs


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