public InProcessServer(string assemblyName, ITestOutputHelper output)
        {
            this.output = output;

            // localhost instead of machine name, as its not possible to get machine name when running non windows.
            var machineName = "localhost";

            this.url = "http://" + machineName + ":" + random.Next(5000, 14000).ToString();

            output.WriteLine(string.Format("{0}: Launching application at: {1}", DateTime.Now.ToString("G"), this.url));

            this.httpListenerConnectionString = this.Start(assemblyName);

            output.WriteLine(string.Format("{0}: Starting listener at: {1}", DateTime.Now.ToString("G"), this.httpListenerConnectionString));

            this.listener = new TelemetryHttpListenerObservable(this.httpListenerConnectionString);
            try
            {
                this.listener.Start();
            }
            catch (HttpListenerException ex)
            {
                output.WriteLine(string.Format("{0}: Error starting listener.ErrorCode {1} Native Code {2}", DateTime.Now.ToString("G"), ex.ErrorCode, ex.NativeErrorCode));
                throw ex;
            }
        }
        public static Envelope[] ReceiveItemsOfType <T>(
            this TelemetryHttpListenerObservable listener,
            int timeOut)
        {
            var result = listener
                         .Where(item => (item is T))
                         .TakeUntil(DateTimeOffset.UtcNow.AddMilliseconds(timeOut))
                         .ToEnumerable()
                         .ToArray();

            return(result);
        }
        public static Envelope[] ReceiveItems(
            this TelemetryHttpListenerObservable listener,
            int timeOut)
        {
            if (null == listener)
            {
                throw new ArgumentNullException("listener");
            }

            var result = listener
                         .TakeUntil(DateTimeOffset.UtcNow.AddMilliseconds(timeOut))
                         .ToEnumerable()
                         .ToArray();

            return(result);
        }
        public InProcessServer(string assemblyName, ITestOutputHelper output)
        {
            this.output = output;

            var machineName = Environment.GetEnvironmentVariable("COMPUTERNAME");

            this.url = "http://" + machineName + ":" + random.Next(5000, 14000).ToString();

            output.WriteLine(string.Format("{0}: Launching application at: {1}", DateTime.Now.ToString("G"), this.url));

            this.httpListenerConnectionString = this.Start(assemblyName);

            output.WriteLine(string.Format("{0}: Starting listener at: {1}", DateTime.Now.ToString("G"), this.httpListenerConnectionString));

            this.listener = new TelemetryHttpListenerObservable(this.httpListenerConnectionString);
            this.listener.Start();
        }
Пример #5
0
        private bool StartListener(string listenerConnectionString)
        {
            output.WriteLine(string.Format("{0}: Starting listener at: {1}", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"), this.httpListenerConnectionString));

            this.listener = new TelemetryHttpListenerObservable(listenerConnectionString, this.output);
            try
            {
                this.listener.Start();
                output.WriteLine(string.Format("{0}: Started listener", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt")));
            }
            catch (HttpListenerException ex)
            {
                output.WriteLine(string.Format("{0}: Error starting listener.ErrorCode {1} Native Code {2}", DateTime.Now.ToString("G"), ex.ErrorCode, ex.NativeErrorCode));
                return(false);
            }

            return(true);
        }
        public static Envelope[] ReceiveItemsOfType <T>(
            this TelemetryHttpListenerObservable listener,
            int count,
            int timeOut)
        {
            var result = listener
                         .Where(item => (item is T))
                         .TakeUntil(DateTimeOffset.UtcNow.AddMilliseconds(timeOut))
                         .Take(count)
                         .ToEnumerable()
                         .ToArray();

            if (result.Length != count)
            {
                throw new InvalidDataException("Incorrect number of items. Expected: " + count + " Received: " + result.Length);
            }

            return(result);
        }