mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Darthified code
This commit is contained in:
1 parent
5b80c1e4fe
commit
ae64db8a13
198 files changed
+1339
-1305
No files matched your search
@@ -79,7 +79,7 @@ namespace Artemis.Core.Services
|
||||
if (IsInitialized)
|
||||
throw new ArtemisCoreException("Cannot initialize the core as it is already initialized.");
|
||||
|
||||
var versionAttribute = typeof(CoreService).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
|
||||
AssemblyInformationalVersionAttribute? versionAttribute = typeof(CoreService).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
|
||||
_logger.Information("Initializing Artemis Core version {version}", versionAttribute?.InformationalVersion);
|
||||
ApplyLoggingLevel();
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace Artemis.Core.Services
|
||||
_pluginService.CopyBuiltInPlugins();
|
||||
_pluginService.LoadPlugins(StartupArguments.Contains("--ignore-plugin-lock"));
|
||||
|
||||
var surfaceConfig = _surfaceService.ActiveSurface;
|
||||
ArtemisSurface surfaceConfig = _surfaceService.ActiveSurface;
|
||||
if (surfaceConfig != null)
|
||||
_logger.Information("Initialized with active surface entity {surfaceConfig}-{guid}", surfaceConfig.Name, surfaceConfig.EntityId);
|
||||
else
|
||||
@@ -123,7 +123,7 @@ namespace Artemis.Core.Services
|
||||
_introAnimation.Render(args.DeltaTime, args.Canvas, _rgbService.BitmapBrush.Bitmap.Info);
|
||||
}
|
||||
|
||||
var introLength = _introAnimation.AnimationProfile.GetAllLayers().Max(l => l.TimelineLength);
|
||||
TimeSpan introLength = _introAnimation.AnimationProfile.GetAllLayers().Max(l => l.TimelineLength);
|
||||
|
||||
// Stop rendering after the profile finishes (take 1 second extra in case of slow updates)
|
||||
Task.Run(async () =>
|
||||
@@ -167,7 +167,7 @@ namespace Artemis.Core.Services
|
||||
lock (_dataModelExpansions)
|
||||
{
|
||||
// Update all active modules
|
||||
foreach (var dataModelExpansion in _dataModelExpansions)
|
||||
foreach (BaseDataModelExpansion dataModelExpansion in _dataModelExpansions)
|
||||
dataModelExpansion.Update(args.DeltaTime);
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ namespace Artemis.Core.Services
|
||||
}
|
||||
|
||||
// Update all active modules
|
||||
foreach (var module in modules)
|
||||
foreach (Module module in modules)
|
||||
module.InternalUpdate(args.DeltaTime);
|
||||
|
||||
// If there is no ready bitmap brush, skip the frame
|
||||
@@ -194,12 +194,12 @@ namespace Artemis.Core.Services
|
||||
return;
|
||||
|
||||
// Render all active modules
|
||||
using var canvas = new SKCanvas(_rgbService.BitmapBrush.Bitmap);
|
||||
using SKCanvas canvas = new SKCanvas(_rgbService.BitmapBrush.Bitmap);
|
||||
canvas.Clear(new SKColor(0, 0, 0));
|
||||
if (!ModuleRenderingDisabled)
|
||||
{
|
||||
// While non-activated modules may be updated above if they expand the main data model, they may never render
|
||||
foreach (var module in modules.Where(m => m.IsActivated))
|
||||
foreach (Module module in modules.Where(m => m.IsActivated))
|
||||
module.InternalRender(args.DeltaTime, _surfaceService.ActiveSurface, canvas, _rgbService.BitmapBrush.Bitmap.Info);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Artemis.Core.Services
|
||||
private void BlinkDevice(ArtemisDevice device, int blinkCount)
|
||||
{
|
||||
// Create a LED group way at the top
|
||||
var ledGroup = new ListLedGroup(device.Leds.Select(l => l.RgbLed))
|
||||
ListLedGroup ledGroup = new ListLedGroup(device.Leds.Select(l => l.RgbLed))
|
||||
{
|
||||
Brush = new SolidColorBrush(new Color(255, 255, 255)),
|
||||
ZIndex = 999
|
||||
|
||||
@@ -28,11 +28,11 @@ namespace Artemis.Core.Services
|
||||
_profileService = profileService;
|
||||
_pluginService.PluginEnabled += PluginServiceOnPluginEnabled;
|
||||
|
||||
var activationUpdateTimer = new Timer(2000);
|
||||
Timer activationUpdateTimer = new Timer(2000);
|
||||
activationUpdateTimer.Start();
|
||||
activationUpdateTimer.Elapsed += ActivationUpdateTimerOnElapsed;
|
||||
|
||||
foreach (var module in _pluginService.GetPluginsOfType<Module>())
|
||||
foreach (Module module in _pluginService.GetPluginsOfType<Module>())
|
||||
InitialiseOrApplyPriority(module);
|
||||
}
|
||||
|
||||
@@ -56,8 +56,8 @@ namespace Artemis.Core.Services
|
||||
_logger.Information("Clearing active module override");
|
||||
|
||||
// Always deactivate all other modules whenever override is called
|
||||
var modules = _pluginService.GetPluginsOfType<Module>().ToList();
|
||||
foreach (var module in modules.Where(m => m != overrideModule))
|
||||
List<Module> modules = _pluginService.GetPluginsOfType<Module>().ToList();
|
||||
foreach (Module module in modules.Where(m => m != overrideModule))
|
||||
OverrideDeactivate(module);
|
||||
|
||||
ActiveModuleOverride = overrideModule;
|
||||
@@ -81,7 +81,7 @@ namespace Artemis.Core.Services
|
||||
{
|
||||
// The conditions of the active module override may be matched, in that case reactivate as a non-override
|
||||
// the principle is different for this service but not for the module
|
||||
var shouldBeActivated = ActiveModuleOverride.EvaluateActivationRequirements();
|
||||
bool shouldBeActivated = ActiveModuleOverride.EvaluateActivationRequirements();
|
||||
if (shouldBeActivated && ActiveModuleOverride.IsActivatedOverride)
|
||||
{
|
||||
ActiveModuleOverride.Deactivate(true);
|
||||
@@ -96,14 +96,14 @@ namespace Artemis.Core.Services
|
||||
return;
|
||||
}
|
||||
|
||||
var stopwatch = new Stopwatch();
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
|
||||
var modules = _pluginService.GetPluginsOfType<Module>().ToList();
|
||||
var tasks = new List<Task>();
|
||||
foreach (var module in modules)
|
||||
List<Module> modules = _pluginService.GetPluginsOfType<Module>().ToList();
|
||||
List<Task> tasks = new List<Task>();
|
||||
foreach (Module module in modules)
|
||||
{
|
||||
var shouldBeActivated = module.EvaluateActivationRequirements();
|
||||
bool shouldBeActivated = module.EvaluateActivationRequirements();
|
||||
if (shouldBeActivated && !module.IsActivated)
|
||||
tasks.Add(ActivateModule(module));
|
||||
else if (!shouldBeActivated && module.IsActivated)
|
||||
@@ -127,7 +127,7 @@ namespace Artemis.Core.Services
|
||||
if (module.PriorityCategory == category && module.Priority == priority)
|
||||
return;
|
||||
|
||||
var modules = _pluginService.GetPluginsOfType<Module>().Where(m => m.PriorityCategory == category).OrderBy(m => m.Priority).ToList();
|
||||
List<Module> modules = _pluginService.GetPluginsOfType<Module>().Where(m => m.PriorityCategory == category).OrderBy(m => m.Priority).ToList();
|
||||
if (modules.Contains(module))
|
||||
modules.Remove(module);
|
||||
|
||||
@@ -135,9 +135,9 @@ namespace Artemis.Core.Services
|
||||
modules.Insert(priority, module);
|
||||
|
||||
module.PriorityCategory = category;
|
||||
for (var index = 0; index < modules.Count; index++)
|
||||
for (int index = 0; index < modules.Count; index++)
|
||||
{
|
||||
var categoryModule = modules[index];
|
||||
Module categoryModule = modules[index];
|
||||
categoryModule.Priority = index;
|
||||
|
||||
// Don't save modules whose priority hasn't been initialized yet
|
||||
@@ -236,8 +236,8 @@ namespace Artemis.Core.Services
|
||||
|
||||
private void InitialiseOrApplyPriority(Module module)
|
||||
{
|
||||
var category = module.DefaultPriorityCategory;
|
||||
var priority = 1;
|
||||
ModulePriorityCategory category = module.DefaultPriorityCategory;
|
||||
int priority = 1;
|
||||
|
||||
module.Entity = _moduleRepository.GetByPluginGuid(module.PluginInfo.Guid);
|
||||
if (module.Entity != null)
|
||||
|
||||
@@ -44,26 +44,26 @@ namespace Artemis.Core.Services
|
||||
public void CopyBuiltInPlugins()
|
||||
{
|
||||
OnCopyingBuildInPlugins();
|
||||
var pluginDirectory = new DirectoryInfo(Path.Combine(Constants.DataFolder, "plugins"));
|
||||
DirectoryInfo pluginDirectory = new DirectoryInfo(Path.Combine(Constants.DataFolder, "plugins"));
|
||||
|
||||
// Iterate built-in plugins
|
||||
var builtInPluginDirectory = new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(), "Plugins"));
|
||||
foreach (var subDirectory in builtInPluginDirectory.EnumerateDirectories())
|
||||
DirectoryInfo builtInPluginDirectory = new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(), "Plugins"));
|
||||
foreach (DirectoryInfo subDirectory in builtInPluginDirectory.EnumerateDirectories())
|
||||
{
|
||||
// Load the metadata
|
||||
var builtInMetadataFile = Path.Combine(subDirectory.FullName, "plugin.json");
|
||||
string builtInMetadataFile = Path.Combine(subDirectory.FullName, "plugin.json");
|
||||
if (!File.Exists(builtInMetadataFile))
|
||||
throw new ArtemisPluginException("Couldn't find the built-in plugins metadata file at " + builtInMetadataFile);
|
||||
|
||||
var builtInPluginInfo = JsonConvert.DeserializeObject<PluginInfo>(File.ReadAllText(builtInMetadataFile));
|
||||
PluginInfo builtInPluginInfo = JsonConvert.DeserializeObject<PluginInfo>(File.ReadAllText(builtInMetadataFile));
|
||||
|
||||
// Find the matching plugin in the plugin folder
|
||||
var match = pluginDirectory.EnumerateDirectories().FirstOrDefault(d => d.Name == subDirectory.Name);
|
||||
DirectoryInfo match = pluginDirectory.EnumerateDirectories().FirstOrDefault(d => d.Name == subDirectory.Name);
|
||||
if (match == null)
|
||||
CopyBuiltInPlugin(subDirectory);
|
||||
else
|
||||
{
|
||||
var metadataFile = Path.Combine(match.FullName, "plugin.json");
|
||||
string metadataFile = Path.Combine(match.FullName, "plugin.json");
|
||||
if (!File.Exists(metadataFile))
|
||||
{
|
||||
_logger.Debug("Copying missing built-in plugin {builtInPluginInfo}", builtInPluginInfo);
|
||||
@@ -74,7 +74,7 @@ namespace Artemis.Core.Services
|
||||
try
|
||||
{
|
||||
// Compare versions, copy if the same when debugging
|
||||
var pluginInfo = JsonConvert.DeserializeObject<PluginInfo>(File.ReadAllText(metadataFile));
|
||||
PluginInfo pluginInfo = JsonConvert.DeserializeObject<PluginInfo>(File.ReadAllText(metadataFile));
|
||||
#if DEBUG
|
||||
if (builtInPluginInfo.Version >= pluginInfo.Version)
|
||||
{
|
||||
@@ -111,17 +111,17 @@ namespace Artemis.Core.Services
|
||||
UnloadPlugins();
|
||||
|
||||
// Load the plugin assemblies into the plugin context
|
||||
var pluginDirectory = new DirectoryInfo(Path.Combine(Constants.DataFolder, "plugins"));
|
||||
foreach (var subDirectory in pluginDirectory.EnumerateDirectories())
|
||||
DirectoryInfo pluginDirectory = new DirectoryInfo(Path.Combine(Constants.DataFolder, "plugins"));
|
||||
foreach (DirectoryInfo subDirectory in pluginDirectory.EnumerateDirectories())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Load the metadata
|
||||
var metadataFile = Path.Combine(subDirectory.FullName, "plugin.json");
|
||||
string metadataFile = Path.Combine(subDirectory.FullName, "plugin.json");
|
||||
if (!File.Exists(metadataFile)) _logger.Warning(new ArtemisPluginException("Couldn't find the plugins metadata file at " + metadataFile), "Plugin exception");
|
||||
|
||||
// Locate the main entry
|
||||
var pluginInfo = JsonConvert.DeserializeObject<PluginInfo>(File.ReadAllText(metadataFile));
|
||||
PluginInfo pluginInfo = JsonConvert.DeserializeObject<PluginInfo>(File.ReadAllText(metadataFile));
|
||||
pluginInfo.Directory = subDirectory;
|
||||
|
||||
LoadPlugin(pluginInfo);
|
||||
@@ -133,7 +133,7 @@ namespace Artemis.Core.Services
|
||||
}
|
||||
|
||||
// Activate plugins after they are all loaded
|
||||
foreach (var pluginInfo in _plugins.Where(p => p.Enabled))
|
||||
foreach (PluginInfo pluginInfo in _plugins.Where(p => p.Enabled))
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -172,14 +172,14 @@ namespace Artemis.Core.Services
|
||||
if (_plugins.Contains(pluginInfo))
|
||||
UnloadPlugin(pluginInfo);
|
||||
|
||||
var pluginEntity = _pluginRepository.GetPluginByGuid(pluginInfo.Guid);
|
||||
PluginEntity pluginEntity = _pluginRepository.GetPluginByGuid(pluginInfo.Guid);
|
||||
if (pluginEntity == null)
|
||||
pluginEntity = new PluginEntity {Id = pluginInfo.Guid, IsEnabled = true};
|
||||
|
||||
pluginInfo.PluginEntity = pluginEntity;
|
||||
pluginInfo.Enabled = pluginEntity.IsEnabled;
|
||||
|
||||
var mainFile = Path.Combine(pluginInfo.Directory.FullName, pluginInfo.Main);
|
||||
string mainFile = Path.Combine(pluginInfo.Directory.FullName, pluginInfo.Main);
|
||||
if (!File.Exists(mainFile))
|
||||
throw new ArtemisPluginException(pluginInfo, "Couldn't find the plugins main entry at " + mainFile);
|
||||
|
||||
@@ -215,10 +215,10 @@ namespace Artemis.Core.Services
|
||||
if (pluginTypes.Count == 0)
|
||||
throw new ArtemisPluginException(pluginInfo, "Plugin contains no implementation of Plugin");
|
||||
|
||||
var pluginType = pluginTypes.Single();
|
||||
Type pluginType = pluginTypes.Single();
|
||||
try
|
||||
{
|
||||
var parameters = new IParameter[]
|
||||
IParameter[] parameters = new IParameter[]
|
||||
{
|
||||
new Parameter("PluginInfo", pluginInfo, false)
|
||||
};
|
||||
@@ -365,8 +365,8 @@ 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"));
|
||||
DirectoryInfo pluginDirectory = new DirectoryInfo(Path.Combine(Constants.DataFolder, "plugins", builtInPluginDirectory.Name));
|
||||
bool createLockFile = File.Exists(Path.Combine(pluginDirectory.FullName, "artemis.lock"));
|
||||
|
||||
// Remove the old directory if it exists
|
||||
if (Directory.Exists(pluginDirectory.FullName))
|
||||
|
||||
@@ -11,9 +11,9 @@ namespace Artemis.Core.Services
|
||||
public DataModelService(IPluginService pluginService)
|
||||
{
|
||||
// Add data models of already loaded plugins
|
||||
foreach (var module in pluginService.GetPluginsOfType<Module>().Where(p => p.Enabled))
|
||||
foreach (Module module in pluginService.GetPluginsOfType<Module>().Where(p => p.Enabled))
|
||||
AddModuleDataModel(module);
|
||||
foreach (var dataModelExpansion in pluginService.GetPluginsOfType<BaseDataModelExpansion>().Where(p => p.Enabled))
|
||||
foreach (BaseDataModelExpansion dataModelExpansion in pluginService.GetPluginsOfType<BaseDataModelExpansion>().Where(p => p.Enabled))
|
||||
AddDataModelExpansionDataModel(dataModelExpansion);
|
||||
|
||||
// Add data models of new plugins when they get enabled
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Artemis.Core.Services
|
||||
|
||||
public LayerBrushDescriptor GetDefaultLayerBrush()
|
||||
{
|
||||
var defaultReference = _settingsService.GetSetting("ProfileEditor.DefaultLayerBrushDescriptor", new LayerBrushReference
|
||||
PluginSetting<LayerBrushReference> defaultReference = _settingsService.GetSetting("ProfileEditor.DefaultLayerBrushDescriptor", new LayerBrushReference
|
||||
{
|
||||
BrushPluginGuid = Guid.Parse("92a9d6ba-6f7a-4937-94d5-c1d715b4141a"),
|
||||
BrushType = "ColorBrush"
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace Artemis.Core.Services
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var surfaceDevice in deviceProvider.Devices)
|
||||
foreach (IRGBDevice surfaceDevice in deviceProvider.Devices)
|
||||
{
|
||||
_logger.Debug("Device provider {deviceProvider} added {deviceName}",
|
||||
deviceProvider.GetType().Name, surfaceDevice.DeviceInfo?.DeviceName);
|
||||
|
||||
@@ -38,13 +38,13 @@ namespace Artemis.Core.Services
|
||||
|
||||
public List<ProfileDescriptor> GetProfileDescriptors(ProfileModule module)
|
||||
{
|
||||
var profileEntities = _profileRepository.GetByPluginGuid(module.PluginInfo.Guid);
|
||||
List<ProfileEntity> profileEntities = _profileRepository.GetByPluginGuid(module.PluginInfo.Guid);
|
||||
return profileEntities.Select(e => new ProfileDescriptor(module, e)).ToList();
|
||||
}
|
||||
|
||||
public ProfileDescriptor CreateProfileDescriptor(ProfileModule module, string name)
|
||||
{
|
||||
var profileEntity = new ProfileEntity {Id = Guid.NewGuid(), Name = name, PluginGuid = module.PluginInfo.Guid};
|
||||
ProfileEntity profileEntity = new ProfileEntity {Id = Guid.NewGuid(), Name = name, PluginGuid = module.PluginInfo.Guid};
|
||||
_profileRepository.Add(profileEntity);
|
||||
|
||||
return new ProfileDescriptor(module, profileEntity);
|
||||
@@ -52,14 +52,14 @@ namespace Artemis.Core.Services
|
||||
|
||||
public void ActivateLastProfile(ProfileModule profileModule)
|
||||
{
|
||||
var activeProfile = GetLastActiveProfile(profileModule);
|
||||
ProfileDescriptor activeProfile = GetLastActiveProfile(profileModule);
|
||||
if (activeProfile != null)
|
||||
ActivateProfile(activeProfile);
|
||||
}
|
||||
|
||||
public async Task ActivateLastProfileAnimated(ProfileModule profileModule)
|
||||
{
|
||||
var activeProfile = GetLastActiveProfile(profileModule);
|
||||
ProfileDescriptor activeProfile = GetLastActiveProfile(profileModule);
|
||||
if (activeProfile != null)
|
||||
await ActivateProfileAnimated(activeProfile);
|
||||
}
|
||||
@@ -69,11 +69,11 @@ namespace Artemis.Core.Services
|
||||
if (profileDescriptor.ProfileModule.ActiveProfile?.EntityId == profileDescriptor.Id)
|
||||
return profileDescriptor.ProfileModule.ActiveProfile;
|
||||
|
||||
var profileEntity = _profileRepository.Get(profileDescriptor.Id);
|
||||
ProfileEntity profileEntity = _profileRepository.Get(profileDescriptor.Id);
|
||||
if (profileEntity == null)
|
||||
throw new ArtemisCoreException($"Cannot find profile named: {profileDescriptor.Name} ID: {profileDescriptor.Id}");
|
||||
|
||||
var profile = new Profile(profileDescriptor.ProfileModule, profileEntity);
|
||||
Profile profile = new Profile(profileDescriptor.ProfileModule, profileEntity);
|
||||
InstantiateProfile(profile);
|
||||
|
||||
profileDescriptor.ProfileModule.ChangeActiveProfile(profile, _surfaceService.ActiveSurface);
|
||||
@@ -87,11 +87,11 @@ namespace Artemis.Core.Services
|
||||
if (profileDescriptor.ProfileModule.ActiveProfile?.EntityId == profileDescriptor.Id)
|
||||
return profileDescriptor.ProfileModule.ActiveProfile;
|
||||
|
||||
var profileEntity = _profileRepository.Get(profileDescriptor.Id);
|
||||
ProfileEntity profileEntity = _profileRepository.Get(profileDescriptor.Id);
|
||||
if (profileEntity == null)
|
||||
throw new ArtemisCoreException($"Cannot find profile named: {profileDescriptor.Name} ID: {profileDescriptor.Id}");
|
||||
|
||||
var profile = new Profile(profileDescriptor.ProfileModule, profileEntity);
|
||||
Profile profile = new Profile(profileDescriptor.ProfileModule, profileEntity);
|
||||
InstantiateProfile(profile);
|
||||
|
||||
void ActivatingProfileSurfaceUpdate(object sender, SurfaceConfigurationEventArgs e)
|
||||
@@ -146,23 +146,23 @@ namespace Artemis.Core.Services
|
||||
|
||||
public void DeleteProfile(ProfileDescriptor profileDescriptor)
|
||||
{
|
||||
var profileEntity = _profileRepository.Get(profileDescriptor.Id);
|
||||
ProfileEntity profileEntity = _profileRepository.Get(profileDescriptor.Id);
|
||||
_profileRepository.Remove(profileEntity);
|
||||
}
|
||||
|
||||
public void UpdateProfile(Profile profile, bool includeChildren)
|
||||
{
|
||||
_logger.Debug("Updating profile " + profile);
|
||||
var memento = JsonConvert.SerializeObject(profile.ProfileEntity, MementoSettings);
|
||||
string memento = JsonConvert.SerializeObject(profile.ProfileEntity, MementoSettings);
|
||||
profile.RedoStack.Clear();
|
||||
profile.UndoStack.Push(memento);
|
||||
|
||||
profile.Save();
|
||||
if (includeChildren)
|
||||
{
|
||||
foreach (var folder in profile.GetAllFolders())
|
||||
foreach (Folder folder in profile.GetAllFolders())
|
||||
folder.Save();
|
||||
foreach (var layer in profile.GetAllLayers())
|
||||
foreach (Layer layer in profile.GetAllLayers())
|
||||
layer.Save();
|
||||
}
|
||||
|
||||
@@ -180,8 +180,8 @@ namespace Artemis.Core.Services
|
||||
return false;
|
||||
}
|
||||
|
||||
var top = profile.UndoStack.Pop();
|
||||
var memento = JsonConvert.SerializeObject(profile.ProfileEntity, MementoSettings);
|
||||
string top = profile.UndoStack.Pop();
|
||||
string memento = JsonConvert.SerializeObject(profile.ProfileEntity, MementoSettings);
|
||||
profile.RedoStack.Push(memento);
|
||||
profile.ProfileEntity = JsonConvert.DeserializeObject<ProfileEntity>(top, MementoSettings);
|
||||
|
||||
@@ -204,8 +204,8 @@ namespace Artemis.Core.Services
|
||||
return false;
|
||||
}
|
||||
|
||||
var top = profile.RedoStack.Pop();
|
||||
var memento = JsonConvert.SerializeObject(profile.ProfileEntity, MementoSettings);
|
||||
string top = profile.RedoStack.Pop();
|
||||
string memento = JsonConvert.SerializeObject(profile.ProfileEntity, MementoSettings);
|
||||
profile.UndoStack.Push(memento);
|
||||
profile.ProfileEntity = JsonConvert.DeserializeObject<ProfileEntity>(top, MementoSettings);
|
||||
|
||||
@@ -224,7 +224,7 @@ namespace Artemis.Core.Services
|
||||
|
||||
public string ExportProfile(ProfileDescriptor profileDescriptor)
|
||||
{
|
||||
var profileEntity = _profileRepository.Get(profileDescriptor.Id);
|
||||
ProfileEntity profileEntity = _profileRepository.Get(profileDescriptor.Id);
|
||||
if (profileEntity == null)
|
||||
throw new ArtemisCoreException($"Cannot find profile named: {profileDescriptor.Name} ID: {profileDescriptor.Id}");
|
||||
|
||||
@@ -233,7 +233,7 @@ namespace Artemis.Core.Services
|
||||
|
||||
public ProfileDescriptor ImportProfile(string json, ProfileModule profileModule)
|
||||
{
|
||||
var profileEntity = JsonConvert.DeserializeObject<ProfileEntity>(json, ExportSettings);
|
||||
ProfileEntity profileEntity = JsonConvert.DeserializeObject<ProfileEntity>(json, ExportSettings);
|
||||
|
||||
// Assign a new GUID to make sure it is unique in case of a previous import of the same content
|
||||
profileEntity.UpdateGuid(Guid.NewGuid());
|
||||
@@ -245,11 +245,11 @@ namespace Artemis.Core.Services
|
||||
|
||||
public ProfileDescriptor GetLastActiveProfile(ProfileModule module)
|
||||
{
|
||||
var moduleProfiles = _profileRepository.GetByPluginGuid(module.PluginInfo.Guid);
|
||||
List<ProfileEntity> moduleProfiles = _profileRepository.GetByPluginGuid(module.PluginInfo.Guid);
|
||||
if (!moduleProfiles.Any())
|
||||
return CreateProfileDescriptor(module, "Default");
|
||||
|
||||
var profileEntity = moduleProfiles.FirstOrDefault(p => p.IsActive) ?? moduleProfiles.FirstOrDefault();
|
||||
ProfileEntity profileEntity = moduleProfiles.FirstOrDefault(p => p.IsActive) ?? moduleProfiles.FirstOrDefault();
|
||||
return profileEntity == null ? null : new ProfileDescriptor(module, profileEntity);
|
||||
}
|
||||
|
||||
@@ -258,8 +258,8 @@ namespace Artemis.Core.Services
|
||||
if (module.ActiveProfile == null)
|
||||
return;
|
||||
|
||||
var profileEntities = _profileRepository.GetByPluginGuid(module.PluginInfo.Guid);
|
||||
foreach (var profileEntity in profileEntities)
|
||||
List<ProfileEntity> profileEntities = _profileRepository.GetByPluginGuid(module.PluginInfo.Guid);
|
||||
foreach (ProfileEntity profileEntity in profileEntities)
|
||||
{
|
||||
profileEntity.IsActive = module.ActiveProfile.EntityId == profileEntity.Id;
|
||||
_profileRepository.Save(profileEntity);
|
||||
@@ -272,8 +272,8 @@ namespace Artemis.Core.Services
|
||||
/// <param name="surface"></param>
|
||||
private void ActiveProfilesPopulateLeds(ArtemisSurface surface)
|
||||
{
|
||||
var profileModules = _pluginService.GetPluginsOfType<ProfileModule>();
|
||||
foreach (var profileModule in profileModules.Where(p => p.ActiveProfile != null).ToList())
|
||||
List<ProfileModule> profileModules = _pluginService.GetPluginsOfType<ProfileModule>();
|
||||
foreach (ProfileModule profileModule in profileModules.Where(p => p.ActiveProfile != null).ToList())
|
||||
profileModule.ActiveProfile.PopulateLeds(surface);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Artemis.Storage.Entities.Surface;
|
||||
using Artemis.Storage.Repositories.Interfaces;
|
||||
using RGB.NET.Core;
|
||||
using Serilog;
|
||||
@@ -38,12 +39,12 @@ namespace Artemis.Core.Services
|
||||
public ArtemisSurface CreateSurfaceConfiguration(string name)
|
||||
{
|
||||
// Create a blank config
|
||||
var configuration = new ArtemisSurface(_rgbService.Surface, name, _renderScaleSetting.Value);
|
||||
ArtemisSurface configuration = new ArtemisSurface(_rgbService.Surface, name, _renderScaleSetting.Value);
|
||||
|
||||
// Add all current devices
|
||||
foreach (var rgbDevice in _rgbService.LoadedDevices)
|
||||
foreach (IRGBDevice rgbDevice in _rgbService.LoadedDevices)
|
||||
{
|
||||
var plugin = _pluginService.GetPluginByDevice(rgbDevice);
|
||||
Plugin plugin = _pluginService.GetPluginByDevice(rgbDevice);
|
||||
configuration.Devices.Add(new ArtemisDevice(rgbDevice, plugin, configuration));
|
||||
}
|
||||
|
||||
@@ -69,7 +70,7 @@ namespace Artemis.Core.Services
|
||||
lock (_surfaceConfigurations)
|
||||
{
|
||||
// Mark only the new surface as active
|
||||
foreach (var configuration in _surfaceConfigurations)
|
||||
foreach (ArtemisSurface configuration in _surfaceConfigurations)
|
||||
{
|
||||
configuration.IsActive = configuration == ActiveSurface;
|
||||
configuration.ApplyToEntity();
|
||||
@@ -81,7 +82,7 @@ namespace Artemis.Core.Services
|
||||
// Apply the active surface entity to the devices
|
||||
if (ActiveSurface != null)
|
||||
{
|
||||
foreach (var device in ActiveSurface.Devices)
|
||||
foreach (ArtemisDevice device in ActiveSurface.Devices)
|
||||
device.ApplyToRgbDevice();
|
||||
}
|
||||
|
||||
@@ -95,7 +96,7 @@ namespace Artemis.Core.Services
|
||||
surface.ApplyToEntity();
|
||||
if (includeDevices)
|
||||
{
|
||||
foreach (var deviceConfiguration in surface.Devices)
|
||||
foreach (ArtemisDevice deviceConfiguration in surface.Devices)
|
||||
{
|
||||
deviceConfiguration.ApplyToEntity();
|
||||
if (surface.IsActive)
|
||||
@@ -115,7 +116,7 @@ namespace Artemis.Core.Services
|
||||
|
||||
lock (_surfaceConfigurations)
|
||||
{
|
||||
var entity = surface.SurfaceEntity;
|
||||
SurfaceEntity entity = surface.SurfaceEntity;
|
||||
_surfaceConfigurations.Remove(surface);
|
||||
_surfaceRepository.Remove(entity);
|
||||
}
|
||||
@@ -125,17 +126,17 @@ namespace Artemis.Core.Services
|
||||
|
||||
private void LoadFromRepository()
|
||||
{
|
||||
var configs = _surfaceRepository.GetAll();
|
||||
foreach (var surfaceEntity in configs)
|
||||
List<SurfaceEntity> configs = _surfaceRepository.GetAll();
|
||||
foreach (SurfaceEntity surfaceEntity in configs)
|
||||
{
|
||||
// Create the surface entity
|
||||
var surfaceConfiguration = new ArtemisSurface(_rgbService.Surface, surfaceEntity, _renderScaleSetting.Value);
|
||||
foreach (var position in surfaceEntity.DeviceEntities)
|
||||
ArtemisSurface surfaceConfiguration = new ArtemisSurface(_rgbService.Surface, surfaceEntity, _renderScaleSetting.Value);
|
||||
foreach (DeviceEntity position in surfaceEntity.DeviceEntities)
|
||||
{
|
||||
var device = _rgbService.Surface.Devices.FirstOrDefault(d => d.GetDeviceIdentifier() == position.DeviceIdentifier);
|
||||
IRGBDevice device = _rgbService.Surface.Devices.FirstOrDefault(d => d.GetDeviceIdentifier() == position.DeviceIdentifier);
|
||||
if (device != null)
|
||||
{
|
||||
var plugin = _pluginService.GetPluginByDevice(device);
|
||||
Plugin plugin = _pluginService.GetPluginByDevice(device);
|
||||
surfaceConfiguration.Devices.Add(new ArtemisDevice(device, plugin, surfaceConfiguration, position));
|
||||
}
|
||||
}
|
||||
@@ -148,7 +149,7 @@ namespace Artemis.Core.Services
|
||||
}
|
||||
|
||||
// When all surface configs are loaded, apply the active surface config
|
||||
var active = SurfaceConfigurations.FirstOrDefault(c => c.IsActive);
|
||||
ArtemisSurface active = SurfaceConfigurations.FirstOrDefault(c => c.IsActive);
|
||||
if (active != null)
|
||||
SetActiveSurfaceConfiguration(active);
|
||||
else
|
||||
@@ -167,17 +168,17 @@ namespace Artemis.Core.Services
|
||||
|
||||
private void AddDeviceIfMissing(IRGBDevice rgbDevice, ArtemisSurface surface)
|
||||
{
|
||||
var deviceIdentifier = rgbDevice.GetDeviceIdentifier();
|
||||
var device = surface.Devices.FirstOrDefault(d => d.DeviceEntity.DeviceIdentifier == deviceIdentifier);
|
||||
string deviceIdentifier = rgbDevice.GetDeviceIdentifier();
|
||||
ArtemisDevice device = surface.Devices.FirstOrDefault(d => d.DeviceEntity.DeviceIdentifier == deviceIdentifier);
|
||||
|
||||
if (device != null)
|
||||
return;
|
||||
|
||||
// Find an existing device config and use that
|
||||
var existingDeviceConfig = surface.SurfaceEntity.DeviceEntities.FirstOrDefault(d => d.DeviceIdentifier == deviceIdentifier);
|
||||
DeviceEntity existingDeviceConfig = surface.SurfaceEntity.DeviceEntities.FirstOrDefault(d => d.DeviceIdentifier == deviceIdentifier);
|
||||
if (existingDeviceConfig != null)
|
||||
{
|
||||
var plugin = _pluginService.GetPluginByDevice(rgbDevice);
|
||||
Plugin plugin = _pluginService.GetPluginByDevice(rgbDevice);
|
||||
device = new ArtemisDevice(rgbDevice, plugin, surface, existingDeviceConfig);
|
||||
}
|
||||
// Fall back on creating a new device
|
||||
@@ -188,7 +189,7 @@ namespace Artemis.Core.Services
|
||||
rgbDevice.DeviceInfo,
|
||||
deviceIdentifier
|
||||
);
|
||||
var plugin = _pluginService.GetPluginByDevice(rgbDevice);
|
||||
Plugin plugin = _pluginService.GetPluginByDevice(rgbDevice);
|
||||
device = new ArtemisDevice(rgbDevice, plugin, surface);
|
||||
}
|
||||
|
||||
@@ -203,7 +204,7 @@ namespace Artemis.Core.Services
|
||||
{
|
||||
lock (_surfaceConfigurations)
|
||||
{
|
||||
foreach (var surfaceConfiguration in _surfaceConfigurations)
|
||||
foreach (ArtemisSurface surfaceConfiguration in _surfaceConfigurations)
|
||||
AddDeviceIfMissing(e.Device, surfaceConfiguration);
|
||||
}
|
||||
|
||||
@@ -212,7 +213,7 @@ namespace Artemis.Core.Services
|
||||
|
||||
private void RenderScaleSettingOnSettingChanged(object sender, EventArgs e)
|
||||
{
|
||||
foreach (var surfaceConfiguration in SurfaceConfigurations)
|
||||
foreach (ArtemisSurface surfaceConfiguration in SurfaceConfigurations)
|
||||
{
|
||||
surfaceConfiguration.UpdateScale(_renderScaleSetting.Value);
|
||||
OnSurfaceConfigurationUpdated(new SurfaceConfigurationEventArgs(surfaceConfiguration));
|
||||
|
||||
Reference in new issue
Block a user