Inheritance: BaseParserCommand, IParserCommand
Exemplo n.º 1
0
        private List<IParserCommand> ParseCommands(XElement node)
        {
            var subCommands = new List<IParserCommand>();
            foreach (var childNode in node.Elements())
            {
                IParserCommand parsedAction = null;
                switch (childNode.Name.ToString().ToLowerInvariant())
                {
                    case "extract":
                        parsedAction = new Jackett.Irc.Models.AutoDL.Parser.Extract();
                        break;
                    case "http":
                        parsedAction = new Jackett.Irc.Models.AutoDL.Parser.Http(childNode, logFactory.CreateLogger< Jackett.Irc.Models.AutoDL.Parser.Http>());
                        break;
                    case "ignore":
                        parsedAction = new Jackett.Irc.Models.AutoDL.Parser.Ignore(logFactory.CreateLogger<Jackett.Irc.Models.AutoDL.Parser.Ignore>());
                        break;
                    case "regex":
                        parsedAction = new Jackett.Irc.Models.AutoDL.Parser.Regex(childNode, logFactory.CreateLogger<Jackett.Irc.Models.AutoDL.Parser.Regex>());
                        break;
                    case "string":
                        parsedAction = new Jackett.Irc.Models.AutoDL.Parser.String(childNode, logFactory.CreateLogger<Jackett.Irc.Models.AutoDL.Parser.String>());
                        break;
                    case "var":
                        parsedAction = new Jackett.Irc.Models.AutoDL.Parser.Var(childNode, logFactory.CreateLogger<Jackett.Irc.Models.AutoDL.Parser.Var>());
                        break;
                    case "varenc":
                        parsedAction = new Jackett.Irc.Models.AutoDL.Parser.VarEnc(childNode, logFactory.CreateLogger<Jackett.Irc.Models.AutoDL.Parser.VarEnc>());
                        break;
                    case "varreplace":
                        parsedAction = new Jackett.Irc.Models.AutoDL.Parser.VarReplace(childNode, logFactory.CreateLogger<Jackett.Irc.Models.AutoDL.Parser.VarReplace>());
                        break;
                    case "vars":
                        parsedAction = new Jackett.Irc.Models.AutoDL.Parser.Vars(childNode, logFactory.CreateLogger<Jackett.Irc.Models.AutoDL.Parser.Vars>());
                        break;
                    case "setregex":
                        parsedAction = new Jackett.Irc.Models.AutoDL.Parser.SetRegex(childNode, logFactory.CreateLogger<Jackett.Irc.Models.AutoDL.Parser.SetRegex>());
                        break;
                    case "if":
                        parsedAction = new Jackett.Irc.Models.AutoDL.Parser.If(childNode, logFactory.CreateLogger<Jackett.Irc.Models.AutoDL.Parser.If>());
                        break;
                    case "extractone":
                        parsedAction = new Jackett.Irc.Models.AutoDL.Parser.ExtractOne(childNode, logFactory.CreateLogger<Jackett.Irc.Models.AutoDL.Parser.ExtractOne>());
                        break;
                    case "extracttags":
                        parsedAction = new Jackett.Irc.Models.AutoDL.Parser.ExtractTags(childNode, logFactory.CreateLogger<Jackett.Irc.Models.AutoDL.Parser.ExtractTags>());
                        break;
                    case "setvarif":
                        parsedAction = new Jackett.Irc.Models.AutoDL.Parser.SetVarIf(childNode, logFactory.CreateLogger<Jackett.Irc.Models.AutoDL.Parser.SetVarIf>());
                        break;
                }

                if (parsedAction == null)
                {
                    var msg = "Failed to parse AutoDL action: " + childNode.Name;
                    logger.LogError(msg);
                    //throw new Exception(msg);
                }

                var baseCommand = parsedAction as BaseParserCommand;
                if (baseCommand != null)
                {
                    baseCommand.Children = ParseCommands(childNode);
                }

                subCommands.Add(parsedAction);
            }

            return subCommands;
        }
        private List <IParserCommand> ParseCommands(XElement node)
        {
            var subCommands = new List <IParserCommand>();

            foreach (var childNode in node.Elements())
            {
                IParserCommand parsedAction = null;
                switch (childNode.Name.ToString().ToLowerInvariant())
                {
                case "extract":
                    parsedAction = new Jackett.Irc.Models.AutoDL.Parser.Extract();
                    break;

                case "http":
                    parsedAction = new Jackett.Irc.Models.AutoDL.Parser.Http(childNode, logFactory.CreateLogger <Jackett.Irc.Models.AutoDL.Parser.Http>());
                    break;

                case "ignore":
                    parsedAction = new Jackett.Irc.Models.AutoDL.Parser.Ignore(logFactory.CreateLogger <Jackett.Irc.Models.AutoDL.Parser.Ignore>());
                    break;

                case "regex":
                    parsedAction = new Jackett.Irc.Models.AutoDL.Parser.Regex(childNode, logFactory.CreateLogger <Jackett.Irc.Models.AutoDL.Parser.Regex>());
                    break;

                case "string":
                    parsedAction = new Jackett.Irc.Models.AutoDL.Parser.String(childNode, logFactory.CreateLogger <Jackett.Irc.Models.AutoDL.Parser.String>());
                    break;

                case "var":
                    parsedAction = new Jackett.Irc.Models.AutoDL.Parser.Var(childNode, logFactory.CreateLogger <Jackett.Irc.Models.AutoDL.Parser.Var>());
                    break;

                case "varenc":
                    parsedAction = new Jackett.Irc.Models.AutoDL.Parser.VarEnc(childNode, logFactory.CreateLogger <Jackett.Irc.Models.AutoDL.Parser.VarEnc>());
                    break;

                case "varreplace":
                    parsedAction = new Jackett.Irc.Models.AutoDL.Parser.VarReplace(childNode, logFactory.CreateLogger <Jackett.Irc.Models.AutoDL.Parser.VarReplace>());
                    break;

                case "vars":
                    parsedAction = new Jackett.Irc.Models.AutoDL.Parser.Vars(childNode, logFactory.CreateLogger <Jackett.Irc.Models.AutoDL.Parser.Vars>());
                    break;

                case "setregex":
                    parsedAction = new Jackett.Irc.Models.AutoDL.Parser.SetRegex(childNode, logFactory.CreateLogger <Jackett.Irc.Models.AutoDL.Parser.SetRegex>());
                    break;

                case "if":
                    parsedAction = new Jackett.Irc.Models.AutoDL.Parser.If(childNode, logFactory.CreateLogger <Jackett.Irc.Models.AutoDL.Parser.If>());
                    break;

                case "extractone":
                    parsedAction = new Jackett.Irc.Models.AutoDL.Parser.ExtractOne(childNode, logFactory.CreateLogger <Jackett.Irc.Models.AutoDL.Parser.ExtractOne>());
                    break;

                case "extracttags":
                    parsedAction = new Jackett.Irc.Models.AutoDL.Parser.ExtractTags(childNode, logFactory.CreateLogger <Jackett.Irc.Models.AutoDL.Parser.ExtractTags>());
                    break;

                case "setvarif":
                    parsedAction = new Jackett.Irc.Models.AutoDL.Parser.SetVarIf(childNode, logFactory.CreateLogger <Jackett.Irc.Models.AutoDL.Parser.SetVarIf>());
                    break;
                }

                if (parsedAction == null)
                {
                    var msg = "Failed to parse AutoDL action: " + childNode.Name;
                    logger.LogError(msg);
                    //throw new Exception(msg);
                }

                var baseCommand = parsedAction as BaseParserCommand;
                if (baseCommand != null)
                {
                    baseCommand.Children = ParseCommands(childNode);
                }

                subCommands.Add(parsedAction);
            }

            return(subCommands);
        }