protected override async Task ApplyProfile(ProfileBase profile)
        {
            if (_subscriber != null)
            {
                await _subscriber.DisposeAsync();

                _subscriber = null;
            }

            if (profile is RestProfile restProfile)
            {
                _profile = restProfile;

                var requestClient = CreateRequestClient();
                var tokenProvider = new TokenProvider(CreateRequestClient, _profile.ServerUser, _profile.ServerPassword);

                var token = await tokenProvider.GetToken();

                var serverUri  = new Uri(_profile.ServerName);
                var signalRUri = new Uri(serverUri, "/cosei");

                var subscriber = new SignalRSubscriber(signalRUri.AbsoluteUri,
                                                       options =>
                {
                    options.Headers.Add("Authorization", $"Bearer {token}");
                },
                                                       exception =>
                {
                    _dispatcher.BeginInvokeOnMainThread(async() => await _errorService.ShowAlert(exception));
                });

                var snippetStore       = new SnippetStore(requestClient, tokenProvider);
                var csScriptRunService = new CsScriptRunService(_clipboardService);
                SnippetService = new SnippetService(snippetStore, _messenger, csScriptRunService, _dispatcher, subscriber, _profile.ServerUser);
                var userStore = new UserStore(requestClient, tokenProvider);
                UserService = new UserService(userStore, _messenger, _dispatcher, subscriber);

                await subscriber.StartAsync();

                _subscriber = subscriber;
            }
        }
Beispiel #2
0
        protected override async Task ApplyProfile(ProfileBase profile)
        {
            if (_rabbitMqModelFactory != null)
            {
                _rabbitMqModelFactory.Dispose();
                _rabbitMqModelFactory = null;
            }

            if (profile is RmqProfile rmqProfile)
            {
                _profile = rmqProfile;

                _rabbitMqModelFactory = new RabbitMqModelFactory(
                    _profile.RabbitMqHost,
                    _profile.RabbitMqVirtualHost,
                    _profile.RabbitMqUser,
                    _profile.RabbitMqPassword);

                var requestClient = CreateRequestClient();
                var tokenProvider = new TokenProvider(CreateRequestClient, _profile.ServerUser, _profile.ServerPassword);
                var subscriber    = new RabbitMqSubscriber(
                    _rabbitMqModelFactory,
                    exception =>
                {
                    _dispatcher.BeginInvokeOnMainThread(async() => await _errorService.ShowAlertAsync(exception));
                });

                var snippetStore       = new SnippetStore(requestClient, tokenProvider);
                var csScriptRunService = new CsScriptRunService(_clipboardService);
                var pyScriptRunService = new PyScriptRunService(_clipboardService);
                SnippetService = new SnippetService(snippetStore, _messenger, csScriptRunService, pyScriptRunService, _dispatcher, subscriber, _profile.ServerUser);
                var userStore = new UserStore(requestClient, tokenProvider);
                UserService = new UserService(userStore, _messenger, _dispatcher, subscriber);

                await subscriber.StartAsync();

                Subscriber = subscriber;
            }
        }