/// <summary> /// Parse commands from plugin.yml /// </summary> /// <param name="map"></param> /// <returns></returns> /// <remarks></remarks> private static List <PluginCommand> ParseCommands(Mapping map) { try { List <PluginCommand> l = new List <PluginCommand>(); Scalar sc = new Scalar(); Sequence seq = new Sequence(); Type typeScalar = sc.GetType(); Type typeSequence = seq.GetType(); Type typeMapping = map.GetType(); if (map.GetType() != typeMapping) { return(l); } foreach (MappingEntry entry in map.Enties) { PluginCommand pc = new PluginCommand { Name = ((Scalar)entry.Key).Text }; if (entry.Value.GetType() == typeMapping) { foreach (MappingEntry secondlevel in ((Mapping)entry.Value).Enties) { if (secondlevel.Key.GetType() != typeScalar) { continue; } switch (((Scalar)secondlevel.Key).Text) { case "description": pc.Description = ((Scalar)secondlevel.Value).Text; break; case "usage": pc.Usage = ((Scalar)secondlevel.Value).Text; break; case "alias": if (entry.Value.GetType() == typeSequence) { pc.Aliases = ArrayFromSequence((Sequence)secondlevel.Value); } else if (entry.Value.GetType() == typeScalar) { pc.Aliases = new string[1]; // ReSharper disable once PossibleInvalidCastException pc.Aliases[0] = ((Scalar)entry.Value).Text; } break; case "aliases": if (entry.Value.GetType() == typeSequence) { pc.Aliases = ArrayFromSequence((Sequence)secondlevel.Value); } else if (entry.Value.GetType() == typeScalar) { pc.Aliases = new string[1]; // ReSharper disable once PossibleInvalidCastException pc.Aliases[0] = ((Scalar)entry.Value).Text; } break; } } } l.Add(pc); } return(l); } catch (Exception ex) { Logger.Log(LogLevel.Warning, "InstalledPlugin", "An exception occured when trying to load plugin commands", ex.Message); return(new List <PluginCommand>()); } }
/// <summary> /// Parse commands from plugin.yml /// </summary> /// <param name="map"></param> /// <returns></returns> /// <remarks></remarks> private static List<PluginCommand> ParseCommands(Mapping map) { try { List<PluginCommand> l = new List<PluginCommand>(); Scalar sc = new Scalar(); Sequence seq = new Sequence(); Type typeScalar = sc.GetType(); Type typeSequence = seq.GetType(); Type typeMapping = map.GetType(); if (map.GetType() != typeMapping) return l; foreach (MappingEntry entry in map.Enties) { PluginCommand pc = new PluginCommand {Name = ((Scalar) entry.Key).Text}; if (entry.Value.GetType() == typeMapping) { foreach (MappingEntry secondlevel in ((Mapping) entry.Value).Enties) { if (secondlevel.Key.GetType() != typeScalar) continue; switch (((Scalar) secondlevel.Key).Text) { case "description": pc.Description = ((Scalar) secondlevel.Value).Text; break; case "usage": pc.Usage = ((Scalar) secondlevel.Value).Text; break; case "alias": if (entry.Value.GetType() == typeSequence) { pc.Aliases = ArrayFromSequence((Sequence) secondlevel.Value); } else if (entry.Value.GetType() == typeScalar) { pc.Aliases = new string[1]; // ReSharper disable once PossibleInvalidCastException pc.Aliases[0] = ((Scalar) entry.Value).Text; } break; case "aliases": if (entry.Value.GetType() == typeSequence) { pc.Aliases = ArrayFromSequence((Sequence) secondlevel.Value); } else if (entry.Value.GetType() == typeScalar) { pc.Aliases = new string[1]; // ReSharper disable once PossibleInvalidCastException pc.Aliases[0] = ((Scalar) entry.Value).Text; } break; } } } l.Add(pc); } return l; } catch (Exception ex) { Logger.Log(LogLevel.Warning, "InstalledPlugin", "An exception occured when trying to load plugin commands", ex.Message); return new List<PluginCommand>(); } }