123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- using InABox.Core;
- using Inflector;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace InABox.Poster.CSV
- {
- public class CSVPosterSettings : PosterSettings
- {
- [FileNameEditor("CSV Files (*.csv)|*.csv", RequireExisting = false)]
- public string DefaultOutputFile { get; set; }
- public override string DefaultScript(Type TPostable)
- {
- var tName = TPostable.Name;
- var decapital = tName[0..1].ToLower() + tName[1..];
- var ns = TPostable.Namespace;
- return @"
- using " + ns + @";
- using InABox.Poster.CSV;
- using System.Collections.Generic;
- public class Module
- {
- // Output Results for CSV
- public ICSVExport Results { get; set; }
- public bool Process(IEnumerable<" + tName + @"> items)
- {
- // Create new export object. You can use any object as your map,
- // but for simple cases just use " + tName + @"
- var export = new CSVExport<" + tName + @">();
- // Define the mapping from the fields of " + tName + @" to columns in the CSV file.
- export.DefineMapping(new()
- {
- new(""ID"", " + decapital + @" => " + decapital + @".ID),
- new(""Column1"", " + decapital + @" => " + decapital + @".Column1),
- new(""Column2"", " + decapital + @" => " + decapital + @".Column2),
- new(""Column3"", " + decapital + @" => " + decapital + @".Column3)
- // etc.
- });
- foreach(var item in items)
- {
- // Do processing
- export.Add(item);
- }
- Results = export; // Set result
- return true; // return true for success.
- }
- }";
- }
- }
- }
|