Пример #1
0
        private void JSONBtn_Click(object sender, EventArgs e)
        {
            var s      = ClipboardManager.GetClipboardContent();
            var result = JSONFormatter.Format(s);

            ClipboardManager.InsertClipboardText(result);
            Close();
        }
Пример #2
0
        public void JSONBinFormatsToStream()
        {
            var test = TestResourceFactory.CreateRandom() as MockClassC;
            var json = new JSONFormatter();

            var stream = json.FormatObjStream(test);

            var binFormatted = json.Format(stream);
            var buffer = json.Unformat(binFormatted);

            Assert.AreEqual(binFormatted, buffer);

            var unformatted = json.UnformatObj<MockClassA>(binFormatted) as MockClassC;

            Assert.AreEqual(unformatted.Id, test.Id);
            Assert.AreEqual(unformatted.Name, test.Name);
            Assert.AreEqual(unformatted.GetSomeCheckSum[0], test.GetSomeCheckSum[0]);
            Assert.AreEqual(unformatted.Location.X, test.Location.X);
            Assert.AreEqual(unformatted.Location.Y, test.Location.Y);
            Assert.AreEqual(unformatted.Location.Z, test.Location.Z);
            Assert.AreEqual(unformatted.Location.W, test.Location.W);
            Assert.AreEqual(unformatted.ReferenceCode, test.ReferenceCode);
            Assert.AreEqual(unformatted.ReplicationID, test.ReplicationID);
        }
Пример #3
0
        /// <summary>
        /// Create overview!
        /// </summary>
        public void CreateOverview(VBox RequestOverview, Font CaptionFont)
        {
            // Overview clear
            RequestOverview.Clear();

            // Information
            RequestOverview.PackStart(new Label(Director.Properties.Resources.RequestUrl + ":")
            {
                Font = CaptionFont
            }, false, false);

            // Create URL
            RequestOverview.PackStart(new LinkLabel(Url)
            {
                Uri        = new Uri(Url),
                MarginLeft = 10
            }, false, false);

            // Method
            RequestOverview.PackStart(new Label(Director.Properties.Resources.RequestMethod + ":")
            {
                Font      = CaptionFont,
                MarginTop = 20
            }, false, false);

            // Create URL
            RequestOverview.PackStart(new Label(HTTP_METHOD)
            {
                MarginLeft = 10
            }, false, false);

            // Headers
            if (Headers.Count > 0)
            {
                RequestOverview.PackStart(new Label(Director.Properties.Resources.RequestHeaders + ":")
                {
                    Font      = CaptionFont,
                    MarginTop = 20
                }, false, false);
                foreach (var h in Headers)
                {
                    RequestOverview.PackStart(new ListItem(string.Format("{0} - {1}", h.Name, h.Value)));
                }
            }

            // Files
            if (Files.Count > 0)
            {
                RequestOverview.PackStart(new Label(Director.Properties.Resources.RequestFiles + ":")
                {
                    Font      = CaptionFont,
                    MarginTop = 20
                }, false, false);
                foreach (var h in Files)
                {
                    RequestOverview.PackStart(new ListItem(h.FileName));
                }
            }

            // Request
            // Request
            if (RequestTemplate != null && RequestTemplate.Length > 0)
            {
                RequestOverview.PackStart(new Label(string.Format("{0} ({1}) :", Director.Properties.Resources.RequestTemplate, RequestTemplateTypeS))
                {
                    Font      = CaptionFont,
                    MarginTop = 20
                }, false, false);

                TextEntry RequestTextEntry = new TextEntry()
                {
                    Margin = 10, Sensitive = false, MultiLine = true
                };

                if (RequestTemplateType == ContentType.JSON)
                {
                    RequestTextEntry.Text = JSONFormatter.Format(RequestTemplate);

                    if (RequestTextEntry.Text == null || RequestTextEntry.Text.Trim().Length == 0)
                    {
                        RequestTextEntry.Text = RequestTemplate;
                    }
                }
                else
                {
                    RequestTextEntry.Text = RequestTemplate;
                }
                RequestOverview.PackStart(RequestTextEntry);


                Button ClipboardButtonReq = new Button(Image.FromResource(DirectorImages.COPY_ICON), "")
                {
                    WidthRequest     = 30,
                    HeightRequest    = 30,
                    ExpandHorizontal = false,
                    ExpandVertical   = false,
                    MarginRight      = 10,
                    TooltipText      = Director.Properties.Resources.CopyInClipboard
                };
                ClipboardButtonReq.Clicked += delegate
                {
                    Clipboard.SetText(RequestTextEntry.Text);
                };
                RequestOverview.PackStart(ClipboardButtonReq, hpos: WidgetPlacement.End);
            }

            // Requested code
            if (ExpectedStatusCode > 0)
            {
                RequestOverview.PackStart(new Label(Director.Properties.Resources.ExpectedStatusCode + ":")
                {
                    Font = CaptionFont
                }, false, false);
                RequestOverview.PackStart(new ListItem(ExpectedStatusCode + ""));
            }


            // Request
            if (ResponseTemplate != null && ResponseTemplate.Length > 0)
            {
                RequestOverview.PackStart(new Label(string.Format("{0} ({1}): ", Director.Properties.Resources.ResponseTemplate, ResponseTemplateTypeS))
                {
                    Font      = CaptionFont,
                    MarginTop = (ExpectedStatusCode > 0) ? 20 : 0
                }, false, false);

                TextEntry ResponseTextEntry = new TextEntry()
                {
                    Margin = 10, Sensitive = false, MultiLine = true
                };

                if (ResponseTemplate.Trim().StartsWith("{"))
                {
                    ResponseTextEntry.Text = JSONFormatter.Format(ResponseTemplate);
                }
                else
                {
                    ResponseTextEntry.Text = ResponseTemplate;
                }
                RequestOverview.PackStart(ResponseTextEntry);
                Button ClipboardButton = new Button(Image.FromResource(DirectorImages.COPY_ICON), "")
                {
                    WidthRequest     = 30,
                    HeightRequest    = 30,
                    ExpandHorizontal = false,
                    ExpandVertical   = false,
                    MarginRight      = 10,
                    MarginBottom     = 10,
                    TooltipText      = Director.Properties.Resources.CopyInClipboard
                };
                ClipboardButton.Clicked += delegate
                {
                    Clipboard.SetText(ResponseTextEntry.Text);
                };
                RequestOverview.PackStart(ClipboardButton, hpos: WidgetPlacement.End);
            }
        }
Пример #4
0
        /// <summary>
        /// Create set window.
        /// </summary>
        public SetWindow(RequestWidget _reqW, ResponseWidget _resP)
        {
            // Set
            ReqWidget = _reqW;
            ResWidget = _resP;

            // Set default size
            Width  = 450;
            Height = 500;

            // This window can not be maximalized
            Resizable = true;

            // Icon
            Icon = Image.FromResource(DirectorImages.EDIT_ICON);

            // Set content
            Title = Director.Properties.Resources.SetContentTitle;

            // Center screen
            InitialLocation = WindowLocation.CenterScreen;

            // Create input area
            VBox InputArea = new VBox();

            // Prepare input
            TextInput = new TextEntry()
            {
                ExpandVertical   = true,
                ExpandHorizontal = true,
                MultiLine        = true
            };

            TextInput.Text = "";

            // Content type combo box
            ContentTypeSelect = new ComboBox();
            ContentTypeSelect.Items.Add(ContentType.JSON, "JSON");
            ContentTypeSelect.Items.Add(ContentType.XML, "XML");
            ContentTypeSelect.Items.Add(ContentType.PLAIN, "PLAIN");
            ContentTypeSelect.SelectedIndex = 0;

            if (ReqWidget != null)
            {
                if (ReqWidget.ActiveRequest.RequestTemplateType == ContentType.JSON)
                {
                    TextInput.Text = JSONFormatter.Format(ReqWidget.ActiveRequest.RequestTemplate);
                }
                if (TextInput.Text.Length == 0)
                {
                    TextInput.Text = ReqWidget.ActiveRequest.RequestTemplate;
                }
                ContentTypeSelect.SelectedItem = ReqWidget.ActiveRequest.RequestTemplateType;
            }
            else if (ResWidget != null)
            {
                if (ResWidget.ActiveRequest.ResponseTemplateType == ContentType.JSON)
                {
                    TextInput.Text = JSONFormatter.Format(ResWidget.ActiveRequest.ResponseTemplate);
                }
                if (TextInput.Text.Length == 0)
                {
                    TextInput.Text = ResWidget.ActiveRequest.ResponseTemplate;
                }
                ContentTypeSelect.SelectedItem = ResWidget.ActiveRequest.ResponseTemplateType;
            }

            // Add
            InputArea.PackStart(new Label()
            {
                Markup = "<b>Content type:</b>"
            });
            InputArea.PackStart(ContentTypeSelect, false, true);


            ScrollView ScrollTextInput = new ScrollView()
            {
                Content = TextInput
            };

            InputArea.PackStart(new Label()
            {
                Markup = "<b>" + Director.Properties.Resources.PasteInput + "</b>"
            });
            InputArea.PackStart(ScrollTextInput, true, true);

            // Prepare output
            InputArea.PackStart(new Label()
            {
                Markup = "<b>" + Director.Properties.Resources.Output + "</b>"
            });
            ErrorReport = new MarkdownView();
            InputArea.PackStart(ErrorReport, true, true);

            // Btn
            Button ConfirmButton = new Button(Image.FromResource(DirectorImages.OK_ICON),
                                              Director.Properties.Resources.ConfirmInput)
            {
                WidthRequest     = 150,
                ExpandHorizontal = false,
                ExpandVertical   = false
            };

            InputArea.PackStart(ConfirmButton, expand: false, hpos: WidgetPlacement.End);

            // Save
            ConfirmButton.Clicked += ConfirmButton_Clicked;

            // Content is input area
            Content = InputArea;
        }