public static IKeyCommand CreateCommand(ConfigCommand item) { var manifest = GetCommandManifest(item.CommandType); IPlugin plugin = Plugins.FirstOrDefault(p => p.NameSpace == manifest.NameSpace); if (plugin == null) { LogManager.Logger(typeof(ConfigurationHelper)) .Error("Błąd tworzenia komendy. Nie znaleziono pluginu."); LogManager.Logger(typeof(ConfigurationHelper)) .WarnFormat("Komenda [{0}] została pominięta.", item.Id); return(null); } try { IKeyCommand command = plugin.CreateCommand( manifest.Command, new KeyCommandConfig { Id = item.Id, Description = item.Description, Icon = GetImage(item.IconPath), Parameters = item.Parameters, KeyCode = GetKeys(item.Key) }); if (command != null) { return(command); } LogManager.Logger(typeof(ConfigurationHelper)) .Error("Błąd tworzenia komendy. Plugin nie zwrócił instancji."); LogManager.Logger(typeof(ConfigurationHelper)) .WarnFormat("Komenda [{0}] została pominięta.", item.Id); } catch (Exception ex) { LogManager.Logger(typeof(ConfigurationHelper)) .Error("Błąd tworzenia komendy", ex); LogManager.Logger(typeof(ConfigurationHelper)) .WarnFormat("Komenda [{0}] została pominięta.", item.Id); } return(null); }
private static ConfigCommand ReadCommandFromConfig(XElement element) { var configCommand = new ConfigCommand(); var node = element; if (node != null) { configCommand.Id = node.Attribute("id").Value; configCommand.Key = node.Attribute("key").Value; configCommand.CommandType = node.Attribute("commandType").Value; var attr = node.Attribute("parent"); if (attr != null) { configCommand.Parent = attr.Value; } attr = node.Attribute("parameters"); if (attr != null) { configCommand.Parameters = attr.Value; } attr = node.Attribute("iconPath"); if (attr != null) { configCommand.IconPath = attr.Value; } attr = node.Attribute("description"); if (attr != null) { configCommand.Description = attr.Value; } attr = node.Attribute("globalKey"); if (attr != null) { configCommand.GlobalKey = attr.Value; } } return(configCommand); }