/// <summary>
        ///		Initializes a new instance of the <see cref="TcpClientTransportManager"/> class.
        /// </summary>
        /// <param name="configuration">
        ///		The <see cref="RpcClientConfiguration"/> which describes transport configuration.
        /// </param>
        public TcpClientTransportManager(RpcClientConfiguration configuration)
            : base(configuration)
        {
#if !API_SIGNATURE_TEST
            base.SetTransportPool(configuration.TcpTransportPoolProvider(() => new TcpClientTransport(this), configuration.CreateTransportPoolConfiguration()));
#endif
        }
Esempio n. 2
0
        public static void RegisterAppWin(RpcClient client, RpcClientConfiguration cfg)
        {
#if NETCOREAPP2_0 || NETSTANDARD2_0
            throw new PlatformNotSupportedException(".NET Core does not have support to Mincrosoft Windows Registry.");
#else
            var key = Registry.ClassesRoot.OpenSubKey($"discord-{cfg.ApplicationId}");

            if (key != null)
            {
                Registry.ClassesRoot.DeleteSubKeyTree($"discord-{cfg.ApplicationId}");
            }

            key = Registry.ClassesRoot.CreateSubKey($"discord-{cfg.ApplicationId}");
            key.SetValue(string.Empty, $"URL: Run Game {cfg.ApplicationId} Protocol");
            key.SetValue("URL Protocol", string.Empty);

            var command = key.CreateSubKey(@"shell\open\command");
            command.SetValue(string.Empty, cfg.ExecutablePath);

            var icon = key.CreateSubKey("DefaultIcon");
            icon.SetValue(string.Empty, cfg.ExecutablePath);

            icon.Close();
            command.Close();
            key.Close();

            client.RaiseLogEvent(client, LogLevel.Info, "Registered registry key for this app.");
#endif
        }
Esempio n. 3
0
        /// <summary>
        ///		Initializes a new instance of the <see cref="ClientTransportManager"/> class.
        /// </summary>
        /// <param name="configuration">
        ///		The <see cref="RpcClientConfiguration"/> which contains various configuration information.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///		<paramref name="configuration"/> is <c>null</c>.
        /// </exception>
        protected ClientTransportManager(RpcClientConfiguration configuration)
        {
            Contract.EndContractBlock();

            this.configuration  = configuration ?? throw new ArgumentNullException(nameof(configuration));
            requestContextPool  = configuration.RequestContextPoolProvider(() => new ClientRequestContext(configuration), configuration.CreateRequestContextPoolConfiguration());
            responseContextPool = configuration.ResponseContextPoolProvider(() => new ClientResponseContext(configuration), configuration.CreateResponseContextPoolConfiguration());
        }
Esempio n. 4
0
 /// <summary>
 ///		Initializes a new instance of the <see cref="ClientRequestContext"/> class with specified configuration.
 /// </summary>
 /// <param name="configuration">
 ///		An <see cref="RpcClientConfiguration"/> to tweak this instance initial state.
 /// </param>
 public ClientRequestContext(RpcClientConfiguration configuration)
 {
     methodNameBuffer = new MemoryStream((configuration ?? RpcClientConfiguration.Default).InitialMethodNameBufferLength);
     argumentsBuffer  = new MemoryStream((configuration ?? RpcClientConfiguration.Default).InitialArgumentsBufferLength);
     sendingBuffer    = new ArraySegment <byte> [4];
     ArgumentsPacker  = Packer.Create(argumentsBuffer, false);
     messageType      = MessageType.Response;
     stopwatch        = new Stopwatch();
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="InProcClientTransportManager"/> class.
        /// </summary>
        /// <param name="configuration">
        ///		The <see cref="RpcClientConfiguration"/> which contains various configuration information.
        /// </param>
        /// <param name="target">
        ///		The target server to be invoked.
        ///	</param>
        /// <exception cref="ArgumentNullException">
        ///		<paramref name="configuration"/> is <c>null</c>.
        ///		Or, <paramref name="target"/> is <c>null</c>.
        /// </exception>
        public InProcClientTransportManager(RpcClientConfiguration configuration, InProcServerTransportManager target)
            : base(configuration)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            this._target = target;
            this._cancellationTokenSource = new CancellationTokenSource();
            this.SetTransportPool(new OnTheFlyObjectPool <InProcClientTransport>(conf => new InProcClientTransport(this), new ObjectPoolConfiguration()));
        }
        /// <summary>
        ///		Initializes a new instance of the <see cref="ClientTransportManager"/> class.
        /// </summary>
        /// <param name="configuration">
        ///		The <see cref="RpcClientConfiguration"/> which contains various configuration information.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///		<paramref name="configuration"/> is <c>null</c>.
        /// </exception>
        protected ClientTransportManager(RpcClientConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            Contract.EndContractBlock();

            this._configuration       = configuration;
            this._requestContextPool  = configuration.RequestContextPoolProvider(() => new ClientRequestContext(configuration), configuration.CreateRequestContextPoolConfiguration());
            this._responseContextPool = configuration.ResponseContextPoolProvider(() => new ClientResponseContext(configuration), configuration.CreateResponseContextPoolConfiguration());
        }
		public void TestConnectAsync_Timeout()
		{
			var testNetworkIPEndPont = new IPEndPoint( IPAddress.Parse( "198.51.100.1" ), 12345 ); // c.f. http://tools.ietf.org/html/rfc5737)
			var configuration = new RpcClientConfiguration();
			configuration.ConnectTimeout = TimeSpan.FromMilliseconds( 20 );
			using ( var target = new TcpClientTransportManager( configuration ) )
			{
				var actual = Assert.Throws<AggregateException>( () => target.ConnectAsync( testNetworkIPEndPont ).Wait( TimeSpan.FromSeconds( 1 ) ) );
				Assert.That( actual.InnerExceptions.Count, Is.EqualTo( 1 ) );
				Assert.That( actual.InnerException, Is.InstanceOf<RpcException>() );
				Assert.That( ( actual.InnerException as RpcException ).RpcError, Is.EqualTo( RpcError.ConnectionTimeoutError ), actual.ToString() );
			}
		}
        public void TestConnectAsync_Timeout()
        {
            var testNetworkIPEndPont = new IPEndPoint(IPAddress.Parse("198.51.100.1"), 12345);                 // c.f. http://tools.ietf.org/html/rfc5737)
            var configuration        = new RpcClientConfiguration();

            configuration.ConnectTimeout = TimeSpan.FromMilliseconds(20);
            using (var target = new TcpClientTransportManager(configuration))
            {
                var actual = Assert.Throws <AggregateException>(() => target.ConnectAsync(testNetworkIPEndPont).Wait(TimeSpan.FromSeconds(1)));
                Assert.That(actual.InnerExceptions.Count, Is.EqualTo(1));
                Assert.That(actual.InnerException, Is.InstanceOf <RpcException>());
                Assert.That((actual.InnerException as RpcException).RpcError, Is.EqualTo(RpcError.ConnectionTimeoutError), actual.ToString());
            }
        }
Esempio n. 9
0
        /// <summary>
        ///		Initializes a new instance of the <see cref="ClientRequestContext"/> class with specified configuration.
        /// </summary>
        /// <param name="configuration">
        ///		An <see cref="RpcClientConfiguration"/> to tweak this instance initial state.
        /// </param>
        public ClientRequestContext(RpcClientConfiguration configuration)
        {
            this._methodNameBuffer =
                new MemoryStream((configuration ?? RpcClientConfiguration.Default).InitialMethodNameBufferLength);
            this._argumentsBuffer =
                new MemoryStream((configuration ?? RpcClientConfiguration.Default).InitialArgumentsBufferLength);
            this.SendingBuffer = new ArraySegment <byte> [4];
#if MONO
            this._unifiedSendingBuffer = new MemoryStream((configuration ?? RpcClientConfiguration.Default).InitialReceiveBufferLength);
#endif
            this._argumentsPacker = Packer.Create(this._argumentsBuffer, false);
            this._messageType     = MessageType.Response;
            this._stopwatch       = new Stopwatch();
        }
        public void TestConnectAsync_ImplicitTimeout_TranslationOk()
        {
            if (Environment.OSVersion.Platform != PlatformID.Win32NT)
            {
                Assert.Inconclusive("This test dependes on WinSock2");
            }

            var testNetworkIPEndPont = new IPEndPoint(IPAddress.Parse("198.51.100.1"), 12345);                 // c.f. http://tools.ietf.org/html/rfc5737)
            var configuration        = new RpcClientConfiguration();

            using (var target = new TcpClientTransportManager(configuration))
            {
                // WinSock TCP/IP has 20sec timeout...
                var actual = Assert.Throws <AggregateException>(() => target.ConnectAsync(testNetworkIPEndPont).Result.Dispose());
                Assert.That(actual.InnerExceptions.Count, Is.EqualTo(1));
                Assert.That(actual.InnerException, Is.InstanceOf <RpcException>());
                Assert.That((actual.InnerException as RpcException).RpcError, Is.EqualTo(RpcError.ConnectionTimeoutError), actual.ToString());
            }
        }
 /// <summary>
 ///		Initializes a new instance of the <see cref="ClientTransportManager{T}"/> class.
 /// </summary>
 /// <param name="configuration">
 ///		The <see cref="RpcClientConfiguration"/> which contains various configuration information.
 /// </param>
 /// <exception cref="ArgumentNullException">
 ///		<paramref name="configuration"/> is <c>null</c>.
 /// </exception>
 /// <remarks>
 ///		The derived class must call <see cref="SetTransportPool"/> in the end of constructor
 ///		unless it implements special process which does not use transport pool at all.
 /// </remarks>
 protected ClientTransportManager(RpcClientConfiguration configuration)
     : base(configuration)
 {
     this._activeTransports = new ConcurrentDictionary <TTransport, object>();
 }
		public void TestConnectAsync_ImplicitTimeout_TranslationOk()
		{
			if ( Environment.OSVersion.Platform != PlatformID.Win32NT )
			{
				Assert.Inconclusive( "This test dependes on WinSock2" );
			}

			var testNetworkIPEndPont = new IPEndPoint( IPAddress.Parse( "198.51.100.1" ), 12345 ); // c.f. http://tools.ietf.org/html/rfc5737)
			var configuration = new RpcClientConfiguration();
			using ( var target = new TcpClientTransportManager( configuration ) )
			{
				// WinSock TCP/IP has 20sec timeout...
				var actual = Assert.Throws<AggregateException>( () => target.ConnectAsync( testNetworkIPEndPont ).Result.Dispose() );
				Assert.That( actual.InnerExceptions.Count, Is.EqualTo( 1 ) );
				Assert.That( actual.InnerException, Is.InstanceOf<RpcException>() );
				Assert.That( ( actual.InnerException as RpcException ).RpcError, Is.EqualTo( RpcError.ConnectionTimeoutError ), actual.ToString() );
			}
		}
Esempio n. 13
0
		/// <summary>
		///		Initializes a new instance of the <see cref="ClientTransportManager"/> class.
		/// </summary>
		/// <param name="configuration">
		///		The <see cref="RpcClientConfiguration"/> which contains various configuration information.
		/// </param>
		/// <exception cref="ArgumentNullException">
		///		<paramref name="configuration"/> is <c>null</c>.
		/// </exception>
		protected ClientTransportManager( RpcClientConfiguration configuration )
		{
			if ( configuration == null )
			{
				throw new ArgumentNullException( "configuration" );
			}

			Contract.EndContractBlock();

			this._configuration = configuration;
			this._requestContextPool = configuration.RequestContextPoolProvider( () => new ClientRequestContext( configuration ), configuration.CreateRequestContextPoolConfiguration() );
			this._responseContextPool = configuration.ResponseContextPoolProvider( () => new ClientResponseContext( configuration ), configuration.CreateResponseContextPoolConfiguration() );
		}
Esempio n. 14
0
		/// <summary>
		///		Initializes a new instance of the <see cref="ClientRequestContext"/> class with specified configuration.
		/// </summary>
		/// <param name="configuration">
		///		An <see cref="RpcClientConfiguration"/> to tweak this instance initial state.
		/// </param>
		public ClientRequestContext( RpcClientConfiguration configuration )
		{
			this._methodNameBuffer =
				new MemoryStream( ( configuration ?? RpcClientConfiguration.Default ).InitialMethodNameBufferLength );
			this._argumentsBuffer =
				new MemoryStream( ( configuration ?? RpcClientConfiguration.Default ).InitialArgumentsBufferLength );
			this.SendingBuffer = new ArraySegment<byte>[ 4 ];
#if MONO
			this._unifiedSendingBuffer = new MemoryStream( ( configuration ?? RpcClientConfiguration.Default ).InitialReceiveBufferLength );
#endif
			this._argumentsPacker = Packer.Create( this._argumentsBuffer, false );
			this._messageType = MessageType.Response;
			this._stopwatch = new Stopwatch();
		}
 /// <summary>
 ///		Initializes a new instance of the <see cref="ClientResponseContext"/> class with specified configuration.
 /// </summary>
 /// <param name="configuration">
 ///		An <see cref="RpcClientConfiguration"/> to tweak this instance initial state.
 /// </param>
 public ClientResponseContext(RpcClientConfiguration configuration)
     : base((configuration ?? RpcClientConfiguration.Default).InitialReceiveBufferLength)
 {
     this.ErrorStartAt  = -1;
     this.ResultStartAt = -1;
 }
Esempio n. 16
0
 public Target(RpcClientConfiguration configuration) : base(configuration)
 {
 }
Esempio n. 17
0
			public Target( RpcClientConfiguration configuration ) : base( configuration ) { }
Esempio n. 18
0
 /// <summary>
 ///		Initializes a new instance of the <see cref="UdpClientTransportManager"/> class.
 /// </summary>
 /// <param name="configuration">
 ///		The <see cref="RpcClientConfiguration"/> which describes transport configuration.
 /// </param>
 public UdpClientTransportManager(RpcClientConfiguration configuration)
     : base(configuration)
 {
     SetTransportPool(configuration.UdpTransportPoolProvider(() => new UdpClientTransport(this), configuration.CreateTransportPoolConfiguration()));
 }
Esempio n. 19
0
		/// <summary>
		///		Initializes a new instance of the <see cref="ClientResponseContext"/> class with specified configuration.
		/// </summary>
		/// <param name="configuration">
		///		An <see cref="RpcClientConfiguration"/> to tweak this instance initial state.
		/// </param>
		public ClientResponseContext( RpcClientConfiguration configuration )
			: base( ( configuration ?? RpcClientConfiguration.Default ).InitialReceiveBufferLength )
		{
			this.ErrorStartAt = -1;
			this.ResultStartAt = -1;
		}