示例#1
0
        private void StartClient()
        {
            _client = new ClientCommunicationService();
            if (_enableLogging)
            {
                ILoggerService loggerService = new LoggerService();
                _client.CurrentLogLevel = _logLevel;
                _client.LogFileName     = _logFileName;
                _client.LoggerService   = loggerService;
            }

            _client.MulticastIPAddress = _multicastIPAddress;
            _client.MulticastPort      = _multicastPort;
            _client.ServerIPAddress    = _serverIPAddress;
            _client.ServerPort         = _serverPort;
            _client.UseMulticast       = _useMulticast;
            _client.DataReceived      += new EventHandler <DataReceivedEventArgs>(OnDataReceived);
            try
            {
                _client.Start();
                ClearGrid();
                SendRequestForMessageList();
            }
            catch (SocketException)
            {
                StopClient();
                MessageBox.Show(this, "Error connecting to server " + _serverIPAddress + ":" +
                                _serverPort + Environment.NewLine + "Configure server address and port.", "Mocs Notification", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                ShowConfigurationForm();
            }
        }
示例#2
0
 private void StopClient()
 {
     if (_client != null)
     {
         _client.DataReceived -= new EventHandler <DataReceivedEventArgs>(OnDataReceived);
         if (_client.IsStarted)
         {
             _client.Stop();
         }
         _client = null;
     }
 }
示例#3
0
        public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <IClientCommunicationRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ClientCommunication>(null));
            var service = new ClientCommunicationService(mock.LoggerMock.Object,
                                                         mock.RepositoryMock.Object,
                                                         mock.ModelValidatorMockFactory.ClientCommunicationModelValidatorMock.Object,
                                                         mock.BOLMapperMockFactory.BOLClientCommunicationMapperMock,
                                                         mock.DALMapperMockFactory.DALClientCommunicationMapperMock);

            ApiClientCommunicationResponseModel response = await service.Get(default(int));

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
示例#4
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IClientCommunicationRepository>();
            var model = new ApiClientCommunicationRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <ClientCommunication>())).Returns(Task.FromResult(new ClientCommunication()));
            var service = new ClientCommunicationService(mock.LoggerMock.Object,
                                                         mock.RepositoryMock.Object,
                                                         mock.ModelValidatorMockFactory.ClientCommunicationModelValidatorMock.Object,
                                                         mock.BOLMapperMockFactory.BOLClientCommunicationMapperMock,
                                                         mock.DALMapperMockFactory.DALClientCommunicationMapperMock);

            CreateResponse <ApiClientCommunicationResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.ClientCommunicationModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiClientCommunicationRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <ClientCommunication>()));
        }
示例#5
0
        public async void All()
        {
            var mock    = new ServiceMockFacade <IClientCommunicationRepository>();
            var records = new List <ClientCommunication>();

            records.Add(new ClientCommunication());
            mock.RepositoryMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records));
            var service = new ClientCommunicationService(mock.LoggerMock.Object,
                                                         mock.RepositoryMock.Object,
                                                         mock.ModelValidatorMockFactory.ClientCommunicationModelValidatorMock.Object,
                                                         mock.BOLMapperMockFactory.BOLClientCommunicationMapperMock,
                                                         mock.DALMapperMockFactory.DALClientCommunicationMapperMock);

            List <ApiClientCommunicationResponseModel> response = await service.All();

            response.Should().HaveCount(1);
            mock.RepositoryMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>()));
        }
示例#6
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IClientCommunicationRepository>();
            var model = new ApiClientCommunicationRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new ClientCommunicationService(mock.LoggerMock.Object,
                                                         mock.RepositoryMock.Object,
                                                         mock.ModelValidatorMockFactory.ClientCommunicationModelValidatorMock.Object,
                                                         mock.BOLMapperMockFactory.BOLClientCommunicationMapperMock,
                                                         mock.DALMapperMockFactory.DALClientCommunicationMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.ClientCommunicationModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
示例#7
0
文件: MocsForm.cs 项目: ruudkok/MoCS
 private void StopClient()
 {
     if (_client != null)
     {
         _client.DataReceived -= new EventHandler<DataReceivedEventArgs>(OnDataReceived);
         if (_client.IsStarted)
         {
             _client.Stop();
         }
         _client = null;
     }
 }
示例#8
0
文件: MocsForm.cs 项目: ruudkok/MoCS
        private void StartClient()
        {
            _client = new ClientCommunicationService();
            if (_enableLogging)
            {
                ILoggerService loggerService = new LoggerService();
                _client.CurrentLogLevel = _logLevel;
                _client.LogFileName = _logFileName;
                _client.LoggerService = loggerService;
            }

            _client.MulticastIPAddress = _multicastIPAddress;
            _client.MulticastPort = _multicastPort;
            _client.ServerIPAddress = _serverIPAddress;
            _client.ServerPort = _serverPort;
            _client.UseMulticast = _useMulticast;
            _client.DataReceived += new EventHandler<DataReceivedEventArgs>(OnDataReceived);
            try
            {
                _client.Start();
                ClearGrid();
                SendRequestForMessageList();
            }
            catch (SocketException)
            {
                StopClient();
                MessageBox.Show(this, "Error connecting to server " + _serverIPAddress + ":" +
                                    _serverPort + Environment.NewLine + "Configure server address and port.", "Mocs Notification", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                ShowConfigurationForm();
            }
        }