public virtual async Task <Token> LoginWithCredentials(string username, string password, string client_id, string client_secret, string[] scopes = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            await Logout(state : null, client_id : client_id, cancellationToken : cancellationToken).ConfigureAwait(false);

            if (scopes == null)
            {
                scopes = "openid profile user_info".Split(' ');
            }

            TokenClient tokenClient = _containerProvider.GetContainer().Resolve <TokenClient>(new NamedParameter("clientId", client_id), new NamedParameter("secret", client_secret));

            TokenResponse tokenResponse = await tokenClient.RequestResourceOwnerPasswordAsync(username, password, scope : string.Join(" ", scopes), cancellationToken : cancellationToken).ConfigureAwait(false);

            if (tokenResponse.IsError)
            {
                throw tokenResponse.Exception ?? new Exception($"{tokenResponse.Error} {tokenResponse.Raw}");
            }

            Token token = tokenResponse;

            string jsonToken = JsonConvert.SerializeObject(token);

            if (UseSecureStorage())
            {
                await SecureStorage.SetAsync("Token", jsonToken).ConfigureAwait(false);
            }
            else
            {
                Preferences.Set("Token", jsonToken);
            }

            return(token);
        }
Esempio n. 2
0
        public static Type GetWindowObject(string assemblyName)
        {
            IContainerProvider ContainerProvider = ServiceLocator.Current.GetInstance <IContainerProvider>();
            ICarefulIoc        unityContainer    = ContainerProvider.GetContainer();

            //foreach (var item in unityContainer.Registrations.ToList())
            //{
            //    if (item.RegisteredType.Name == assemblyName)
            //    {
            //        return item.RegisteredType;
            //    }
            //}
            return(null);
        }
 public override void OnInitialized(IContainerProvider containerProvider)
 {
     containerProvider
     .Resolve <IEventAggregator>()
     .GetEvent <ApplicationExiting>()
     .Subscribe(
         () =>
     {
         if (containerProvider.GetContainer().IsRegistered <IAcceleriderUser>())
         {
             containerProvider.Resolve <IAcceleriderUser>().SaveToLocalDisk();
         }
     },
         true);
 }
Esempio n. 4
0
        public static IContainer CurrentContainer()
        {
            //create and configure container if one does not yet exist
            if (_Current == null)
            {
                lock (_TypeLock)
                {
                    if (_Current == null)
                    {
                        _Current = _ContainerProvider.GetContainer();
                    }
                }
            }

            return(_Current);
        }
        public void OnInitialized(IContainerProvider containerProvider)
        {
            var ea = containerProvider.GetContainer().Resolve <IEventAggregator>();

            ea.GetEvent <FaceRecogTriggeredEvent>().Subscribe(
                () =>
            {
                var service = containerProvider.Resolve <TriggerRecognitionNavigation>();
                service.NaviateToTriggerRecogView();
            }, true);


            ea.GetEvent <AppShuttingDownEvent>().Subscribe(() =>
            {
                ServiceLocator.Current.GetInstance <AlgorithmService>().Shutdown();
            }, true);
        }
Esempio n. 6
0
        /// <summary>
        /// Sets the <see cref="DependencyResolver" /> to use the App Container for resolving types
        /// </summary>
        protected override void SetDependencyResolver(IContainerProvider containerProvider)
        {
            base.SetDependencyResolver(containerProvider);
            DependencyResolver.ResolveUsing((Type type, object[] dependencies) =>
            {
                var container = containerProvider.GetContainer();

                foreach (var dependency in dependencies)
                {
                    if (dependency is Android.Content.Context context)
                    {
                        var resolver = container.Resolve <Func <Android.Content.Context, object> >(type);
                        return(resolver.Invoke(context));
                    }
                }
                container.Resolve <ILoggerFacade>().Log($"Could not locate an Android.Content.Context to resolve {type.Name}", Category.Warn, Priority.High);
                return(container.Resolve(type));
            });
        }
Esempio n. 7
0
        /// <summary>
        /// Sets the <see cref="DependencyResolver" /> to use the App Container for resolving types
        /// </summary>
        protected override void SetDependencyResolver(IContainerProvider containerProvider)
        {
            base.SetDependencyResolver(containerProvider);
            DependencyResolver.ResolveUsing((Type type, object[] dependencies) =>
            {
                var container  = containerProvider.GetContainer();
                var parameters = new List <Parameter>();
                foreach (var dependency in dependencies)
                {
                    if (dependency is Android.Content.Context context)
                    {
                        parameters.Add(new TypedParameter(typeof(Android.Content.Context), context));
                    }
                    else
                    {
                        container.Resolve <ILoggerFacade>().Log($"Resolving an unknown type {dependency.GetType().Name}", Category.Warn, Priority.High);
                        parameters.Add(new TypedParameter(dependency.GetType(), dependency));
                    }
                }

                return(container.Resolve(type, parameters.ToArray()));
            });
        }
Esempio n. 8
0
        public virtual async Task <Token> LoginWithCredentials(string username, string password, string client_id, string client_secret, string[] scopes = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            await Logout(state : null, client_id : client_id, cancellationToken : cancellationToken);

            if (scopes == null)
            {
                scopes = "openid profile user_info".Split(' ');
            }

            TokenClient tokenClient = _containerProvider.GetContainer().Resolve <TokenClient>(new NamedParameter("clientId", client_id), new NamedParameter("secret", client_secret));

            TokenResponse tokenResponse = await tokenClient.RequestResourceOwnerPasswordAsync(username, password, scope : string.Join(" ", scopes), cancellationToken : cancellationToken).ConfigureAwait(false);

            if (tokenResponse.IsError)
            {
                throw tokenResponse.Exception ?? new Exception($"{tokenResponse.Error} {tokenResponse.Raw}");
            }

            Account account = Token.FromTokenToAccount(tokenResponse);

            await _accountStore.SaveAsync(account, _clientAppProfile.AppName).ConfigureAwait(false);

            return(account);
        }
Esempio n. 9
0
 public static IContainer GetBaseContainer(this IContainerProvider container) =>
 container.GetContainer();