예제 #1
0
        static public axis fromJson(string json)
        {
            if (jsonParser == null)
            {
                jsonParser = new Regex("\"input\": \"(.*)\",.*" +
                                       "\"key\": \"(.*)\",.*" +
                                       "\"type\": \"(.*)\",.*" +
                                       "\"isKey\": \"(.*)\",.*" +
                                       "\"name\": \"(.*)\",.*" +
                                       "\"rest\": \"(.*)\"");
            }
            MatchCollection matches = jsonParser.Matches(json);
            GroupCollection groups  = matches[0].Groups;

            string   input  = groups[1].Value;
            int      ikey   = Int32.Parse(groups[2].Value);
            KeyCode  key    = (KeyCode)ikey;
            int      itype  = Int32.Parse(groups[3].Value);
            axisType type   = (axisType)itype;
            int      iIsKey = Int32.Parse(groups[4].Value);
            bool     isKey  = (iIsKey != 0);
            string   name   = groups[5].Value;
            float    rest   = float.Parse(groups[6].Value, CultureInfo.InvariantCulture);

            axis a = new axis();

            a.input = input;
            a.key   = key;
            a.type  = type;
            a.isKey = isKey;
            a.name  = name;
            a.rest  = rest;
            return(a);
        }
예제 #2
0
 static void GetDataFromStream(StreamReader file, uint count, DataType[] output)
 {
     string[] tokens = file.ReadLine().Split(new char[] { ' ' });
     for (int i = 0; i < count; i++)
     {
         output[i] = DataType.Parse(tokens[i]);
     }
 }
예제 #3
0
        static void Main(string[] args)
        {
            MyAlias temp = Math.Min(10, 5);

            Console.WriteLine(temp);

            MyAlias result = MyAlias.Parse("42");

            Console.WriteLine(result);
        }
예제 #4
0
        public int getAmountOffers()
        {
            string myStr = this.WrappedElement.FindElement(By.XPath(".//span[@class='filter_count filter_count__inline' or @class='filter_count']")).Text;

            if (myStr.Contains("("))
            {
                myStr = myStr.Trim('(', ')');
            }
            return(Int32.Parse(myStr));
        }
예제 #5
0
        static Signal GetSignal(string wire, ref Dictionary <string, string> sourcePerWire, ref Dictionary <string, Signal> signalPerWire)
        {
            if (signalPerWire.ContainsKey(wire))
            {
                return(signalPerWire[wire]);
            }
            var source = sourcePerWire[wire];

            sourcePerWire.Remove(wire);
            Regex           regex;
            MatchCollection matches;

            Signal Value(Group valueGroup, Group wireGroup, ref Dictionary <string, string> sourcePerWire, ref Dictionary <string, Signal> signalPerWire)
            {
                if (valueGroup.Value != "")
                {
                    return(Signal.Parse(valueGroup.Value));
                }
                return(GetSignal(wireGroup.Value, ref sourcePerWire, ref signalPerWire));
            }

            Signal SetSignal(string wire, Signal signal, ref Dictionary <string, Signal> signalPerWire)
            {
                if (signalPerWire.ContainsKey(wire))
                {
                    throw new Exception(String.Format("SignalPerWire already contains value {0} for wire {1}. Cannot insert value {2}", signalPerWire[wire], wire, signal));
                }
                signalPerWire[wire] = signal;
                return(signal);
            }

            // BINARY OPERATORS
            regex   = new Regex(@"^((?<lhs_value>\d+)|(?<lhs_wire>[a-z]+)) (?<operator>AND|OR|LSHIFT|RSHIFT) ((?<rhs_value>\d+)|(?<rhs_wire>[a-z]+))$", RegexOptions.None);
            matches = regex.Matches(source);
            if (matches.Count() == 1)
            {
                Signal value;
                var    groups = matches[0].Groups;
                var    op     = groups["operator"].Value;
                var    lhs    = Value(groups["lhs_value"], groups["lhs_wire"], ref sourcePerWire, ref signalPerWire);
                var    rhs    = Value(groups["rhs_value"], groups["rhs_wire"], ref sourcePerWire, ref signalPerWire);
                switch (op)
                {
                case "AND":
                    value = lhs & rhs;
                    break;

                case "OR":
                    value = lhs | rhs;
                    break;

                case "LSHIFT":
                    value = (lhs << rhs) & 0xffff;
                    break;

                case "RSHIFT":
                    value = lhs >> rhs;
                    break;

                default:
                    throw new Exception(String.Format("Unknown binary operatior {0}", op));
                }
                return(SetSignal(wire, value, ref signalPerWire));
            }

            // UNARY OPERATOR
            regex   = new Regex(@"^NOT ((?<value>\d+)|(?<wire>[a-z]+))$", RegexOptions.None);
            matches = regex.Matches(source);
            if (matches.Count() == 1)
            {
                var groups = matches[0].Groups;
                var value  = (~Value(groups["value"], groups["wire"], ref sourcePerWire, ref signalPerWire)) & 0xffff;
                return(SetSignal(wire, value, ref signalPerWire));
            }

            // ASSIGNMENT
            regex   = new Regex(@"^(?<value>\d+)|(?<wire>[a-z]+)$", RegexOptions.None);
            matches = regex.Matches(source);
            if (matches.Count() == 1)
            {
                var groups = matches[0].Groups;
                var value  = Value(groups["value"], groups["wire"], ref sourcePerWire, ref signalPerWire);
                return(SetSignal(wire, value, ref signalPerWire));
            }

            throw new Exception(String.Format("Unknown instruction {0} for wire {1}", source, wire));
        }
 private async void Button_Click(object sender, RoutedEventArgs e)
 {
     var userID     = Int32.Parse(inputId.Text);
     var letterList = await GetAllLettersForUser(userID);
 }