Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="randomPort"></param>
        public Server(bool randomPort)
        {
            this.SocketContainer = new SocketContainer();
            setHostName(this.SocketContainer);

            if (randomPort)
            {
                bool foundOpenPort = false;
                this.SocketContainer.ListeningPort = PortNumberGenerator.getRandomPort();
                while (!foundOpenPort)
                {
                    try
                    {
                        Client c = new Client();
                        c.connect(this.SocketContainer.HostName, this.SocketContainer.ListeningPort);
                        c.disconnect();
                        this.SocketContainer.ListeningPort = PortNumberGenerator.getRandomPort();
                    }
                    catch (Exception)
                    {
                        foundOpenPort = true;
                    }
                }
            }
            else
            {
                this.SocketContainer.ListeningPort = 2702;                                                                         // use as default
                Int32 listeningPort = 2702;                                                                                        // default
                Int32.TryParse(ConfigurationManager.AppSettings[config.AppConfigSettingsConstants.ServerPort], out listeningPort); // if this fails, default is fine
                this.SocketContainer.ListeningPort = listeningPort;
            }
        }
 static InlineGenerators()
 {
     _alphaCharGenerator   = new AlphaCharGenerator();
     _digitCharGenerator   = new DigitCharGenerator();
     _lowerCaseAlphaChar   = _alphaCharGenerator.AsLowerCase();
     _upperCaseAlphaChar   = _alphaCharGenerator.AsUpperCase();
     _simpleValueGenerator = new SimpleValueGenerator <char>();
     _stringGenerator      = new SimpleValueGenerator <string>();
     _lowercaseString      = new ValueConversion <string, string>(_stringGenerator, s => s.ToLowerInvariant());
     _uppercaseString      = new ValueConversion <string, string>(_stringGenerator, s => s.ToUpperInvariant());
     _lowercaseAlphaString = new ValueConversion <string, string>(
         AlphaString(System.Guid.NewGuid().ToString().Length), s => s.ToLowerInvariant());
     _uppercaseAlphaString = new ValueConversion <string, string>(
         AlphaString(System.Guid.NewGuid().ToString().Length), s => s.ToUpperInvariant());
     _identifierStringGenerator = new IdentifierStringGenerator(_digitCharGenerator, _alphaCharGenerator);
     _uriGenerator       = new SimpleValueGenerator <Uri>();
     _uriStringGenerator = new ValueConversion <Uri, string>(_uriGenerator, u => u.ToString());
     _guid                    = new SimpleValueGenerator <Guid>();
     _intGenerator            = new SimpleValueGenerator <int>();
     _doubleGenerator         = new SimpleValueGenerator <double>();
     _longGenerator           = new SimpleValueGenerator <long>();
     _unsignedLongGenerator   = new SimpleValueGenerator <ulong>();
     _byteGenerator           = new SimpleValueGenerator <byte>();
     _decimalGenerator        = new SimpleValueGenerator <decimal>();
     _uintGenerator           = new SimpleValueGenerator <uint>();
     _ushortGenerator         = new SimpleValueGenerator <ushort>();
     _shortGenerator          = new SimpleValueGenerator <short>();
     _digitGenerator          = new DigitGenerator();
     _positiveDigitGenerator  = new PositiveDigitGenerator(_digitGenerator);
     _ipStringGenerator       = new IpStringGenerator();
     _portNumberGenerator     = new PortNumberGenerator();
     _actionGenerator         = new SimpleInstanceGenerator <Action>();
     _notStartedTaskGenerator = new NotStartedTaskGenerator();
     _ipAddressGenerator      = new SimpleValueGenerator <IPAddress>();
     _dateTimeGenerator       = new SimpleValueGenerator <DateTime>();
     _timeSpanGenerator       = new SimpleValueGenerator <TimeSpan>();
     _boolGenerator           = new SimpleValueGenerator <bool>();
     _objectGenerator         = new SimpleValueGenerator <object>();
     _methodInfoGenerator     = new SimpleValueGenerator <MethodInfo>();
     _typeGenerator           = new SimpleValueGenerator <Type>();
     _exceptionGenerator      = new SimpleValueGenerator <Exception>();
 }