Exemple #1
0
        private void SendCurrentJson() {
            if (!socketClientAdapter.isSocketConnected()) {
                MessageBox.Show("Socket was closed.");
                return;
            }

            JObject jobj = new JObject();
            JsonData jsonData = new JsonData();

            for (int i = 0; i < currentJsonView.Items.Count; i++) {
                ListViewItem item = currentJsonView.Items[i];
                string name = item.SubItems[0].Text;
                string value = item.SubItems[1].Text;
                string type = item.SubItems[2].Text;

                if (type.Equals("string")) {
                    jobj.Add(name, value);
                } else if (type.Equals("int")) {
                    jobj.Add(name, int.Parse(value));
                } else if (type.Equals("double")) {
                    jobj.Add(name, double.Parse(value));
                }
                jsonData.AddProperty(name, value, type);
            }
            if (jobj.GetValue("request") == null) {
                MessageBox.Show("JSON must have 'request' property");
                return;
            }

            socketClientAdapter.Send(Encoding.UTF8.GetBytes(jobj.ToString()));
            AppendEventLog("Sent a json.");

            savedJsonListView.Items.Add(jobj.GetValue("request"));
            savedJsonList.Add(jsonData);
            currentJsonView.Items.Clear();
        }