Exemple #1
0
    public static void WebSocket_Http_Duplex_Buffered(NetHttpMessageEncoding messageEncoding)
    {
        EndpointAddress endpointAddress;
        NetHttpBinding  binding        = null;
        ClientReceiver  clientReceiver = null;
        InstanceContext context        = null;
        DuplexChannelFactory <IWSDuplexService> channelFactory = null;
        IWSDuplexService client = null;

        try
        {
            // *** SETUP *** \\
            binding = new NetHttpBinding()
            {
                MaxReceivedMessageSize = ScenarioTestHelpers.SixtyFourMB,
                MaxBufferSize          = ScenarioTestHelpers.SixtyFourMB,
            };
            binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;
            binding.MessageEncoding = messageEncoding;

            clientReceiver  = new ClientReceiver();
            context         = new InstanceContext(clientReceiver);
            endpointAddress = new EndpointAddress(Endpoints.WebSocketHttpDuplexBuffered_Address + Enum.GetName(typeof(NetHttpMessageEncoding), messageEncoding));
            channelFactory  = new DuplexChannelFactory <IWSDuplexService>(context, binding, endpointAddress);
            client          = channelFactory.CreateChannel();

            // *** EXECUTE *** \\
            // Invoking UploadData
            client.UploadData(ScenarioTestHelpers.CreateInterestingString(123));

            // Invoking StartPushingData
            client.StartPushingData();
            Assert.True(clientReceiver.ReceiveDataInvoked.WaitOne(ScenarioTestHelpers.TestTimeout),
                        String.Format("Test case timeout was reached while waiting for the buffered response from the Service. Timeout was: {0}", ScenarioTestHelpers.TestTimeout));
            clientReceiver.ReceiveDataInvoked.Reset();
            // Invoking StopPushingData
            client.StopPushingData();
            Assert.True(clientReceiver.ReceiveDataCompleted.WaitOne(ScenarioTestHelpers.TestTimeout),
                        String.Format("Test case timeout was reached while waiting for the buffered response from the Service to be completed. Timeout was: {0}", ScenarioTestHelpers.TestTimeout));
            clientReceiver.ReceiveDataCompleted.Reset();

            // Getting results from server via callback.
            client.GetLog();
            Assert.True(clientReceiver.LogReceived.WaitOne(ScenarioTestHelpers.TestTimeout),
                        String.Format("Test case timeout was reached while waiting for the Logging from the Service to be received. Timeout was: {0}", ScenarioTestHelpers.TestTimeout));

            // *** VALIDATE *** \\
            Assert.True(clientReceiver.ServerLog.Count > 0,
                        "The logging done by the Server was not returned via the Callback.");

            // *** CLEANUP *** \\
            ((ICommunicationObject)client).Close();
            channelFactory.Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)client, channelFactory);
        }
    }
Exemple #2
0
        public Client Start(SdjMainViewModel main)
        {
            SdjMainViewModel           = main;
            Receiver                   = new ClientReceiver(main);
            _debug                     = new Debug("Connection");
            Config                     = ClientConfig.LoadConfig();
            ClientInfo.Instance.Client = ScsClientFactory.CreateClient(new ScsTcpEndPoint(Config.Ip, Config.Port));
            ClientInfo.Instance.Client.MessageReceived += Client_MessageReceived;
            ClientInfo.Instance.Client.Disconnected    += Client_Disconnected;
            ClientInfo.Instance.ReplyMessenger          = new RequestReplyMessenger <IScsClient>(ClientInfo.Instance.Client);
            ClientInfo.Instance.ReplyMessenger.Start();

            ClientInfo.Instance.Client.ConnectTimeout = 400;

            while (ClientInfo.Instance.Client.CommunicationState == CommunicationStates.Disconnected)
            {
                try
                {
#if DEBUG
                    Thread.Sleep(1000);
#endif
                    ClientInfo.Instance.Client.Connect();
                }
                catch (TimeoutException e)
                {
                    _debug.Log(e.Message);
                }
            }

            PeriodicTask.StartNew(80, RefreshData);

            Sender = new ClientSender(ClientInfo.Instance.Client, ClientInfo.Instance.ReplyMessenger);
            return(this);
        }
Exemple #3
0
 public virtual void MidiSequence()
 {
     ClientReceiver receiver = new ClientReceiver ();
     _client.ProcessFunc += receiver.SequenceMidiAction;
     _client.Start ();
     Thread.Sleep (100);
     Assert.IsTrue (receiver.Called > 0);
 }
Exemple #4
0
 public virtual void MidiPlayNote()
 {
     ClientReceiver receiver = new ClientReceiver ();
     _client.ProcessFunc += receiver.PlayMidiNoteAction;
     _client.Start ();
     Thread.Sleep (100);
     Assert.IsTrue (receiver.Called > 0);
 }
Exemple #5
0
        public virtual void MidiPlayNote()
        {
            ClientReceiver receiver = new ClientReceiver();

            _client.ProcessFunc += receiver.PlayMidiNoteAction;
            _client.Start();
            Thread.Sleep(100);
            Assert.IsTrue(receiver.Called > 0);
        }
Exemple #6
0
        public virtual void MidiSequence()
        {
            ClientReceiver receiver = new ClientReceiver();

            _client.ProcessFunc += receiver.SequenceMidiAction;
            _client.Start();
            Thread.Sleep(100);
            Assert.IsTrue(receiver.Called > 0);
        }
        public virtual void AudioCopying()
        {
            ClientReceiver receiver = new ClientReceiver();

            _client.ProcessFunc = receiver.CopyInToOutAction;
            _client.Start();
            Thread.Sleep(2000);
            Assert.IsTrue(receiver.Called > 0);
        }
Exemple #8
0
        public Client()
        {
            TcpClient client = new TcpClient();

            client.Connect("localhost", 1017);
            receiver = new ClientReceiver(this);
            stream   = client.GetStream();

            stream.BeginRead(buffer, 0, buffer.Length, new AsyncCallback(OnRead), null);
        }
Exemple #9
0
 public virtual void AudioAddMultipleActions()
 {
     ClientReceiver receiver = new ClientReceiver ();
     _client.ProcessFunc += receiver.CallBackOneAction;
     _client.ProcessFunc += receiver.CallBackTwoAction;
     _client.Start ();
     Thread.Sleep (200);
     _client.Stop ();
     Assert.AreEqual (3, receiver.Called);
 }
        public virtual void AudioAddMultipleActions()
        {
            ClientReceiver receiver = new ClientReceiver();

            _client.ProcessFunc += receiver.CallBackOneAction;
            _client.ProcessFunc += receiver.CallBackTwoAction;
            _client.Start();
            Thread.Sleep(200);
            _client.Stop();
            Assert.AreEqual(3, receiver.Called);
        }
Exemple #11
0
 public Program()
 {
     discover = new ClientDiscovery("gang?", "Dopple gang");
     receiver = new ClientReceiver();
     receiver.OnDataReceived += Receiver_OnDataReceived;
     handlers = new Dictionary <string, ICommandHandler>();
     handlers.Add("Task", new TaskHandler());
     handlers.Add("Audio", new AudioHandler());
     handlers.Add("Visuals", new VisualsHandler());
     handlers.Add("Windows", new WindowsHandler());
     handlers.Add("SystemInfo", new SystemInfoHandler());
     handlers.Add("CMD", new CMDHandler());
 }
 public virtual void StartAfterStopped()
 {
     using (Processor client = new Processor("testing", 1)) {
         ClientReceiver receiver = new ClientReceiver();
         client.ProcessFunc += receiver.ChannelCounterAction;
         Assert.IsTrue(client.Start());
         client.Stop();
         Assert.IsTrue(client.Start());
         Assert.AreEqual(1, client.AudioInPorts.Count());
         Thread.Sleep(100);
         Assert.AreEqual(1, receiver.Called);
     }
 }
Exemple #13
0
        /// <inheritdoc />
        public void Connect()
        {
            if (this.IsRunning)
            {
                throw new InvalidOperationException("Client is already running.");
            }

            if (this.IsConnected)
            {
                throw new InvalidOperationException("Client is already connected to remote host.");
            }

            if (this.ClientConfiguration == null)
            {
                throw new ArgumentNullException(nameof(this.ClientConfiguration), "Undefined Client configuration.");
            }

            if (this.ClientConfiguration.Port <= 0)
            {
                throw new ArgumentException($"Invalid port number '{this.ClientConfiguration.Port}' in configuration.", nameof(this.ClientConfiguration.Port));
            }

            if (NetworkHelper.BuildIPAddress(this.ClientConfiguration.Host) == null)
            {
                throw new ArgumentException($"Invalid host address '{this.ClientConfiguration.Host}' in configuration", nameof(this.ClientConfiguration.Host));
            }


            if (this.ClientConfiguration.BufferSize <= 0)
            {
                throw new ArgumentException($"Invalid buffer size '{this.ClientConfiguration.BufferSize}' in configuration.", nameof(this.ClientConfiguration.BufferSize));
            }

            this.sender        = new ClientSender(this.CreateSocketEventArgs(null));
            this.receiver      = new ClientReceiver(this);
            this.connectSocket = this.CreateSocketEventArgs(null);
            this.connectSocket.RemoteEndPoint = NetworkHelper.CreateIPEndPoint(this.ClientConfiguration.Host, this.ClientConfiguration.Port);

            SocketError error = this.connector.Connect(this.connectSocket);

            if (!this.IsConnected && error != SocketError.Success)
            {
                this.OnError(new InvalidOperationException("No se puede conectar con el servidor."));
                return;
            }

            this.IsRunning = true;
            this.sender.Start();
        }
        public IActionResult CreateFactor(string name, string family, string phone, string address)
        {
            string         CurrentUserID = User.FindFirstValue(ClaimTypes.NameIdentifier);
            ClientReceiver cr            = _ctx.ClientReceivers.SingleOrDefault(o => o.CRuser == CurrentUserID);

            cr = new ClientReceiver()
            {
                CRuser       = CurrentUserID,
                nameofcr     = name,
                lastnameofcr = family,
                addressofcr  = address,
                phoneofcr    = phone,
            };

            _ctx.ClientReceivers.Add(cr);
            _ctx.SaveChanges();
            return(RedirectToAction("Payment"));
        }
Exemple #15
0
        /// <inheritdoc />
        public void Connect()
        {
            if (IsRunning)
            {
                throw new InvalidOperationException("Client is already running.");
            }

            if (IsConnected)
            {
                throw new InvalidOperationException("Client is already connected to remote host.");
            }

            if (ClientConfiguration == null)
            {
                throw new ArgumentNullException(nameof(ClientConfiguration), "Undefined Client configuration.");
            }

            if (ClientConfiguration.Port <= 0)
            {
                throw new ArgumentException($"Invalid port number '{ClientConfiguration.Port}' in configuration.", nameof(ClientConfiguration.Port));
            }

            if (NetworkHelper.BuildIPAddress(ClientConfiguration.Host) == null)
            {
                throw new ArgumentException($"Invalid host address '{ClientConfiguration.Host}' in configuration", nameof(ClientConfiguration.Host));
            }

            SocketError error = connector.Connect(connectSocketArgs);

            if (!IsConnected && error != SocketError.Success)
            {
                OnError(new InvalidOperationException("Could not connect to login server."));
                return;
            }

            receiver = new ClientReceiver(this);
            if (!Socket.ReceiveAsync(receiveSocketArgs))
            {
                receiver.Receive(receiveSocketArgs);
            }

            IsRunning = true;
        }
Exemple #16
0
    public static void WebSocket_Http_Duplex_TextBuffered_KeepAlive()
    {
        NetHttpBinding binding = null;
        ClientReceiver clientReceiver = null;
        InstanceContext context = null;
        DuplexChannelFactory<IWSDuplexService> channelFactory = null;
        IWSDuplexService client = null;

        try
        {
            // *** SETUP *** \\
            binding = new NetHttpBinding()
            {
                MaxReceivedMessageSize = ScenarioTestHelpers.SixtyFourMB,
                MaxBufferSize = ScenarioTestHelpers.SixtyFourMB,
            };
            binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;
            binding.MessageEncoding = NetHttpMessageEncoding.Text;
            binding.WebSocketSettings.KeepAliveInterval = TimeSpan.FromSeconds(2);

            clientReceiver = new ClientReceiver();
            context = new InstanceContext(clientReceiver);
            channelFactory = new DuplexChannelFactory<IWSDuplexService>(context, binding, new EndpointAddress(Endpoints.WebSocketHttpDuplexTextBuffered_Address));
            client = channelFactory.CreateChannel();

            // *** EXECUTE *** \\
            // Invoking UploadData
            client.UploadData(ScenarioTestHelpers.CreateInterestingString(123));

            // Invoking StartPushingData
            client.StartPushingData();
            Assert.True(clientReceiver.ReceiveDataInvoked.WaitOne(ScenarioTestHelpers.TestTimeout),
                String.Format("Test case timeout was reached while waiting for the buffered response from the Service. Timeout was: {0}", ScenarioTestHelpers.TestTimeout));
            clientReceiver.ReceiveDataInvoked.Reset();
            // Invoking StopPushingData
            client.StopPushingData();
            Assert.True(clientReceiver.ReceiveDataCompleted.WaitOne(ScenarioTestHelpers.TestTimeout),
                String.Format("Test case timeout was reached while waiting for the buffered response from the Service to be completed. Timeout was: {0}", ScenarioTestHelpers.TestTimeout));
            clientReceiver.ReceiveDataCompleted.Reset();

            // Getting results from server via callback.
            client.GetLog();
            Assert.True(clientReceiver.LogReceived.WaitOne(ScenarioTestHelpers.TestTimeout),
                String.Format("Test case timeout was reached while waiting for the Logging from the Service to be received. Timeout was: {0}", ScenarioTestHelpers.TestTimeout));

            // *** VALIDATE *** \\
            Assert.True(clientReceiver.ServerLog.Count > 0,
                "The logging done by the Server was not returned via the Callback.");

            // *** CLEANUP *** \\
            ((ICommunicationObject)client).Close();
            channelFactory.Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\  
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)client, channelFactory);
        }
    }
Exemple #17
0
    public static void WebSocket_Http_Duplex_BinaryStreamed()
    {
        NetHttpBinding  binding        = null;
        ClientReceiver  clientReceiver = null;
        InstanceContext context        = null;
        DuplexChannelFactory <IWSDuplexService> channelFactory = null;
        IWSDuplexService     client       = null;
        FlowControlledStream uploadStream = null;

        try
        {
            // *** SETUP *** \\
            binding = new NetHttpBinding()
            {
                MaxReceivedMessageSize = ScenarioTestHelpers.SixtyFourMB,
                MaxBufferSize          = ScenarioTestHelpers.SixtyFourMB,
            };
            binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;
            binding.TransferMode    = TransferMode.Streamed;
            binding.MessageEncoding = NetHttpMessageEncoding.Binary;

            clientReceiver = new ClientReceiver();
            context        = new InstanceContext(clientReceiver);

            channelFactory = new DuplexChannelFactory <IWSDuplexService>(context, binding, Endpoints.WebSocketHttpDuplexBinaryStreamed_Address);
            client         = channelFactory.CreateChannel();

            // *** EXECUTE *** \\
            using (Stream stream = client.DownloadStream())
            {
                int readResult;
                // Read from the stream, 1000 bytes at a time.
                byte[] buffer = new byte[1000];
                do
                {
                    readResult = stream.Read(buffer, 0, buffer.Length);
                }while (readResult != 0);
            }

            uploadStream = new FlowControlledStream();
            uploadStream.ReadThrottle   = TimeSpan.FromMilliseconds(500);
            uploadStream.StreamDuration = TimeSpan.FromSeconds(1);

            client.UploadStream(uploadStream);
            client.StartPushingStream();
            // Wait for the callback to get invoked before telling the service to stop streaming.
            // This ensures we can read from the stream on the callback while the NCL layer at the service
            // is still writing the bytes from the stream to the wire.
            // This will deadlock if the transfer mode is buffered because the callback will wait for the
            // stream, and the NCL layer will continue to buffer the stream until it reaches the end.

            Assert.True(clientReceiver.ReceiveStreamInvoked.WaitOne(ScenarioTestHelpers.TestTimeout),
                        String.Format("Test case timeout was reached while waiting for the stream response from the Service. Timeout was: {0}", ScenarioTestHelpers.TestTimeout));
            clientReceiver.ReceiveStreamInvoked.Reset();

            // Upload the stream while we are downloading a different stream
            uploadStream = new FlowControlledStream();
            uploadStream.ReadThrottle   = TimeSpan.FromMilliseconds(500);
            uploadStream.StreamDuration = TimeSpan.FromSeconds(1);
            client.UploadStream(uploadStream);

            client.StopPushingStream();
            // Waiting on ReceiveStreamCompleted from the ClientReceiver.
            Assert.True(clientReceiver.ReceiveStreamCompleted.WaitOne(ScenarioTestHelpers.TestTimeout),
                        String.Format("Test case timeout was reached while waiting for the stream response from the Service to be completed. Timeout was: {0}", ScenarioTestHelpers.TestTimeout));
            clientReceiver.ReceiveStreamCompleted.Reset();

            // Getting results from server via callback.
            client.GetLog();
            Assert.True(clientReceiver.LogReceived.WaitOne(ScenarioTestHelpers.TestTimeout),
                        String.Format("Test case timeout was reached while waiting for the Logging from the Service to be received. Timeout was: {0}", ScenarioTestHelpers.TestTimeout));

            // *** VALIDATE *** \\
            Assert.True(clientReceiver.ServerLog.Count > 0,
                        "The logging done by the Server was not returned via the Callback.");

            // *** CLEANUP *** \\
            ((ICommunicationObject)client).Close();
            channelFactory.Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)client, channelFactory);
            clientReceiver.Dispose();
        }
    }
Exemple #18
0
    public static void WebSocket_Https_Duplex_TextBuffered_KeepAlive()
    {
#if FULLXUNIT_NOTSUPPORTED
        bool root_Certificate_Installed = Root_Certificate_Installed();
        if (!root_Certificate_Installed)
        {
            Console.WriteLine("---- Test SKIPPED --------------");
            Console.WriteLine("Attempting to run the test in ToF, a ConditionalFact evaluated as FALSE.");
            Console.WriteLine("Root_Certificate_Installed evaluated as {0}", root_Certificate_Installed);
            return;
        }
#endif
        TextMessageEncodingBindingElement textMessageEncodingBindingElement = null;
        HttpsTransportBindingElement httpsTransportBindingElement = null;
        CustomBinding binding = null;
        ClientReceiver clientReceiver = null;
        InstanceContext context = null;
        DuplexChannelFactory<IWSDuplexService> channelFactory = null;
        IWSDuplexService client = null;

        try
        {
            // *** SETUP *** \\
            textMessageEncodingBindingElement = new TextMessageEncodingBindingElement();
            httpsTransportBindingElement = new HttpsTransportBindingElement()
            {
                MaxReceivedMessageSize = ScenarioTestHelpers.SixtyFourMB,
                MaxBufferSize = ScenarioTestHelpers.SixtyFourMB
            };
            httpsTransportBindingElement.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;
            httpsTransportBindingElement.WebSocketSettings.KeepAliveInterval = TimeSpan.FromSeconds(2);
            binding = new CustomBinding(textMessageEncodingBindingElement, httpsTransportBindingElement);

            clientReceiver = new ClientReceiver();
            context = new InstanceContext(clientReceiver);
            channelFactory = new DuplexChannelFactory<IWSDuplexService>(context, binding, new EndpointAddress(Endpoints.WebSocketHttpsDuplexTextBuffered_Address));
            client = channelFactory.CreateChannel();

            // *** EXECUTE *** \\
            // Invoking UploadData
            client.UploadData(ScenarioTestHelpers.CreateInterestingString(123));

            // Invoking StartPushingData
            client.StartPushingData();
            Assert.True(clientReceiver.ReceiveDataInvoked.WaitOne(ScenarioTestHelpers.TestTimeout),
                String.Format("Test case timeout was reached while waiting for the buffered response from the Service. Timeout was: {0}", ScenarioTestHelpers.TestTimeout));
            clientReceiver.ReceiveDataInvoked.Reset();
            // Invoking StopPushingData
            client.StopPushingData();
            Assert.True(clientReceiver.ReceiveDataCompleted.WaitOne(ScenarioTestHelpers.TestTimeout),
                String.Format("Test case timeout was reached while waiting for the buffered response from the Service to be completed. Timeout was: {0}", ScenarioTestHelpers.TestTimeout));
            clientReceiver.ReceiveDataCompleted.Reset();

            // Getting results from server via callback.
            client.GetLog();
            Assert.True(clientReceiver.LogReceived.WaitOne(ScenarioTestHelpers.TestTimeout),
                String.Format("Test case timeout was reached while waiting for the Logging from the Service to be received. Timeout was: {0}", ScenarioTestHelpers.TestTimeout));

            // *** VALIDATE *** \\
            Assert.True(clientReceiver.ServerLog.Count > 0,
                "The logging done by the Server was not returned via the Callback.");

            // *** CLEANUP *** \\
            ((ICommunicationObject)client).Close();
            channelFactory.Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\  
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)client, channelFactory);
        }
    }
Exemple #19
0
    public static void WebSocket_Http_Duplex_BinaryStreamed()
    {
        NetHttpBinding binding = null;
        ClientReceiver clientReceiver = null;
        InstanceContext context = null;
        DuplexChannelFactory<IWSDuplexService> channelFactory = null;
        IWSDuplexService client = null;
        FlowControlledStream uploadStream = null;

        try
        {
            // *** SETUP *** \\
            binding = new NetHttpBinding()
            {
                MaxReceivedMessageSize = ScenarioTestHelpers.SixtyFourMB,
                MaxBufferSize = ScenarioTestHelpers.SixtyFourMB,
            };
            binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;
            binding.TransferMode = TransferMode.Streamed;
            binding.MessageEncoding = NetHttpMessageEncoding.Binary;

            clientReceiver = new ClientReceiver();
            context = new InstanceContext(clientReceiver);

            channelFactory = new DuplexChannelFactory<IWSDuplexService>(context, binding, Endpoints.WebSocketHttpDuplexBinaryStreamed_Address);
            client = channelFactory.CreateChannel();

            // *** EXECUTE *** \\
            using (Stream stream = client.DownloadStream())
            {
                int readResult;
                // Read from the stream, 1000 bytes at a time.
                byte[] buffer = new byte[1000];
                do
                {
                    readResult = stream.Read(buffer, 0, buffer.Length);
                }
                while (readResult != 0);
            }

            uploadStream = new FlowControlledStream();
            uploadStream.ReadThrottle = TimeSpan.FromMilliseconds(500);
            uploadStream.StreamDuration = TimeSpan.FromSeconds(1);

            client.UploadStream(uploadStream);
            client.StartPushingStream();
            // Wait for the callback to get invoked before telling the service to stop streaming.
            // This ensures we can read from the stream on the callback while the NCL layer at the service
            // is still writing the bytes from the stream to the wire.  
            // This will deadlock if the transfer mode is buffered because the callback will wait for the
            // stream, and the NCL layer will continue to buffer the stream until it reaches the end.

            Assert.True(clientReceiver.ReceiveStreamInvoked.WaitOne(ScenarioTestHelpers.TestTimeout),
                String.Format("Test case timeout was reached while waiting for the stream response from the Service. Timeout was: {0}", ScenarioTestHelpers.TestTimeout));
            clientReceiver.ReceiveStreamInvoked.Reset();

            // Upload the stream while we are downloading a different stream
            uploadStream = new FlowControlledStream();
            uploadStream.ReadThrottle = TimeSpan.FromMilliseconds(500);
            uploadStream.StreamDuration = TimeSpan.FromSeconds(1);
            client.UploadStream(uploadStream);

            client.StopPushingStream();
            // Waiting on ReceiveStreamCompleted from the ClientReceiver.
            Assert.True(clientReceiver.ReceiveStreamCompleted.WaitOne(ScenarioTestHelpers.TestTimeout),
                String.Format("Test case timeout was reached while waiting for the stream response from the Service to be completed. Timeout was: {0}", ScenarioTestHelpers.TestTimeout));
            clientReceiver.ReceiveStreamCompleted.Reset();

            // Getting results from server via callback.
            client.GetLog();
            Assert.True(clientReceiver.LogReceived.WaitOne(ScenarioTestHelpers.TestTimeout),
                String.Format("Test case timeout was reached while waiting for the Logging from the Service to be received. Timeout was: {0}", ScenarioTestHelpers.TestTimeout));

            // *** VALIDATE *** \\
            Assert.True(clientReceiver.ServerLog.Count > 0,
                "The logging done by the Server was not returned via the Callback.");

            // *** CLEANUP *** \\
            ((ICommunicationObject)client).Close();
            channelFactory.Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)client, channelFactory);
            clientReceiver.Dispose();
        }
    }
Exemple #20
0
    ///////////////////////////////////////////////////
    #region Init

    private void Awake()
    {
        _messenger = GetComponent <ClientMessenger>();
        _receiver  = GetComponent <ClientReceiver>();
    }
Exemple #21
0
    public static void WebSocket_Https_Duplex_TextStreamed()
    {
        TextMessageEncodingBindingElement textMessageEncodingBindingElement = null;
        HttpsTransportBindingElement httpsTransportBindingElement = null;
        CustomBinding binding = null;
        ClientReceiver clientReceiver = null;
        InstanceContext context = null;
        DuplexChannelFactory<IWSDuplexService> channelFactory = null;
        IWSDuplexService client = null;
        FlowControlledStream uploadStream = null;

        try
        {
            // *** SETUP *** \\
            textMessageEncodingBindingElement = new TextMessageEncodingBindingElement();
            httpsTransportBindingElement = new HttpsTransportBindingElement()
            {
                MaxReceivedMessageSize = ScenarioTestHelpers.DefaultMaxReceivedMessageSize,
                MaxBufferSize = ScenarioTestHelpers.DefaultMaxReceivedMessageSize,
                TransferMode = TransferMode.Streamed
            };
            httpsTransportBindingElement.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;
            binding = new CustomBinding(textMessageEncodingBindingElement, httpsTransportBindingElement);

            clientReceiver = new ClientReceiver();
            context = new InstanceContext(clientReceiver);

            channelFactory = new DuplexChannelFactory<IWSDuplexService>(context, binding, Endpoints.WebSocketHttpsDuplexTextStreamed_Address);
            client = channelFactory.CreateChannel();

            // *** EXECUTE *** \\
            using (Stream stream = client.DownloadStream())
            {
                int readResult;
                // Read from the stream, 1000 bytes at a time.
                byte[] buffer = new byte[1000];
                do
                {
                    readResult = stream.Read(buffer, 0, buffer.Length);
                }
                while (readResult != 0);
            }

            uploadStream = new FlowControlledStream();
            uploadStream.ReadThrottle = TimeSpan.FromMilliseconds(500);
            uploadStream.StreamDuration = TimeSpan.FromSeconds(1);

            client.UploadStream(uploadStream);
            client.StartPushingStream();
            // Wait for the callback to get invoked before telling the service to stop streaming.
            // This ensures we can read from the stream on the callback while the NCL layer at the service
            // is still writing the bytes from the stream to the wire.  
            // This will deadlock if the transfer mode is buffered because the callback will wait for the
            // stream, and the NCL layer will continue to buffer the stream until it reaches the end.

            Assert.True(clientReceiver.ReceiveStreamInvoked.WaitOne(ScenarioTestHelpers.TestTimeout),
                "Test case timeout was reached while waiting for the stream response from the Service.");
            clientReceiver.ReceiveStreamInvoked.Reset();

            // Upload the stream while we are downloading a different stream
            uploadStream = new FlowControlledStream();
            uploadStream.ReadThrottle = TimeSpan.FromMilliseconds(500);
            uploadStream.StreamDuration = TimeSpan.FromSeconds(1);
            client.UploadStream(uploadStream);

            client.StopPushingStream();
            // Waiting on ReceiveStreamCompleted from the ClientReceiver.
            Assert.True(clientReceiver.ReceiveStreamCompleted.WaitOne(ScenarioTestHelpers.TestTimeout),
                "Test case timeout was reached while waiting for the stream response from the Service to be completed.");
            clientReceiver.ReceiveStreamCompleted.Reset();

            // *** VALIDATE *** \\
            // Validation is based on no exceptions being thrown.

            // *** CLEANUP *** \\
            ((ICommunicationObject)client).Close();
            channelFactory.Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)client, channelFactory);
            clientReceiver.Dispose();
        }
    }
Exemple #22
0
 public virtual void StartAfterStopped()
 {
     using (Processor client = new Processor ("testing", 1)) {
         ClientReceiver receiver = new ClientReceiver ();
         client.ProcessFunc += receiver.ChannelCounterAction;
         Assert.IsTrue (client.Start ());
         client.Stop ();
         Assert.IsTrue (client.Start ());
         Assert.AreEqual (1, client.AudioInPorts.Count ());
         Thread.Sleep (100);
         Assert.AreEqual (1, receiver.Called);
     }
 }
Exemple #23
0
    public static void WebSocket_Https_Duplex_BinaryStreamed()
    {
        BinaryMessageEncodingBindingElement binaryMessageEncodingBindingElement = null;
        HttpsTransportBindingElement        httpsTransportBindingElement        = null;
        CustomBinding   binding        = null;
        ClientReceiver  clientReceiver = null;
        InstanceContext context        = null;
        DuplexChannelFactory <IWSDuplexService> channelFactory = null;
        IWSDuplexService     client       = null;
        FlowControlledStream uploadStream = null;

        try
        {
            // *** SETUP *** \\
            binaryMessageEncodingBindingElement = new BinaryMessageEncodingBindingElement();
            httpsTransportBindingElement        = new HttpsTransportBindingElement();
            httpsTransportBindingElement.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;
            httpsTransportBindingElement.MaxReceivedMessageSize           = ScenarioTestHelpers.DefaultMaxReceivedMessageSize;
            httpsTransportBindingElement.MaxBufferSize = ScenarioTestHelpers.DefaultMaxReceivedMessageSize;
            httpsTransportBindingElement.TransferMode  = TransferMode.Streamed;
            binding = new CustomBinding(binaryMessageEncodingBindingElement, httpsTransportBindingElement);

            clientReceiver = new ClientReceiver();
            context        = new InstanceContext(clientReceiver);

            channelFactory = new DuplexChannelFactory <IWSDuplexService>(context, binding, Endpoints.WebSocketHttpsDuplexBinaryStreamed_Address);
            client         = channelFactory.CreateChannel();

            // *** EXECUTE *** \\
            using (Stream stream = client.DownloadStream())
            {
                int readResult;
                // Read from the stream, 1000 bytes at a time.
                byte[] buffer = new byte[1000];
                do
                {
                    readResult = stream.Read(buffer, 0, buffer.Length);
                }while (readResult != 0);
            }

            uploadStream = new FlowControlledStream();
            uploadStream.ReadThrottle   = TimeSpan.FromMilliseconds(500);
            uploadStream.StreamDuration = TimeSpan.FromSeconds(1);

            client.UploadStream(uploadStream);
            client.StartPushingStream();
            // Wait for the callback to get invoked before telling the service to stop streaming.
            // This ensures we can read from the stream on the callback while the NCL layer at the service
            // is still writing the bytes from the stream to the wire.
            // This will deadlock if the transfer mode is buffered because the callback will wait for the
            // stream, and the NCL layer will continue to buffer the stream until it reaches the end.

            Assert.True(clientReceiver.ReceiveStreamInvoked.WaitOne(ScenarioTestHelpers.TestTimeout), "Test case timeout was reached while waiting for the stream response from the Service.");
            clientReceiver.ReceiveStreamInvoked.Reset();

            // Upload the stream while we are downloading a different stream
            uploadStream = new FlowControlledStream();
            uploadStream.ReadThrottle   = TimeSpan.FromMilliseconds(500);
            uploadStream.StreamDuration = TimeSpan.FromSeconds(1);
            client.UploadStream(uploadStream);

            client.StopPushingStream();
            // Waiting on ReceiveStreamCompleted from the ClientReceiver.
            clientReceiver.ReceiveStreamCompleted.WaitOne();
            clientReceiver.ReceiveStreamCompleted.Reset();

            // *** VALIDATE *** \\
            // Validation is based on no exceptions being thrown.

            // *** CLEANUP *** \\
            ((ICommunicationObject)client).Close();
            channelFactory.Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)client, channelFactory);
            clientReceiver.Dispose();
        }
    }
Exemple #24
0
 public virtual void AudioCopying()
 {
     ClientReceiver receiver = new ClientReceiver ();
     _client.ProcessFunc = receiver.CopyInToOutAction;
     _client.Start ();
     Thread.Sleep (2000);
     Assert.IsTrue (receiver.Called > 0);
 }