Data model - Added data model visualization view model

Debugger - Split debugger into different tabs
Debugger - Added data model debugger
This commit is contained in:
SpoinkyNL committed 2020-06-29 00:22:16 +02:00
1 parent 1bc8d65237
commit 98ec26304a
33 files changed
+565 -236

No files matched your search

+3 -2
View File
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using Artemis.Core.Events;
using Artemis.Core.Exceptions;
@@ -107,8 +108,8 @@ namespace Artemis.Core.Services
private void UpdatePluginCache()
{
_modules = _pluginService.GetPluginsOfType<Module>();
_dataModelExpansions = _pluginService.GetPluginsOfType<BaseDataModelExpansion>();
_modules = _pluginService.GetPluginsOfType<Module>().Where(p => p.Enabled).ToList();
_dataModelExpansions = _pluginService.GetPluginsOfType<BaseDataModelExpansion>().Where(p => p.Enabled).ToList();
}
private void ConfigureJsonConvert()
+23 -22
View File
@@ -3,10 +3,8 @@ using System.Collections.ObjectModel;
using System.Linq;
using Artemis.Core.Events;
using Artemis.Core.Exceptions;
using Artemis.Core.Models;
using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Abstract.DataModels;
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
using Artemis.Core.Plugins.Exceptions;
using Artemis.Core.Services.Interfaces;
@@ -17,8 +15,8 @@ namespace Artemis.Core.Services
/// </summary>
public class DataModelService : IDataModelService
{
private readonly IPluginService _pluginService;
private readonly List<DataModel> _dataModelExpansions;
private readonly IPluginService _pluginService;
internal DataModelService(IPluginService pluginService)
{
@@ -27,6 +25,11 @@ namespace Artemis.Core.Services
_pluginService.PluginEnabled += PluginServiceOnPluginEnabled;
_pluginService.PluginDisabled += PluginServiceOnPluginDisabled;
foreach (var module in _pluginService.GetPluginsOfType<Module>().Where(m => m.InternalExpandsMainDataModel))
AddModuleDataModel(module);
foreach (var dataModelExpansion in _pluginService.GetPluginsOfType<BaseDataModelExpansion>())
AddDataModelExpansionDataModel(dataModelExpansion);
}
public ReadOnlyCollection<DataModel> DataModelExpansions
@@ -64,27 +67,25 @@ namespace Artemis.Core.Services
private void PluginServiceOnPluginEnabled(object sender, PluginEventArgs e)
{
if (e.PluginInfo.Instance is Module module && module.InternalExpandsMainDataModel)
{
if (module.InternalDataModel.DataModelDescription == null)
{
module.InternalDataModel.DataModelDescription = module.InternalGetDataModelDescription();
if (module.InternalDataModel.DataModelDescription == null)
throw new ArtemisPluginException(module.PluginInfo, "Module overrides GetDataModelDescription but returned null");
}
_dataModelExpansions.Add(module.InternalDataModel);
}
AddModuleDataModel(module);
else if (e.PluginInfo.Instance is BaseDataModelExpansion dataModelExpansion)
{
if (dataModelExpansion.InternalDataModel.DataModelDescription == null)
{
dataModelExpansion.InternalDataModel.DataModelDescription = dataModelExpansion.GetDataModelDescription();
if (dataModelExpansion.InternalDataModel.DataModelDescription == null)
throw new ArtemisPluginException(dataModelExpansion.PluginInfo, "Data model expansion overrides GetDataModelDescription but returned null");
}
AddDataModelExpansionDataModel(dataModelExpansion);
}
_dataModelExpansions.Add(dataModelExpansion.InternalDataModel);
}
private void AddDataModelExpansionDataModel(BaseDataModelExpansion dataModelExpansion)
{
if (dataModelExpansion.InternalDataModel.DataModelDescription == null)
throw new ArtemisPluginException(dataModelExpansion.PluginInfo, "Data model expansion overrides GetDataModelDescription but returned null");
AddExpansion(dataModelExpansion.InternalDataModel);
}
private void AddModuleDataModel(Module module)
{
if (module.InternalDataModel.DataModelDescription == null)
throw new ArtemisPluginException(module.PluginInfo, "Module overrides GetDataModelDescription but returned null");
AddExpansion(module.InternalDataModel);
}
private void PluginServiceOnPluginDisabled(object sender, PluginEventArgs e)
@@ -46,7 +46,8 @@ namespace Artemis.Core.Services.Interfaces
/// Enables the provided plugin
/// </summary>
/// <param name="plugin"></param>
void EnablePlugin(Plugin plugin);
/// <param name="isAutoEnable">If true, fails if there is a lock file present</param>
void EnablePlugin(Plugin plugin, bool isAutoEnable = false);
/// <summary>
/// Disables the provided plugin
+15 -26
View File
@@ -148,22 +148,14 @@ namespace Artemis.Core.Services
// Activate plugins after they are all loaded
foreach (var pluginInfo in _plugins.Where(p => p.Enabled))
{
if (!pluginInfo.LastEnableSuccessful)
{
pluginInfo.Enabled = false;
_logger.Warning("Plugin failed to load last time, disabling it now to avoid instability. Plugin info: {pluginInfo}", pluginInfo);
continue;
}
try
{
EnablePlugin(pluginInfo.Instance);
EnablePlugin(pluginInfo.Instance, true);
}
catch (Exception)
{
// ignored, logged in EnablePlugin
}
}
LoadingPlugins = false;
@@ -204,11 +196,10 @@ namespace Artemis.Core.Services
var pluginEntity = _pluginRepository.GetPluginByGuid(pluginInfo.Guid);
if (pluginEntity == null)
pluginEntity = new PluginEntity {Id = pluginInfo.Guid, IsEnabled = true, LastEnableSuccessful = true};
pluginEntity = new PluginEntity {Id = pluginInfo.Guid, IsEnabled = true};
pluginInfo.PluginEntity = pluginEntity;
pluginInfo.Enabled = pluginEntity.IsEnabled;
pluginInfo.LastEnableSuccessful = pluginEntity.LastEnableSuccessful;
var mainFile = Path.Combine(pluginInfo.Directory.FullName, pluginInfo.Main);
if (!File.Exists(mainFile))
@@ -294,20 +285,15 @@ namespace Artemis.Core.Services
}
}
public void EnablePlugin(Plugin plugin)
public void EnablePlugin(Plugin plugin, bool isAutoEnable = false)
{
lock (_plugins)
{
_logger.Debug("Enabling plugin {pluginInfo}", plugin.PluginInfo);
plugin.PluginInfo.LastEnableSuccessful = false;
plugin.PluginInfo.ApplyToEntity();
_pluginRepository.SavePlugin(plugin.PluginInfo.PluginEntity);
try
{
plugin.SetEnabled(true);
plugin.SetEnabled(true, isAutoEnable);
}
catch (Exception e)
{
@@ -316,16 +302,16 @@ namespace Artemis.Core.Services
}
finally
{
// We got this far so the plugin enabled and we didn't crash horribly, yay
if (plugin.PluginInfo.Enabled)
{
plugin.PluginInfo.LastEnableSuccessful = true;
plugin.PluginInfo.ApplyToEntity();
// On an auto-enable, ensure PluginInfo.Enabled is true even if enable failed, that way a failure on auto-enable does
// not affect the user's settings
if (isAutoEnable)
plugin.PluginInfo.Enabled = true;
_pluginRepository.SavePlugin(plugin.PluginInfo.PluginEntity);
plugin.PluginInfo.ApplyToEntity();
_pluginRepository.SavePlugin(plugin.PluginInfo.PluginEntity);
if (plugin.PluginInfo.Enabled)
_logger.Debug("Successfully enabled plugin {pluginInfo}", plugin.PluginInfo);
}
}
}
@@ -398,13 +384,16 @@ namespace Artemis.Core.Services
private static void CopyBuiltInPlugin(DirectoryInfo builtInPluginDirectory)
{
var pluginDirectory = new DirectoryInfo(Path.Combine(Constants.DataFolder, "plugins", builtInPluginDirectory.Name));
var createLockFile = File.Exists(Path.Combine(pluginDirectory.FullName, "artemis.lock"));
// Remove the old directory if it exists
if (Directory.Exists(pluginDirectory.FullName))
pluginDirectory.RecursiveDelete();
pluginDirectory.DeleteRecursively();
Directory.CreateDirectory(pluginDirectory.FullName);
builtInPluginDirectory.CopyFilesRecursively(pluginDirectory);
if (createLockFile)
File.Create(Path.Combine(pluginDirectory.FullName, "artemis.lock")).Close();
}
#region Events