Example #1
0
        public static FilterResult AddAtStartAndAtEndFilter(FilterContext context)
        {
            FilterResult result = new FilterResult();

            using (StringWriter resultWriter = new StringWriter())
            {
                using (StringReader sr = new StringReader(context.Text))
                {
                    string line = String.Empty;
                    while ((line = sr.ReadLine()) != null)
                    {
                        string leftText  = (string)context.Parameters[0];
                        string rightText = (string)context.Parameters[1];
                        string newLine   = string.Format("{0}{1}{2}", leftText, line, rightText);
                        resultWriter.WriteLine(newLine);
                    }
                }
                result.Text = resultWriter.ToString();
            }
            return(result);
        }
Example #2
0
        public static FilterResult EmptyLinesFilter(FilterContext context)
        {
            FilterResult result = new FilterResult();

            using (StringWriter resultWriter = new StringWriter())
            {
                using (StringReader sr = new StringReader(context.Text))
                {
                    string line = String.Empty;
                    while ((line = sr.ReadLine()) != null)
                    {
                        if (!String.IsNullOrWhiteSpace(line))
                        {
                            resultWriter.WriteLine(line);
                        }
                    }
                }
                result.Text = resultWriter.ToString();
            }
            return(result);
        }
Example #3
0
        public static FilterResult StringToEndFilter(FilterContext context)
        {
            string       toText = (string)context.Parameters[0];
            FilterResult result = new FilterResult();

            using (StringWriter resultWriter = new StringWriter())
            {
                using (StringReader sr = new StringReader(context.Text))
                {
                    string line = String.Empty;
                    while ((line = sr.ReadLine()) != null)
                    {
                        int    positionOftoText = line.IndexOf(toText);
                        string newLine          = line.Substring(0, positionOftoText);
                        resultWriter.WriteLine(newLine);
                    }
                }
                result.Text = resultWriter.ToString();
            }
            return(result);
        }
Example #4
0
        public static FilterResult NotContainsFilter(FilterContext context)
        {
            string       notContainsText = (string)context.Parameters[0];
            FilterResult result          = new FilterResult();

            using (StringWriter resultWriter = new StringWriter())
            {
                using (StringReader sr = new StringReader(context.Text))
                {
                    string line = String.Empty;
                    while ((line = sr.ReadLine()) != null)
                    {
                        if (line.Contains(notContainsText))
                        {
                            resultWriter.WriteLine(line);
                        }
                    }
                }
                result.Text = resultWriter.ToString();
            }
            return(result);
        }
Example #5
0
        public static FilterResult EndsWidhFilter(FilterContext context)
        {
            string       endsWith = (string)context.Parameters[0];
            FilterResult result   = new FilterResult();

            using (StringWriter resultWriter = new StringWriter())
            {
                using (StringReader sr = new StringReader(context.Text))
                {
                    string line = String.Empty;
                    while ((line = sr.ReadLine()) != null)
                    {
                        if (!line.EndsWith(endsWith))
                        {
                            resultWriter.WriteLine(line);
                        }
                    }
                }
                result.Text = resultWriter.ToString();
            }
            return(result);
        }
Example #6
0
        private void toolStripButtonProcess_Click(object sender, EventArgs e)
        {
            FilterHelper  filterHelper = new FilterHelper();
            StringBuilder text         = new StringBuilder();

            for (int count = 0; count < 20; count++)
            {
                text.AppendLine(string.Format("{0}-{0}-{0}", count));
                //text.AppendLine("");
                //text.AppendLine(" ");
                //text.AppendLine("  ");
                //text.AppendLine("   ");
            }
            text.AppendLine("3-3-3");
            text.AppendLine("7-7-7");
            //richTextBox1.Text = text.ToString();
            //string resultText = text.ToString();
            string            resultText  = richTextBox1.Text;
            List <BaseFilter> controlList = new List <BaseFilter>();

            foreach (BaseFilter filter in scenarioSelector1.panelActiveFilter.Controls)
            {
                controlList.Add(filter);
            }
            controlList.Reverse();

            foreach (BaseFilter filter in controlList)
            {
                List <object> filterParameters = filter.Values;
                FilterContext filterContext    = new FilterContext()
                {
                    Parameters = filterParameters,
                    Text       = resultText
                };
                FilterResult filterResult = filterHelper.filterList[filter.Key].Invoke(filterContext);
                resultText = filterResult.Text;
            }
            richTextBox2.Text = resultText;
        }