CustomPosterSettings.cs 1.3 KB

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