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


C# FileHelperAsyncEngine类代码示例

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


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

示例1: RunAsyncConstructor

        private static void RunAsyncConstructor(Encoding enc, params string[] pathElements)
        {
            var asyncEngine = new FileHelperAsyncEngine<CustomersVerticalBar>(enc);
            Assert.AreEqual(enc, asyncEngine.Encoding);

            CoreRunAsync(asyncEngine, pathElements);
        }
开发者ID:mgmccarthy,项目名称:FileHelpers,代码行数:7,代码来源:Encoding.cs

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

示例3: AsyncFieldIndexBad2

        public void AsyncFieldIndexBad2()
        {
            var engine = new FileHelperAsyncEngine(typeof (SampleType));

            Assert.Throws<BadUsageException>(()
                => engine.WriteNextValues());
        }
开发者ID:abombss,项目名称:FileHelpers,代码行数:7,代码来源:WritersFieldIndexers.cs

示例4: RunAsyncConstructor

        private void RunAsyncConstructor(Encoding enc, params string[] pathElements)
        {
            asyncEngine = new FileHelperAsyncEngine<CustomersVerticalBar>(enc);
            Check.That(enc).IsEqualTo(asyncEngine.Encoding);

            CoreRunAsync(pathElements);
        }
开发者ID:mgmccarthy,项目名称:FileHelpers,代码行数:7,代码来源:FileEncoding.cs

示例5: RunAsyncConstructor

		private void RunAsyncConstructor(string fileName, Encoding enc)
		{
			asyncEngine = new FileHelperAsyncEngine(typeof (CustomersVerticalBar), enc);
			Assert.AreEqual(enc, asyncEngine.Encoding);

			CoreRunAsync(fileName);
		}
开发者ID:BD-GitHub,项目名称:filehelpers,代码行数:7,代码来源:Encoding.cs

示例6: AsyncFieldIndex1

        public void AsyncFieldIndex1()
        {
            var engine = new FileHelperAsyncEngine(typeof (SampleType));

            var sw = new StringWriter();
            engine.BeginWriteStream(sw);

            engine[0] = new DateTime(2003, 2, 1);
            engine[1] = "B";
            engine[2] = 18;

            engine.WriteNextValues();

            engine.Close();

            engine.BeginReadString(sw.GetStringBuilder().ToString());
            engine.ReadNext();

            Assert.AreEqual(new DateTime(2003, 2, 1), engine[0]);
            Assert.AreEqual("B", engine[1]);
            Assert.AreEqual(18, engine[2]);

            Assert.AreEqual(new DateTime(2003, 2, 1), engine.LastRecordValues[0]);
            Assert.AreEqual("B", engine.LastRecordValues[1]);
            Assert.AreEqual(18, engine.LastRecordValues[2]);

            engine.ReadNext();

            Assert.IsNull(engine.LastRecord);
            Assert.IsNull(engine.LastRecordValues);
        }
开发者ID:abombss,项目名称:FileHelpers,代码行数:31,代码来源:WritersFieldIndexers.cs

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

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

示例9: AsyncRead

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

			SampleType rec1, rec2;

			Common.BeginReadTest(asyncEngine, @"Good\test1.txt");

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

			Assert.IsTrue(rec1 != rec2);

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

			Assert.IsTrue(rec1 != rec2);

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

			asyncEngine.Close();
		}
开发者ID:BD-GitHub,项目名称:filehelpers,代码行数:26,代码来源:Readers.cs

示例10: AsyncRead

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

            SampleType rec1, rec2;

            Assert.AreEqual(0, asyncEngine.LineNumber);
            TestCommon.BeginReadTest(asyncEngine, "Good", "Test1.txt");

            rec1 = (SampleType) asyncEngine.ReadNext();
            Assert.IsNotNull(rec1);
            Assert.AreEqual(1, asyncEngine.LineNumber);

            rec2 = (SampleType) asyncEngine.ReadNext();
            Assert.IsNotNull(rec1);
            Assert.AreEqual(2, asyncEngine.LineNumber);

            Assert.IsTrue(rec1 != rec2);

            rec1 = (SampleType) asyncEngine.ReadNext();
            Assert.IsNotNull(rec2);
            Assert.AreEqual(3, asyncEngine.LineNumber);
            rec1 = (SampleType) asyncEngine.ReadNext();
            Assert.IsNotNull(rec2);
            Assert.AreEqual(4, asyncEngine.LineNumber);

            Assert.IsTrue(rec1 != rec2);

            Assert.AreEqual(4, asyncEngine.TotalRecords);
            Assert.AreEqual(0, asyncEngine.ErrorManager.ErrorCount);
        }
开发者ID:hoffmanc,项目名称:FileHelpers,代码行数:31,代码来源:LineCounter.cs

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

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

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

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

示例15: WriteEvents

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

            engine = new FileHelperAsyncEngine<SampleType>();

            engine.BeforeWriteRecord += new BeforeWriteHandler<SampleType>(engine_BeforeWriteRecord);
            engine.AfterWriteRecord += new AfterWriteHandler<SampleType>(engine_AfterWriteRecord);

            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.BeginWriteFile("tempEvent.txt");
            engine.WriteNexts(res);
            engine.Close();

            File.Delete("tempEvent.txt");
            Assert.AreEqual(2, engine.TotalRecords);
            Assert.AreEqual(2, before);
            Assert.AreEqual(2, after);
        }
开发者ID:mgmccarthy,项目名称:FileHelpers,代码行数:32,代码来源:EventsAsync.cs


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