Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
        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);
            }
        }