示例#1
0
        private static void DisplayParsedItems(PFParseString parse)
        {
            int    numItems;
            int    inx;
            string item;

            numItems = System.Convert.ToInt32(parse.NumItems);

            Program._messageLog.WriteLine("Use get first and next");
            item = (string)parse.GetFirst();
            while (!parse.EOL)
            {
                Program._messageLog.WriteLine(item);
                item = (string)parse.GetNext();
            }

            Program._messageLog.WriteLine("Use get last and prev");
            item = (string)parse.GetLast();
            while (!parse.EOL)
            {
                Program._messageLog.WriteLine(item);
                item = (string)parse.GetPrev();
            }

            Program._messageLog.WriteLine("for 1 to count");
            for (inx = 0; inx <= numItems - 1; inx++)
            {
                item = (string)(parse.Get(inx));
                Program._messageLog.WriteLine(inx.ToString() + ": " + item);
            }
        }
示例#2
0
        private static void GetParseKey(PFParseString parse, int key)
        {
            string sItem;

            sItem = (string)(parse.Get(key));
            Program._messageLog.WriteLine("Key: " + key.ToString() + "   Value: " + sItem + "   EOL: " + parse.EOL);
        }
示例#3
0
        public static void ParseStringAutomaticTest()
        {
            try
            {
                Program._messageLog.WriteLine("\r\n\r\nRunning ParseStringAutomaticTest ...");

                PFParseString parse         = new PFParseString();
                string        stringToParse = "";

                Program._messageLog.WriteLine("\r\nNoKey");
                parse.KeyType      = PFParseString.PFArgumentKeyType.NoKey;
                parse.Delimiters   = " ,";
                parse.QuotedValues = true;
                stringToParse      = (string)("parm1 parm2 third_parm \"this is fourth param\"");
                Program._messageLog.WriteLine("StringToParse = " + stringToParse);
                parse.StringToParse = stringToParse;

                DisplayParsedItems(parse);
                GetParseKey(parse, 2);

                Program._messageLog.WriteLine("\r\n\r\n");
                Program._messageLog.WriteLine("CharKey");
                parse.KeyType      = PFParseString.PFArgumentKeyType.CharKey;
                parse.Delimiters   = "-/";
                parse.QuotedValues = false;
                stringToParse      = "/Usa -Ume -ppassword -sSERV01 /Iineturl /Ierror";
                //sStringToParse = "/Usa -ppassword -sSERV01 /Iineturl"
                //sStringToParse = "/Usa -ppassword -s""SERV01 """"-moi-"""""" /Iineturl"
                Program._messageLog.WriteLine("StringToParse = " + stringToParse);
                parse.StringToParse = stringToParse;
                DisplayParsedItems(parse);
                GetParseKey(parse, "U");
                GetParseKey(parse, "s");
                GetParseKey(parse, "i");
                GetParseKey(parse, "/x");

                Program._messageLog.WriteLine("\r\n\r\n");
                Program._messageLog.WriteLine("NamedKey");
                parse.KeyType = PFParseString.PFArgumentKeyType.NamedKey;
                //parse.Delimiters = ",";
                parse.Delimiters   = " ,";
                parse.QuotedValues = true;
                stringToParse      = " Application=MineVer01, Username=\"Me ,And You\", Password=moi1999, Server=DOWN24HRADAY, InternetConnection=\"On The Fritz\"";
                Program._messageLog.WriteLine("StringToParse = " + stringToParse);
                //sStringToParse = "Mojo, Application=MineVer01, MidLife and cries, Username=moi, Password=moi1999, Server=DOWN24HRADAY, InternetConnection=OnTheFritz, BadLast"
                parse.StringToParse = stringToParse;
                DisplayParsedItems(parse);
                GetParseKey(parse, "Nothing");
                GetParseKey(parse, "Application");
                GetParseKey(parse, "username");
                GetParseKey(parse, "password");
                GetParseKey(parse, "InternetConnection");

                Program._messageLog.WriteLine("\r\n\r\n");
                Program._messageLog.WriteLine("NamedKey (second run)");
                parse.KeyType       = PFParseString.PFArgumentKeyType.NamedKey;
                parse.Delimiters    = " ,";
                parse.QuotedValues  = false;
                stringToParse       = "Mojo, Application=MineVer01, MidLife and cries, Username=moi, Password=moi1999, Server=DOWN24HRADAY, InternetConnection=OnTheFritz, BadLast";
                parse.StringToParse = stringToParse;
                Program._messageLog.WriteLine("StringToParse = " + stringToParse);
                DisplayParsedItems(parse);
                GetParseKey(parse, "Nothing");
                GetParseKey(parse, "Application");
                GetParseKey(parse, "username");
                GetParseKey(parse, "password");
                GetParseKey(parse, "InternetConnection");
                GetParseKey(parse, parse.NumItems - 1);
                GetParseKey(parse, "BadLast");

                Program._messageLog.WriteLine("\r\n\r\n");
                Program._messageLog.WriteLine("CharKey (using keylist");
                parse.KeyType      = PFParseString.PFArgumentKeyType.CharKey;
                parse.Delimiters   = "-/";
                parse.QuotedValues = false;
                stringToParse      = "/Usa -xme -ppassword -sSERV01 /Iineturl /eerror";
                Program._messageLog.WriteLine("StringToParse = " + stringToParse);
                parse.StringToParse = stringToParse;
                DisplayParsedItems(parse);
                Program._messageLog.WriteLine("Show KV first to last ...");
                if (parse.NumKeys > 0)
                {
                    PFParseString.PFKeyValuePair kv = parse.GetKeyValuePair(PFParseString.PFScroll.First);
                    while (kv.Key != string.Empty)
                    {
                        _msg.Length = 0;
                        _msg.Append("Key = ");
                        _msg.Append(kv.Key);
                        _msg.Append(", value = ");
                        _msg.Append(kv.Value);
                        Program._messageLog.WriteLine(_msg.ToString());
                        kv = parse.GetKeyValuePair(PFParseString.PFScroll.Next);
                    }
                }
                else
                {
                    Program._messageLog.WriteLine("ERROR: No keys found in string that was parsed. There should have been some keys.");
                }


                Program._messageLog.WriteLine("\r\n\r\nShow KV last to first ...");
                if (parse.NumKeys > 0)
                {
                    PFParseString.PFKeyValuePair kv = parse.GetKeyValuePair(PFParseString.PFScroll.Last);
                    while (kv.Key != string.Empty)
                    {
                        _msg.Length = 0;
                        _msg.Append("Key = ");
                        _msg.Append(kv.Key);
                        _msg.Append(", value = ");
                        _msg.Append(kv.Value);
                        Program._messageLog.WriteLine(_msg.ToString());
                        kv = parse.GetKeyValuePair(PFParseString.PFScroll.Previous);
                    }
                }
                else
                {
                    Program._messageLog.WriteLine("ERROR: No keys found in string that was parsed. There should have been some keys.");
                }

                Program._messageLog.WriteLine("\r\nShow params first to last ...");
                if (parse.NumItems > 0)
                {
                    string itm = parse.Get(PFParseString.PFScroll.First);
                    while (parse.EOL == false)
                    {
                        _msg.Length = 0;
                        _msg.Append("Parsed Item = ");
                        _msg.Append(itm);
                        Program._messageLog.WriteLine(_msg.ToString());
                        itm = parse.Get(PFParseString.PFScroll.Next);
                    }
                }
                else
                {
                    Program._messageLog.WriteLine("ERROR: No parsed items found in string that was parsed. There should have been some parameters.");
                }

                Program._messageLog.WriteLine("\r\nShow params last to first ...");
                if (parse.NumItems > 0)
                {
                    string itm = parse.Get(PFParseString.PFScroll.Last);
                    while (parse.EOL == false)
                    {
                        _msg.Length = 0;
                        _msg.Append("Parsed Item = ");
                        _msg.Append(itm);
                        Program._messageLog.WriteLine(_msg.ToString());
                        itm = parse.Get(PFParseString.PFScroll.Previous);
                    }
                }
                else
                {
                    Program._messageLog.WriteLine("ERROR: No parsed items found in string that was parsed. There should have been some parameters.");
                }
            }
            catch (Exception ex)
            {
                string sMessage;
                sMessage = (string)("Error occured while trying to run parse test." + "\r\n" + "\r\n" + AppMessages.FormatErrorMessage(ex));
                AppMessages.DisplayErrorMessage(sMessage, true, true);
            }
        }