public List <T> Get <T>(List <Command> commands)
        {
            TcpClient     client = null;
            NetworkStream stream = null;

            try
            {
                client = new TcpClient();
                client.Connect(_ip, _port);

                stream = client.GetStream();
                var streamWrapperService = new StreamWrapperService(stream);

                var result = new List <T>();

                foreach (var command in commands)
                {
                    streamWrapperService.SendCommand(command);
                    result.Add(streamWrapperService.ReciveObject <T>());
                }

                return(result);
            }
            finally
            {
                stream?.Close();
                client?.Close();
            }
        }
Exemple #2
0
        public void Handle()
        {
            var stream        = _client.GetStream();
            var streamWrapper = new StreamWrapperService(stream);

            while (true)
            {
                var command = streamWrapper.ReciveCommand();

                if (command == null)
                {
                    if (!stream.DataAvailable)
                    {
                        stream.Close();
                        _client.Close();
                        return;
                    }

                    continue;
                }

                switch (command.CommandType)
                {
                case CommandType.GetTestInformation:
                    new GetTestInformationHandler(streamWrapper).Handle(command);
                    break;

                case CommandType.GetTests:
                    new GetTestsHandler(streamWrapper).Handle(command);
                    break;

                case CommandType.GetImage:
                    new GetImageHandler(streamWrapper).Handle(command);
                    break;

                case CommandType.GetImagesInformation:
                    new GetImagesInformationHandler(streamWrapper).Handle(command);
                    break;

                case CommandType.GetPlatoons:
                    new GetPlatoonsHandler(streamWrapper).Handle(command);
                    break;

                case CommandType.GetSubjects:
                    new GetSubjectsHandler(streamWrapper).Handle(command);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
 public GetImagesInformationHandler(StreamWrapperService streamWrapperService)
 {
     _streamWrapperService = streamWrapperService;
 }
Exemple #4
0
 public GetPlatoonsHandler(StreamWrapperService streamWrapperService)
 {
     _streamWrapperService = streamWrapperService;
     _platoonFileService   = new PlatoonFileService(ConfigContainer.GetConfig <ServerConfig>().SaveFolder);
 }
Exemple #5
0
 public GetSubjectsHandler(StreamWrapperService streamWrapperService)
 {
     _streamWrapperService = streamWrapperService;
     _subjectFileService   = new SubjectFileService(ConfigContainer.GetConfig <ServerConfig>().SaveFolder);
 }
Exemple #6
0
 public GetTestsHandler(StreamWrapperService streamWrapperService)
 {
     _streamWrapperService = streamWrapperService;
 }