public AuthenticationService(AntiforgeryStorage storage, AntiforgeryService antiforgeryService,
                                     AddressStorage addressStorage, AuthenticationStorage authenticationStorage,
                                     IUnityContainer container)
        {
            if (storage == null || antiforgeryService == null ||
                addressStorage == null || authenticationStorage == null ||
                container == null)
            {
                throw new ArgumentException();
            }

            this._storage               = storage;
            this._antiforgeryService    = antiforgeryService;
            this._addressStorage        = addressStorage;
            this._authenticationStorage = authenticationStorage;
            this._container             = container;
        }
        /// <inheritdoc />
        public async void ProcessTask()
        {
            var shouldSyncGlucose = false;

            var syncGlucose = await SecureStorage.GetAsync("SyncGlucose");

            if (!string.IsNullOrEmpty(syncGlucose))
            {
                shouldSyncGlucose = bool.Parse(syncGlucose);
            }

            if (await AuthenticationStorage.GetTokenPayloadAsync() == null || !shouldSyncGlucose)
            {
                return;
            }

            var lastPocRun = await SecureStorage.GetAsync("LastGlucoseSyncPoCRun");

            if (string.IsNullOrEmpty(lastPocRun))
            {
                lastPocRun = DateTime.Now.AddMinutes(-6).ToString("s");
            }

            if (DateTime.Parse(lastPocRun) < DateTime.Now.AddMinutes(-5))
            {
                var lastSync = await SecureStorage.GetAsync("LastGlucoseSync");

                if (string.IsNullOrEmpty(lastSync))
                {
                    lastSync = new DateTime(2015, 12, 12, 8, 0, 0).ToString("s");
                }

                var lastRun      = DateTime.Parse(lastSync);
                var measurements = await this.GlucoseRepository.LoadGlucoseDataAsync(lastRun.AddMinutes(-5), lastRun.AddMinutes(10));

                await this.GlucoseService.UploadGlucoseDataAsync(measurements);

                await SecureStorage.SetAsync("LastGlucoseSync", lastRun.AddMinutes(10).ToString("s"));

                await SecureStorage.SetAsync("LastGlucoseSyncPoCRun", DateTime.Now.ToString("s"));
            }
        }
        private async Task <bool> TryUpdateAuthenticationAsync(GrpcApplicationAgent agent, HostEndpointAddress endpointAddress)
        {
            var input = await LoginDialog.GetInputAsync("Authentication required");

            if (input == null)
            {
                ToastHelper.Display("Authentication required", ToastLength.Long);
                return(false);
            }

            var loginResponse = await GetLoginResponseAsync(agent, input);

            if (loginResponse.InvalidCredentials)
            {
                ToastHelper.Display("Invalid credentials", ToastLength.Long);
                return(false);
            }

            var authenticationStorage = new AuthenticationStorage(endpointAddress);
            await authenticationStorage.UpdateAsync(loginResponse.AccessToken, loginResponse.RefreshToken).ConfigureAwait(false);

            return(true);
        }
Beispiel #4
0
        public static void CreateAndRun(bool forceSoftwareRenderingMode)
        {
            FilesStorage.Initialize(EntryPoint.ApplicationDataDirectory);

            if (!AppArguments.GetBool(AppFlag.DisableLogging))
            {
                var logFilename = EntryPoint.GetLogName("Main Log");
                Logging.Initialize(FilesStorage.Instance.GetFilename("Logs", logFilename), AppArguments.GetBool(AppFlag.OptimizeLogging));
                Logging.Write($"App version: {BuildInformation.AppVersion} ({BuildInformation.Platform}, {WindowsVersionHelper.GetVersion()})");
            }

            if (AppArguments.GetBool(AppFlag.DisableSaving))
            {
                ValuesStorage.Initialize();
                CacheStorage.Initialize();
                AuthenticationStorage.Initialize();
            }
            else
            {
                ValuesStorage.Initialize(FilesStorage.Instance.GetFilename("Values.data"),
                                         InternalUtils.GetValuesStorageEncryptionKey(),
                                         AppArguments.GetBool(AppFlag.DisableValuesCompression));
                CacheStorage.Initialize(FilesStorage.Instance.GetFilename("Cache.data"), AppArguments.GetBool(AppFlag.DisableValuesCompression));
                AuthenticationStorage.Initialize(FilesStorage.Instance.GetFilename("Authentication.data"),
                                                 AppArguments.GetBool(AppFlag.DisableValuesCompression));
                if (MathUtils.Random(0, 10) == 0)
                {
                    LazierCached.Purge();
                }

                FatalErrorHandler.FatalError += OnFatalError;
            }

            if (AppArguments.GetBool(AppFlag.NoProxy, true))
            {
                WebRequest.DefaultWebProxy = null;
            }

            NonfatalError.Initialize();
            LocaleHelper.InitializeAsync().Wait();

            var softwareRenderingModeWasEnabled = IsSoftwareRenderingModeEnabled();

            if (forceSoftwareRenderingMode)
            {
                ValuesStorage.Set(AppAppearanceManager.KeySoftwareRendering, true);
            }

            if (IsSoftwareRenderingModeEnabled())
            {
                SwitchToSoftwareRendering();
            }

            var app = new App();

            // Some sort of safe mode
            if (forceSoftwareRenderingMode && !softwareRenderingModeWasEnabled)
            {
                Toast.Show("Safe mode", "Failed to start the last time, now CM uses software rendering", () => {
                    if (ModernDialog.ShowMessage(
                            "Would you like to switch back to hardware rendering? You can always do that in Settings/Appearance. App will be restarted.",
                            "Switch back", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                    {
                        ValuesStorage.Set(AppAppearanceManager.KeySoftwareRendering, false);
                        Storage.SaveBeforeExit(); // Just in case
                        WindowsHelper.RestartCurrentApplication();
                    }
                });
            }

            app.Run();
        }
Beispiel #5
0
        public static void CreateAndRun(bool forceSoftwareRenderingMode)
        {
            FilesStorage.Initialize(EntryPoint.ApplicationDataDirectory);

            if (!AppArguments.GetBool(AppFlag.DisableLogging))
            {
                var logFilename = EntryPoint.GetLogName("Main Log");
                Logging.Initialize(FilesStorage.Instance.GetFilename("Logs", logFilename), AppArguments.GetBool(AppFlag.OptimizeLogging));
                Logging.Write($"App version: {BuildInformation.AppVersion} ({BuildInformation.Platform}, {WindowsVersionHelper.GetVersion()})");
            }

            Storage.TemporaryBackupsDirectory = FilesStorage.Instance.GetTemporaryDirectory("Storages Backups");
            if (AppArguments.GetBool(AppFlag.DisableSaving))
            {
                ValuesStorage.Initialize();
                CacheStorage.Initialize();
                AuthenticationStorage.Initialize();
            }
            else
            {
                ValuesStorage.Initialize(FilesStorage.Instance.GetFilename("Values.data"),
                                         InternalUtils.GetValuesStorageEncryptionKey(),
                                         AppArguments.GetBool(AppFlag.DisableValuesCompression));
                CacheStorage.Initialize(FilesStorage.Instance.GetFilename("Cache.data"), AppArguments.GetBool(AppFlag.DisableValuesCompression));
                AuthenticationStorage.Initialize(FilesStorage.Instance.GetFilename("Authentication.data"),
                                                 AppArguments.GetBool(AppFlag.DisableValuesCompression));
                if (MathUtils.Random(0, 10) == 0)
                {
                    LazierCached.Purge();
                }

                FatalErrorHandler.FatalError += OnFatalError;
            }

            if (AppArguments.GetBool(AppFlag.NoProxy, true))
            {
                WebRequest.DefaultWebProxy = null;
            }

            NonfatalError.Initialize();
            LocaleHelper.InitializeAsync().Wait();

            var softwareRenderingModeWasEnabled = IsSoftwareRenderingModeEnabled();

            if (forceSoftwareRenderingMode)
            {
                ValuesStorage.Set(AppAppearanceManager.KeySoftwareRendering, true);
            }

            if (IsSoftwareRenderingModeEnabled())
            {
                SwitchToSoftwareRendering();
            }

            var app = new App();

            // Some sort of safe mode
            if (forceSoftwareRenderingMode && !softwareRenderingModeWasEnabled)
            {
                Toast.Show("Safe mode", "Failed to start the last time, now CM uses software rendering", () => {
                    if (MessageDialog.Show(
                            "Would you like to switch back to hardware rendering? You can always do that in Settings/Appearance. App will be restarted.",
                            "Switch back", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                    {
                        ValuesStorage.Set(AppAppearanceManager.KeySoftwareRendering, false);
                        Storage.SaveBeforeExit(); // Just in case
                        WindowsHelper.RestartCurrentApplication();
                    }
                });
            }

            var move = AppArguments.Get(AppFlag.MoveApp);

            if (move != null && File.Exists(move))
            {
                for (var i = 0; i < 10; i++)
                {
                    if (FileUtils.TryToDelete(move) || !File.Exists(move))
                    {
                        break;
                    }
                    Thread.Sleep(100);
                }
                Toast.Show("App moved", $"App moved from AC root folder, now Oculus Rift should work better", () => {
                    var originalRemoved = File.Exists(move) ? "failed to remove original file" : "original file removed";
                    if (MessageDialog.Show(
                            $"New location is “{MainExecutingFile.Location}”, {originalRemoved}. Please don’t forget to recreate any shortcuts you might have created.",
                            "Content Manager is moved",
                            new MessageDialogButton {
                        [MessageBoxResult.Yes] = "View new location",
                        [MessageBoxResult.No] = UiStrings.Ok
                    }) == MessageBoxResult.Yes)
                    {
                        WindowsHelper.ViewFile(MainExecutingFile.Location);
                    }
                });
            }

            app.Run();
        }
        private static async Task SetAuthorization(RestRequest request)
        {
            var accessTokenPayload = await AuthenticationStorage.GetTokenPayloadAsync();

            request.AddHeader("authorization", $"Bearer {accessTokenPayload.AccessToken}");
        }