예제 #1
0
        private async void ProcessRequest(IRequestAuthenticationMessage request)
        {
            Settings.IValues values = _settingsProvider.GetValues();

            AuthenticationRequest authenticationRequest = new AuthenticationRequest
            {
                password = request.Password,
                email    = request.EMail
            };

            string serializedRequest = authenticationRequest.ToJson();

            HttpContent content = new StringContent(serializedRequest, System.Text.Encoding.UTF8, "application/json");

            HttpClient client = new HttpClient();

            var response = await client.PostAsync(values.AuthenticationEndpoint, content);

            string result = await response.Content.ReadAsStringAsync();

            AuthenticationResponse authenticationResponse = JsonSerializer.DeserializeFromString <AuthenticationResponse>(result);

            if (authenticationResponse.GetUserAuthTokenResult != null)
            {
                _messageMediator.Publish(new AuthenticationResponseMessage(authenticationResponse.GetUserAuthTokenResult.AccountId, authenticationResponse.GetUserAuthTokenResult.UserAuthToken));
            }
            else
            {
                _messageMediator.Publish(new AuthenticationResponseMessage(authenticationResponse.ErrorCode, authenticationResponse.Message, authenticationResponse.Source));
            }
        }
예제 #2
0
파일: Machine.cs 프로젝트: ibebbs/Harmonize
        public void Initialize()
        {
            Settings.IValues settings = _settingsProvider.GetValues();

            _currentState   = _stateFactory.ConstructState(Name.Stopped);
            _currentContext = ContextFactory.Create(settings.EMail, settings.Password);

            EnterState();

            _transitionSubscription = _messageMediator.GetEvent <ITransitionToStateMessage>().ObserveOn(_asyncHelper.AsyncScheduler).Subscribe(ProcessTransition);
        }
예제 #3
0
        private async void Authenticate(IAuthenticatedContext context)
        {
            Settings.IValues settings = _settingsProvider.GetValues();

            try
            {
                Hub.Session.IInfo sessionInfo = await _authenticationProvider.AuthenticateAsync(settings.HarmonyHubAddress, context.AuthenticationToken);

                ISessionContext sessionContext = context.ForSession(sessionInfo);

                _messageMediator.Publish(new TransitionToStateMessage <ISessionContext>(Name.EstablishingSession, sessionContext));
            }
            catch
            {
                _messageMediator.Publish(new TransitionToStateMessage <IContext>(Name.Stopped, context));
            }
        }
예제 #4
0
        private async void CreateSession(ISessionContext context)
        {
            Settings.IValues settings = _settingsProvider.GetValues();

            Hub.Endpoint.IInstance endpoint = _endpointFactory.Create(settings.HarmonyHubAddress, context.SessionInfo);

            try
            {
                await endpoint.ConnectAsync();

                IActiveContext activeContext = context.Activate(context.SessionInfo, new Hub.Session.Instance(endpoint));

                _messageMediator.Publish(new TransitionToStateMessage <IActiveContext>(Name.Synchronizing, activeContext));
            }
            catch
            {
                _messageMediator.Publish(new TransitionToStateMessage <IContext>(Name.Stopped, context));
            }
        }
예제 #5
0
파일: Factory.cs 프로젝트: ibebbs/Harmonize
        public IConnection ForConnection()
        {
            Settings.IValues settings = _settingsProvider.GetValues();

            return(new Connection(settings.LocalCommandEndpoint, settings.OwlCommandEndpoint));
        }