IDynamicDashboardDataPresenter.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using InABox.Core;
  2. using Newtonsoft.Json;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. namespace InABox.Wpf.Dashboard;
  11. public interface IDynamicDashboardDataPresenter : IPolymorphicallySerialisable
  12. {
  13. /// <summary>
  14. /// The desired height for this presenter while previewing in design mode.
  15. /// </summary>
  16. int PreviewHeight { get; }
  17. /// <summary>
  18. /// Sets whether this dashboard is in preview mode.
  19. /// </summary>
  20. bool IsPreview { get; set; }
  21. object Properties { get; set; }
  22. /// <summary>
  23. /// Component for the data of this presenter; can be safely assumed to be non-<see langword="null"/> when <see cref="Setup"/> is called.
  24. /// This may be set later, if the user changes the data they've selected, so the setter should be used to manage data refreshes.
  25. /// </summary>
  26. DynamicDashboardDataComponent DataComponent { get; set; }
  27. /// <summary>
  28. /// Sets up the data presenter; returns the UI element to be rendered to the user.
  29. /// </summary>
  30. /// <returns>
  31. /// <see langword="null"/> if some error occurred and the data cannot be presented; otherwise, returns the control.
  32. /// </returns>
  33. FrameworkElement? Setup();
  34. /// <summary>
  35. /// Update the dashboard with <paramref name="data"/>.
  36. /// </summary>
  37. /// <param name="data">The data to be rendered.</param>
  38. void Refresh(DynamicDashboardData data);
  39. void Shutdown(CancelEventArgs? cancel);
  40. }
  41. public interface IDynamicDashboardDataPresenter<TProperties> : IDynamicDashboardDataPresenter
  42. where TProperties: class, new()
  43. {
  44. /// <summary>
  45. /// The properties for the presenter; can be safely assumed to be non-<see langword="null"/> when <see cref="IDynamicDashboardDataPresenter.Setup"/>
  46. /// is called. This may be modified by the presenter, and any changes made will be persisted.
  47. /// </summary>
  48. new TProperties Properties { get; set; }
  49. object IDynamicDashboardDataPresenter.Properties
  50. {
  51. get => Properties;
  52. set => Properties = (value as TProperties)!;
  53. }
  54. }