Ejemplo n.º 1
0
    public starInfo(string infoString)
    {
        var lines = infoString.Split(',');

        hygID      = ParseUtility.SafeParseInt(lines[0]);
        hipID      = ParseUtility.SafeParseInt(lines[1]);
        ProperName = lines[6];

        colourIndex = ParseUtility.SafeParseFloat(lines[16]);
        color       = colourUtility.colourIndexToRGB(colourIndex);


        AppMagnitude      = ParseUtility.SafeParseFloat(lines[13]);
        AbsoluteMagnitude = ParseUtility.SafeParseFloat(lines[14]);

        position = new Vector3(
            ParseUtility.SafeParseFloat(lines[17]),
            ParseUtility.SafeParseFloat(lines[18]),
            ParseUtility.SafeParseFloat(lines[19]));

        position = Vector3.ClampMagnitude(position, 1000);

        velocity = new Vector3(
            ParseUtility.SafeParseFloat(lines[20]),
            ParseUtility.SafeParseFloat(lines[21]),
            ParseUtility.SafeParseFloat(lines[22]));
    }
Ejemplo n.º 2
0
        public static bool SupportsType(Type type)
        {
            if (!type.IsValueType || string.IsNullOrEmpty(type.AssemblyQualifiedName) || type.FullName == SYSTEM_VOID)
            {
                return(false);
            }

            if (typeSupportCache.TryGetValue(type.AssemblyQualifiedName, out var info))
            {
                return(info.IsSupported);
            }

            var supported = false;

            var fields = type.GetFields(INSTANCE_FLAGS);

            if (fields.Length > 0)
            {
                if (fields.Any(it => !ParseUtility.CanParse(it.FieldType)))
                {
                    supported = false;
                    info      = new StructInfo(supported, null);
                }
                else
                {
                    supported = true;
                    info      = new StructInfo(supported, fields);
                }
            }

            typeSupportCache.Add(type.AssemblyQualifiedName, info);

            return(supported);
        }
Ejemplo n.º 3
0
            public void SetValue(object instance, string input, int fieldIndex)
            {
                var field = Fields[fieldIndex];

                object val;

                if (field.FieldType == typeof(string))
                {
                    val = input;
                }
                else
                {
                    if (!ParseUtility.TryParse(input, field.FieldType, out val, out Exception ex))
                    {
                        ExplorerCore.LogWarning("Unable to parse input!");
                        if (ex != null)
                        {
                            ExplorerCore.Log(ex.ReflectionExToString());
                        }
                        return;
                    }
                }

                field.SetValue(instance, val);
            }
Ejemplo n.º 4
0
        public void EmptyContainers()
        {
            JsonValue value = ParseUtility.ParseAndValidate(@"{ ""dict"": { ""array"": [{}] }, ""array"": [ [], {}, [], {} ] }");

            Assert.Equal(1, value["dict"].Object.Count);
            Assert.Equal(4, value["array"].Array.Count);
        }
Ejemplo n.º 5
0
        public static object GetValue(FieldInfo field, string stringValue)
        {
            string type = field.FieldType.Name;

            if (ParseUtility.IsInt64(type))
            {
                return(long.Parse(stringValue));
            }
            if (ParseUtility.IsInt32(type))
            {
                return(int.Parse(stringValue));
            }
            if (ParseUtility.IsSingle(type))
            {
                return(float.Parse(stringValue));
            }
            if (ParseUtility.IsDouble(type))
            {
                return(double.Parse(stringValue));
            }
            if (ParseUtility.IsBoolean(type))
            {
                return(bool.Parse(stringValue));
            }
            return(stringValue);
        }
        private void OnRequestLine(string part1, string part2, string part3)
        {
            if (part1.StartsWith("http/"))
            {
                int code;
                if (!ParseUtility.TryParseInt(part2, out code))
                {
                    throw new BadRequestException(
                              string.Concat("Second word in the status line should be a HTTP code, you specified ", part2, "."));
                }

                if (_messageSerializer != null)
                {
                    _message = new HttpResponse(code, part3, part1);
                }
                else
                {
                    _message = new HttpResponseBase(code, part3, part1);
                }
            }
            else
            {
                if (!part3.StartsWith("http/"))
                {
                    throw new BadRequestException(
                              string.Concat("Status line for requests should end with the HTTP version. Your line ended with ", part3, "."));
                }

                _message = _messageSerializer != null
                    ? new HttpRequest(part1, part2, part3)
                    : new HttpRequestBase(part1, part2, part3);
            }
        }
Ejemplo n.º 7
0
            public string GetValue(object instance, int fieldIndex)
            {
                var field = Fields[fieldIndex];
                var value = field.GetValue(instance);

                return(ParseUtility.ToStringForInput(value, field.FieldType));
            }
Ejemplo n.º 8
0
        public override bool InRectange(FreeUIUtil.Rectangle rec, IEventArgs args)
        {
            if (pos == null || change)
            {
                pos = selector.Select(args);
            }
            int   px = (int)(pos.GetX());
            int   py = (int)(pos.GetY());
            float r  = 0f;

            try
            {
                r = /*float.Parse(radius)*/ ParseUtility.QuickFloatParse(radius);
            }
            catch (Exception)
            {
                r = FreeUtil.ReplaceFloat(radius, args);
            }
            float x1 = rec.x - r;
            float x2 = rec.x + rec.width + r;
            float y1 = rec.y - r;
            float y2 = rec.y + rec.height + r;

            // 圆心在矩形的加上圆半径的范围内
            return(px >= x1 && px <= x2 && py >= y1 && py <= y2);
        }
Ejemplo n.º 9
0
    public StarInfo(string csvLine)
    {
        var lines = csvLine.Split(',');

        hygId             = ParseUtility.SafeIntParse(lines[0]);
        hipId             = ParseUtility.SafeIntParse(lines[1]);
        properName        = lines[6];
        apparentMagnitude = ParseUtility.SafeFloatParse(lines[13]);
        absoluteMagnitude = ParseUtility.SafeFloatParse(lines[14]);

        colorIndex = ParseUtility.SafeFloatParse(lines[16]);
        color      = ColorUtility.ColorIndexToRGB(colorIndex);

        position = new Vector3(
            ParseUtility.SafeFloatParse(lines[17]),
            ParseUtility.SafeFloatParse(lines[18]),
            ParseUtility.SafeFloatParse(lines[19])
            );
        velocity = new Vector3(
            ParseUtility.SafeFloatParse(lines[20]),
            ParseUtility.SafeFloatParse(lines[21]),
            ParseUtility.SafeFloatParse(lines[22])
            );
        position = Vector3.ClampMagnitude(position, 1000);
    }
Ejemplo n.º 10
0
        public void ArrayEnum()
        {
            dynamic           value   = ParseUtility.ParseAndValidate(@"{ ""array"": [ 0, 1, 2, 3, 4 ] }");
            dynamic           darray  = value.array;
            dynamic           darray2 = value["array"];
            IEnumerable <int> iarray  = darray;
            IEnumerable <int> iarray2 = darray2;

            Assert.Equal(iarray, iarray2);

            object[] array = darray;
            List <KeyValuePair <string, int> > array1 = value.array;
            List <KeyValuePair <int, int> >    array2 = value.array;

            int i = 0;

            foreach (decimal child in array)
            {
                int h = (int)child;
                Assert.Equal(h, int.Parse(array1[i].Key));
                Assert.Equal(h, array1[i].Value);
                Assert.Equal(h, array2[i].Key);
                Assert.Equal(h, array2[i].Value);
                Assert.Equal(h, (int)darray[i]);
                Assert.Equal(h, i++);
            }

            for (i = 0; i < array.Length; i++)
            {
                int h = (int)(decimal)array[i];
                Assert.Equal(h, i);
            }
        }
Ejemplo n.º 11
0
        public void SimpleLookupTypes()
        {
            dynamic value = ParseUtility.ParseAndValidate(
                @"{
    ""string"": ""bar"",
    ""int"": 32,
    ""double"": 32.5,
    ""bool"": true,
    ""null"": null,
    ""array"": [ 0, 1, 2 ],
    ""dict"": { ""array"": [ 0, 1, 2 ] }
}");

            string stringValue = value.@string;
            int    intValue    = value.@int;
            double doubleValue = value.@double;
            bool   boolValue   = value.@bool;
            object nullValue   = value.@null;

            object[] arrayValue = value.array;
            IDictionary <string, object> dictValue = value.dict;

            Assert.Equal("bar", stringValue);
            Assert.Equal(32, intValue);
            Assert.Equal(32.5, doubleValue);
            Assert.True(boolValue);
            Assert.Null(nullValue);
            Assert.Equal(3, arrayValue.Length);
            Assert.Equal(1, dictValue.Count);
        }
Ejemplo n.º 12
0
        public void ToDateSuccess()
        {
            DateTime date       = new DateTime(1970, 7, 4, 12, 0, 30, 500, DateTimeKind.Local);
            dynamic  value      = ParseUtility.ParseAndValidate($@"{{ ""date"": ""{date.ToString("O", CultureInfo.InvariantCulture)}"" }}");
            DateTime parsedDate = value.date;

            Assert.Equal(date, parsedDate);
        }
Ejemplo n.º 13
0
        public void ToDateFailed()
        {
            DateTime      date  = new DateTime(1970, 7, 4, 12, 0, 30, 500, DateTimeKind.Local);
            dynamic       value = ParseUtility.ParseAndValidate($@"{{ ""date"": ""Foo{date.ToString("O", CultureInfo.InvariantCulture)}"" }}");
            JsonException ex    = Assert.Throws <JsonException>(() => (DateTime)value.date);

            Assert.IsType <FormatException>(ex.InnerException);
        }
Ejemplo n.º 14
0
        public void ParseException()
        {
            JsonException ex = Assert.Throws <JsonException>(() => ParseUtility.ParseAndValidate(@"{ ""foo"":: bar }"));

            Assert.True(ex.HasToken);
            Assert.Equal(0, ex.TokenLine);
            Assert.Equal(8, ex.TokenColumn);
            Assert.Equal(":", ex.TokenText);
        }
Ejemplo n.º 15
0
        public void ConvertArrayIntermediate2()
        {
            JsonValue value = ParseUtility.ParseAndValidate(@"[ [ 2, 4, 6, 8 ], [ 1, 3, 5 ] ]");

            int[][] ints = value.ToObject <int[][]>();

            Assert.Equal(2, ints.Length);
            Assert.Equal(new int[][] { new int[] { 2, 4, 6, 8 }, new int[] { 1, 3, 5 } }, ints);
        }
Ejemplo n.º 16
0
        public void ExceptionArray()
        {
            JsonException ex = Assert.Throws <JsonException>(() => ParseUtility.ParseAndValidate(@"{ ""foo"": [ 1, 2, { ""3"": { ""array"": [[,,]] } ] } }"));

            Assert.True(ex.HasToken);
            Assert.Equal(0, ex.TokenLine);
            Assert.Equal(37, ex.TokenColumn);
            Assert.Equal(",", ex.TokenText);
        }
Ejemplo n.º 17
0
        public void TokenException()
        {
            JsonException ex = Assert.Throws <JsonException>(() => ParseUtility.ParseAndValidate(@"{ foo: bar }"));

            Assert.True(ex.HasToken);
            Assert.Equal(0, ex.TokenLine);
            Assert.Equal(2, ex.TokenColumn);
            Assert.Equal("foo", ex.TokenText.Substring(0, 3));
        }
Ejemplo n.º 18
0
 public void WritePrimitives()
 {
     Assert.Equal("null", ParseUtility.SerializeAndValidate(null, formatted: false));
     Assert.Equal("true", ParseUtility.SerializeAndValidate(true, formatted: false));
     Assert.Equal("false", ParseUtility.SerializeAndValidate(false, formatted: false));
     Assert.Equal("\"hello world\"", ParseUtility.SerializeAndValidate("hello world", formatted: false));
     Assert.Equal("12.34", ParseUtility.SerializeAndValidate(decimal.Parse("12.34"), formatted: false));
     Assert.Equal("[1,2,3,4]", ParseUtility.SerializeAndValidate(new uint[] { 1, 2, 3, 4 }, formatted: false));
     Assert.Equal("[1,\"2\",3,null,\"01/02/2003 00:00:00\"]", ParseUtility.SerializeAndValidate(new object[] { 1, "2", 3.0, null, DateTime.Parse("1/2/2003") }, formatted: false));
 }
Ejemplo n.º 19
0
        public void DictionaryEnum()
        {
            dynamic value = ParseUtility.ParseAndValidate(@"{ ""0"": 0, ""1"": 1, ""2"": 2, ""3"": 3, ""4"": 4 }");

            foreach (KeyValuePair <string, object> pair in value)
            {
                int i = (int)(decimal)pair.Value;
                Assert.Equal(i, int.Parse(pair.Key));
            }
        }
Ejemplo n.º 20
0
        public void ConvertArrayIntermediate1()
        {
            JsonValue value = ParseUtility.ParseAndValidate(@"[ 1, 2, 3, 4 ]");

            int[]    ints    = value.ToObject <int[]>();
            object[] objects = value.ToObject <object[]>();

            Assert.Equal(4, objects.Length);
            Assert.Equal(4, ints.Length);
            Assert.Equal(new int[] { 1, 2, 3, 4 }, ints);
        }
Ejemplo n.º 21
0
        // CacheObjectCell Apply

        public virtual void OnCellApplyClicked()
        {
            if (State == ValueState.Boolean)
            {
                SetUserValue(this.CellView.Toggle.isOn);
            }
            else
            {
                if (ParseUtility.TryParse(CellView.InputField.Text, LastValueType, out object value, out Exception ex))
                {
                    SetUserValue(value);
                }
Ejemplo n.º 22
0
        public override bool IsIn(IEventArgs args, UnitPosition entity)
        {
            if (pos == null || change)
            {
                pos = selector.Select(args);
            }
            float r = 0f;

            try
            {
                r = /*float.Parse(radius)*/ ParseUtility.QuickFloatParse(radius);
            }
            catch (Exception)
            {
                r = FreeUtil.ReplaceFloat(radius, args);
            }

            double dx = MyMath.Abs(entity.GetX() - pos.GetX());

            if (dx > r)
            {
                if (useOut)
                {
                    return(true);
                }
                return(false);
            }
            double dz = MyMath.Abs(entity.GetZ() - pos.GetZ());

            if (dz > r)
            {
                if (useOut)
                {
                    return(true);
                }
                return(false);
            }
            double dy     = MyMath.Abs(entity.GetY() - pos.GetY());
            float  zrange = FreeUtil.ReplaceFloat(zRange, args);

            if (zrange <= 0)
            {
                zrange = 170;
            }

            bool isIn = (dx * dx + dz * dz) <= r * r && (dy < zrange);

            if (useOut)
            {
                return(!isIn);
            }
            return(isIn);
        }
Ejemplo n.º 23
0
        public static IPara GetPara(object obj, string field)
        {
            if (obj == null)
            {
                return(null);
            }
            FieldInfo    f    = GetField(obj, field);
            AbstractPara para = null;

            if (f != null)
            {
                string type = f.FieldType.Name;

                if (ParseUtility.IsInt64(type))
                {
                    para = new LongPara(field);
                }
                if (ParseUtility.IsInt32(type))
                {
                    para = new IntPara(field);
                }
                if (ParseUtility.IsSingle(type))
                {
                    para = new FloatPara(field);
                }
                if (ParseUtility.IsDouble(type))
                {
                    para = new DoublePara(field);
                }
                if (ParseUtility.IsString(type))
                {
                    para = new StringPara(field);
                }
                if (ParseUtility.IsBoolean(type))
                {
                    para = new BoolPara(field);
                }
                try
                {
                    if (para != null)
                    {
                        para.SetValue(f.GetValue(obj));
                    }
                }
                catch (Exception e)
                {
                    throw new GameConfigExpception(field + " is not a valid field.\n" + ExceptionUtil.GetExceptionContent(e));
                }
            }
            return(para);
        }
Ejemplo n.º 24
0
        protected virtual void SetValueState(CacheObjectCell cell, ValueStateArgs args)
        {
            // main value label
            if (args.valueActive)
            {
                cell.ValueLabel.text            = ValueLabelText;
                cell.ValueLabel.supportRichText = args.valueRichText;
                cell.ValueLabel.color           = args.valueColor;
            }
            else
            {
                cell.ValueLabel.text = "";
            }

            // Type label (for primitives)
            cell.TypeLabel.gameObject.SetActive(args.typeLabelActive);
            if (args.typeLabelActive)
            {
                cell.TypeLabel.text = SignatureHighlighter.Parse(LastValueType, false);
            }

            // toggle for bools
            cell.Toggle.gameObject.SetActive(args.toggleActive);
            if (args.toggleActive)
            {
                cell.Toggle.interactable = CanWrite;
                cell.Toggle.isOn         = (bool)Value;
                cell.ToggleText.text     = Value.ToString();
            }

            // inputfield for numbers
            cell.InputField.UIRoot.SetActive(args.inputActive);
            if (args.inputActive)
            {
                cell.InputField.Text = ParseUtility.ToStringForInput(Value, LastValueType);
                cell.InputField.Component.readOnly = !CanWrite;
            }

            // apply for bool and numbers
            cell.ApplyButton.Component.gameObject.SetActive(args.applyActive);

            // Inspect button only if last value not null.
            if (cell.InspectButton != null)
            {
                cell.InspectButton.Component.gameObject.SetActive(args.inspectActive && !LastValueWasNull);
            }

            // allow IValue for null strings though
            cell.SubContentButton.Component.gameObject.SetActive(args.subContentButtonActive && (!LastValueWasNull || State == ValueState.String));
        }
Ejemplo n.º 25
0
        public void ParseStringWithHeaders(string actual, string expected)
        {
            var actualResult = ParseUtility.ParseString(
                new HeaderStruct(() => new[] { actual }),
                string.Empty);

            actualResult.Should().Be(expected);

            actualResult = ParseUtility.ParseString(
                new HeaderStruct(() => new List<string> { actual }),
                string.Empty);

            actualResult.Should().Be(expected);
        }
Ejemplo n.º 26
0
 public override IPara Initial(string con, string v)
 {
     com.wd.free.para.BoolPara p = (com.wd.free.para.BoolPara) this.Copy();
     p.name = EMPTY_NAME;
     try
     {
         p.value = ParseUtility.QuickBoolParse(v);
     }
     catch (Exception)
     {
         p.value = false;
     }
     return(p);
 }
Ejemplo n.º 27
0
        public void DictionaryEnum()
        {
            JsonValue value = ParseUtility.ParseAndValidate(@"{ ""0"": 0, ""1"": 1, ""2"": 2, ""3"": 3, ""4"": 4 }");

            foreach (KeyValuePair <string, JsonValue> pair in value.Object)
            {
                Assert.Equal(int.Parse(pair.Key), pair.Value.Number);
            }

            foreach (string key in value.Object.Keys)
            {
                Assert.True(value.Object.ContainsKey(key));
                Assert.Equal(int.Parse(key), value[key].Number);
            }
        }
Ejemplo n.º 28
0
 public T TryGetHeaderValue <T>(string headerName, T defaultValue)
 {
     if (Headers.ContainsKey(headerName))
     {
         try
         {
             return(ParseUtility.ChangeType <T>(Headers[headerName]));
         }
         catch (Exception)
         {
             return(defaultValue);
         }
     }
     return(defaultValue);
 }
Ejemplo n.º 29
0
        public void Comment()
        {
            JsonValue value = ParseUtility.ParseAndValidate(
                @"{
/*  Comment
    Comment
    Comment */
    ""foo"":  1,
// Comment
// Comment
    ""bar"": 2
}");

            Assert.Equal(1, value["foo"].Number);
            Assert.Equal(2, value["bar"].Number);
        }
Ejemplo n.º 30
0
        public void ParseString(string actual, string expected)
        {
            var actualResult = ParseUtility.ParseString(
                (object)null,
                new FuncGetter<object>((carrier, name) => new[] { actual }),
                string.Empty);

            actualResult.Should().Be(expected);

            actualResult = ParseUtility.ParseString(
                (object)null,
                new FuncGetter<object>((carrier, name) => new List<string> { actual }),
                string.Empty);

            actualResult.Should().Be(expected);
        }