Beispiel #1
0
        public static T1 GetClientProxy <T1>(
            ReliableSamHelper helper,
            string serverDestination,
            out JsonSamServiceInterceptor interceptor,
            JsonSamClientSettings jsonSamClientSettings,
            Action <RpcRethrowableException>
            advancedRpcRethrowableExceptionHandling = null
            )
        {
            if (helper == null)
            {
                throw new ArgumentNullException(
                          MyNameof.GetLocalVarName(() => helper));
            }
            if (string.IsNullOrWhiteSpace(serverDestination))
            {
                throw new ArgumentNullException(
                          MyNameof.GetLocalVarName(() => serverDestination));
            }
            var factory = new ProxyFactory();

            interceptor = new JsonSamServiceInterceptor(
                helper,
                typeof(T1),
                serverDestination,
                jsonSamClientSettings,
                advancedRpcRethrowableExceptionHandling
                );
            return(factory.CreateProxy <T1>(interceptor));
        }
Beispiel #2
0
        /**/
        private static readonly Logger _log
            = LogManager.GetCurrentClassLogger();
        /**/
        public static async Task <SamClientInfo <T1> > CreateInstance(
            string samServerAddress,
            int samServerPort,
            string serverDestination,
            CancellationToken cancellationToken,
            JsonSamClientSettings jsonSamClientSettings,
            string clientPrivateKeys = null,
            Action <RpcRethrowableException>
            advancedRpcRethrowableExceptionHandling = null,
            bool useReconnectingSamHelper           = false,
            string i2CpOptions = null
            )
        {
            var        result = new SamClientInfo <T1>();
            ISamHelper samHelperSend;
            var        samHelperSettings = new SamHelperSettings()
            {
                SamServerAddress   = samServerAddress,
                SamServerPort      = samServerPort,
                SessionPrivateKeys = clientPrivateKeys,
                I2CpOptions        = i2CpOptions
            };

            if (!useReconnectingSamHelper)
            {
                samHelperSend = await SamHelper.SamHelper.CreateInstance(
                    samHelperSettings,
                    cancellationToken
                    ).ConfigureAwait(false);
            }
            else
            {
                samHelperSend = await ReconnectingSamHelper.CreateInstance(
                    new ReconnectingSamHelperSettings()
                {
                    ImplementationHelperSettings = samHelperSettings
                },
                    cancellationToken
                    ).ConfigureAwait(false);
            }
            try
            {
                result.SamHelperSend = samHelperSend;
                var reliableHelperSend = new ReliableSamHelper(
                    samHelperSend,
                    new ReliableSamHelperSettings()
                    );
                result.ReliableHelperSend = reliableHelperSend;
                result.JsonClient         =
                    JsonSamServiceInterceptor.GetClientProxy <T1>(
                        reliableHelperSend,
                        serverDestination,
                        out result.SamInterceptor,
                        jsonSamClientSettings,
                        advancedRpcRethrowableExceptionHandling
                        );
            }
            catch (Exception)
            {
                await samHelperSend.MyDisposeAsync().ConfigureAwait(false);

                throw;
            }
            return(result);
        }