Пример #1
0
        public void Try_deserialize_event_with_not_found_ClrType()
        {
            var textSerializer  = new JsonTextSerializer();
            var eventSerializer = new EventSerializer(textSerializer);

            var serializedData = textSerializer.Serialize(new SpokeSomething("Hi"));

            var metadata = new EventSource.Metadata(new[]
            {
                new KeyValuePair <string, object>(MetadataKeys.AggregateId, Guid.NewGuid().ToString()),
                new KeyValuePair <string, object>(MetadataKeys.StreamSequenceNumber, 1.ToString()),
                new KeyValuePair <string, object>(MetadataKeys.EventClrType, "Cars.UnitTests.EventSerializerTests+NotFoundClrType, Cars.UnitTests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")
            });

            var mockCommitedEvent = new Mock <ICommitedEvent>();

            mockCommitedEvent.Setup(e => e.Version).Returns(1);
            mockCommitedEvent.Setup(e => e.AggregateId).Returns(Guid.NewGuid);
            mockCommitedEvent.Setup(e => e.SerializedData).Returns(serializedData);
            mockCommitedEvent.Setup(e => e.SerializedMetadata).Returns(textSerializer.Serialize(metadata));

            Action act = () => eventSerializer.Deserialize(mockCommitedEvent.Object);

            act.ShouldThrowExactly <EventTypeNotFoundException>();
        }
Пример #2
0
        private static string Serialize(object graph)
        {
            var serializer = new JsonTextSerializer();
            var writer     = new StringWriter();

            serializer.Serialize(writer, graph);
            return(writer.ToString());
        }
Пример #3
0
 public void NewtonsoftJsonSerializerToStream()
 {
     for (var i = 0; i < N; i++)
     {
         _jsonSerializer.Serialize(_data, _jsonSerializerStream);
         _jsonSerializerStream.Position = 0;
     }
 }
Пример #4
0
        private static string Serialize(object payload)
        {
            var serializer = new JsonTextSerializer();

            using (var writer = new StringWriter()) {
                serializer.Serialize(writer, payload);
                return(writer.ToString());
            }
        }
        public EventData Serialize(IVersionedEvent e, Type sourceType, string correlationId)
        {
            using (var writer = new StringWriter())
            {
                _serializer.Serialize(writer, e);
                var eventType = e.GetType();
                return(new EventData
                {
                    Version = e.Version,
                    SourceId = e.SourceId.ToString(),
                    Payload = writer.ToString(),
                    SourceType = sourceType.Name,
                    CorrelationId = correlationId,

                    AssemblyName = e.GetType().Assembly.FullName,
                    Namespace = eventType.Namespace,
                    TypeName = eventType.Name,
                    FullName = eventType.FullName
                });
            }
        }
Пример #6
0
        static void Main(string[] args)
        {
            try
            {
                IText        text              = new Text();
                IConcordance concordance       = new Concordance();
                var          concordanceParser = new ConcordanceParser();
                var          configuration     = new GlobalConfiguration();

                if (args.Length != 0)
                {
                    configuration.FileNames = args;
                }
                else
                {
                    using var reader = new StreamReader("../../../config.json");
                    var json = reader.ReadToEnd();
                    configuration = JsonConvert.DeserializeObject <GlobalConfiguration>(json);
                }


                foreach (var fileName in configuration.FileNames)
                {
                    using var stream = new StreamReader(new FileStream(fileName, FileMode.Open));
                    var textParser = new TextParser();
                    var textReader = new TextModelReader(stream);
                    text = textParser.ParseText(textReader.ReadAllText());
                }

                foreach (var fileName in configuration.FileNames)
                {
                    using var stream = new StreamReader(new FileStream(fileName, FileMode.Open));
                    var textParser = new TextParser();
                    var textReader = new TextModelReader(stream);
                    concordance = concordanceParser.ParseText(textReader.ReadAllText());
                }

                var jsonText = JsonTextSerializer.Serialize(text);
                var jsonConc = JsonTextSerializer.Serialize(concordance);

                using (var writer = new StreamWriter("../../../text.json"))
                {
                    var textModelWriter = new TextModelWriter(writer);
                    textModelWriter.Write(jsonText);
                }

                using (var writer = new StreamWriter("../../../concordance.json"))
                {
                    var textModelWriter = new TextModelWriter(writer);
                    textModelWriter.Write(jsonConc);
                }
                Console.WriteLine();
                Console.WriteLine("----Select words from question sentences with length 10------------------------");
                Console.WriteLine();
                foreach (var word in text.GetWordsFromQuestionSentences(10))
                {
                    Console.WriteLine(word);
                }
                Console.WriteLine();
                Console.WriteLine("----Order sentences by words count-------------------------");
                Console.WriteLine();
                foreach (var sentence in text.OrderSentencesByWordsCount())
                {
                    Console.Write(sentence);
                    Console.Write(" --- ");
                    Console.Write($"{sentence.WordsCount} words");
                    Console.WriteLine();
                }
                Console.WriteLine();
                Console.WriteLine("-----Deleting words with length 10--------------");
                Console.WriteLine();
                text.DeleteWords(10);
                foreach (var sentence in text.Sentences)
                {
                    Console.WriteLine(sentence);
                }
                Console.WriteLine();
                Console.WriteLine("-----Replacing words: \"In\" replace by \"In word replaced\"----------------");
                Console.WriteLine();
                text.ReplaceWord("In", "In word replaced");
                foreach (var sentence in text.Sentences)
                {
                    Console.WriteLine(sentence);
                }

                Console.WriteLine("------------------------------------");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Пример #7
0
        public HttpStatusTransport(int port = 80)
        {
            var htmlPage       = this.GetAssembly().GetResourceString("Status.htm");
            var xmlSerializer  = new XmlTextSerializer();
            var jsonSerializer = new JsonTextSerializer()
            {
                UseCamelCase = true
            };

            _httpServer = new SimpleHttpServer();
            _httpServer.AddGetHandler("/", ctx =>
            {
                ctx.Response.Write(htmlPage);
            });
            _httpServer.AddGetHandler("/xml", ctx =>
            {
                if (OnFetchStatus == null)
                {
                    return;
                }
                var statuses             = OnFetchStatus.Invoke();
                ctx.Response.ContentType = SerializerMimeTypes.Xml;
                xmlSerializer.Serialize(statuses, ctx.Response.OutputStream);
            });
            _httpServer.AddGetHandler("/json", ctx =>
            {
                if (OnFetchStatus == null)
                {
                    return;
                }
                var statuses             = OnFetchStatus.Invoke();
                ctx.Response.ContentType = SerializerMimeTypes.Json;
                jsonSerializer.Serialize(statuses, ctx.Response.OutputStream);
            });
            _httpServer.AddGetHandler("/gccollect", ctx =>
            {
                GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
                GC.Collect();
                GC.WaitForPendingFinalizers();
                ctx.Response.ContentType = SerializerMimeTypes.Json;
                ctx.Response.Write("true");
            });
            _httpServer.AddGetHandler("/discovery", ctx =>
            {
                var services       = DiscoveryService.GetRegisteredServices();
                var statusServices = services.Where(s => s.Category == DiscoveryService.FrameworkCategory && s.Name == "STATUS.HTTP").ToArray();
                ctx.Response.WriteLine("<html><head><title>Discovered Status Services</title></head><body style='padding:30px;'><h1 style='text-align:center;'>Discovered status services</h1>");
                foreach (var g in statusServices.GroupBy(s => new { s.EnvironmentName, s.MachineName }).OrderBy(s => s.Key.EnvironmentName))
                {
                    ctx.Response.WriteLine($"<h3>Environment: {g.Key.EnvironmentName} - Machine: {g.Key.MachineName}</h3>");
                    ctx.Response.WriteLine("<ul>");
                    foreach (var ss in g)
                    {
                        var dct = (Dictionary <string, object>)ss.Data.GetValue();
                        ctx.Response.WriteLine("<li style='list-style-type: none;'>");
                        foreach (var ssAddress in ss.Addresses)
                        {
                            ctx.Response.WriteLine($"<a href='http://{ssAddress.ToString()}:{dct["Port"]}/' target='_blank' style='text-decoration: none;color: blue;'>{ssAddress.ToString()}</a> /");
                        }
                        ctx.Response.WriteLine($" {ss.ApplicationName}</li>");
                    }
                    ctx.Response.WriteLine("</ul>");
                }
                ctx.Response.WriteLine("</body></html>");
            });
            StartListening(port).WaitAsync();
            Core.Status.DeAttachObject(_httpServer);
        }
Пример #8
0
        public void Setup()
        {
            Core.InitDefaults();

            var sTest = new STest
            {
                FirstName = "Daniel",
                LastName  = "Redondo",
                Age       = 35,
                value     = 166
            };

            _data = new List <STest>
            {
                sTest, sTest, sTest, sTest, sTest, sTest,
                sTest, sTest, sTest, sTest, sTest, sTest,
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 0, Age = 1, Brother = sTest
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 1, Age = 2, Brother = sTest
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 2, Age = 3, Brother = sTest
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 3, Age = 4, Brother = sTest
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 4, Age = 5, Brother = sTest
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 5, Age = 6, Brother = sTest
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 6, Age = 7, Brother = sTest
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 7, Age = 8, Brother = sTest
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 8, Age = 9, Brother = sTest
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 9, Age = 10, Brother = sTest
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 10, Age = 11
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 11, Age = 12
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 12, Age = 13
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 13, Age = 14
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 14, Age = 15
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 15, Age = 16
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 16, Age = 17
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 17, Age = 18
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 18, Age = 19
                },
            };

            _jsonSerializer       = new JsonTextSerializer();
            _binData              = _jsonSerializer.Serialize(_data);
            _jsonSerializerStream = new MemoryStream();
            _jsonSerializer.Serialize(_data, _jsonSerializerStream);

            _xmlSerializer       = new XmlTextSerializer();
            _binData             = _xmlSerializer.Serialize(_data);
            _xmlSerializerStream = new MemoryStream();
            _xmlSerializer.Serialize(_data, _xmlSerializerStream);

            _binSerializer       = new BinaryFormatterSerializer();
            _binData             = _binSerializer.Serialize(_data);
            _binSerializerStream = new MemoryStream();
            _binSerializer.Serialize(_data, _binSerializerStream);

            _utf8jsonSerializer       = new Utf8JsonTextSerializer();
            _binData                  = _utf8jsonSerializer.Serialize(_data);
            _utf8jsonSerializerStream = new MemoryStream();
            _utf8jsonSerializer.Serialize(_data, _utf8jsonSerializerStream);

            _msgPackSerializer       = new MsgPackSerializer();
            _binData                 = _msgPackSerializer.Serialize(_data);
            _msgPackSerializerStream = new MemoryStream();
            _msgPackSerializer.Serialize(_data, _msgPackSerializerStream);

            _nBinary       = new NBinarySerializer();
            _binData       = _nBinary.Serialize(_data);
            _nBinaryStream = new MemoryStream();
            _nBinary.Serialize(_data, _nBinaryStream);

            _rawBinary       = new RawBinarySerializer();
            _binData         = _rawBinary.Serialize(_data);
            _rawBinaryStream = new MemoryStream();
            _rawBinary.Serialize(_data, _rawBinaryStream);
        }