Beispiel #1
0
        public static string Replace(string input, TextFilterCommand command)
        {
            // If they didn't pass in a second argument, then we're using String.Empty (so, less "replace" and more "remove"
            var replaceWith = command.CommandArgs.Count > 1 ? command.CommandArgs[1] : String.Empty;

            return(input.Replace(command.CommandArgs[0], replaceWith));
        }
Beispiel #2
0
        public static string AddQuerysgtringArg(string input, TextFilterCommand command)
        {
            var uriBuilder            = new UriBuilder(input);
            NameValueCollection query = HttpUtility.ParseQueryString(uriBuilder.Query);

            query[command.CommandArgs["1"]] = command.CommandArgs["2"];
            uriBuilder.Query = query.ToString();
            return(uriBuilder.Uri.AbsoluteUri);
        }
Beispiel #3
0
        public static string ExtractFromXml(string input, TextFilterCommand command)
        {
            var doc = new XmlDocument();

            doc.LoadXml(input);

            XmlNode node = doc.DocumentElement.SelectSingleNode(command.CommandArgs[0]);

            return(node != null ? node.Value : String.Empty);
        }
Beispiel #4
0
        public static string Get(string input, TextFilterCommand command)
        {
            string url = command.CommandArgs.ContainsKey(0) ? command.CommandArgs[0] : input;

            if (!url.ToLower().StartsWith("http"))
            {
                url = String.Concat("http://", url);
            }

            var client = new WebClient();

            return(client.DownloadString(url));
        }
Beispiel #5
0
        public void PopulateCommand()
        {
            var command = new TextFilterCommand();

            command.CommandName = "Replace";
            command.CommandArgs.Add("1", "a");
            command.CommandArgs.Add("2", "b");

            Assert.AreEqual("Replace", command.CommandName);
            Assert.AreEqual("replace", command.NormalizedCommandName);
            Assert.AreEqual("a", command.CommandArgs.First().Value);
            Assert.AreEqual("b", command.CommandArgs.Last().Value);
        }
Beispiel #6
0
        public void AddCommandByObject()
        {
            var command = new TextFilterCommand();

            command.CommandName = "Replace";
            command.CommandArgs.Add("a", "b");

            var pipeline = new TextFilterPipeline();

            pipeline.AddCommand(command);

            Assert.AreEqual(1, pipeline.Commands.Count());
            Assert.AreEqual("Replace", pipeline.Commands.First().CommandName);
            Assert.AreEqual("b", pipeline.Commands.First().CommandArgs.First().Value);
        }
Beispiel #7
0
        public static string Extract(string input, TextFilterCommand command)
        {
            var doc = new HtmlDocument();

            doc.LoadHtml(input);

            HtmlNode node = doc.DocumentNode.SelectSingleNode(command.CommandArgs[0]);

            if (node == null)
            {
                node = doc.DocumentNode.QuerySelector(command.CommandArgs[0]);
            }

            return(node != null ? node.InnerHtml : String.Empty);
        }
Beispiel #8
0
        public static string Format(string input, TextFilterCommand command)
        {
            string template = command.CommandArgs.ContainsKey(0) ? command.CommandArgs[0] : String.Empty;

            template = command.CommandArgs.ContainsKey("template") && !String.IsNullOrWhiteSpace(command.CommandArgs["template"]) ? command.CommandArgs["template"] : template;

            foreach (var variable in command.Pipeline.Variables)
            {
                template = template.Replace(String.Concat("{", variable.Key, "}"), variable.Value.ToString());
            }

            // Escape any remaining {string} patterns, because these will break String.Format...
            template = Regex.Replace(template, "{([^0-9]+)}", "{{$1}}");

            return(String.Format(template, input));
        }
Beispiel #9
0
        public static string TransformXml(string input, TextFilterCommand command)
        {
            var arguments = new XsltArgumentList();

            // We're going to do this transform using the templae as XSL
            var xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(input);

            var transform = new XslCompiledTransform();

            transform.Load(XmlReader.Create(new StringReader(command.Pipeline.GetVariable(command.CommandArgs[0]).ToString())));

            var writer = new StringWriter();

            transform.Transform(xmlDoc, arguments, writer);
            return(writer.ToString());
        }
Beispiel #10
0
        public static string ExtractFromJson(string input, TextFilterCommand command)
        {
            var jobject = (JToken)JObject.Parse(input);

            foreach (string segment in command.CommandArgs["1"].Split('.'))
            {
                if (segment[0] == '~')
                {
                    jobject = jobject[Convert.ToInt32(segment.Replace("~", String.Empty))];
                    continue;
                }

                if (jobject[segment] is JValue)
                {
                    return(jobject[segment].ToString());
                }

                jobject = jobject[segment];
            }

            return(String.Empty);
        }
Beispiel #11
0
        public static string WrapInTag(string input, TextFilterCommand command)
        {
            var stringWriter = new StringWriter();
            var tagBuilder   = new HtmlTextWriter(stringWriter);

            // The second argument should be the class
            if (command.CommandArgs.ContainsKey(1))
            {
                tagBuilder.AddAttribute("class", command.CommandArgs[1]);
            }

            // The third argument should be the id
            if (command.CommandArgs.ContainsKey(2))
            {
                tagBuilder.AddAttribute("id", command.CommandArgs[2]);
            }

            tagBuilder.RenderBeginTag(command.CommandArgs[0]);
            tagBuilder.Write(input);
            tagBuilder.RenderEndTag();

            return(stringWriter.ToString());
        }
Beispiel #12
0
        public static string Read(string input, TextFilterCommand command)
        {
            string fullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, command.CommandArgs.First().Value.Replace("/", @"\\").TrimStart(@"\\".ToCharArray()));

            return(File.ReadAllText(fullPath));
        }
 public static string Append(string input, TextFilterCommand command)
 {
     return(String.Concat(input, "BAZ"));
 }
Beispiel #14
0
 public static string Clear(string input, TextFilterCommand command)
 {
     return(String.Empty);
 }
Beispiel #15
0
 public static string Trim(string input, TextFilterCommand command)
 {
     return(input.Trim());
 }
Beispiel #16
0
 public static string ReplaceAll(string input, TextFilterCommand command)
 {
     return(command.DefaultArgument);
 }
Beispiel #17
0
 public static string Append(string input, TextFilterCommand command)
 {
     return(String.Concat(input, command.DefaultArgument));
 }
 public static string MyMethod(string input, TextFilterCommand command)
 {
     return("MyMethod");
 }