示例#1
0
        private void LoadFromFile(string fileName)
        {
            string json = File.ReadAllText(fileName);

            JsonViewer.ShowTab(Tabs.Viewer);
            JsonViewer.Json = json;
        }
        private void LoadFromFile(string fileName)
        {
            string json = File.ReadAllText(fileName);

            JsonViewer.ShowTab(Tabs.Viewer);
            JsonViewer.refreshFromString(json);
        }
示例#3
0
 public override void AddToTab(TabPage tabPage)
 {
     viewer       = new JsonViewer();
     tabPage.Text = "JSON";
     tabPage.Controls.Add(viewer);
     viewer.Dock = DockStyle.Fill;
 }
        public MainWindow()
        {
            InitializeComponent();

            //Switch between the two modes of loading the JSON

            try
            {
                var client = new WebClient {
                    Proxy = null
                };
                client.DownloadStringCompleted += delegate(object sender, DownloadStringCompletedEventArgs args)
                {
                    JsonViewer.Load(args.Result);
                    TextBlock.Text = "Loading finished";
                };
                TextBlock.Text = "Loading...";

                // Choose 1
                //client.DownloadStringAsync(new Uri("http://jsonplaceholder.typicode.com/posts"));
                //client.DownloadStringAsync(new Uri("http://jsonplaceholder.typicode.com/comments"));
                //client.DownloadStringAsync(new Uri("http://jsonplaceholder.typicode.com/albums"));
                //client.DownloadStringAsync(new Uri("http://jsonplaceholder.typicode.com/photos"));
                //client.DownloadStringAsync(new Uri("http://jsonplaceholder.typicode.com/todos"));
                //client.DownloadStringAsync(new Uri("http://jsonplaceholder.typicode.com/users"));
                client.DownloadStringAsync(new Uri("https://localhost:44300/JJISDatalinksApi/datalinks/all"));
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                const string json = "{\"one\": \"two\",\"key\": \"value\"}";
                JsonViewer.Load(json);
            }
        }
示例#5
0
        private void LoadFromClipboard()
        {
            string json = Clipboard.GetText();

            if (!String.IsNullOrEmpty(json))
            {
                JsonViewer.ShowTab(Tabs.Viewer);
                JsonViewer.Json = json;
            }
        }
示例#6
0
        private void LoadFromFile(string fileName)
        {
            //string json = File.ReadAllText(fileName);
            JsonViewer.ShowTab(Tabs.Viewer);
            //JsonViewer.Json = json;

            Control c = JsonViewer.Controls.Find("txtJson", true)[0];

            ((TextEditorControlEx)c).LoadFile(fileName);
        }
示例#7
0
        public PostMapping(ElasticSearchClient currentElasticSearchInstance, string index, string type)
        {
            InitializeComponent();
            jsonViewer = new JsonViewer();
            jsonViewer.ShowTab(Tabs.Viewer);
            jsonViewer.Dock = DockStyle.Fill;
            panel2.Controls.Add(jsonViewer);

            textBox1.Text = index;
            textBox2.Text = type;
            this.currentElasticSearchInstance = currentElasticSearchInstance;
        }
示例#8
0
        /** constructor
         */
        public Main()
        {
            //deleter
            this.deleter = new Fee.Deleter.Deleter();

            //viewer
            this.viewer = new JsonViewer();

            //JSON化するリスト。
            System.Collections.Generic.Dictionary <string, System.Object> t_list = new System.Collections.Generic.Dictionary <string, System.Object>();
            {
                ulong t_list_1 = 100;
                t_list.Add("item1", t_list_1);

                System.Collections.Generic.List <System.Object> t_list_2 = new System.Collections.Generic.List <object>();
                t_list.Add("item2", t_list_2);
                {
                    System.Collections.Generic.List <System.Object> t_list_2_1 = new System.Collections.Generic.List <object>();
                    t_list_2.Add(t_list_2_1);
                    {
                        t_list_2_1.Add(ulong.MaxValue);
                        t_list_2_1.Add(-100);
                        t_list_2_1.Add("asdf");
                        t_list_2_1.Add(new int[] { 1, 2, 3 });
                        t_list_2_1.Add(3.33f);
                        t_list_2_1.Add(true);
                        t_list_2_1.Add(100.3m);
                    }

                    string t_list_2_2 = "xyz";
                    t_list_2.Add(t_list_2_2);
                }
                System.Collections.Generic.List <System.Object> t_list_3 = new System.Collections.Generic.List <object>();
                t_list.Add("item3", t_list_3);

                System.Collections.Generic.List <System.Object> t_list_4 = new System.Collections.Generic.List <object>();
                t_list.Add("item4", t_list_4);
            }

            //JSONをビュワーに登録。
            this.viewer.CreateScroll(0, Fee.JsonItem.Convert.ObjectToJsonItem(t_list));
        }
示例#9
0
 private void MainForm_Load(object sender, EventArgs e)
 {
     JsonViewer.ShowTab(Tabs.Text);
     JsonViewer.ShowGeneratorEventHandler += new EventHandler(generatorToolStripMenuItem_Click);
 }
示例#10
0
        private void MainWindowLoaded(object sender, RoutedEventArgs e)
        {
            Title = string.Format("{0} v{1}", Title, Settings.Default.CurrentVersion);

            var netVersion = new GetDotNetVersion().Get45PlusFromRegistry();

            if (netVersion.Version == null)
            {
                MessageBoxResult choice = MessageBox.Show("Required .NET Version 4.6.2 not found. Please update.", "New Version", MessageBoxButton.OKCancel);

                if (choice == MessageBoxResult.OK)
                {
                    Process.Start("https://www.microsoft.com/en-us/download/details.aspx?id=53345");
                }
                else
                {
                    return;
                }
            }
            else
            {
                Title += string.Format(" | .NET Version: {0}", netVersion.Version);
            }

            items = new List <Item>();

            objects = new List <Obj>();

            codes = new Codes(this);

            var client = new WebClient
            {
                BaseAddress = Settings.Default.VersionUrl,
                Encoding    = Encoding.UTF8,
                CachePolicy =
                    new System.Net.Cache.RequestCachePolicy(
                        System.Net.Cache.RequestCacheLevel.BypassCache)
            };

            client.Headers.Add("Cache-Control", "no-cache");
            client.DownloadStringCompleted += ClientDownloadStringCompleted;

            // try to get current version
            try
            {
                client.DownloadStringAsync(new Uri(string.Format("{0}{1}", client.BaseAddress, "version.txt")));
            }
            catch (Exception ex)
            {
                LogError(ex, "Error loading current version.");
            }

            // try to load json data
            try
            {
                var file = Assembly.GetExecutingAssembly().GetManifestResourceStream("BotwTrainer.items.json");
                if (file != null)
                {
                    using (var reader = new StreamReader(file))
                    {
                        var data = reader.ReadToEnd();
                        json = JObject.Parse(data);

                        JsonViewer.Load(data);

                        // Shrine data
                        var shrines = json.SelectToken("Shrines").Value <JObject>().Properties().ToList().OrderBy(x => x.Name);
                        foreach (var shrine in shrines)
                        {
                            ShrineList.Items.Add(new ComboBoxItem {
                                Content = shrine.Value["Name"], Tag = shrine.Name
                            });
                        }

                        // Tower data
                        var towers = json.SelectToken("Towers").Value <JObject>().Properties().ToList().OrderBy(x => x.Name);
                        foreach (var tower in towers)
                        {
                            TowerList.Items.Add(new ComboBoxItem {
                                Content = tower.Value["Name"], Tag = tower.Name
                            });
                        }

                        // Ranches
                        var ranches = json.SelectToken("Ranches").Value <JObject>().Properties().ToList().OrderBy(x => x.Name);
                        foreach (var ranch in ranches)
                        {
                            RanchList.Items.Add(new ComboBoxItem {
                                Content = ranch.Value["Name"], Tag = ranch.Name
                            });
                        }

                        // Misc
                        var misc = json.SelectToken("Misc").Value <JObject>().Properties().ToList().OrderBy(x => x.Name);
                        foreach (var m in misc)
                        {
                            MiscList.Items.Add(new ComboBoxItem {
                                Content = m.Value["Name"], Tag = m.Name
                            });
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogError(ex, "Error loading json.");
            }

            IpAddress.Text = Settings.Default.IpAddress;

            Save.IsEnabled = HasChanged;
        }
示例#11
0
        private void MainWindowLoaded(object sender, RoutedEventArgs e)
        {
            // Testing
            // this.TabControl.IsEnabled = true;

            this.Title = string.Format("{0} v{1}", this.Title, Settings.Default.CurrentVersion);

            this.items = new List <Item>();

            this.codes = new Codes(this);

            var client = new WebClient
            {
                BaseAddress = Settings.Default.VersionUrl,
                Encoding    = Encoding.UTF8,
                CachePolicy =
                    new System.Net.Cache.RequestCachePolicy(
                        System.Net.Cache.RequestCacheLevel.BypassCache)
            };

            client.Headers.Add("Cache-Control", "no-cache");
            client.DownloadStringCompleted += this.ClientDownloadStringCompleted;

            // try to get current version
            try
            {
                client.DownloadStringAsync(new Uri(string.Format("{0}{1}", client.BaseAddress, "version.txt")));
            }
            catch (Exception ex)
            {
                this.LogError(ex, "Error loading current version.");
            }

            // try to load json data
            try
            {
                var file = Assembly.GetExecutingAssembly().GetManifestResourceStream("BotwTrainer.items.json");
                using (var reader = new StreamReader(file))
                {
                    var data = reader.ReadToEnd();
                    this.json = JObject.Parse(data);

                    JsonViewer.Load(data);

                    // Shrine data
                    var shrines = this.json.SelectToken("Shrines").Value <JObject>().Properties().ToList().OrderBy(x => x.Name);
                    foreach (var shrine in shrines)
                    {
                        ShrineList.Items.Add(new ComboBoxItem {
                            Content = shrine.Value["Name"], Tag = shrine.Name
                        });
                    }

                    // Tower data
                    var towers = this.json.SelectToken("Towers").Value <JObject>().Properties().ToList().OrderBy(x => x.Name);
                    foreach (var tower in towers)
                    {
                        TowerList.Items.Add(new ComboBoxItem {
                            Content = tower.Value["Name"], Tag = tower.Name
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                this.LogError(ex, "Error loading json.");
            }

            IpAddress.Text = Settings.Default.IpAddress;

            this.Save.IsEnabled = this.HasChanged;
        }
示例#12
0
 private void MainForm_Load(object sender, EventArgs e)
 {
     JsonViewer.ShowTab(Tabs.Text);
 }
示例#13
0
        /// <summary>
        ///     开始请求
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                //初始化状态
                toolStripStatusState.Text = "请求中...";
                lbResCode.Text            = "请求中...";
                lbResCode.ForeColor       = Color.Black;
                Control c = JsonViewer.Controls.Find("txtJson", true)[0];
                ((TextBox)c)?.Clear();
                richResHeader.Clear();
                richExcutReq.Clear();

                var endPoint  = txtEndPoint.Text.Trim();
                var resource  = txtResource.Text.Trim();
                var reqbody   = richReqBody.Text;
                var userName  = txtUserName.Text.Trim();
                var pwd       = txtPassword.Text.Trim();
                var authType  = cbAuthType.Text;
                var mediaType = cbMediaType.Text;

                //保存请求数据
                SaveRestInfo();

                //认证
                IAuthenticator iaAuthenticator;
                if (authType == "NTLM")
                {
                    ICredentials ic = new NetworkCredential(userName, pwd);
                    iaAuthenticator = new NtlmAuthenticator(ic);
                }
                else if (authType == "Basic")
                {
                    iaAuthenticator = new HttpBasicAuthenticator(userName, pwd);
                }
                else
                {
                    //TODO
                    iaAuthenticator = new HttpBasicAuthenticator(userName, pwd);
                    //iaAuthenticator = new SimpleAuthenticator(userName, pwd);(userName, pwd);
                }

                if (string.IsNullOrEmpty(resource))
                {
                    Uri uri = new Uri(endPoint);
                    resource = uri.AbsolutePath;
                    endPoint = uri.AbsoluteUri.Replace(resource, "");
                }
                IRestSharp   iRestSharp = new RestSharpClient(endPoint, iaAuthenticator);
                IRestRequest iRequest   = new RestRequest(new Uri(endPoint + resource));
                iRequest.Method = (Method)Enum.Parse(typeof(Method), cbMethod.Text);

                foreach (var line in richCurrReqHeader.Lines)
                {
                    var val = line.Trim();
                    if (val.Contains(":"))
                    {
                        var firstIndex = val.IndexOf(":", StringComparison.Ordinal);
                        var key        = val.Substring(0, firstIndex);
                        var value      = val.Substring(firstIndex + 1, val.Length - firstIndex - 1);
                        iRequest.AddHeader(key, value);
                    }
                    else
                    {
                        MessageBox.Show("填写的请求头参数不正确");
                        break;
                    }
                }

                if (!string.IsNullOrEmpty(mediaType))
                {
                    iRequest.AddParameter(mediaType, reqbody, ParameterType.RequestBody);
                }
                //var iResponse = iRestSharp.Execute(iRequest);

                var asyncHandle = iRestSharp.ExecuteAsync(iRequest, response =>
                {
                    this.Invoke(new Action(() =>
                    {
                        toolStripStatusState.Text = response.ResponseStatus.ToString();
                    }));
                    var headerStr = "";
                    foreach (var parameter in response.Headers)
                    {
                        headerStr += parameter.Name + ":" + parameter.Value + "\n";
                    }

                    richExcutReq.Invoke(new Action(() =>
                    {
                        richExcutReq.Clear();
                        string reqContentType = "", reqBody = "";
                        foreach (var requestParameter in response.Request.Parameters)
                        {
                            if (requestParameter.Type == ParameterType.RequestBody)
                            {
                                reqContentType = requestParameter.Name;
                                reqBody        = requestParameter.Value.ToString();
                            }
                            else
                            {
                                richExcutReq.AppendText(requestParameter.Name + ":" + requestParameter.Value + "\n");
                            }
                        }
                        richExcutReq.AppendText("\n*****************************" + reqContentType + "*******************************\n");
                        richExcutReq.AppendText(reqBody);
                    }));
                    this.Invoke(new Action(() =>
                    {
                        richResHeader.Text  = headerStr.Trim(':');
                        lbResCode.Text      = Convert.ToInt32(response.StatusCode) + " " + response.StatusCode;
                        lbResCode.ForeColor = response.StatusCode == HttpStatusCode.OK ? Color.Green : Color.Red;
                    }));
                    JsonViewer.Invoke(new Action(() =>
                    {
                        JsonViewer.Json           = response.Content;
                        toolStripStatusState.Text = response.ResponseStatus.ToString();
                    }));
                });
                // abort the request on demand
                //asyncHandle.Abort();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "请求失败,请检查配置信息");
            }
        }
示例#14
0
        /** constructor
         */
        public JsonViewer_Item(string a_label, JsonViewer a_viewer, int a_layer, Fee.JsonItem.JsonItem a_jsonitem)
        {
            //deleter
            this.deleter = new Fee.Deleter.Deleter();

            //viewer
            this.viewer = a_viewer;

            //layer
            this.layer = a_layer;

            //jsonitem
            this.jsonitem = a_jsonitem;

            string t_text;

            UnityEngine.Color t_color = UnityEngine.Color.black;
            {
                if (a_jsonitem == null)
                {
                    t_text = a_label;
                }
                else
                {
                    //親がインデックス配列ならインデックス、連想配列ならキー名。
                    t_text = "label = " + a_label + "\n";

                    //データタイプ名。
                    t_text += a_jsonitem.GetValueType().ToString() + "\n";

                    //データ。
                    switch (a_jsonitem.GetValueType())
                    {
                    case Fee.JsonItem.ValueType.AssociativeArray:
                    {
                        t_text += "count = " + a_jsonitem.GetListMax().ToString() + "\n";
                        t_color = new UnityEngine.Color(0.2f, 0.3f, 0.2f, 1.0f);
                    } break;

                    case Fee.JsonItem.ValueType.IndexArray:
                    {
                        t_text += "count = " + a_jsonitem.GetListMax().ToString() + "\n";
                        t_color = new UnityEngine.Color(0.4f, 0.2f, 0.5f, 1.0f);
                    } break;

                    case Fee.JsonItem.ValueType.BoolData:
                    {
                        t_text += "value = " + a_jsonitem.GetBoolData().ToString() + "\n";
                        t_color = new UnityEngine.Color(0.1f, 0.2f, 0.4f, 1.0f);
                    } break;

                    case Fee.JsonItem.ValueType.SignedNumber:
                    {
                        t_text += "value = " + a_jsonitem.GetSignedNumber().ToString() + "\n";
                        t_color = new UnityEngine.Color(0.5f, 0.2f, 0.8f, 1.0f);
                    } break;

                    case Fee.JsonItem.ValueType.UnsignedNumber:
                    {
                        t_text += "value = " + a_jsonitem.GetUnsignedNumber().ToString() + "\n";
                        t_color = new UnityEngine.Color(0.4f, 0.6f, 0.3f, 1.0f);
                    } break;

                    case Fee.JsonItem.ValueType.FloatingNumber:
                    {
                        t_text += "value = " + a_jsonitem.GetFloatingNumber().ToString() + "\n";
                        t_color = new UnityEngine.Color(0.2f, 0.2f, 0.5f, 1.0f);
                    } break;

                    case Fee.JsonItem.ValueType.DecimalNumber:
                    {
                        t_text += "value = " + a_jsonitem.GetDecimalNumber().ToString() + "\n";
                        t_color = new UnityEngine.Color(0.1f, 0.1f, 0.1f, 1.0f);
                    } break;

                    case Fee.JsonItem.ValueType.StringData:
                    {
                        t_text += "value = " + a_jsonitem.GetStringData() + "\n";
                        t_color = new UnityEngine.Color(0.5f, 0.2f, 0.2f, 1.0f);
                    } break;
                    }
                }
            }

            //text
            this.text = Fee.Render2D.Text2D.Create(this.deleter, 0);
            this.text.SetText(t_text);
            this.text.SetAlignmentType(Fee.Render2D.Text2D_HorizontalAlignmentType.Left, Fee.Render2D.Text2D_VerticalAlignmentType.Top);
            this.text.SetColor(in t_color);
            this.text.SetClip(true);
            this.text.SetVisible(false);

            //button
            this.button = Fee.Ui.Button.Create(this.deleter, 0);
            this.button.SetNormalTexture(UnityEngine.Texture2D.whiteTexture);
            this.button.SetOnTexture(UnityEngine.Texture2D.whiteTexture);
            this.button.SetDownTexture(UnityEngine.Texture2D.whiteTexture);
            this.button.SetLockTexture(UnityEngine.Texture2D.whiteTexture);
            this.button.SetNormalColor(0.8f, 0.8f, 0.8f, 1.0f);
            this.button.SetOnColor(0.7f, 0.7f, 0.7f, 1.0f);
            this.button.SetDownColor(0.6f, 0.6f, 0.6f, 1.0f);
            this.button.SetLockColor(0.5f, 0.5f, 0.5f, 1.0f);
            this.button.SetOnButtonClick(this, -1);
            this.button.SetClip(true);
            this.button.SetVisible(false);
            this.button.SetDragCancelFlag(true);
        }