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


C# FileHelperAsyncEngine.WriteNext方法代码示例

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


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

示例1: generateBtn_Click

        private void generateBtn_Click(object sender, EventArgs e)
        {
            List<Record> recordList = new List<Record>();

            var engine = new FileHelperAsyncEngine<Record>();

            engine.HeaderText = engine.GetFileHeader();

            recordList = RecordCreator.getRecords();

            try
            {
                using (engine.BeginWriteFile(savePathTB.Text))
                {
                    foreach (Record rec in recordList)
                    {
                        engine.WriteNext(rec);
                    }
                }
                DialogResult result;
                result = MessageBox.Show("Done! Open file?", "File generated.", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    System.Diagnostics.Process.Start(savePathTB.Text);
                }
                
            }

            catch(Exception error)
            {
                DialogResult result;

                result = MessageBox.Show(error.Message, "Error!", MessageBoxButtons.RetryCancel);

                if (result == DialogResult.Retry)
                {
                    generateButton.PerformClick();
                }

            }
        }
开发者ID:SamCousinsGB,项目名称:TestDataGenerator,代码行数:41,代码来源:Form1.cs

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

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

示例4: ExportApprovalList

        public void ExportApprovalList(string fileName, CancellationToken token)
        {
            using (DatabaseContext context = GetContext())
            {
                // init engine
                FileHelperAsyncEngine<CsvApprovalItem> engine = new FileHelperAsyncEngine<CsvApprovalItem>() { HeaderText = CsvApprovalItem.HeaderLine };
                engine.BeginWriteFile(fileName);

                // look for approval items
                var query = context.ViewApprovalLists.Where("[email protected]", new ObjectParameter("st", APPROVAL_STATUS_NEW));
                foreach (ViewApprovalList item in query)
                {
                    if (token.IsCancellationRequested) break;
                    engine.WriteNext(new CsvApprovalItem()
                    {
                        ItemID = item.Id,
                        EngineName = item.EngineName,
                        ProductName = item.SearchName,
                        FoundName = item.Name,
                        URL = item.Url,
                        Price = item.Price,
                        Command = APPROVAL_COMMAND_UNDEFINED
                    });
                }
                engine.Close();
            }
        }
开发者ID:Infarch,项目名称:MyPerlModules,代码行数:27,代码来源:DatabaseManager.cs

示例5: AppendToEmptyAsync

        public void AppendToEmptyAsync()
        {
            FileHelperEngine engineOld = new FileHelperEngine(typeof (SampleType));
            FileHelperAsyncEngine engine = new FileHelperAsyncEngine(typeof (SampleType));

            SampleType rec = new SampleType();

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

            File.Copy(TestCommon.GetPath("Good", "TestEmpty.txt"), "tempEmpty.txt", true);

            engine.BeginAppendToFile(@"tempEmpty.txt");
            engine.WriteNext(rec);
            engine.Close();

            SampleType[] res2 = (SampleType[]) engineOld.ReadFile(@"tempEmpty.txt");

            Assert.AreEqual(1, res2.Length);
            Assert.AreEqual(rec.Field1, res2[0].Field1);

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


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