예제 #1
0
        /// <summary>
        /// Creates a new Yacs <see cref="Hub"/>. This can accept connections from many <see cref="Channel"/> instances.
        /// </summary>
        /// <param name="port">The port on which the server will be listening.</param>
        /// <param name="options">The server options.</param>
        public Hub(int port, HubOptions options = null)
        {
            _port    = port;
            _options = options
                       ?? new HubOptions();

            OptionsValidator.Validate(_options);

            _tcpServer = new TcpListener(IPAddress.Any, port);

            _shouldContinueDiscoveryTask      = true;
            _shouldContinueNewConnectionsTask = true;

            _newChannelOptions = new ChannelOptions
            {
                Encoding            = _options.Encoding,
                ReceptionBufferSize = _options.ReceptionBufferSize,
                ActiveMonitoring    = _options.ActiveChannelMonitoring
            };

            if (_options.IsDiscoverable)
            {
                IsDiscoveryEnabled = true;
                _udpServer         = new UdpClient(_options.DiscoveryPort);
                _discoveryTask     = Task.Run(DiscoveryLoop);
            }

            _enabled = true;
            _tcpServer.Start();
            _newConnectionsTask = Task.Run(NewConnectionListenerLoop);
        }
예제 #2
0
        internal Channel(TcpClient tcpClient, ChannelOptions options)
        {
            OptionsValidator.Validate(options);

            Identifier = new ChannelIdentifier(tcpClient.Client.RemoteEndPoint);
            _options   = options;
            _tcpClient = tcpClient;
            _shouldContinueMessageReceptionTask = true;
            _messageReceptionTask = Task.Run(ReceptionLoop);
            _protocol             = new Protocol();
        }
예제 #3
0
        private static bool Validate(Options options)
        {
            var validationResult = OptionsValidator.Validate(options);

            if (validationResult.isValid == false)
            {
                ConsoleHelpers.WriteErrors(validationResult.errors);
                _returnCode = FAILURE;
            }

            return(validationResult.isValid);
        }
예제 #4
0
        public void IsJsonPathAndIsEnvVarAreMutuallyExclusive()
        {
            var opts = new Options
            {
                ConfigFile   = Path.GetTempFileName(),
                IsAppSetting = true,
                IsJsonPath   = true,
                IsValueEnvironmentVariable = true,
                Name  = "TestKey",
                Value = "$.Manufacturers[?(@.Name == 'Acme Co')].Name"
            };

            var result = OptionsValidator.Validate(opts);

            Assert.True(result.HasValue());
            Assert.Equal(result.Value().Value, ExitCode.JsonPathAndEnvVarAreMutuallyExclusive.Value);
        }
예제 #5
0
        private bool Validate(Options options, ViewModel viewModel)
        {
            var validator         = new OptionsValidator();
            var validationResults = validator.Validate(options);

            var validationHelper = new ValidationModelHelper(r => {
                object model       = viewModel;
                var injectSettings = r.Record as InjectSettings;
                if (injectSettings != null)
                {
                    model = viewModel.InjectSettings.FirstOrDefault(i => String.Equals(i.File, injectSettings.File));
                }
                return(model);
            });

            validationHelper.ApplyValidationResults(validationResults, viewModel);

            return(!validationResults.HasErrors);
        }
예제 #6
0
        /// <summary>The get next problem.</summary>
        /// <param name="storyName">The story name.</param>
        /// <param name="options">The options.</param>
        /// <returns>The <see cref="ReadModel.Problem"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when an argument is null.</exception>
        /// <exception cref="BusinessValidationException">Thrown when arguments do not pass validation.</exception>
        /// <exception cref="ArgumentException">Thrown when the story doesn't exist.</exception>
        public Problem GetNextProblem(string storyName, IList <int> options)
        {
            if (string.IsNullOrWhiteSpace(storyName))
            {
                throw new ArgumentNullException("storyName");
            }

            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            // Check basic options validity.
            var optionsValidator = new OptionsValidator();
            ValidationResults optionsValidationResults = optionsValidator.Validate(options);

            if (!optionsValidationResults.IsValid)
            {
                throw new BusinessValidationException(optionsValidationResults);
            }

            // Get the story.
            Model.Story story = this.storyRepository.GetStoryByName(storyName);

            if (story == null)
            {
                throw new ArgumentException(string.Format("The story {0} doesn't exist.", storyName));
            }

            var optionsStoryValidator = new OptionsStoryValidator(story);
            ValidationResults optionsStoryvalidationResults = optionsStoryValidator.Validate(options);

            if (!optionsStoryvalidationResults.IsValid)
            {
                throw new BusinessValidationException(optionsStoryvalidationResults);
            }

            Model.Problem firstProblem = story.Steps.First(step => step.Number == 1).Problems.First();
            Problem       problem      = this.GetProblem(firstProblem, options, 0);

            return(problem);
        }
예제 #7
0
        /// <summary>The get next problem.</summary>
        /// <param name="storyName">The story name.</param>
        /// <param name="options">The options.</param>
        /// <returns>The <see cref="ReadModel.Problem"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when an argument is null.</exception>
        /// <exception cref="BusinessValidationException">Thrown when arguments do not pass validation.</exception>
        /// <exception cref="ArgumentException">Thrown when the story doesn't exist.</exception>
        public Problem GetNextProblem(string storyName, IList<int> options)
        {
            if (string.IsNullOrWhiteSpace(storyName))
            {
                throw new ArgumentNullException("storyName");
            }

            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            // Check basic options validity.
            var optionsValidator = new OptionsValidator();
            ValidationResults optionsValidationResults = optionsValidator.Validate(options);
            if (!optionsValidationResults.IsValid)
            {
                throw new BusinessValidationException(optionsValidationResults);
            }

            // Get the story.
            Model.Story story = this.storyRepository.GetStoryByName(storyName);

            if (story == null)
            {
                throw new ArgumentException(string.Format("The story {0} doesn't exist.", storyName));
            }

            var optionsStoryValidator = new OptionsStoryValidator(story);
            ValidationResults optionsStoryvalidationResults = optionsStoryValidator.Validate(options);
            if (!optionsStoryvalidationResults.IsValid)
            {
                throw new BusinessValidationException(optionsStoryvalidationResults);
            }

            Model.Problem firstProblem = story.Steps.First(step => step.Number == 1).Problems.First();
            Problem problem = this.GetProblem(firstProblem, options, 0);
            return problem;
        }