Esempio n. 1
0
 public void XmlSerializerToStream()
 {
     for (var i = 0; i < N; i++)
     {
         _xmlSerializer.Serialize(_data, _xmlSerializerStream);
         _xmlSerializerStream.Position = 0;
     }
 }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }