コード例 #1
0
 public TrinitySoapClient(ISoapClientFactory soapClientFactory,
                          string host,
                          int port,
                          string userName,
                          string password)
 {
     endpoint   = new Uri($"http://{host}:{port}");
     soapClient = soapClientFactory.Factory(userName, password);
     soapParser = new TrinitySoapParser();
 }
コード例 #2
0
        public SoapConfigViewModel(IConnectionSettingsProvider settings, ISoapClientFactory clientFactory)
        {
            port          = (settings.GetSettings().Port ?? 7878).ToString();
            user          = settings.GetSettings().User;
            pass          = settings.GetSettings().Password;
            host          = settings.GetSettings().Host ?? "127.0.0.1";
            this.settings = settings;

            Save = new DelegateCommand(() =>
            {
                int?port = null;
                if (int.TryParse(Port, out int port_))
                {
                    port = port_;
                }
                settings.UpdateSettings(User, Password, Host, port);
                IsModified = false;
            });

            TestConnection = new AsyncAutoCommand(async() =>
            {
                int?port = null;
                if (int.TryParse(Port, out int port_))
                {
                    port = port_;
                }
                var client = new TrinitySoapClient(clientFactory, host, port ?? 0, user !, pass !);
                try
                {
                    var response = await client.ExecuteCommand("server info");
                    if (response.Success)
                    {
                        TestConnectionOutput = "Success:\n" + response.Message;
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(response.Message))
                        {
                            TestConnectionOutput =
                                "Server responded, but response ill-formed. Is it TrinityCore based server?";
                        }
                        else
                        {
                            TestConnectionOutput = "Server responded, but command failed: " + response.Message;
                        }
                    }
                }
                catch (Exception e)
                {
                    TestConnectionOutput = "Connection failed: " + e.Message;
                }
            }, _ => !string.IsNullOrEmpty(host) && int.TryParse(port, out var _) && !string.IsNullOrEmpty(user) && !string.IsNullOrEmpty(pass));

            PropertyChanged += (_, _) => TestConnection.RaiseCanExecuteChanged();
        }
コード例 #3
0
        public SoapRemoteConnectorService(IConnectionSettingsProvider connectionSettings,
                                          ISoapClientFactory soapClientFactory)
        {
            this.connectionSettings = connectionSettings;
            var settings = connectionSettings.GetSettings();

            if (settings.IsEmpty)
            {
                trinitySoapClient = null;
            }
            else
            {
                trinitySoapClient = new TrinitySoapClient(soapClientFactory, settings.Host !, settings.Port !.Value, settings.User !, settings.Password !);
            }
        }
コード例 #4
0
        /// <summary>
        ///     Gets a <see cref="ISoapClient" /> instance from the factory and releases
        ///     when the action completes.
        /// </summary>
        /// <typeparam name="TSoapClient">The SOAP client type</typeparam>
        /// <typeparam name="TResult">The result type</typeparam>
        /// <param name="factory">The factory to use</param>
        /// <param name="action">The action to execute</param>
        /// <returns>The action result</returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static TResult GetAndRelease <TSoapClient, TResult>(this ISoapClientFactory factory, Func <TSoapClient, TResult> action)
            where TSoapClient : ISoapClient
        {
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            var client = factory.Get <TSoapClient>();

            try
            {
                return(action(client));
            }
            finally
            {
                factory.Release(client);
            }
        }
コード例 #5
0
        /// <summary>
        ///     Gets a <see cref="ISoapClient" /> instance from the factory and releases
        ///     when the action completes.
        /// </summary>
        /// <typeparam name="TSoapClient">The SOAP client type</typeparam>
        /// <typeparam name="TResult">The result type</typeparam>
        /// <param name="factory">The factory to use</param>
        /// <param name="action">The action to execute</param>
        /// <param name="ct">The cancellation token</param>
        /// <returns>A task that can be awaited for the result</returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static async Task <TResult> GetAndReleaseAsync <TSoapClient, TResult>(
            this ISoapClientFactory factory, Func <TSoapClient, CancellationToken, Task <TResult> > action, CancellationToken ct = default(CancellationToken))
            where TSoapClient : ISoapClient
        {
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            var client = factory.Get <TSoapClient>();

            try
            {
                return(await action(client, ct).ConfigureAwait(false));
            }
            finally
            {
                factory.Release(client);
            }
        }
コード例 #6
0
 /// <summary>
 ///     Gets a <see cref="ISoapClient" /> instance from the factory and releases
 ///     when the action completes.
 /// </summary>
 /// <param name="factory">The factory to use</param>
 /// <param name="action">The action to execute</param>
 /// <exception cref="ArgumentNullException"></exception>
 public static void GetAndRelease(this ISoapClientFactory factory, Action <SoapClient> action)
 {
     GetAndRelease <SoapClient>(factory, action);
 }
コード例 #7
0
 /// <summary>
 ///     Gets a <see cref="ISoapClient" /> instance from the factory and releases
 ///     when the action completes.
 /// </summary>
 /// <typeparam name="TResult">The result type</typeparam>
 /// <param name="factory">The factory to use</param>
 /// <param name="action">The action to execute</param>
 /// <param name="ct">The cancellation token</param>
 /// <returns>A task that can be awaited for the result</returns>
 /// <exception cref="ArgumentNullException"></exception>
 public static async Task <TResult> GetAndReleaseAsync <TResult>(
     this ISoapClientFactory factory, Func <SoapClient, CancellationToken, Task <TResult> > action, CancellationToken ct = default(CancellationToken))
 {
     return(await GetAndReleaseAsync <SoapClient, TResult>(factory, action, ct).ConfigureAwait(false));
 }
コード例 #8
0
 /// <summary>
 ///     Gets a <see cref="ISoapClient" /> instance from the factory and releases
 ///     when the action completes.
 /// </summary>
 /// <param name="factory">The factory to use</param>
 /// <param name="action">The action to execute</param>
 /// <param name="ct">The cancelattion token</param>
 /// <returns>A task that can be awaited</returns>
 /// <exception cref="ArgumentNullException"></exception>
 public static async Task GetAndReleaseAsync(
     this ISoapClientFactory factory, Func <SoapClient, CancellationToken, Task> action, CancellationToken ct = default(CancellationToken))
 {
     await GetAndReleaseAsync <SoapClient>(factory, action, ct).ConfigureAwait(false);
 }
コード例 #9
0
 /// <summary>
 ///     Gets a <see cref="ISoapClient" /> instance from the factory and releases
 ///     when the action completes.
 /// </summary>
 /// <typeparam name="TResult">The result type</typeparam>
 /// <param name="factory">The factory to use</param>
 /// <param name="action">The action to execute</param>
 /// <returns>The action result</returns>
 /// <exception cref="ArgumentNullException"></exception>
 public static TResult GetAndRelease <TResult>(this ISoapClientFactory factory, Func <SoapClient, TResult> action)
 {
     return(GetAndRelease <SoapClient, TResult>(factory, action));
 }