Beispiel #1
0
        public ThemeForm(JsonArray themes)
        {
            this.StartPosition = FormStartPosition.Manual;
            this.Location = MainForm.StartPos;

            Controls.AddRange(new Control[3] {ThemeLabel,ThemeBox,ConfirmButton});

            ThemeLabel.Text = "Theme: ";
            for (int i = 0; i < themes.Count; i++)
            {
                ThemeBox.Items.Add(themes[i].ToString());
            }
            ThemeBox.SelectedItem = ThemeBox.Items[0];
            ConfirmButton.Text = "Confirm";

            ThemeLabel.Location = new Point(10, 10);
            ThemeLabel.Size = new Size(50,20);
            ThemeBox.Location = new Point(60, 10);
            ThemeBox.Size = new Size(200,20);
            ThemeBox.Text = "0";

            ConfirmButton.Location = new Point(10, 35);
            ConfirmButton.Width = 250;
            ConfirmButton.Click += delegate
            {
                Theme = ThemeBox.SelectedItem.ToString();
                Close();
            };

            Size = new Size(290,105);
        }
        public void Clear()
        {
            JsonArray a = new JsonArray { 1 };
            Assert.AreEqual(1, a.Count);

            a.Clear();
            Assert.AreEqual(0, a.Count);
        }
 public static string Params2Json(params object[] objs)
 {
     JsonArray json = new JsonArray();
     foreach (object obj in objs)
     {
         json.Add(obj);
     }
     return json.ToString();
 }
        public void Contains()
        {
            int v = 1;

            JsonArray a = new JsonArray { v };

            Assert.IsFalse(a.Contains(2));
            Assert.IsFalse(a.Contains(null));
            Assert.IsTrue(a.Contains(v));
        }
Beispiel #5
0
        public void Remove()
        {
            object v = 1;
            JsonArray j = new JsonArray();
            j.Add(v);

            Assert.AreEqual(1, j.Count);

            Assert.AreEqual(false, j.Remove(2));
            Assert.AreEqual(false, j.Remove(null));
            Assert.AreEqual(true, j.Remove(v));
            Assert.AreEqual(false, j.Remove(v));

            Assert.AreEqual(0, j.Count);
        }
        public void IndexOf()
        {
            object v1 = 1;
            object v2 = 2;
            object v3 = 3;

            JsonArray j = new JsonArray();
            j.Add(v1);

            Assert.AreEqual(0, j.IndexOf(v1));

            j.Add(v2);
            Assert.AreEqual(0, j.IndexOf(v1));
            Assert.AreEqual(1, j.IndexOf(v2));
        }
        public void Insert()
        {
            object v1 = 1;
            object v2 = 2;
            object v3 = 3;
            object v4 = 4;

            JsonArray j = new JsonArray();

            j.Add(v1);
            j.Add(v2);
            j.Add(v3);
            j.Insert(1, v4);

            Assert.AreEqual(0, j.IndexOf(v1));
            Assert.AreEqual(1, j.IndexOf(v4));
            Assert.AreEqual(2, j.IndexOf(v2));
            Assert.AreEqual(3, j.IndexOf(v3));
        }
Beispiel #8
0
    private void LoadHeroList()
    {
        string str = ResourceManager.Instance.LoadText(DataPath.HeroList);

        SimpleJson.JsonObject obj = SimpleJson.SimpleJson.DeserializeObject(str) as SimpleJson.JsonObject;
        obj = obj["result"] as SimpleJson.JsonObject;
        SimpleJson.JsonArray heroes = obj["heroes"] as SimpleJson.JsonArray;
        _heroList = new List <HeroBase>();
        for (int i = 0; i < heroes.Count; i++)
        {
            SimpleJson.JsonObject hero = heroes[i] as SimpleJson.JsonObject;
            HeroBase hb = new HeroBase();
            hb.dbName      = hero[0].ToString();
            hb.dbNameShort = hb.dbName.Substring(14);
            hb.id          = int.Parse(hero[1].ToString());
            hb.localName   = hero[2].ToString();
            hb.smallImg    = "UI/Image/heroes/selection/" + hb.dbName;
            hb.bigImg      = "UI/Image/heroes/" + hb.dbNameShort;
            _heroList.Add(hb);
        }
    }
 public void Set(JsonArray array, ListKind listKind)
 {
     var names = array.ConvertAll(x => x.ToString()).Where(x => !string.IsNullOrWhiteSpace(x));
     Set(names, listKind);
 }
 public void InsertNegativeIndexShouldThrow()
 {
     JsonArray j = new JsonArray();
     j.Insert(-1, 1);
 }
Beispiel #11
0
 public static int GetIntAt(this JsonArray obj, int index)
 {
     return((int)(long)obj[index]);
 }
Beispiel #12
0
        void TextBlockTips__Changed(object sender, TextChangedEventArgs e)
        {
            //this.ButtonApplyConfig_.IsEnabled = true;

            // Tips
            string[] tips = this.TextBlockTips_.Text.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
            JsonArray tipsArray = new JsonArray();
            foreach (string tip in tips)
            {
                tipsArray.Add(tip);
            }
            Config["Tips"] = tipsArray;

            SaveConfigFile();
        }
        public void InsertNull()
        {
            JsonArray j = new JsonArray();
            j.Insert(0, null);

            Assert.AreEqual(null, j[0]);
        }
Beispiel #14
0
 public override void Add (JsonNode aItem)
 {
     var tmp = new JsonArray();
     tmp.Add(aItem);
     Set(tmp);
 }
Beispiel #15
0
        public static JsonNode Deserialize(System.IO.BinaryReader aReader)
        {
            JSONBinaryTag type = (JSONBinaryTag)aReader.ReadByte();
            switch(type)
            {
            case JSONBinaryTag.Array:
            {
                int count = aReader.ReadInt32();
                JsonArray tmp = new JsonArray();
                for(int i = 0; i < count; i++)
                    tmp.Add(Deserialize(aReader));
                return tmp;
            }
            case JSONBinaryTag.Class:
            {
                int count = aReader.ReadInt32();                
                JsonClass tmp = new JsonClass();
                for(int i = 0; i < count; i++)
                {
                    string key = aReader.ReadString();
                    var val = Deserialize(aReader);
                    tmp.Add(key, val);
                }
                return tmp;
            }
            case JSONBinaryTag.Value:
            {
                return new JsonData(aReader.ReadString());
            }
            case JSONBinaryTag.IntValue:
            {
                return new JsonData(aReader.ReadInt32());
            }
            case JSONBinaryTag.DoubleValue:
            {
                return new JsonData(aReader.ReadDouble());
            }
            case JSONBinaryTag.BoolValue:
            {
                return new JsonData(aReader.ReadBoolean());
            }
            case JSONBinaryTag.FloatValue:
            {
                return new JsonData(aReader.ReadSingle());
            }
 
            default:
            {
                throw new Exception("Error deserializing Json. Unknown tag: " + type);
            }
            }
        }
        public void Iterate()
        {
            JsonArray a = new JsonArray { 1, 2, 3, 4, 5 };

            int i = 1;
            foreach (object o in a)
            {
                Assert.AreEqual(i, o);
                ++i;
            }
        }
        public void Item()
        {
            object v1 = 1;
            object v2 = 2;
            object v3 = 3;
            object v4 = 4;

            JsonArray j = new JsonArray();

            j.Add(v1);
            j.Add(v2);
            j.Add(v3);

            j[1] = v4;

            Assert.AreEqual(-1, j.IndexOf(v2));
            Assert.AreEqual(1, j.IndexOf(v4));
        }
        public void InsertShouldInsertAtZeroIndex()
        {
            object v1 = 1;
            object v2 = 2;

            JsonArray j = new JsonArray();

            j.Insert(0, v1);
            Assert.AreEqual(0, j.IndexOf(v1));

            j.Insert(0, v2);
            Assert.AreEqual(1, j.IndexOf(v1));
            Assert.AreEqual(0, j.IndexOf(v2));
        }
 public void InsertOutOfRangeIndexShouldThrow()
 {
     JsonArray j = new JsonArray();
     j.Insert(2, 1);
 }
Beispiel #20
0
 /// <summary>
 /// Приводит объект в массиве к указанному типу
 /// </summary>
 public static T GetAt <T>(this JsonArray obj, int index)
 {
     return((T)obj[index]);
 }
        public void RemoveAt()
        {
            object v1 = 1;
            object v2 = 2;
            object v3 = 3;

            JsonArray j = new JsonArray();
            j.Add(v1);
            j.Add(v2);
            j.Add(v3);

            Assert.AreEqual(true, j.Contains(v1));
            j.RemoveAt(0);
            Assert.AreEqual(false, j.Contains(v1));

            Assert.AreEqual(true, j.Contains(v3));
            j.RemoveAt(1);
            Assert.AreEqual(false, j.Contains(v3));

            Assert.AreEqual(1, j.Count);
        }
Beispiel #22
0
 public static float GetFloatAt(this JsonArray obj, int index)
 {
     return(Convert.ToSingle(obj[index]));
 }
Beispiel #23
0
 public override JsonNode this[int aIndex]
 {
     get
     {
         return new JsonLazyCreator(this);
     }
     set
     {
         var tmp = new JsonArray();
         tmp.Add(value);
         Set(tmp);
     }
 }
 public void RemoveAtOutOfRangeIndexShouldBeError()
 {
     JsonArray j = new JsonArray();
     j.RemoveAt(0);
 }
 /// <summary>
 /// Encode the array type.
 /// </summary>
 private int encodeArray(JsonArray msg, JsonObject value, int offset, byte[] buffer, JsonObject proto)
 {
     object value_type, value_tag;
     if (value.TryGetValue("type", out value_type) && value.TryGetValue("tag", out value_tag))
     {
         if (this.util.isSimpleType(value_type.ToString()))
         {
             offset = this.writeBytes(buffer, offset, this.encodeTag(value_type.ToString(), Convert.ToInt32(value_tag)));
             offset = this.writeBytes(buffer, offset, Encoder.encodeUInt32((uint)msg.Count));
             foreach (object item in msg)
             {
                 offset = this.encodeProp(item, value_type.ToString(), offset, buffer, null);
             }
         }
         else
         {
             foreach (object item in msg)
             {
                 offset = this.writeBytes(buffer, offset, this.encodeTag(value_type.ToString(), Convert.ToInt32(value_tag)));
                 offset = this.encodeProp(item, value_type.ToString(), offset, buffer, proto);
             }
         }
     }
     return offset;
 }
 public void RemoveNegtiveIndexShouldBeError()
 {
     JsonArray j = new JsonArray();
     j.RemoveAt(-1);
 }