예제 #1
0
        public void AcceptCallback(IAsyncResult ar)
        {
            try
            {
                LOG.Info($"Accepted Callback port: {Port}");
                // Create new socket for client
                Socket handler = ListenerSocket.EndAccept(ar);
                byte[] buffer  = new byte[2];
                handler.Receive(buffer);
                string data = Encoding.Default.GetString(buffer);
                Console.ForegroundColor = ConsoleColor.Blue;
                Console.WriteLine($"Data: '{data}'");
                Console.ResetColor();
                // Add new client to ClientController
                ClientController.AddClient(handler, data);

                // Start listening again
                ListenerSocket.BeginAccept(AcceptCallback, ListenerSocket);
            }
            catch (Exception)
            {
                //throw new Exception("Base Accept error" + ex);
                Console.WriteLine("Connection was forcibly closed by the remote host");
            }
        }
예제 #2
0
        public void TestGetClients()
        {
            DatabaseHelper.InitialiseDb();
            Client _testClient = new Client("Add me to the list");

            ClientController.AddClient(_testClient);
            Assert.IsNotNull(ClientController.GetClients());
            ClientController.DeleteProject(_testClient);
        }
예제 #3
0
        public void TestClientExistsTrue()
        {
            DatabaseHelper.InitialiseDb();
            Client _testClient = new Client("Fancy Pants Client");

            ClientController.AddClient(_testClient);
            Assert.AreEqual(_testClient.Exists(), true);
            ClientController.DeleteProject(_testClient);
        }
예제 #4
0
        public void TestGetClientById()
        {
            DatabaseHelper.InitialiseDb();
            Client _testClient = new Client("Add me to the list");

            ClientController.AddClient(_testClient);
            int _clientId = ClientController.GetClientByName("Add me to the list").Id;

            Assert.AreEqual(ClientController.GetClientById(_clientId).Name, "Add me to the list");
            ClientController.DeleteProject(_testClient);
        }
        public void AddClientTest()
        {
            ClientController cc     = new ClientController();
            Client           client = new Client();

            client.full_name      = "mairon";
            client.identification = 5415;
            var result = cc.AddClient(client) as RedirectResult;

            Assert.AreEqual("~/Client/Client", result.Url);
        }
예제 #6
0
    private async Task AcceptConnectionsAsync()
    {
        while (!_acceptConnectionsToken.IsCancellationRequested)
        {
            var socketClient = new SocketClient();
            var linkedCts    = CancellationTokenSource.CreateLinkedTokenSource(socketClient.Token, _acceptConnectionsToken);

            try
            {
                var newClientSocket = await _serverSocket.AcceptAsync(_acceptConnectionsToken);

                var clientIp = newClientSocket.RemoteEndPoint?.ToString();

                Log.Logger.Information($"Подключился новый клиент: {clientIp}");

                await socketClient.CreateAsync(newClientSocket, _acceptConnectionsToken);

                _clientController.AddClient(clientIp, socketClient);

                _events.CallClientConnectedEvent(this, clientIp);

                // await _clientController.BroadcastAllAsync("Подключился новый клиент", _listenerToken);

                var _ = Task.Run(() => DataReceiverAsync(socketClient, _token), linkedCts.Token);
            }
            catch (Exception ex)
            {
                if (ex is TaskCanceledException ||
                    ex is OperationCanceledException ||
                    ex is ObjectDisposedException ||
                    ex is InvalidOperationException)
                {
                    _isListen = false;
                    // if (socketClient != null)
                    //     socketClient.Dispose();

                    Log.Logger.Information($"Stopped listening");
                    break;
                }
                else
                {
                    // if (socketClient != null)
                    //     socketClient.Dispose();

                    Log.Logger.Error($"Возникла ошибка во время ожидация новых подключений: {ex}");
                    continue;
                }
            }
        }

        _isListen = false;
    }
예제 #7
0
        private void button2_Click(object sender, EventArgs e)
        {
            stopWatch.Stop();

            Project _newProject = new Project();

            // Preconditon: If selected item and the text field are not null
            if (ProjectDropDown.SelectedItem != null)
            {
                _newProject.Name = ProjectDropDown.SelectedItem.ToString();
            }
            else if (!String.IsNullOrEmpty(ProjectDropDown.Text))
            {
                _newProject.Name = ProjectDropDown.Text;
            }

            Client _newClient = new Client();

            // Preconditon: If selected item and the text field are not null
            if (ClientDropDown.SelectedItem != null)
            {
                _newClient.Name = ClientDropDown.SelectedItem.ToString();
            }
            else if (!String.IsNullOrEmpty(ClientDropDown.Text))
            {
                _newClient.Name = ClientDropDown.Text;
            }

            // Preconditon: If there isn't a new client create it
            if (!(_newClient.Exists()))
            {
                ClientController.AddClient(_newClient);
            }

            _newProject.ClientId = _newClient.Id;
            _newProject.Client   = _newClient;

            // Preconditon: project is not null
            if (_newProject.Exists())
            {
                _newProject.Id = ProjectController.GetProjectsByClientId(_newClient.Id).Where(p => p.Name == _newProject.Name).First().Id;
            }
            else if (_newProject != null)
            {
                ProjectController.AddProject(_newProject);
            }

            Task _newTask = new Task(_newProject.Id, textBoxNotes.Text, textBoxTime.Text);

            TaskController.AddTask(_newTask);
            ClearForm();
        }
        public async Task TestCreateClient()
        {
            Client client = new Client()
            {
                FirstName = "Johnny",
                LastName  = "Bravo",
            };

            this.clientRepositoryMock.Setup(t => t.Insert(It.IsAny <Client>())).Verifiable();

            await controller.AddClient(client);

            this.clientRepositoryMock.VerifyAll();
        }
            public void Add_passes_through()
            {
                var cmdletMock = CmdletMock.CreateMock();
                var ctxName    = Guid.NewGuid().ToString();

                var newClient = new Models.Client
                {
                    ClientId = "MyClientId"
                };

                using (var ctx = _dbContextFixture.GetContext(ctxName))
                {
                    var controller = new ClientController(ctx, cmdletMock.Object);
                    controller.AddClient(newClient, true);
                }

                cmdletMock.Verify(cmdlet => cmdlet.WriteObject(newClient), Times.Exactly(1));
            }
            public async Task Adds_to_database()
            {
                var cmdletMock = CmdletMock.CreateMock();
                var ctxName    = Guid.NewGuid().ToString();

                var newClient = new Models.Client
                {
                    ClientId           = "MyClientId",
                    AllowedScopes      = new[] { "Scope1" },
                    AllowedGrantTypes  = new[] { "Grant1" },
                    AllowedCorsOrigins = new[] { "Origin1" },
                    Claims             = new[] { new Claim("ClaimType1", "Claim1"), },
                    Properties         = new Dictionary <string, string> {
                        { "Key1", "Value1" }
                    },
                    RedirectUris = new[] { "Redirect1" }
                };

                using (var ctx = _dbContextFixture.GetContext(ctxName))
                {
                    var controller = new ClientController(ctx, cmdletMock.Object);
                    controller.AddClient(newClient, false);
                }

                using (var ctx = _dbContextFixture.GetContext(ctxName))
                {
                    var clients = ctx.Clients.ToList();
                    Assert.Single(clients);

                    var store  = new ClientStore(ctx, NullLogger <ClientStore> .Instance);
                    var client = await store.FindClientByIdAsync("MyClientId");

                    Assert.NotNull(client);
                    Assert.Equal(1, client.AllowedScopes.Count);
                    Assert.Equal(1, client.AllowedGrantTypes.Count);
                    Assert.Equal(1, client.AllowedCorsOrigins.Count);
                    Assert.Equal(1, client.Claims.Count);
                    Assert.Equal(1, client.Properties.Count);
                    Assert.Equal(1, client.RedirectUris.Count);
                }
            }