Ejemplo n.º 1
0
        public void CanConvertFrom()
        {
            UriConverter vrt = new UriConverter();

            Assert.IsTrue(vrt.CanConvertFrom(typeof(string)), "Conversion from a string instance must be supported.");
            Assert.IsFalse(vrt.CanConvertFrom(typeof(int)));
        }
        public override async Task ConnectAsync()
        {
            await base.ConnectAsync();

            if (_webSocketTransport != null)
            {
                _webSocketTransport.OnTextReceived   -= OnTextReceived;
                _webSocketTransport.OnBinaryReceived -= OnBinaryReceived;
                _webSocketTransport.OnAborted        -= OnAborted;
                _webSocketTransport.Dispose();
            }
            Uri uri = UriConverter.GetServerUri(true, ServerUri, EIO, Options.Path, Options.Query);

            _clientWebSocket = ClientWebSocketProvider();
            if (Options.ExtraHeaders != null)
            {
                foreach (var item in Options.ExtraHeaders)
                {
                    _clientWebSocket.SetRequestHeader(item.Key, item.Value);
                }
            }
            _webSocketTransport = new WebSocketTransport(_clientWebSocket, EIO)
            {
                ConnectionTimeout = Options.ConnectionTimeout
            };
            _webSocketTransport.OnTextReceived   = OnTextReceived;
            _webSocketTransport.OnBinaryReceived = OnBinaryReceived;
            _webSocketTransport.OnAborted        = OnAborted;
            Debug.WriteLine($"[Websocket] Connecting");
            await _webSocketTransport.ConnectAsync(uri).ConfigureAwait(false);

            Debug.WriteLine($"[Websocket] Connected");
        }
Ejemplo n.º 3
0
        protected override async Task OpenAsync(OpenedMessage msg)
        {
            Uri uri = UriConverter.GetServerUri(false, ServerUri, EIO, Options.Path, Options.Query);

            _httpUri = uri + "&sid=" + msg.Sid;
            await base.OpenAsync(msg);
        }
Ejemplo n.º 4
0
        public void ConvertFrom()
        {
            UriConverter vrt    = new UriConverter();
            object       actual = vrt.ConvertFrom("svn://localhost/Spring/trunk/");

            Assert.IsNotNull(actual);
            Assert.AreEqual(typeof(System.Uri), actual.GetType());
        }
Ejemplo n.º 5
0
        protected override Task <IResourceInfo> GetAsyncInternal(UriString uri, IImmutableSession metadata)
        {
            var settingIdentifier = UriConverter?.Convert <string>(uri) ?? uri;
            var exeConfig         = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            var settings          = FindConnectionStringSettings(exeConfig, settingIdentifier);

            return(Task.FromResult <IResourceInfo>(new ConnectionStringInfo(uri, settings?.ConnectionString)));
        }
        public void EmptyStringIsDeserializedIntoNull()
        {
            UriConverter converter = new UriConverter();
            string       text      = "";
            Uri?         uri       = converter.Deserialize(text.AsMemory(), CultureInfo.InvariantCulture, null);

            uri.Should().BeNull();
        }
        public void UriDeserializerIsValid()
        {
            UriConverter converter = new UriConverter();
            string       text      = "http://localhost:3000/";
            Uri?         uri       = converter.Deserialize(text.AsMemory(), CultureInfo.InvariantCulture, null);

            uri.Should().Be(new Uri("http://localhost:3000/"));
        }
Ejemplo n.º 8
0
 public Router(HttpClient httpClient, Func <IClientWebSocket> clientWebSocketProvider, SocketIOOptions options)
 {
     HttpClient = httpClient;
     ClientWebSocketProvider = clientWebSocketProvider;
     UriConverter            = new UriConverter();
     _messageQueue           = new Queue <IMessage>();
     Options = options;
 }
Ejemplo n.º 9
0
 public BaseTransport(SocketIOOptions options, IJsonSerializer jsonSerializer, ILogger logger)
 {
     Options        = options;
     MessageSubject = new Subject <IMessage>();
     JsonSerializer = jsonSerializer;
     UriConverter   = new UriConverter();
     _messageQueue  = new Queue <IMessage>();
     _logger        = logger;
 }
Ejemplo n.º 10
0
        protected override Task <IResourceInfo> GetAsyncInternal(UriString uri, IImmutableSession metadata)
        {
            var settingIdentifier = UriConverter?.Convert <string>(uri) ?? uri;
            var exeConfig         = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            var actualKey         = FindActualKey(exeConfig, settingIdentifier) ?? settingIdentifier;
            var element           = exeConfig.AppSettings.Settings[actualKey];

            return(Task.FromResult <IResourceInfo>(new AppSettingInfo(uri, element?.Value, ImmutableSession.Empty.Set(Use <IResourceNamespace> .Namespace, x => x.ActualName, settingIdentifier))));
        }
Ejemplo n.º 11
0
        public void GetHandshakeUriWithWs80()
        {
            var cvt = new UriConverter();

            var serverUri = new Uri("ws://localhost:80");
            var kvs       = new List <KeyValuePair <string, string> >();
            var result    = cvt.GetServerUri(true, serverUri, 4, string.Empty, kvs);

            Assert.AreEqual("ws://localhost/socket.io/?EIO=4&transport=websocket", result.ToString());
        }
Ejemplo n.º 12
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasDefaultSchema("gateway");

            modelBuilder.ProtectSensitiveInformation();

            modelBuilder.Entity <Application>()
            .Property(a => a.HostUri)
            .HasConversion(UriConverter.Create());
        }
Ejemplo n.º 13
0
 static Converters()
 {
     IPAddress = new IPAddressConverter ();
     Regex = new RegexConverter ();
     ZeroOneBoolean = new ZeroOneBooleanConverter ();
     TextualZeroOneBoolean = new ZeroOneBooleanConverter (true);
     Uri = new UriConverter ();
     Version = new VersionConverter ();
     XmlNode = new XmlNodeConverter ();
 }
        public void UriWithQuotesIsSerializedUsingEscapeCharacters()
        {
            UriConverter  converter     = new UriConverter();
            Uri           uri           = new Uri("http://localhost:3000/?x=\"");
            StringBuilder stringBuilder = new StringBuilder();

            converter.AppendToStringBuilder(stringBuilder, CultureInfo.InvariantCulture, uri, null, ',');
            string serialized = stringBuilder.ToString();

            serialized.Should().Be("\"http://localhost:3000/?x=\"\"\"");
        }
        public void NullUriIsSerializedIntoEmptyString()
        {
            UriConverter  converter     = new UriConverter();
            Uri?          uri           = null;
            StringBuilder stringBuilder = new StringBuilder();

            converter.AppendToStringBuilder(stringBuilder, CultureInfo.InvariantCulture, uri, null, ',');
            string serialized = stringBuilder.ToString();

            serialized.Should().Be("");
        }
        public void UriSerializerIsValid()
        {
            UriConverter  converter     = new UriConverter();
            Uri           uri           = new Uri("http://localhost:3000/");
            StringBuilder stringBuilder = new StringBuilder();

            converter.AppendToStringBuilder(stringBuilder, CultureInfo.InvariantCulture, uri, null, ',');
            string serialized = stringBuilder.ToString();

            serialized.Should().Be("\"http://localhost:3000/\"");
        }
Ejemplo n.º 17
0
 static Converters()
 {
     IPAddress             = new IPAddressConverter();
     Regex                 = new RegexConverter();
     TextualZeroOneBoolean = new ZeroOneBooleanConverter(true);
     Type           = new ReflectedTypeConverter();
     Uri            = new UriConverter();
     Version        = new VersionConverter();
     XmlNode        = new XmlNodeConverter();
     ZeroOneBoolean = new ZeroOneBooleanConverter();
 }
        public void TargetType()
        {
            // Arrange
            IConverter converter    = new UriConverter();
            var        expectedType = typeof(Uri);

            // Act
            var actualType = converter.TargetType;

            // Assert
            Assert.Equal(expectedType, actualType);
        }
Ejemplo n.º 19
0
        public void ConvertFromStringUriKindAbsoluteTest()
        {
            var converter = new UriConverter();

            var propertyMapData = new MemberMapData(null)
            {
                TypeConverter        = converter,
                TypeConverterOptions = { CultureInfo = CultureInfo.CurrentCulture, UriKind = UriKind.Absolute },
            };

            Assert.AreEqual(new Uri("https://test.com"), converter.ConvertFromString("https://test.com", null, propertyMapData));
        }
Ejemplo n.º 20
0
        public void ConvertFromStringUriKindRelativeTest()
        {
            var converter = new UriConverter();

            var propertyMapData = new MemberMapData(null)
            {
                TypeConverter        = converter,
                TypeConverterOptions = { CultureInfo = CultureInfo.CurrentCulture, UriKind = UriKind.Relative },
            };

            Assert.AreEqual(new Uri("/a/b/c", UriKind.Relative), converter.ConvertFromString("/a/b/c", null, propertyMapData));
        }
Ejemplo n.º 21
0
        public void ConvertToStringTest()
        {
            var converter = new UriConverter();

            var propertyMapData = new MemberMapData(null)
            {
                TypeConverter        = converter,
                TypeConverterOptions = { CultureInfo = CultureInfo.CurrentCulture },
            };

            Assert.AreEqual("https://test.com/", converter.ConvertToString(new Uri("https://test.com"), null, propertyMapData));
        }
Ejemplo n.º 22
0
 public void ConvertFromMalformedUriBails()
 {
     try
     {
         UriConverter vrt    = new UriConverter();
         object       actual = vrt.ConvertFrom("$TheAngelGang");
     }
     catch (Exception ex)
     {
         // check that the inner exception was doe to the malformed URL
         Assert.IsTrue(ex.InnerException is UriFormatException);
     }
 }
Ejemplo n.º 23
0
        public void GetHandshakeUriWithHttps80()
        {
            var cvt = new UriConverter();

            var serverUri = new Uri("https://localhost:80");
            var kvs       = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("token", "test")
            };
            var result = cvt.GetServerUri(false, serverUri, 4, string.Empty, kvs);

            Assert.AreEqual("https://localhost:80/socket.io/?EIO=4&transport=polling&token=test", result.ToString());
        }
Ejemplo n.º 24
0
        public void GetHandshakeUriWithWss443()
        {
            var cvt = new UriConverter();

            var serverUri = new Uri("wss://localhost:443");
            var kvs       = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("token", "test")
            };
            var result = cvt.GetServerUri(true, serverUri, 4, string.Empty, kvs);

            Assert.AreEqual("wss://localhost/socket.io/?EIO=4&transport=websocket&token=test", result.ToString());
        }
        public void EmittedDeserializerDeserializesEmptyStringIntoNull()
        {
            UriConverter  converter   = new UriConverter();
            string        text        = "";
            DynamicMethod deserialize = new DynamicMethod("Deserialize", typeof(Uri), new Type[] { typeof(ReadOnlyMemory <char>), typeof(IFormatProvider) }, typeof(UriConverterTests));

            deserialize.GetILGenerator()
            .Ldarga_S(0)
            .Emit(gen => converter.EmitDeserialize(gen, null, null, null))
            .Ret();
            Uri?deserialized = (Uri?)deserialize.Invoke(this, new object?[] { text.AsMemory(), CultureInfo.InvariantCulture }) !;

            deserialized.Should().BeNull();
        }
        public void RelativeConversion()
        {
            // Arrange
            IConverter converter     = new UriConverter();
            var        value         = "hello";
            var        expectedValue = new Uri("hello", UriKind.Relative);

            // Act
            var actualValue = converter.Convert(value, converter.TargetType);

            // Assert
            Assert.NotNull(actualValue);
            Assert.IsType <Uri>(actualValue);
            Assert.Equal(expectedValue, (Uri)actualValue);
        }
        public void AbsoluteConversion()
        {
            // Arrange
            IConverter converter     = new UriConverter();
            var        value         = "http://mgrcommandlineparser.codeplex.com";
            var        expectedValue = new Uri("http://mgrcommandlineparser.codeplex.com");

            // Act
            var actualValue = converter.Convert(value, converter.TargetType);

            // Assert
            Assert.NotNull(actualValue);
            Assert.IsType <Uri>(actualValue);
            Assert.Equal(expectedValue, (Uri)actualValue);
        }
        public void EmittedSerializerSerializesNullUriIntoEmptyString()
        {
            UriConverter  converter = new UriConverter();
            Uri?          uri       = null;
            DynamicMethod serialize = new DynamicMethod("Serialize", typeof(string), new Type[] { typeof(Uri), typeof(IFormatProvider), typeof(char) }, typeof(UriConverterTests));

            serialize.GetILGenerator()
            .DeclareLocal <Uri>(out LocalBuilder local)
            .Newobj <StringBuilder>()
            .Ldarg_0()
            .Emit(gen => converter.EmitAppendToStringBuilder(gen, local, null, null))
            .Callvirt <StringBuilder>("ToString")
            .Ret();
            string serialized = (string)serialize.Invoke(null, new object?[] { uri, CultureInfo.InvariantCulture, ',' }) !;

            serialized.Should().Be("");
        }
Ejemplo n.º 29
0
        public override async Task ConnectAsync()
        {
            await base.ConnectAsync();

            Uri uri = UriConverter.GetServerUri(false, ServerUri, EIO, Options.Path, Options.Query);
            var req = new HttpRequestMessage(HttpMethod.Get, uri);

            if (Options.ExtraHeaders != null)
            {
                foreach (var item in Options.ExtraHeaders)
                {
                    req.Headers.Add(item.Key, item.Value);
                }
            }

            if (EIO == 3)
            {
                _httpTransport = new HttpEio3Transport(HttpClient);
            }
            else
            {
                _httpTransport = new HttpEio4Transport(HttpClient);
            }

            _httpTransport.OnTextReceived   = OnTextReceived;
            _httpTransport.OnBinaryReceived = OnBinaryReceived;

            await _httpTransport.SendAsync(req, new CancellationTokenSource(Options.ConnectionTimeout).Token).ConfigureAwait(false);

            if (_pollingTokenSource != null)
            {
                _pollingTokenSource.Cancel();
            }
            _pollingTokenSource = new CancellationTokenSource();

            StartPolling(_pollingTokenSource.Token);
        }
Ejemplo n.º 30
0
        protected override async Task <IResourceInfo> PutAsyncInternal(UriString uri, Stream stream, IImmutableSession metadata)
        {
            using (var valueReader = new StreamReader(stream))
            {
                var value = await valueReader.ReadToEndAsync();

                var settingIdentifier = UriConverter?.Convert <string>(uri) ?? uri;
                var exeConfig         = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                var settings          = FindConnectionStringSettings(exeConfig, settingIdentifier);

                if (settings is null)
                {
                    exeConfig.ConnectionStrings.ConnectionStrings.Add(new ConnectionStringSettings(settingIdentifier, value));
                }
                else
                {
                    settings.ConnectionString = value;
                }

                exeConfig.Save(ConfigurationSaveMode.Minimal);

                return(await GetAsync(uri));
            }
        }
Ejemplo n.º 31
0
        protected override async Task <IResourceInfo> PutAsyncInternal(UriString uri, Stream stream, IImmutableSession metadata)
        {
            var settingIdentifier = UriConverter?.Convert <string>(uri) ?? uri;
            var exeConfig         = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            var actualKey         = FindActualKey(exeConfig, settingIdentifier) ?? settingIdentifier;
            var element           = exeConfig.AppSettings.Settings[actualKey];

            var value = await ResourceHelper.Deserialize <object>(stream, metadata);

            value = ValueConverter.Convert(value, typeof(string));

            if (element is null)
            {
                exeConfig.AppSettings.Settings.Add(settingIdentifier, (string)value);
            }
            else
            {
                exeConfig.AppSettings.Settings[actualKey].Value = (string)value;
            }

            exeConfig.Save(ConfigurationSaveMode.Minimal);

            return(await GetAsync(uri));
        }