예제 #1
0
        /// <summary>
        /// Gets all users
        /// </summary>
        /// <returns></returns>
        public async Task GetUsersAsync()
        {
            await RunCommandAsync(() => UsersLoading, async() =>
            {
                await Task.Delay(1);

                var credentials = await ClientDataStore.GetLoginCredentialsAsync();

                var result = await WebRequests.PostAsync <ApiResponse <UserResultApiModel> >(
                    url: RouteHelpers.GetAbsoluteRoute(ApiRoutes.GetEnterpriseSetting),
                    bearerToken: credentials.Token
                    );


                // If the response has an error...don't mind to continue
                if (await result.HandleErrorIfFailedAsync())
                {
                    return;
                }
            });
        }
예제 #2
0
        /// <summary>
        /// Sets the settings view model properties based on the data in the client data store
        /// </summary>
        public async Task LoadAsync()
        {
            // Update values from local cache
            await UpdateValuesFromLocalStoreAsync();

            // Get the user token
            var token = (await ClientDataStore.GetLoginCredentialsAsync()).Token;

            // If we don't have a token (so we are not logged in...)
            if (string.IsNullOrEmpty(token))
            {
                // Then do nothing more
                return;
            }

            // Load user profile details form server
            var result = await WebRequests.PostAsync <ApiResponse <UserProfileDetailsApiModel> >(
                // Set URL
                RouteHelpers.GetAbsoluteRoute(ApiRoutes.UpdateUserProfile),
                // Pass in user Token
                bearerToken : token);

            // If it was successful...
            if (result.Successful)
            {
                // TODO: Should we check if the values are different before saving?

                // Create data model from the response
                var dataModel = result.ServerResponse.Response.ToLoginCredentialsDataModel();

                // Re-add our known token
                dataModel.Token = token;

                // Save the new information in the data store
                await ClientDataStore.SaveLoginCredentialsAsync(dataModel);

                // Update values from local cache
                await UpdateValuesFromLocalStoreAsync();
            }
        }
예제 #3
0
        /// <summary>
        /// Configures our application ready for use
        /// </summary>
        private async Task ApplicationSetupAsync()
        {
            // Setup the Dna Framework
            Framework.Construct <DefaultFrameworkConstruction>()
            .AddFileLogger()
            .AddClientDataStore()
            .AddAppsViewModels()
            .AddAppsClientServices()
            .Build();

            // Ensure the client data store
            await ClientDataStore.EnsureDataStoreAsync();

            // Ensure the BaseList data store
            await BaseListItem.EnsureDataStoreAsync();

            // Monitor for server connection status
            MonitorServerStatus();

            // Load new settings
            TaskManager.RunAndForget(ViewModelSettings.LoadAsync);
        }
예제 #4
0
        /// <summary>
        /// Configures our application ready for use
        /// </summary>
        private async Task ApplicationSetupAsync()
        {
            // Set database file name
            string fileName = "Dailylight.db";

            // Set database path
            string dbPath = Path.Combine(System
                                         .Environment
                                         .GetFolderPath(System.Environment.SpecialFolder.Personal), fileName);

            // Setup the Dna Framework
            Framework.Construct <DefaultFrameworkConstruction>()
            .AddClientDataStore(dbPath)
            .Build();

            // Ensure the client data store
            await ClientDataStore.EnsureDataStoreAsync();

            // Set the first page
            SetContentView(Resource.Layout.user_setup);

            // TODO: Monitor for server connection status
        }
예제 #5
0
        /// <summary>
        /// Configures our application ready for use
        /// </summary>
        private async Task ApplicationSetupAsync()
        {
            // Setup the Dna Framework
            Framework.Construct<DefaultFrameworkConstruction>()
                .AddFileLogger()
                .AddClientDataStore()
                .AddLoremIpsumViewModels()
                .AddLoremIpsumClientServices()
                .AddFluentValidators()
                .Build();

            // Ensure the client data store 
            await ClientDataStore.EnsureDataStoreAsync();

            // Monitor for server connection status
            MonitorServerStatus();

            //Load new settings
            TaskManager.RunAndForget(ViewModelSettings.LoadAsync);

            //Load the localization
            TaskManager.RunAndForget(() => ViewModelLocalization.LoadAsync(LanguageType.English));
        }
예제 #6
0
        /// <summary>
        /// Custom startup so we load our IoC immediately before anything else
        /// </summary>
        /// <param name="e"></param>
        protected override async void OnStartup(StartupEventArgs e)
        {
            // Let the base application do what it needs
            base.OnStartup(e);

            // Setup the main application
            await ApplicationSetupAsync();

            // Log it
            Logger.LogDebugSource("Application starting...");

            // Setup the application view model based on if we are logged in
            ViewModelApplication.GoToPage(
                // If we are logged in...
                await ClientDataStore.HasCredentialsAsync() ?
                // Go to chat page
                ApplicationPage.Analysis :
                // Otherwise, go to login page
                ApplicationPage.Login);

            // Show the main window
            Current.MainWindow = new MainWindow();
            Current.MainWindow.Show();
        }
예제 #7
0
 /// <summary>
 /// Return the first row of the users login credentials
 /// </summary>
 /// <returns></returns>
 private async Task GetLoginCredentialsAsync()
 {
     var result = await ClientDataStore.GetLoginCredentialsAsync();
 }
예제 #8
0
        /// <summary>
        /// Updates a specific value from the client data store for the user profile details
        /// and attempts to update the server to match those details.
        /// For example, updating the first name of the user.
        /// </summary>
        /// <param name="displayName">The display name for logging and display purposes of the property we are updating</param>
        /// <param name="propertyToUpdate">The property from the <see cref="LoginCredentialsDataModel"/> to be updated</param>
        /// <param name="newValue">The new value to update the property to</param>
        /// <param name="setApiModel">Sets the correct property in the <see cref="UpdateUserProfileApiModel"/> model that this property maps to</param>
        /// <returns></returns>
        private async Task <bool> UpdateUserCredentialsValueAsync(string displayName, Expression <Func <LoginCredentialsDataModel, string> > propertyToUpdate, string newValue, Action <UpdateUserProfileApiModel, string> setApiModel)
        {
            // Log it
            Logger.LogDebugSource($"Saving {displayName}...");

            // Get the current known credentials
            var credentials = await ClientDataStore.GetLoginCredentialsAsync();

            // Get the property to update from the credentials
            var toUpdate = propertyToUpdate.GetPropertyValue(credentials);

            // Log it
            Logger.LogDebugSource($"{displayName} currently {toUpdate}, updating to {newValue}");

            // Check if the value is the same. If so...
            if (toUpdate == newValue)
            {
                // Log it
                Logger.LogDebugSource($"{displayName} is the same, ignoring");

                // Return true
                return(true);
            }

            // Set the property
            propertyToUpdate.SetPropertyValue(newValue, credentials);

            // Create update details
            var updateApiModel = new UpdateUserProfileApiModel();

            // Ask caller to set appropriate value
            setApiModel(updateApiModel, newValue);

            // Update the server with the details
            var result = await WebRequests.PostAsync <ApiResponse>(
                // Set URL
                RouteHelpers.GetAbsoluteRoute(ApiRoutes.UpdateUserProfile),
                // Pass the Api model
                updateApiModel,
                // Pass in user Token
                bearerToken : credentials.Token);

            // If the response has an error...
            if (await result.DisplayErrorIfFailedAsync($"Update {displayName}"))
            {
                // Log it
                Logger.LogDebugSource($"Failed to update {displayName}. {result.ErrorMessage}");

                // Return false
                return(false);
            }

            // Log it
            Logger.LogDebugSource($"Successfully updated {displayName}. Saving to local database cache...");

            // Store the new user credentials the data store
            await ClientDataStore.SaveLoginCredentialsAsync(credentials);

            // Return successful
            return(true);
        }