CustomPosterSettings.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. // Customise 'model' before loading data. Return false if the post needs to be cancelled.
  23. public bool BeforePost(IDataModel<" + tName + @"> model)
  24. {
  25. return true;
  26. }
  27. public bool Process(IDataModel<" + tName + @"> model)
  28. {
  29. foreach(var " + decapital + @" in model.GetTable<" + tName + @">().ToObjects<" + tName + @">())
  30. {
  31. // Do processing
  32. }
  33. return true; // return true for success.
  34. }
  35. // Perform any post-processing. All the items of type '" + tName + @" will be saved after this function is called.
  36. public void AfterPost(IDataModel<" + tName + @"> model)
  37. {
  38. }
  39. }";
  40. }
  41. }
  42. }