void IpInputControl_GotFocus(object sender, EventArgs e)
        {
            MaskedTextBox Text = ((MaskedTextBox)sender);
            String        temp = Text.Text;

            Text.Text = "";
            Text.AppendText(temp);
            Text.SelectAll();

            _focusedBox = Int32.Parse(Text.Tag.ToString());
        }
        static int Main(string[] args)
        {
            bool         clearscreen  = false;
            bool         filter       = false;
            FilterAction filteraction = FilterAction.Remove;
            string       mask         = null;
            int          rc           = 0;


            #region Command Line Parsing

            if (args.Length > 0)
            {
                foreach (string arg in args)
                {
                    if (arg.Length > 1 && arg[0] == '/')
                    {
                        switch (arg[1].ToString( ).ToUpper( ))
                        {
                        case "?":
                            return(ShowHelp( ));

                        case "C":
                            if (clearscreen)
                            {
                                return(ShowHelp("Duplicate command line switch /C"));
                            }
                            clearscreen = true;                                     // No longer necessary, provided for backwards compatibility only
                            break;

                        case "F":
                            if (filter)
                            {
                                return(ShowHelp("Duplicate command line switch /F"));
                            }
                            if (arg.Length > 3 && arg[2] == ':')
                            {
                                filter = true;
                                string action = arg.Substring(3);
                                switch (action.ToUpper( ))
                                {
                                case "A":
                                case "ABORT":
                                    filteraction = FilterAction.Abort;
                                    break;

                                case "D":
                                case "DETECT":
                                case "DETECTONLY":
                                    filteraction = FilterAction.DetectOnly;
                                    break;

                                case "E":
                                case "END":
                                case "ENDOFINPUT":
                                    filteraction = FilterAction.EndOfInput;
                                    break;

                                case "R":
                                case "REMOVE":
                                    filteraction = FilterAction.Remove;
                                    break;

                                case "W":
                                case "WHITESPACE":
                                    filteraction = FilterAction.WhiteSpace;
                                    break;

                                default:
                                    return(ShowHelp("Invalid filter argument \"{0}\"", arg));
                                }
                            }
                            else
                            {
                                return(ShowHelp("Invalid filter argument \"{0}\"", arg));
                            }
                            break;

                        case "M":
                            if (!String.IsNullOrEmpty(mask))
                            {
                                return(ShowHelp("Duplicate command line switch /M"));
                            }
                            if (arg.Length == 2)
                            {
                                return(HelpForMask( ));
                            }
                            if (arg.Length > 3 && arg[2] == ':')
                            {
                                mask = arg.Substring(3);
                            }
                            else
                            {
                                return(ShowHelp("Invalid mask specification \"{0}\"", arg));
                            }
                            break;

                        default:
                            return(ShowHelp("Invalid command line argument \"{0}\"", arg));
                        }
                    }
                    else
                    {
                        return(ShowHelp("Invalid command line argument \"{0}\"", arg));
                    }
                }
            }

            #endregion Command Line Parsing


            #region Read Input

            // Read 1 line of input from the console
            string input = String.Empty;
            char   key   = (char)27;
            while (key != (char)13)
            {
                ConsoleKeyInfo keyinfo = Console.ReadKey(true);
                key = keyinfo.KeyChar;
                if (key != (char)13)
                {
                    input += keyinfo.KeyChar.ToString( );
                }
            }

            #endregion Read Input


            #region Clear Screen

            // Though no longer necessary for safety, this feature is provided for backwards compatibility
            if (clearscreen)
            {
                Console.Clear( );
            }

            #endregion Clear Screen


            #region Apply Mask to Input

            if (!String.IsNullOrEmpty(mask))
            {
                using (MaskedTextBox maskedtextbox = new MaskedTextBox(mask))
                {
                    maskedtextbox.Text = String.Empty;
                    maskedtextbox.AppendText(input);
                    input = maskedtextbox.Text;
                }
            }

            #endregion Apply Mask to Input


            #region Apply Filter to Output

            if (filter)
            {
                string specialchars = @"(\^|&|\||<|>|\(|\)|\""|'|\\|%|!)";
                Regex  regex        = new Regex(specialchars);
                if (regex.IsMatch(input))
                {
                    rc = 3;
                    switch (filteraction)
                    {
                    case FilterAction.Abort:
                        input = String.Empty;
                        break;

                    case FilterAction.DetectOnly:
                        break;

                    case FilterAction.EndOfInput:
                        int pos = input.IndexOfAny("^&|<>()\"'\\%!".ToCharArray( ));
                        if (pos != -1)
                        {
                            input = input.Substring(0, pos);
                        }
                        break;

                    case FilterAction.Remove:
                        input = regex.Replace(input, "");
                        break;

                    case FilterAction.WhiteSpace:
                        input = regex.Replace(input, " ");
                        break;
                    }
                }
            }

            #endregion Apply Filter to Output


            // Display the input - which should be redirected for this program to be of any use
            Console.WriteLine(input);

            // Returncode 0 for success, 2 if the input was empty or whitespace only, 3 if "forbidden" characters were detected
            if (rc != 3 && string.IsNullOrWhiteSpace(input))
            {
                rc = 2;
            }
            return(rc);
        }
Esempio n. 3
0
 public void AppendText(string text)
 {
     baseTextBox.AppendText(text);
 }