CustomPosterSettings.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using InABox.Core;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace InABox.Poster.Custom
  8. {
  9. public class CustomPosterSettings : PosterSettings
  10. {
  11. public override string DefaultScript(Type TPostable)
  12. {
  13. var tName = TPostable.Name;
  14. var decapital = tName[0..1].ToLower() + tName[1..];
  15. var ns = TPostable.Namespace;
  16. return @"
  17. using " + ns + @";
  18. using InABox.Core;
  19. using System.Collections.Generic;
  20. public class Module
  21. {
  22. // Output Results
  23. public IPostResult<" + tName + @"> Results { get; set; }
  24. // Customise 'model' before loading data. Return false if the post needs to be cancelled.
  25. public bool BeforePost(IDataModel<" + tName + @"> model)
  26. {
  27. return true;
  28. }
  29. public bool Process(IDataModel<" + tName + @"> model)
  30. {
  31. Results = new PostResult<" + tName + @">();
  32. foreach(var " + decapital + @" in model.GetTable<" + tName + @">().ToObjects<" + tName + @">())
  33. {
  34. // Do processing
  35. Results.AddSuccess(decapital);
  36. }
  37. return true; // return true for success.
  38. }
  39. // Perform any post-processing. All the items of type '" + tName + @" will be saved after this function is called.
  40. public void AfterPost(IDataModel<" + tName + @"> model)
  41. {
  42. }
  43. }";
  44. }
  45. }
  46. }