Пример #1
0
        }                                  // Grabs a double and returns it

        //Display Menu
        static void displayAndGrabMenuOption()
        {
            /*
             * All you have to do is add the function name to the list and list options and your set
             * The list calls it and then loops back to Main.
             * Making sure that the user input is a number was more work.
             */

            int method_to_run;

            string[]      list_options = { "Package price finder", "Temperature to array", "Book Discounts", "Overtime Calculator", "Lots of Numbers", "Lots of Strings" }; // Names of Menu options
            List <Action> functionList = new List <Action>();                                                                                                               // Makes a new list to hold the functions

            functionList.AddRange(new Action[] { runPackagePrice, tempPushArray, howManyBooks, hoursWorked, intHandling, stringHandling });                                 // Adds functions to the lists


            // Loops thru menu options
            for (int i = 0; i < list_options.Length; i++)
            {
                Console.WriteLine("{0}: {1}", i + 1, list_options[i]);
            }

            method_to_run = StringParse.Int("Pick an option from 1 to " + list_options.Length);

            functionList[method_to_run - 1]();

            Console.Clear();
        }                               // Holds the method calls and menu options
Пример #2
0
        }                                  // Uses the list Distinct call and displays all of it

        static void findValue(double[] data)
        {
            int        arr_value;
            List <int> positions = new List <int>();


            Console.WriteLine("Enter the digit you want to find. Will return all instances of value and place in array.");
            arr_value = StringParse.Int("Value");

            for (int i = 0; i < data.Length; i++)
            {
                if (data[i] == arr_value)
                {
                    positions.Add(i);
                }
            }

            Console.Write("{0} was found at positon(s): ", arr_value);
            foreach (int i in positions)
            {
                Console.Write(" |{0}| ", i);
            }

            Console.WriteLine();
        }                                 // Loops thru the array and checks for the given double. Returns position of array if found
Пример #3
0
        }                                          // Calculates temperature based on user input for all the months

        static double getTemp(string month)
        {
            double temp;

            Console.Write("How hot was it in {0}: ", month);

            temp = StringParse.Double();

            return(temp);
        }                                  // Grabs a double and returns it
Пример #4
0
        }                         // More range practice

        static double getPackWeight()
        {
            double number;

            Console.Write("Enter the package weight: ");

            number = StringParse.Double();

            return(number);
        }                                        // Grabs a double of package weight
        public void SetEquipmentData()
        {
            var unit = _unitsMenuController.Roster.ActiveUnit.UnitData;

            foreach (var equipmentData in unit.Outfit)
            {
                var equipmentKey = StringParse.GetItemKey(equipmentData);
                var equipment    = _productsController.GetProduct(equipmentKey);
                var qualityKey   = StringParse.GetItemQualityKey(equipmentData);
                var quality      = EnumParse.ParseStringToEnum <ItemQuality>(qualityKey);
                _cells.First(x => x.Group == equipment.ProductGroup).SetEquipmentData(equipment, quality);
            }
        }
Пример #6
0
        }                                            // Calculates overtime pay based on hours and given payrate

        // Book Thing
        static void howManyBooks()
        {
            int    book_num;
            double book_price;
            double total_cost;
            double total_cost_discounted;
            double discount;

            Console.Write("How many books are you gonna need: ");
            book_num = StringParse.Int();

            Console.Write("How much does the book cost: ");
            book_price = StringParse.Double();

            discount              = discountDecider(book_num);
            total_cost            = book_num * book_price;
            total_cost_discounted = total_cost * discount;

            Console.WriteLine("You have received a discount of {0} off!", (discount).ToString("0%"));
            Console.WriteLine("Your total is {0}", (total_cost - discount).ToString("$0.00"));
            Console.WriteLine("Without the discount your total would have been {0}", (total_cost).ToString("$0.00"));
            Console.WriteLine("You saved {0} from your discount.", (total_cost_discounted).ToString("$0.00"));
        }                                           // Calculates a discount rate and discount amount based on number of books bought
Пример #7
0
        // Overtime compensation
        static void hoursWorked()
        {
            double hours;
            double overtime    = 0;
            double hourly_wage = 11.50;
            double overtime_payed;
            double regular_wage;
            double total_amount;

            Console.Write("How many hours have you worked this week: ");

            hours = StringParse.Double();

            if (hours < 40)
            {
                Console.WriteLine("No overtime this week.");
            }
            else
            {
                overtime = hours - 40;

                Console.WriteLine("You have {0} hours of overtime this week", overtime);
            }

            overtime_payed = (overtime * hourly_wage) * 1.5;
            regular_wage   = hours * hourly_wage;
            total_amount   = overtime_payed + regular_wage;

            Console.WriteLine(
                "Total overtime payed this week is {0} \n" +
                "Total non-overtime payed this week is {1} \n" +
                "Total amount earned this week is {2}"
                , overtime_payed
                , regular_wage
                , total_amount
                );
        }                                            // Calculates overtime pay based on hours and given payrate
Пример #8
0
        static void stringHandleMenu(List <string> data)
        {
            Console.Clear();

            int  menu_option_position;
            bool exit = false;

            string[] menu_titles = { "Find Entry" };

            foreach (string i in menu_titles)
            {
                Console.WriteLine("{0}: {1}", i.IndexOf(i) + 1, i);
            }

            menu_option_position = StringParse.Int("Command Option [1/" + menu_titles.Length + "]");

            switch (menu_option_position)
            {
            case 1:
                findEntry(data);
                break;

            case 6:
                exit = true;
                break;

            default:
                Console.WriteLine("Command not recognized");
                break;
            }

            if (!exit)
            {
                stringHandleMenu(data);
            }
        }
Пример #9
0
        StringParse stringParse = new StringParse();                            // New String Parser from better basics

        // String Handling
        static void stringHandling()
        {
            Console.Clear();

            string        current_string = "a";
            List <string> data           = new List <string>();

            Console.WriteLine("Enter strings, enter -1 to go to the options menu");

            while (StringParse.IntVarParse(current_string) != -1)
            {
                Console.Write("Input: ");
                current_string = Console.ReadLine();

                if (StringParse.IntVarParse(current_string) == -1)
                {
                    stringHandleMenu(data);
                }
                else
                {
                    data.Add(current_string);
                }
            }
        }
Пример #10
0
 static void Prefix(ref string msg)
 {
     msg = StringParse.ProfanityFilter(msg);
 }
Пример #11
0
        private IXmlAttributeValue ParseAttributeValueAspect(IXmlAttributeValue xmlAttributeValue, CompositeElement newAttributeValue, StringParse stringParse)
        {
            if (xmlAttributeValue == null) throw new ArgumentNullException("xmlAttributeValue");
            if (newAttributeValue == null) throw new ArgumentNullException("newAttributeValue");
            if (stringParse == null) throw new ArgumentNullException("stringParse");
            CompositeElement result = null;

            string rawValue = xmlAttributeValue.UnquotedValue;

            try
            {
                result = stringParse(rawValue);
            }
            catch (SyntaxError syntaxError)
            {
                result = (CompositeElement)syntaxError.ParsingResult;
                result = handleError(result, syntaxError);
            }

            newAttributeValue.AddChild(new XmlToken(L4NTokenNodeType.QUOTE, new StringBuffer(new string('\"', 1)), 0, 1));
            newAttributeValue.AddChild(result);
            int resultLegth = result.GetText().Length;
            if(resultLegth < rawValue.Length)
            {
                string suffix = rawValue.Substring(resultLegth);
                StringBuffer sb = new StringBuffer(suffix);
                XmlToken suffixToken = new XmlToken(L4NTokenNodeType.TEXT , sb, 0, suffix.Length);
                newAttributeValue.AddChild(suffixToken);
            }
            newAttributeValue.AddChild(new XmlToken(L4NTokenNodeType.QUOTE, new StringBuffer(new string('\"', 1)), 0, 1));

            return (IXmlAttributeValue)newAttributeValue;
        }
Пример #12
0
        public static DeviceStates AnalysisData(Rs485ModelForParal rs485ModelForParal)
        {
            string[]  strArray1  = new string[4];
            States[]  partStates = new States[5];
            int       num1       = ((IEnumerable <string>)Rs485Parse.WorkState).ToList <string>().IndexOf(rs485ModelForParal.WorkState);
            CurOrited curOrited;

            switch (num1)
            {
            case 2:
            case 3:
            case 4:
            case 6:
                string[] strArray2 = strArray1;
                curOrited = CurOrited.ELtoR;
                string str1 = curOrited.ToString();
                strArray2[2] = str1;
                break;
            }
            int    result1;
            double numFromString;

            if (int.TryParse(Regex.Match(rs485ModelForParal.PGrid, "\\d+").Value, out result1))
            {
                numFromString = StringParse.GetNumFromString(rs485ModelForParal.RatedPower);
                double result2;
                int    num2 = double.TryParse(numFromString.ToString((IFormatProvider)CultureInfo.InvariantCulture), out result2) ? 1 : 0;
                numFromString = StringParse.GetNumFromString(rs485ModelForParal.InverterSoftwareVersion.Replace(".", ""));
                double result3;
                bool   flag = double.TryParse(numFromString.ToString((IFormatProvider)CultureInfo.InvariantCulture), out result3);
                int    num3 = (int)result2;
                int    num4 = (int)result3;
                int    num5 = flag ? 1 : 0;
                if ((num2 & num5) != 0 && num4 > 20000 && (num3 == 20000 || num3 == 3000) && (num1 == 3 || num1 == 4 || num1 == 6))
                {
                    string[] strArray3 = strArray1;
                    curOrited = CurOrited.NTtoB;
                    string str2 = curOrited.ToString();
                    strArray3[1] = str2;
                }
                else if (num1 == 6)
                {
                    string[] strArray3 = strArray1;
                    curOrited = CurOrited.NTtoB;
                    string str2 = curOrited.ToString();
                    strArray3[1] = str2;
                }
                else
                {
                    if (result1 > 0)
                    {
                        string[] strArray3 = strArray1;
                        curOrited = CurOrited.NBtoT;
                        string str2 = curOrited.ToString();
                        strArray3[1] = str2;
                    }
                    if (result1 < 0)
                    {
                        string[] strArray3 = strArray1;
                        curOrited = CurOrited.NTtoB;
                        string str2 = curOrited.ToString();
                        strArray3[1] = str2;
                    }
                }
            }
            numFromString = StringParse.GetNumFromString(rs485ModelForParal.BattCurrent);
            double result4;

            if (double.TryParse(numFromString.ToString((IFormatProvider)CultureInfo.InvariantCulture), out result4))
            {
                if (num1 == 6)
                {
                    string[] strArray3 = strArray1;
                    curOrited = CurOrited.SBtoT;
                    string str2 = curOrited.ToString();
                    strArray3[3] = str2;
                }
                else
                {
                    if (result4 > 0.0)
                    {
                        string[] strArray3 = strArray1;
                        curOrited = CurOrited.SBtoT;
                        string str2 = curOrited.ToString();
                        strArray3[3] = str2;
                    }
                    if (result4 < 0.0)
                    {
                        string[] strArray3 = strArray1;
                        curOrited = CurOrited.STtoB;
                        string str2 = curOrited.ToString();
                        strArray3[3] = str2;
                    }
                    if (result1 == 0 && Math.Abs(result4) < 0.1)
                    {
                        string[] strArray3 = strArray1;
                        curOrited = CurOrited.SBtoT;
                        string str2 = curOrited.ToString();
                        strArray3[3] = str2;
                    }
                }
            }
            numFromString = StringParse.GetNumFromString(rs485ModelForParal.ChargerPower);
            double result5;

            if (double.TryParse(numFromString.ToString((IFormatProvider)CultureInfo.InvariantCulture), out result5) && (int)result5 != 0)
            {
                string[] strArray3 = strArray1;
                curOrited = CurOrited.WLtoR;
                string str2 = curOrited.ToString();
                strArray3[0] = str2;
            }
            double?soc = new double?(100.0);

            string[] curOrient = strArray1;
            return(new DeviceStates(partStates, soc, curOrient));
        }
Пример #13
0
		public static TableMeta ToMeta(string tableName)
		{
            // Parse a string like;
            // CREATE TABLE SimpleTable ([Id] long not null,[Test] nvarchar(300) ,[When] date , PRIMARY KEY ([Id] ))
			
            TableMeta meta = new TableMeta {ParameterizedTableName = tableName};

			string schema = GetDbSchemaFor( tableName );
			if (string.IsNullOrEmpty( schema ))
				return null;

			StringParse parse = new StringParse( schema );
			if (!parse.Read("CREATE TABLE " + tableName + " ("))
				return null;
			
			while (!parse.Peek(")") && !parse.IsEmpty)
			{
                parse.SkipWhitespace();


				if (parse.Peek("[") || parse.Contains(' '))
				{
                    string fieldName;
                    if (parse.Peek("["))
                    {
                        fieldName = parse.ReadBetween('[', ']');
                    }
                    else
                    {
                        if (parse.Peek("PRIMARY KEY"))
                            break;

                        fieldName = parse.ReadTo(' ');                        
                    }

                    parse.SkipWhitespace();

					TableColumn tc = new TableColumn
					                 	{
					                 		Name = fieldName,
					                 		Get = (t, inst) => ((AnonmousTable) inst)[ t.RawName ],
					                 		Set = (t, inst, val) => ((AnonmousTable) inst)[ t.RawName ] = val
					                 	};

					parse.While( KeywordTriggerDefinitions, tc );

                    meta.Columns.Add(tc);
				}

                if (parse.Peek(","))
                {
                    parse.Read(",");
                    continue;
                }

                if (parse.Peek(")"))
                    break;

                if (parse.Peek("PRIMARY KEY"))
                    break;
             
  				throw new NotImplementedException("Incomplete parsing of " + tableName);
			}

			return meta;
		}
Пример #14
0
        static void intHandleMenu(double[] data)
        {
            int  choice;
            bool exit = false;

            string[] options = { "List all Data", "Find Average", "Find all unique", "Find all Specific", "New Dataset", "Import Dataset", "Exit" };

            Console.WriteLine("What do you want to do with the data set?");

            for (int i = 0; i < options.Length; i++)
            {
                Console.WriteLine("{0}: {1}", i + 1, options[i]);
            }
            // This just lists the menu options
            Console.Write("Data: ");
            choice = StringParse.Int();

            switch (choice)                                                     //  Just picks the correct function to run
            {
            case 1:
                Console.Clear();
                listAllData(data);
                break;

            case 2:
                Console.Clear();
                findAverage(data);
                break;

            case 3:
                Console.Clear();
                listUniq(data);
                break;

            case 4:
                Console.Clear();
                findValue(data);
                break;

            case 5:
                Console.Clear();
                intHandling();
                break;

            case 6:
                Console.Clear();
                intHandleMenu(importFile());
                break;

            case 7:
                Console.Clear();
                exit = true;
                break;

            default:
                Console.Clear();
                Console.WriteLine("Command not recognized");
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
                break;
            }

            if (!exit)
            {
                intHandleMenu(data);
            }
        }                                      // Holds all the menu options for data handler
Пример #15
0
        public static DeviceStates AnalysisData(Rs485ModelForParal rs485ModelForParal)
        {
            string[] strArray1  = new string[4];
            States[] partStates = new States[5];
            int      num1       = 0;
            int      num2       = ((IEnumerable <string>)Rs485Parse.WorkState).ToList <string>().IndexOf(rs485ModelForParal.WorkState);

            Rs485Parse.CurOrited curOrited;
            switch (num2)
            {
            case 2:
            case 3:
            case 4:
            case 6:
                string[] strArray2 = strArray1;
                curOrited = Rs485Parse.CurOrited.ELtoR;
                string str1 = curOrited.ToString();
                strArray2[2] = str1;
                break;
            }
            (double dNo, int iNo, string dNoStr, string iNoStr, bool isConverted)num3 = StringParse.GetNum(rs485ModelForParal.PGrid, 1);
            if (num3.isConverted)
            {
                num1 = num3.iNo;
                double result1;
                int    num4 = double.TryParse(StringParse.GetNumFromString(rs485ModelForParal.RatedPower).ToString((IFormatProvider)CultureInfo.InvariantCulture), out result1) ? 1 : 0;
                double result2;
                bool   flag = double.TryParse(StringParse.GetNumFromString(rs485ModelForParal.InverterSoftwareVersion.Replace(".", "")).ToString((IFormatProvider)CultureInfo.InvariantCulture), out result2);
                int    num5 = (int)result1;
                int    num6 = (int)result2;
                int    num7 = flag ? 1 : 0;
                if ((num4 & num7) != 0 && num6 > 20000 && (num5 == 20000 || num5 == 3000) && (num2 == 3 || num2 == 4 || num2 == 6))
                {
                    string[] strArray3 = strArray1;
                    curOrited = Rs485Parse.CurOrited.NTtoB;
                    string str2 = curOrited.ToString();
                    strArray3[1] = str2;
                }
                else if (num2 == 6)
                {
                    string[] strArray3 = strArray1;
                    curOrited = Rs485Parse.CurOrited.NTtoB;
                    string str2 = curOrited.ToString();
                    strArray3[1] = str2;
                }
                else
                {
                    if (num1 > 0)
                    {
                        string[] strArray3 = strArray1;
                        curOrited = Rs485Parse.CurOrited.NBtoT;
                        string str2 = curOrited.ToString();
                        strArray3[1] = str2;
                    }
                    if (num1 < 0)
                    {
                        string[] strArray3 = strArray1;
                        curOrited = Rs485Parse.CurOrited.NTtoB;
                        string str2 = curOrited.ToString();
                        strArray3[1] = str2;
                    }
                }
            }
            double result;

            if (double.TryParse(StringParse.GetNumFromString(rs485ModelForParal.BattCurrent).ToString((IFormatProvider)CultureInfo.InvariantCulture), out result))
            {
                if (num2 == 6)
                {
                    string[] strArray3 = strArray1;
                    curOrited = Rs485Parse.CurOrited.SBtoT;
                    string str2 = curOrited.ToString();
                    strArray3[3] = str2;
                }
                else
                {
                    if (result > 0.0)
                    {
                        string[] strArray3 = strArray1;
                        curOrited = Rs485Parse.CurOrited.SBtoT;
                        string str2 = curOrited.ToString();
                        strArray3[3] = str2;
                    }
                    if (result < 0.0)
                    {
                        string[] strArray3 = strArray1;
                        curOrited = Rs485Parse.CurOrited.STtoB;
                        string str2 = curOrited.ToString();
                        strArray3[3] = str2;
                    }
                    if (num1 == 0 && Math.Abs(result) < 0.1)
                    {
                        string[] strArray3 = strArray1;
                        curOrited = Rs485Parse.CurOrited.SBtoT;
                        string str2 = curOrited.ToString();
                        strArray3[3] = str2;
                    }
                }
            }
            if (((IEnumerable <string>)Rs485Parse.ChargerWorkstate).ToList <string>().IndexOf(rs485ModelForParal.ChargerWorkstate) == 2)
            {
                string[] strArray3 = strArray1;
                curOrited = Rs485Parse.CurOrited.WLtoR;
                string str2 = curOrited.ToString();
                strArray3[0] = str2;
            }
            double?soc = new double?(100.0);

            string[] curOrient = strArray1;
            return(new DeviceStates(partStates, soc, curOrient));
        }
Пример #16
0
        public static TableMeta ToMeta(string tableName)
        {
            // Parse a string like;
            // CREATE TABLE SimpleTable ([Id] long not null,[Test] nvarchar(300) ,[When] date , PRIMARY KEY ([Id] ))

            TableMeta meta = new TableMeta {
                ParameterizedTableName = tableName
            };

            string schema = GetDbSchemaFor(tableName);

            if (string.IsNullOrEmpty(schema))
            {
                return(null);
            }

            StringParse parse = new StringParse(schema);

            if (!parse.Read("CREATE TABLE " + tableName + " ("))
            {
                return(null);
            }

            while (!parse.Peek(")") && !parse.IsEmpty)
            {
                parse.SkipWhitespace();


                if (parse.Peek("[") || parse.Contains(' '))
                {
                    string fieldName;
                    if (parse.Peek("["))
                    {
                        fieldName = parse.ReadBetween('[', ']');
                    }
                    else
                    {
                        if (parse.Peek("PRIMARY KEY"))
                        {
                            break;
                        }

                        fieldName = parse.ReadTo(' ');
                    }

                    parse.SkipWhitespace();

                    TableColumn tc = new TableColumn
                    {
                        Name = fieldName,
                        Get  = (t, inst) => ((AnonmousTable)inst)[t.RawName],
                        Set  = (t, inst, val) => ((AnonmousTable)inst)[t.RawName] = val
                    };

                    parse.While(KeywordTriggerDefinitions, tc);

                    meta.Columns.Add(tc);
                }

                if (parse.Peek(","))
                {
                    parse.Read(",");
                    continue;
                }

                if (parse.Peek(")"))
                {
                    break;
                }

                if (parse.Peek("PRIMARY KEY"))
                {
                    break;
                }

                throw new NotImplementedException("Incomplete parsing of " + tableName);
            }

            return(meta);
        }