예제 #1
0
        public async Task <PostAnswerResponse> AnswerQuestion(string sessionId, PostAnswerRequest postAnswerRequest)
        {
            var url = $"{httpClient.BaseAddress}/assessment/{sessionId}";

            using (var sc = new StringContent(serialiser.Serialise(postAnswerRequest), Encoding.UTF8, MediaTypeNames.Application.Json))
            {
                var httpResponseMessage = await httpClient.PostAsync(url, sc).ConfigureAwait(false);

                httpResponseMessage.EnsureSuccessStatusCode();
                var contentResponse = await httpResponseMessage.Content.ReadAsStringAsync().ConfigureAwait(false);

                var response = serialiser.Deserialise <PostAnswerResponse>(contentResponse);
                return(response);
            }
        }
        public void Send(IChannel channel)
        {
            var serialisedResponse = _serialiser.Serialise(new { Type = "ERROR", RequestId = _requestId, Error = _serialiser.Serialise(_error) });

            Log.Verbose($"Sending Failed Response: {serialisedResponse}");
            channel.Write(serialisedResponse);
        }
예제 #3
0
        public async Task Run()
        {
            var grid = await generator.GenerateGridAsync();

            var gridAsJson = serialiser.Serialise(grid);
            await writer.WriteAsync(gridAsJson);
        }
예제 #4
0
        public TimedEntityTagHeaderValue Extract(object viewModel)
        {
            var resource = viewModel as ICacheResource;

            if (resource != null)
            {
                return(resource.GetTimedETag());
            }

            return(new TimedEntityTagHeaderValue(_hasher.ComputeHash(_serialiser.Serialise(viewModel))));
        }
        public void Serialise_WithModelContext_ReturnsExpectedXml()
        {
            // Arrange
            var expectedXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><ModelContext Id=\"fe715b9e-facc-4353-bcb1-bec1b313423a\" xmlns=\"http://api.esendex.com/ns/\"><Value>5</Value></ModelContext>";

            var model = new ModelContext
            {
                Id    = new Guid("FE715B9E-FACC-4353-BCB1-BEC1B313423A"),
                Value = 5
            };

            // Act
            var actualXml = serialiser.Serialise(model);

            // Assert
            Assert.AreEqual(expectedXml, actualXml);
        }
예제 #6
0
        public void SendBroadcastMessage(BroadcastMessageType msgType, ISerialiser <AutoDiscoveryMessage, byte[]> serialiser, Int32 multicastPort)
        {
            if (msgType == BroadcastMessageType.None)
            {
                throw new InvalidOperationException("The specified BroadcastMessageType is not valid");
            }

            if (serialiser == null)
            {
                throw new ArgumentException("The specified serialiser is not valid");
            }

            // Create and prepare the arguments
            byte[] temp = serialiser.Serialise(new AutoDiscoveryMessage(_socket.LocalEndPoint, msgType));
            byte[] data = BitConverter.GetBytes(temp.Length).Merge(temp);
            // send the data
            UdpClient cli = new UdpClient();

            cli.Send(data, data.Length, new IPEndPoint(IPAddress.Broadcast, Port));
        }
        public void Print()
        {
            var fixture      = new Fixture();
            var simple       = fixture.Create <SimpleObject>();
            var complex      = fixture.Create <ComplexObject>();
            var simple10     = fixture.CreateMany <SimpleObject>(10).ToArray();
            var simple10000  = fixture.CreateMany <SimpleObject>(10000).ToArray();
            var complex10    = fixture.CreateMany <ComplexObject>(10).ToArray();
            var complex10000 = fixture.CreateMany <ComplexObject>(10000).ToArray();

            var builder = new StringBuilder();

            builder.AppendLine("| Serialiser                | Simple | Complex | Simple (10) | Complex (10) | Simple (10000) | Complex (10000) |");
            builder.AppendLine("| ------------------------- | ------:| -------:| -----------:| ------------:| --------------:| ---------------:|");

            foreach (Type type in SerialiserTypes)
            {
                ISerialiser serialiser = (ISerialiser)Activator.CreateInstance(type);
                var         serialised = new[]
                {
                    serialiser.Serialise(simple),
                    serialiser.Serialise(complex),
                    serialiser.Serialise(simple10),
                    serialiser.Serialise(complex10),
                    serialiser.Serialise(simple10000),
                    serialiser.Serialise(complex10000)
                };

                builder.Append("| ");
                builder.Append(type.Name.PadRight(25));
                builder.Append(" | ");
                builder.Append(string.Join(" | ", serialised.Select(s => s.Length)));
                builder.AppendLine(" |");
            }

            Console.WriteLine(builder.ToString());
        }
예제 #8
0
 public static string[] Serialise <T>(T t, string path)
 {
     CheckFileFormat(path);
     return(serialiser.Serialise <T>(t, path));
 }
예제 #9
0
 /// <summary>
 /// Serialises an <see cref="IEntity" /> through the <see cref="NetworkStream" />.
 /// </summary>
 /// <param name="networkStream">The <see cref="NetworkStream" /> to serialise the <see cref="IEntity" /> across.</param>
 /// <param name="entity">The <see cref="IEntity" /> to serialise.</param>
 public void Serialise(NetworkStream networkStream, T entity)
 {
     serialiser.Serialise(networkStream, entity);
     Log.DebugFormat("{0} entity serialised and sent to network stream", entity);
 }
예제 #10
0
 /// <summary>
 /// Serialise <see cref="T" /> down the wire.
 /// </summary>
 /// <param name="networkStream">The networkStream that connects the Client and Server.</param>
 /// <param name="message">The message which inherits from <see cref="IMessage" />.</param>
 protected virtual void Serialise(NetworkStream networkStream, T message)
 {
     serialiser.Serialise(networkStream, message);
 }
예제 #11
0
        public void Send(IChannel channel)
        {
            var serialisedResponse = _serialiser.Serialise(new { Type = "RESPONSE", Response = _response });

            channel.Write(serialisedResponse);
        }
        public void Send(IChannel channel)
        {
            var serialisedRequest = _serialiser.Serialise(new { Type = "REQUEST", Request = _request });

            channel.Write(serialisedRequest);
        }