using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Drawing; using Google.Protobuf; using Tango.BL.Entities; using Tango.BL.Enumerations; using Tango.PMR.Stubs; using Tango.PMR.Diagnostics; using Tango.FSE.Common.Connection; using Tango.FSE.Common.Diagnostics; using Tango.FSE.Procedures; namespace Tango.FSE.Procedures.Examples.Csv { #region Example //CSV Model must contain properties, not plain fields. public class Person { public String Name { get; set; } public int Age { get; set; } } public class Program { //This example demonstrates CSV file writing and reading. //The csv reading method also accepts a byte array so you can also read a CSV file from resource. public void OnExecute(IProcedureContext context) { //Initialize a list of person model (see Person.csx). List persons = new List(); for (int i = 0; i < 100; i++) { Person p = new Person(); p.Name = "Person " + i; p.Age = i; persons.Add(p); } //Request the user to choose the csv file location. String csvFile = context.RequestFileSave("Select CSV File Location", "*.csv", "persons.csv"); if (csvFile != null) //Check if user selected a file and pressed 'OK'. { //Write the persons list to the selected csv file. context.WriteCsv(csvFile, persons); //Test csv file for reading... persons = context.ReadCsv(csvFile); //Write the reading result to the output window. context.WriteLine(persons); } } } #endregion }