示例#1
0
        private static void SaveChanges(ConfigChange script, string stringFileName)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            var jsonString          = js.Serialize(script);

            jsonString = JSONFormatter.FormatOutput(jsonString);
            File.WriteAllText(stringFileName, jsonString);
        }
示例#2
0
        private void JSONBtn_Click(object sender, EventArgs e)
        {
            var s      = ClipboardManager.GetClipboardContent();
            var result = JSONFormatter.Format(s);

            ClipboardManager.InsertClipboardText(result);
            Close();
        }
示例#3
0
        static void Main(string[] args)
        {
            var    simpleFormatter = new SimpleFormatter();
            var    xmlFormatter    = new XmlFormatter();
            var    jsonFormatter   = new JSONFormatter();
            var    consoleAppender = new ConsoleAppender(xmlFormatter);
            var    fileAppender    = new FileAppender(xmlFormatter, "log.txt");
            Logger logger          = new Logger(consoleAppender, fileAppender);

            logger.Critical("Out of memory!");
            logger.Info("Unused local variable 'name'");

            fileAppender.Close();
        }
示例#4
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);
        }
示例#5
0
        public void JSONWritesJObjectToStream()
        {
            var arraySettings = JSONFormatter.GetDefaultSettings();
            arraySettings.TypeNameHandling = BESSy.Json.TypeNameHandling.Objects;

            var test = TestResourceFactory.CreateRandom() as MockClassC;

            var json = new JSONFormatter(arraySettings);

            var stream = json.FormatObjStream(test);
            var len = stream.Length;

            var copy = new MemoryStream();
            stream.Position = 0;
            stream.CopyTo(copy);

            var unformatted = json.Parse(stream);

            var formatted = json.Unparse(unformatted);

            copy.Position = formatted.Position = 0;

            var orig = new StreamReader(copy).ReadToEnd();
            var unparsed = new StreamReader(formatted).ReadToEnd();

            //Console.Write(b);
            //Console.WriteLine();
            //Console.Write(unparsed);

            var reformatted = json.Parse(formatted);

            Assert.AreEqual(copy.Length, formatted.Length);

            Assert.AreEqual(unformatted, reformatted);

            MockClassC.Validate(unformatted.ToObject<MockClassC>(), reformatted.ToObject<MockClassC>());

            Stream os;
            json.TryUnparse(reformatted, out os);

            Assert.AreEqual(len, os.Length);
        }
示例#6
0
        public void JSONSafeFormatsToStream()
        {
            var test = TestResourceFactory.CreateRandom() as MockClassC;
            var json = new JSONFormatter();

            Stream formatted;

            Assert.IsTrue(json.TryFormatObj(test, out formatted));

            MockClassA raw;

            Assert.IsTrue(json.TryUnformatObj<MockClassA>(formatted, out raw));

            var unformatted = raw 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);

            var invalid = new MemoryStream(Encoding.UTF8.GetBytes("{ this is invalid."));

            //Check false conditions.
            Assert.IsFalse(json.TryFormatObj(default(MockClassA), out formatted));
            Assert.IsFalse(json.TryUnformatObj((Stream)null, out raw));
            Assert.IsFalse(json.TryUnformatObj(invalid, out raw));
        }
示例#7
0
        public void JSONParsesJObjectFromStream()
        {
            var test = TestResourceFactory.CreateRandom() as MockClassC;

            var json = new JSONFormatter();

            var stream = json.FormatObjStream(test);

            var unformatted = json.Parse(stream);

            Assert.AreEqual(unformatted.Value<int>("Id"), test.Id);
            Assert.AreEqual(unformatted.Value<string>("Name"), test.Name);
            Assert.AreEqual((double)unformatted["GetSomeCheckSum"][0], test.GetSomeCheckSum[0]);
            Assert.AreEqual((float)unformatted["Location"]["X"], test.Location.X);
            Assert.AreEqual((float)unformatted["Location"]["Y"], test.Location.Y);
            Assert.AreEqual((float)unformatted["Location"]["Z"], test.Location.Z);
            Assert.AreEqual((float)unformatted["Location"]["W"], test.Location.W);
            Assert.AreEqual((string)unformatted["ReferenceCode"], test.ReferenceCode);
            Assert.AreEqual((Guid)unformatted["ReplicationID"], test.ReplicationID);
        }
示例#8
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);
            }
        }
示例#9
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;
        }
        public void AfmRebuildsWithNewStride()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
            Cleanup();

            var formatter = new JSONFormatter();
            var core = new FileCore<string, long>() { IdSeed = new SeedString(), SegmentSeed = new Seed64(), MinimumCoreStride = 512 };

            var entity = TestResourceFactory.CreateRandom() as MockClassC;
            var largeEntity = TestResourceFactory.CreateRandom().WithName(new String('a', 2000)) as MockClassC;

            long seg = 0;

            using (var afm = new AtomicFileManager<MockClassA>(_testName + ".database", core, new JSONFormatter()))
            {
                afm.Load<string>();

                afm.Rebuilt += new Rebuild<MockClassA>(delegate(Guid transactionId, int newStride, long newLength, int newSeedStride)
                {
                    afm.SaveCore<string>();
                });

                seg = AtomicFileManagerHelper.SaveSegment(afm, entity, entity.Name);

                afm.SaveCore();
            }

            using (var afm = new AtomicFileManager<MockClassA>(_testName + ".database", core, new JSONFormatter()))
            {
                afm.Load<string>();

                afm.Rebuilt += new Rebuild<MockClassA>(delegate(Guid transactionId, int newStride, long newLength, int newSeedStride)
                    {
                        afm.SaveCore<string>();
                    });

               seg = AtomicFileManagerHelper.SaveSegment(afm, largeEntity, largeEntity.Name);
            }

            using (var afm = new AtomicFileManager<MockClassA>(_testName + ".database", core, formatter))
            {
                afm.Load<string>();

                Assert.Greater(afm.Stride, 500);
                Assert.AreEqual(512, afm.Core.MinimumCoreStride);

                var obj = afm.LoadSegmentFrom(seg) as MockClassC;

                Assert.IsNotNull(obj);
                Assert.AreEqual(largeEntity.Id, obj.Id);
                Assert.AreEqual(largeEntity.Name, obj.Name);
                Assert.AreEqual(largeEntity.GetSomeCheckSum, obj.GetSomeCheckSum);
                Assert.AreEqual(largeEntity.Location.X, obj.Location.X);
                Assert.AreEqual(largeEntity.Location.Y, obj.Location.Y);
                Assert.AreEqual(largeEntity.Location.Z, obj.Location.Z);
                Assert.AreEqual(largeEntity.Location.W, obj.Location.W);
                Assert.AreEqual(largeEntity.ReferenceCode, obj.ReferenceCode);
                Assert.AreEqual(largeEntity.ReplicationID, obj.ReplicationID);
            }
        }