|
@@ -92,76 +92,11 @@ public class PanelHost : IPanelHost
|
|
|
|
|
|
#region Panel Properties
|
|
#region Panel Properties
|
|
|
|
|
|
- private void InitializePanelProperties(IBasePanel panel)
|
|
|
|
- {
|
|
|
|
- var propertiesInterface = panel.GetType().GetInterfaceDefinition(typeof(IPropertiesPanel<>));
|
|
|
|
- if (propertiesInterface is not null)
|
|
|
|
- {
|
|
|
|
- var propertiesType = propertiesInterface.GenericTypeArguments[0];
|
|
|
|
- var method = typeof(PanelHost)
|
|
|
|
- .GetMethod(nameof(InitializePanelPropertiesGeneric), BindingFlags.NonPublic | BindingFlags.Instance)
|
|
|
|
- ?.MakeGenericMethod(panel.GetType(), propertiesType)
|
|
|
|
- .Invoke(this, new object?[] { panel });
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- private void InitializePanelPropertiesGeneric<TPanel, TProperties>(TPanel panel)
|
|
|
|
- where TPanel : IPropertiesPanel<TProperties>
|
|
|
|
- where TProperties : BaseObject, IGlobalConfigurationSettings, new()
|
|
|
|
- {
|
|
|
|
- panel.Properties = LoadPanelProperties<TPanel, TProperties>();
|
|
|
|
- }
|
|
|
|
- private TProperties LoadPanelProperties<TPanel, TProperties>()
|
|
|
|
- where TPanel : IPropertiesPanel<TProperties>
|
|
|
|
- where TProperties : BaseObject, IGlobalConfigurationSettings, new()
|
|
|
|
- {
|
|
|
|
- var config = new GlobalConfiguration<TProperties>();
|
|
|
|
- return config.Load();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private void SavePanelProperties<TPanel, TProperties>(TProperties properties)
|
|
|
|
- where TPanel : IPropertiesPanel<TProperties>
|
|
|
|
- where TProperties : BaseObject, IGlobalConfigurationSettings, new()
|
|
|
|
- {
|
|
|
|
- var config = new GlobalConfiguration<TProperties>();
|
|
|
|
- config.Save(properties);
|
|
|
|
- }
|
|
|
|
- private void EditPanelProperties<TPanel, TProperties>()
|
|
|
|
- where TPanel : IPropertiesPanel<TProperties>
|
|
|
|
- where TProperties : BaseObject, IGlobalConfigurationSettings, new()
|
|
|
|
- {
|
|
|
|
- var properties = LoadPanelProperties<TPanel, TProperties>();
|
|
|
|
-
|
|
|
|
- bool result;
|
|
|
|
- if (DynamicGridUtils.TryFindDynamicGrid(typeof(DynamicGrid<>), typeof(TProperties), out var gridType))
|
|
|
|
- {
|
|
|
|
- var grid = (Activator.CreateInstance(gridType) as DynamicGrid<TProperties>)!;
|
|
|
|
- result = grid.EditItems(new TProperties[] { properties });
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- var grid = new DynamicItemsListGrid<TProperties>();
|
|
|
|
- result = grid.EditItems(new TProperties[] { properties });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (result)
|
|
|
|
- {
|
|
|
|
- SavePanelProperties<TPanel, TProperties>(properties);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
private void ConfigurePanel()
|
|
private void ConfigurePanel()
|
|
{
|
|
{
|
|
if (CurrentPanel is null) return;
|
|
if (CurrentPanel is null) return;
|
|
|
|
|
|
- var propertiesInterface = CurrentPanel.GetType().GetInterfaceDefinition(typeof(IPropertiesPanel<>))!;
|
|
|
|
- var propertiesType = propertiesInterface.GenericTypeArguments[0];
|
|
|
|
- var basemethod = typeof(PanelHost)
|
|
|
|
- .GetMethod(nameof(EditPanelProperties), BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
- if (basemethod == null)
|
|
|
|
- return;
|
|
|
|
- var method = basemethod?.MakeGenericMethod(CurrentPanel.GetType(), propertiesType);
|
|
|
|
- if (method != null)
|
|
|
|
- method.Invoke(this, Array.Empty<object?>());
|
|
|
|
|
|
+ PanelUtils.ConfigurePanel(CurrentPanel);
|
|
}
|
|
}
|
|
|
|
|
|
#endregion
|
|
#endregion
|
|
@@ -170,6 +105,9 @@ public class PanelHost : IPanelHost
|
|
|
|
|
|
private void ReloadActions(string sectionName, DataModel model)
|
|
private void ReloadActions(string sectionName, DataModel model)
|
|
{
|
|
{
|
|
|
|
+ ReportUtils.ExportDefinitions.Clear();
|
|
|
|
+ ReportUtils.ExportDefinitions.AddRange(PRSEmailUtils.CreateTemplateDefinitions(model));
|
|
|
|
+
|
|
SetupActions.Clear();
|
|
SetupActions.Clear();
|
|
HostControl.ClearActions();
|
|
HostControl.ClearActions();
|
|
HostControl.ClearReports();
|
|
HostControl.ClearReports();
|
|
@@ -260,15 +198,6 @@ public class PanelHost : IPanelHost
|
|
|
|
|
|
#region Reports
|
|
#region Reports
|
|
|
|
|
|
- private IEnumerable<ReportExportDefinition> AddTemplateDefinitions()
|
|
|
|
- {
|
|
|
|
- if (CurrentPanel is null)
|
|
|
|
- return new List<ReportExportDefinition>() { new ReportExportDefinition("Email Report", PRSDesktop.Resources.email, ReportExportType.PDF,
|
|
|
|
- PRSEmailUtils.DoEmailReport)};
|
|
|
|
- else
|
|
|
|
- return PRSEmailUtils.CreateTemplateDefinitions(CurrentPanel.DataModel(Selection.None));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public static PanelAction CreateReportAction(ReportTemplate template, Func<Selection, DataModel> getDataModel)
|
|
public static PanelAction CreateReportAction(ReportTemplate template, Func<Selection, DataModel> getDataModel)
|
|
{
|
|
{
|
|
var action = new PanelAction
|
|
var action = new PanelAction
|
|
@@ -454,21 +383,12 @@ public class PanelHost : IPanelHost
|
|
|
|
|
|
public T LoadPanel<T>(string moduleName) where T : class, IBasePanel, new()
|
|
public T LoadPanel<T>(string moduleName) where T : class, IBasePanel, new()
|
|
{
|
|
{
|
|
- var panel = new T();
|
|
|
|
|
|
+ var panel = PanelUtils.LoadPanel<T>();
|
|
CurrentPanel = panel;
|
|
CurrentPanel = panel;
|
|
|
|
|
|
- ReportUtils.ExportDefinitions.Clear();
|
|
|
|
- ReportUtils.ExportDefinitions.AddRange(AddTemplateDefinitions());
|
|
|
|
-
|
|
|
|
- InitializePanelProperties(panel);
|
|
|
|
-
|
|
|
|
CurrentModuleName = moduleName;
|
|
CurrentModuleName = moduleName;
|
|
TrackedTicks = DateTime.Now;
|
|
TrackedTicks = DateTime.Now;
|
|
|
|
|
|
- CurrentPanel.IsReady = false;
|
|
|
|
- CurrentPanel.Setup();
|
|
|
|
- CurrentPanel.IsReady = true;
|
|
|
|
-
|
|
|
|
CurrentPanel.OnUpdateDataModel += ReloadActions;
|
|
CurrentPanel.OnUpdateDataModel += ReloadActions;
|
|
|
|
|
|
var model = CurrentPanel.DataModel(Selection.None);
|
|
var model = CurrentPanel.DataModel(Selection.None);
|
|
@@ -530,21 +450,10 @@ public class PanelHost : IPanelHost
|
|
if (CurrentPanel != null)
|
|
if (CurrentPanel != null)
|
|
{
|
|
{
|
|
Heartbeat(DateTime.Now - TrackedTicks, true);
|
|
Heartbeat(DateTime.Now - TrackedTicks, true);
|
|
- try
|
|
|
|
- {
|
|
|
|
- if(CurrentPanel is ISubPanelHost host)
|
|
|
|
- {
|
|
|
|
- host.ShutdownSubPanels(cancel);
|
|
|
|
- }
|
|
|
|
- CurrentPanel.Shutdown(cancel);
|
|
|
|
- if (cancel?.Cancel == true)
|
|
|
|
- {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- catch (Exception e)
|
|
|
|
|
|
+ PanelUtils.UnloadPanel(CurrentPanel, cancel);
|
|
|
|
+ if (cancel?.Cancel == true)
|
|
{
|
|
{
|
|
- Logger.Send(LogType.Error, ClientFactory.UserID, string.Format("Error in UnloadPanel(): {0}\n{1}", e.Message, e.StackTrace));
|
|
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
|
|
|
|
TrackedTicks = DateTime.MinValue;
|
|
TrackedTicks = DateTime.MinValue;
|