Beispiel #1
0
            public async Task Should_create_a_host_that_responds_to_requests()
            {
                using (var client = new HttpClient())
                {
                    var request = new Request {
                        Value = "Hello"
                    };
                    var envelope = new HttpMessageEnvelope(request, TypeMetadataCache <Request> .MessageTypeNames);
                    envelope.RequestId          = NewId.NextGuid().ToString();
                    envelope.DestinationAddress = HostAddress.ToString();
                    envelope.ResponseAddress    = new Uri("reply://localhost:8080/").ToString();

                    var messageBody = JsonConvert.SerializeObject(envelope, JsonMessageSerializer.SerializerSettings);

                    for (var i = 0; i < 5; i++)
                    {
                        var content = new StringContent(messageBody, Encoding.UTF8, "application/vnd.masstransit+json");

                        var timer = Stopwatch.StartNew();

                        string response;
                        using (var result = await client.PostAsync(HostAddress, content))
                        {
                            response = await result.Content.ReadAsStringAsync();
                        }

                        timer.Stop();

                        await Console.Out.WriteLineAsync($"Request complete: {timer.ElapsedMilliseconds}ms");
                    }
                }
            }
            public async Task Should_create_a_host_that_responds_to_requests()
            {
                using (var client = new HttpClient())
                {
                    var request = new Request {
                        Value = "Hello"
                    };
                    var envelope = new HttpMessageEnvelope(request, TypeMetadataCache <Request> .MessageTypeNames);
                    envelope.RequestId          = NewId.NextGuid().ToString();
                    envelope.DestinationAddress = HostAddress.ToString();
                    envelope.ResponseAddress    = new Uri("reply://localhost:8080/").ToString();

                    var messageBody = JsonConvert.SerializeObject(envelope, JsonMessageSerializer.SerializerSettings);

                    for (var i = 0; i < 5; i++)
                    {
                        //                        var content = new StringContent(messageBody, Encoding.UTF8, "application/vnd.masstransit+json");

                        var content = new ByteArrayContent(Encoding.UTF8.GetBytes(messageBody));
                        content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.masstransit+json");


                        var timer = Stopwatch.StartNew();

                        var message = new HttpRequestMessage(HttpMethod.Post, HostAddress);
                        message.Content = content;


                        message.Headers.Add(Clients.HttpHeaders.RequestId, envelope.RequestId);


                        string response;
                        using (var result = await client.SendAsync(message))
                        {
                            result.EnsureSuccessStatusCode();

                            response = await result.Content.ReadAsStringAsync();
                        }

                        timer.Stop();

                        await Console.Out.WriteLineAsync($"Request complete: {timer.ElapsedMilliseconds}ms");
                    }
                }
            }
Beispiel #3
0
        /// <summary>
        /// Get Host IP Address and MAC Address by matching Regex
        /// </summary>
        private void GetHostAddress()
        {
            StreamReader reader = null;

            try
            {
                string regex = (new StringBuilder(@"^\s+(")).Append(HostAddress.IPRegex)
                               .Append(@")\s+(").Append(HostAddress.MACRegex)
                               .Append(@")\s+\S+\s+$").ToString();
                DataRowCollection rows = dataSet.Tables[0].Rows;
                reader = new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(ARPProcess())));

                rows.Clear();
                while (!reader.EndOfStream)
                {
                    GroupCollection groups = Regex.Match(reader.ReadLine(), regex).Groups;
                    if (groups.Count == 3)
                    {
                        HostAddress address = new HostAddress()
                        {
                            IP  = groups[1].Value,
                            MAC = groups[2].Value
                        };

                        rows.Add(address.IP, address.ToString());
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Searching hosts' IP Failed! " + e.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
 public bool Matches(Uri address)
 {
     return(address.ToString().StartsWith(HostAddress.ToString(), StringComparison.OrdinalIgnoreCase));
 }