public void Performance_FullIJsonSerialize_10000() { Console.WriteLine("Time To Beat: 00:00:00.6080608"); var content = File.ReadAllText("Associates.json"); var serializer = new JsonSerializer(); JsonSerializationAbstractionMap.MapGeneric(typeof(IEnumerable <>), typeof(List <>)); IEnumerable <SerializableAssociate> obj; var start = DateTime.Now; for (int i = 0; i < 10000; i++) { var json = JsonValue.Parse(content); obj = serializer.Deserialize <IEnumerable <SerializableAssociate> >(json); } var end = DateTime.Now; Console.WriteLine("Manatee: {0}", end - start); start = DateTime.Now; for (int i = 0; i < 10000; i++) { obj = JsonConvert.DeserializeObject <IEnumerable <SerializableAssociate> >(content); } end = DateTime.Now; Console.WriteLine("NewtonSoft: {0}", end - start); }
public void Performance_FullIJsonSerialize_Single() { Console.WriteLine("Time To Beat: 00:00:00.0230013"); var content = File.ReadAllText("Associates.json"); var serializer = new JsonSerializer(); JsonSerializationAbstractionMap.MapGeneric(typeof(IEnumerable <>), typeof(List <>)); var start = DateTime.Now; var json = JsonValue.Parse(content); var obj = serializer.Deserialize <IEnumerable <SerializableAssociate> >(json); var end = DateTime.Now; Console.WriteLine("Manatee: {0}", end - start); foreach (var serializableAssociate in obj) { Console.WriteLine("\t{0}", serializableAssociate); } start = DateTime.Now; var obj2 = JsonConvert.DeserializeObject <IEnumerable <SerializableAssociate> >(content); end = DateTime.Now; Console.WriteLine("NewtonSoft: {0}", end - start); foreach (var serializableAssociate in obj2) { Console.WriteLine("\t{0}", serializableAssociate); } }
public async void ConvertXsdToJsonSchemaAndBackViaString_CorrectNumberOfPropertiesAndDefinitions() { // string xsdName = "Designer.Tests._TestData.Model.Xsd.schema_3451_8_forms_4106_35721.xsd"; string xsdName = "Designer.Tests._TestData.Model.Xsd.schema_4581_100_forms_5245_41111.xsd"; SchemaKeywordCatalog.Add <InfoKeyword>(); // Arrange XmlReader xsdReader = XmlReader.Create(LoadTestData(xsdName)); XsdToJsonSchema xsdToJsonSchemaConverter = new XsdToJsonSchema(xsdReader); // Act JsonSchema convertedSchema = xsdToJsonSchemaConverter.AsJsonSchema(); JsonSerializer serializer = new JsonSerializer(); JsonValue serializedConvertedSchema = serializer.Serialize(convertedSchema); byte[] byteArray = Encoding.UTF8.GetBytes(serializedConvertedSchema.ToString()); MemoryStream jsonstream = new MemoryStream(byteArray); await WriteData(xsdName + ".json", jsonstream); File.WriteAllText(xsdName + ".json", serializedConvertedSchema.ToString()); string savedJsonSchemaFileTextContent = File.ReadAllText(xsdName + ".json"); TextReader textReader = new StringReader(savedJsonSchemaFileTextContent); JsonValue jsonValue = await JsonValue.ParseAsync(textReader); JsonSchema jsonSchemaFromFile = new Manatee.Json.Serialization.JsonSerializer().Deserialize <JsonSchema>(jsonValue); JsonSchemaToXsd jsonSchemaToXsd = new JsonSchemaToXsd(); XmlSchema xmlschema = jsonSchemaToXsd.CreateXsd(convertedSchema); MemoryStream xmlStream = new MemoryStream(); XmlTextWriter xwriter = new XmlTextWriter(xmlStream, new UpperCaseUtf8Encoding()); xwriter.Formatting = Formatting.Indented; xwriter.WriteStartDocument(false); xmlschema.Write(xmlStream); await WriteData(xsdName + ".new", xmlStream); XmlSchema xmlschemaFromFile = jsonSchemaToXsd.CreateXsd(jsonSchemaFromFile); MemoryStream xmlStreamFile = new MemoryStream(); XmlTextWriter xwriterFile = new XmlTextWriter(xmlStreamFile, new UpperCaseUtf8Encoding()); xwriterFile.Formatting = Formatting.Indented; xwriterFile.WriteStartDocument(false); xmlschemaFromFile.Write(xmlStreamFile); await WriteData(xsdName + ".newfile", xmlStreamFile); Assert.NotNull(convertedSchema); }
public async void Get_Put_Updatemodel_Ok() { string unitTestFolder = Path.GetDirectoryName(new Uri(typeof(DatamodelsControllerTests).Assembly.CodeBase).LocalPath); unitTestFolder = Path.Combine(unitTestFolder, @"..\..\..\_TestData\"); if (File.Exists(unitTestFolder + "Repositories/testuser/ttd/ttd-datamodels/3478/32578/32578.schema.json")) { File.Delete(unitTestFolder + "Repositories/testuser/ttd/ttd-datamodels/3478/32578/32578.schema.json"); } File.Copy(unitTestFolder + "Model/Xsd/schema_2978_1_forms_3478_32578.xsd", unitTestFolder + "Repositories/testuser/ttd/ttd-datamodels/3478/32578/32578.xsd", true); HttpClient client = GetTestClient(); string dataPathWithData = $"{_versionPrefix}/ttd/ttd-datamodels/Datamodels/GetDatamodel?filepath=3478/32578/32578"; HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, dataPathWithData) { }; await AuthenticationUtil.AddAuthenticateAndAuthAndXsrFCookieToRequest(client, httpRequestMessage); HttpResponseMessage response = await client.SendAsync(httpRequestMessage); string responsestring = await response.Content.ReadAsStringAsync(); TextReader textReader = new StringReader(responsestring); JsonValue jsonValue = await JsonValue.ParseAsync(textReader); JsonSchema jsonSchema = new Manatee.Json.Serialization.JsonSerializer().Deserialize <JsonSchema>(jsonValue); dataPathWithData = $"{_versionPrefix}/ttd/ttd-datamodels/Datamodels/UpdateDatamodel?filepath=3478/32578/32578"; var serializer = new JsonSerializer(); JsonValue toar = serializer.Serialize(jsonSchema); string requestBody = toar.ToString(); HttpRequestMessage httpRequestMessagePut = new HttpRequestMessage(HttpMethod.Put, dataPathWithData) { Content = new StringContent(requestBody, Encoding.UTF8, "application/json") }; await AuthenticationUtil.AddAuthenticateAndAuthAndXsrFCookieToRequest(client, httpRequestMessagePut); HttpResponseMessage responsePut = await client.SendAsync(httpRequestMessagePut); Assert.Equal(HttpStatusCode.OK, responsePut.StatusCode); }
public void Performance_IJsonSerializeOnly_Single() { Console.WriteLine("Time To Beat: 00:00:00.0120012"); var content = File.ReadAllText("Associates.json"); var serializer = new JsonSerializer(); JsonSerializationAbstractionMap.MapGeneric(typeof(IEnumerable <>), typeof(List <>)); IEnumerable <SerializableAssociate> obj; var json = JsonValue.Parse(content); var start = DateTime.Now; obj = serializer.Deserialize <IEnumerable <SerializableAssociate> >(json); var end = DateTime.Now; Console.WriteLine("Manatee: {0}", end - start); }
private static string Zip(JsonSchema jsonSchema) { JsonSerializer serializer = new JsonSerializer(); JsonValue json = serializer.Serialize(jsonSchema); byte[] bytes = Encoding.UTF8.GetBytes(json.GetIndentedString()); using (MemoryStream msi = new MemoryStream(bytes)) using (MemoryStream mso = new MemoryStream()) { using (GZipStream gs = new GZipStream(mso, CompressionMode.Compress)) { msi.CopyTo(gs); } return(Convert.ToBase64String(mso.ToArray())); } }
public async Task Get_Datamodel_onlyXsd_Ok() { HttpClient client = GetTestClient(); string dataPathWithData = $"{_versionPrefix}/ttd/ttd-datamodels/Datamodels/GetDatamodel?modelName=35721"; HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, dataPathWithData) { }; await AuthenticationUtil.AddAuthenticateAndAuthAndXsrFCookieToRequest(client, httpRequestMessage); HttpResponseMessage response = await client.SendAsync(httpRequestMessage); string responsestring = await response.Content.ReadAsStringAsync(); TextReader textReader = new StringReader(responsestring); JsonValue jsonValue = await JsonValue.ParseAsync(textReader); JsonSchema jsonSchema = new Manatee.Json.Serialization.JsonSerializer().Deserialize<JsonSchema>(jsonValue); Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(5, jsonSchema.Count); }
public override bool Transform(FilePath transformFile, FilePath targetFile) { var serializer = new JsonSerializer(); var rawPatchJson = transformFile.ReadAllText(); var rawConfigDoc = targetFile.ReadAllText(); try { //arrange var patchJsonValue = JsonValue.Parse(rawPatchJson); var jsonPatch = serializer.Deserialize <JsonPatch>(patchJsonValue); var configJsonValue = JsonValue.Parse(rawConfigDoc); //act var result = jsonPatch.TryApply(configJsonValue); if (result.Success) { targetFile.WriteAllText(configJsonValue.GetIndentedString()); return(true); } var errorMessage = new StringBuilder(7); errorMessage.AppendLine($"{result.Error.TrimEnd('.')} in {targetFile.FullName().Highlight()}"); errorMessage.AppendLine($"Source json BEFORE PATCH:".Highlight()); errorMessage.AppendLine(rawConfigDoc); errorMessage.AppendLine($"PATCH:".Highlight()); errorMessage.AppendLine(rawPatchJson); errorMessage.AppendLine($"Json when PATCH ERROR occured:".Highlight()); errorMessage.AppendLine(configJsonValue.GetIndentedString().Replace("\n", "\r\n")); Log.Error(errorMessage.ToString()); return(false); } catch (IOException e) { Log.Error(e.Message); return(false); } }
public static string ValidateSchema(string jsonText, string schemaText) { var serializer = new Manatee.Json.Serialization.JsonSerializer(); var json = Manatee.Json.JsonValue.Parse(jsonText); var schemaJson = Manatee.Json.JsonValue.Parse(schemaText); var schema = new Manatee.Json.Schema.JsonSchema(); schema.FromJson(schemaJson, serializer); Manatee.Json.Schema.JsonSchemaOptions.OutputFormat = Manatee.Json.Schema.SchemaValidationOutputFormat.Basic; var validationResults = schema.ValidateSchema(); if (!validationResults.IsValid) { json = serializer.Serialize(validationResults); return(JsonHelper.FormatJson(json.ToString())); } else { return(""); } }