public async Task <int> SaveEnvironmentAsync(BlockchainEnvironment envToSave)
 {
     try
     {
         return(await database.InsertOrReplaceAsync(envToSave));
     }
     catch (SQLiteException)
     {
         return(-1);
     }
 }
示例#2
0
        async void ChangeURLEndpoint(object sender, System.EventArgs e)
        {
            if (App.ViewModel.WorkbenchEnvironments.Count > 1)
            {
                return;
            }
            var prompt = new PromptConfig
            {
                IsCancellable = true,
                Message       = $"This lets you change to another Workbench instance with the same Active Directory. Please enter the environment name in the format 'xxx-xxxxxx'",
                OkText        = "Save",
                Title         = "Change API Endpoint?"
            };

            var apiURLResults = await UserDialogs.Instance.PromptAsync(prompt);

            if (!string.IsNullOrEmpty(apiURLResults?.Value) && apiURLResults.Ok)
            {
                var newSiteUrl = $"https://{apiURLResults?.Value}-api.azurewebsites.net/";

                var duplicateEnvironment = App.ViewModel.WorkbenchEnvironments.FirstOrDefault(env => env.SiteUrl == newSiteUrl);

                if (duplicateEnvironment is null)
                {
                    var prevEnv = App.ViewModel.WorkbenchEnvironments[0];
                    App.ViewModel.WorkbenchEnvironments[0].SiteUrl = newSiteUrl;
                    App.ViewModel.AllUsersList.Clear();
                    await LocalDbHelper.Instance.PurgeEnvironments();

                    var environment = new BlockchainEnvironment
                    {
                        ResourceId = prevEnv.ResourceId,
                        ClientId   = prevEnv.ClientId,
                        ReturnUrl  = prevEnv.ReturnUrl,
                        SiteUrl    = newSiteUrl,
                        TenantId   = prevEnv.TenantId,
                        NickName   = prevEnv.NickName
                    };
                    await LocalDbHelper.Instance.SaveEnvironmentAsync(environment);

                    GatewayApi.SiteUrl = newSiteUrl;
                }
                else
                {
                    await DisplayAlert("Error", "This endpoint is already configured", "Ok");
                }
            }
        }
        async Task <bool> executeLoginAsync()
        {
            var localEnvironments = await LocalDbHelper.Instance.GetAllSavedEnvironmentsAsync();

            if (localEnvironments.Count <= 0)
            {
                System.Diagnostics.Debug.WriteLine("################### NO LOCAL ENVIRONMENTS FOUND");

                await configureFirstEnvironment();

                return(false);
            }

            BlockchainEnvironment environment = localEnvironments[0];

            var authService   = ServiceContainer.Resolve <IAuthentication>();
            var loginResponse = await authService.LoginAsync(
                $"https://login.windows.net/{environment.TenantId}",
                environment.ResourceId,
                environment.ClientId,
                environment.ReturnUrl);

            if (loginResponse != null)
            {
                AppCenterHelper.TrackEvent("Logged in", new Dictionary <string, string>()
                {
                    { "username", loginResponse.Profile.DisplayableId }
                });

                Settings.AccessToken = loginResponse.AccessToken;
#if DEBUG
                Settings.AccessTokenExpiration            = new DateTimeOffset(DateTime.UtcNow.AddMinutes(2));
                GatewayApi.Instance.AccessTokenExpiration = new DateTimeOffset(DateTime.UtcNow.AddMinutes(2));
#else
                Settings.AccessTokenExpiration            = loginResponse.ExpiresOn;
                GatewayApi.Instance.AccessTokenExpiration = loginResponse.ExpiresOn;
#endif

                GatewayApi.Instance.SetAuthToken(loginResponse.AccessToken);

                App.LOGGED_OUT = false;

                Device.BeginInvokeOnMainThread(async() =>
                {
                    if (App.Current.MainPage.Navigation.ModalStack.Count == 0)
                    {
                        await App.Current.MainPage.Navigation.PushModalAsync(App.Master);
                    }

                    App.ViewModel.WorkbenchEnvironments = localEnvironments;
                    App.ViewModel.SelectedEnvironment   = environment;
                });

                return(true);
            }
            else
            {
                await App.Logout();

                return(false);
            }
        }
示例#4
0
        public App()
        {
            FlowListView.Init();

            GatewayApi.Instance.ExpiredAccessToken += async(object sender, EventArgs e) =>
            {
                var localEnvironments = await LocalDbHelper.Instance.GetAllSavedEnvironmentsAsync();

                BlockchainEnvironment environment = localEnvironments[0];

                var authService   = ServiceContainer.Resolve <IAuthentication>();
                var loginResponse = await authService.LoginAsync(
                    $"https://login.windows.net/{environment.TenantId}",
                    environment.ResourceId,
                    environment.ClientId,
                    environment.ReturnUrl,
                    isRefresh : true);

                if (loginResponse != null)
                {
                    AppCenterHelper.TrackEvent("Refreshed Token", new Dictionary <string, string>()
                    {
                        { "username", loginResponse.Profile.DisplayableId }
                    });

                    Settings.AccessToken = loginResponse.AccessToken;
                    GatewayApi.Instance.SetAuthToken(loginResponse.AccessToken);
#if DEBUG
                    Settings.AccessTokenExpiration            = new DateTimeOffset(DateTime.Now.AddMinutes(2));
                    GatewayApi.Instance.AccessTokenExpiration = new DateTimeOffset(DateTime.Now.AddMinutes(2));
#else
                    Settings.AccessTokenExpiration            = loginResponse.ExpiresOn;
                    GatewayApi.Instance.AccessTokenExpiration = loginResponse.ExpiresOn;
#endif
                }
                else
                {
                    App.Logout(false);
                }
            };

            GatewayApi.Instance.ExceptionThrown += async(object sender, Exception e) =>
            {
                AppCenterHelper.Report(e, new Dictionary <string, string>()
                {
                    { "baseurl", GatewayApi.SiteUrl }
                });
            };

            ViewModel = new AppViewModel();

            backgroundPage = new BackgroundPage();

            var navPage       = new Xamarin.Forms.NavigationPage(backgroundPage);
            var detailNavPage = new Xamarin.Forms.NavigationPage(new ApplicationsPage());

            ContractsPage = new WorklfowInstanceListPage();

            navPage.BarBackgroundColor       = Constants.NavBarBackgroundColor;
            navPage.BarTextColor             = Constants.NavBarTextColor;
            detailNavPage.BarBackgroundColor = Constants.NavBarBackgroundColor;
            detailNavPage.BarTextColor       = Constants.NavBarTextColor;

            Master = new MasterDetailPage {
                BindingContext = ViewModel
            };
            Master.IsPresentedChanged += (object sender, EventArgs e) =>
            {
                var mdp = sender as MasterDetailPage;
                if (mdp.IsPresented)
                {
                    ((Xamarin.Forms.NavigationPage)mdp.Detail)
                    .On <iOS>()
                    .SetStatusBarTextColorMode(StatusBarTextColorMode.DoNotAdjust);
                }
                else
                {
                    ((Xamarin.Forms.NavigationPage)mdp.Detail)
                    .On <iOS>()
                    .SetStatusBarTextColorMode(StatusBarTextColorMode.MatchNavigationBarTextLuminosity);
                }
            };

            Master.Master = new MasterPage {
                BindingContext = ViewModel
            };
            Master.Detail = detailNavPage;
            Master.SetBinding(MasterDetailPage.IsPresentedProperty, nameof(AppViewModel.MenuPresented), BindingMode.TwoWay);

            Xamarin.Forms.NavigationPage.SetHasNavigationBar(detailNavPage, false);

            try
            {
                MainPage = navPage;
            }
            catch (Exception e)
            {
                AppCenterHelper.Report(e);
            }
        }
示例#5
0
        public SelectedButton(BlockchainEnvironment environment)
        {
            Environment = environment;

            setupUi();
        }