示例#1
0
        private async Task HandleLockingAsync()
        {
            if (await _lockService.IsLockedAsync())
            {
                return;
            }
            var authed = await _userService.IsAuthenticatedAsync();

            if (!authed)
            {
                return;
            }
            var lockOption = _platformUtilsService.LockTimeout();

            if (lockOption == null)
            {
                lockOption = await _storageService.GetAsync <int?>(Constants.LockOptionKey);
            }
            lockOption = lockOption.GetValueOrDefault(-1);
            if (lockOption > 0)
            {
                _messagingService.Send("scheduleLockTimer", lockOption.Value);
            }
            else if (lockOption == 0)
            {
                await _lockService.LockAsync(true);
            }
        }
示例#2
0
        private async Task <RedisValue> MemoLockWithoutSubscriptionAsync(MemoKey key, Func <CancellationToken, Task <RedisValue> > generator, CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                throw new TaskCanceledException();
            }

            var result = await TryGetCachedValue(key).ConfigureAwait(false);

            if (result != null)
            {
                return(result.Value);
            }

            if (cancellationToken.IsCancellationRequested)
            {
                throw new TaskCanceledException();
            }

            try
            {
                return(await _lockService.LockAsync(key.GetLockKey(), async c =>
                {
                    //in case we missed the publication
                    var result = await TryGetCachedValue(key).ConfigureAwait(false);
                    if (result != null)
                    {
                        return result.Value;
                    }
                    return await LockedCallback(key, generator, c).ConfigureAwait(false);
                }, cancellationToken).ConfigureAwait(false));
            }
            catch (TaskCanceledException)
            {
                result = await TryGetCachedValue(key).ConfigureAwait(false);

                if (result != null)
                {
                    return(result.Value);
                }
                throw;
            }
        }
示例#3
0
        public async Task <string> ExclusiveCreateAsync(string name, IContextParameters @params)
        {
            var userId = _userResolver.GetUserId();

            if (string.IsNullOrEmpty(userId))
            {
                throw new ArgumentNullException(nameof(userId));
            }

            if (await _lockService.LockAsync(name) == false)
            {
                await _lockService.UnlockAsync(name);

                //return null;
            }

            var job = await _jobRepository.AddAsync(new Job(name, userId, @params));

            _jobRegistory.AddJob(job);
            _jobRegistory.Enqueue(job.Id);

            return(job.Id);
        }
示例#4
0
        public async Task <long?> ExclusiveCreateAsync <TParams>(string name, TParams @params)
        {
            var userId = _userResolver.GetUserId();

            if (string.IsNullOrEmpty(userId))
            {
                throw new ArgumentNullException(nameof(userId));
            }

            if (await _lockService.LockAsync(name) == false)
            {
                return(null);
            }

            var job = new Job(name, userId, @params);

            job.Id = await _jobRepository.AddAsync(job);

            _jobRegistory.AddJob(job.Id, job);
            _jobRegistory.Enqueue(job.Id);

            return(job.Id);
        }
示例#5
0
        public App(AppOptions appOptions)
        {
            _appOptions                = appOptions ?? new AppOptions();
            _userService               = ServiceContainer.Resolve <IUserService>("userService");
            _broadcasterService        = ServiceContainer.Resolve <IBroadcasterService>("broadcasterService");
            _messagingService          = ServiceContainer.Resolve <IMessagingService>("messagingService");
            _stateService              = ServiceContainer.Resolve <IStateService>("stateService");
            _lockService               = ServiceContainer.Resolve <ILockService>("lockService");
            _syncService               = ServiceContainer.Resolve <ISyncService>("syncService");
            _tokenService              = ServiceContainer.Resolve <ITokenService>("tokenService");
            _cryptoService             = ServiceContainer.Resolve <ICryptoService>("cryptoService");
            _cipherService             = ServiceContainer.Resolve <ICipherService>("cipherService");
            _folderService             = ServiceContainer.Resolve <IFolderService>("folderService");
            _settingsService           = ServiceContainer.Resolve <ISettingsService>("settingsService");
            _collectionService         = ServiceContainer.Resolve <ICollectionService>("collectionService");
            _searchService             = ServiceContainer.Resolve <ISearchService>("searchService");
            _authService               = ServiceContainer.Resolve <IAuthService>("authService");
            _platformUtilsService      = ServiceContainer.Resolve <IPlatformUtilsService>("platformUtilsService");
            _storageService            = ServiceContainer.Resolve <IStorageService>("storageService");
            _secureStorageService      = ServiceContainer.Resolve <IStorageService>("secureStorageService");
            _passwordGenerationService = ServiceContainer.Resolve <IPasswordGenerationService>(
                "passwordGenerationService");
            _i18nService         = ServiceContainer.Resolve <II18nService>("i18nService") as MobileI18nService;
            _deviceActionService = ServiceContainer.Resolve <IDeviceActionService>("deviceActionService");

            Bootstrap();
            _broadcasterService.Subscribe(nameof(App), async(message) =>
            {
                if (message.Command == "showDialog")
                {
                    var details     = message.Data as DialogDetails;
                    var confirmed   = true;
                    var confirmText = string.IsNullOrWhiteSpace(details.ConfirmText) ?
                                      AppResources.Ok : details.ConfirmText;
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        if (!string.IsNullOrWhiteSpace(details.CancelText))
                        {
                            confirmed = await Current.MainPage.DisplayAlert(details.Title, details.Text, confirmText,
                                                                            details.CancelText);
                        }
                        else
                        {
                            await Current.MainPage.DisplayAlert(details.Title, details.Text, confirmText);
                        }
                        _messagingService.Send("showDialogResolve", new Tuple <int, bool>(details.DialogId, confirmed));
                    });
                }
                else if (message.Command == "locked")
                {
                    await LockedAsync(!(message.Data as bool?).GetValueOrDefault());
                }
                else if (message.Command == "lockVault")
                {
                    await _lockService.LockAsync(true);
                }
                else if (message.Command == "logout")
                {
                    if (Migration.MigrationHelpers.Migrating)
                    {
                        return;
                    }
                    Device.BeginInvokeOnMainThread(async() => await LogOutAsync(false));
                }
                else if (message.Command == "loggedOut")
                {
                    // Clean up old migrated key if they ever log out.
                    await _secureStorageService.RemoveAsync("oldKey");
                }
                else if (message.Command == "resumed")
                {
                    if (Device.RuntimePlatform == Device.iOS)
                    {
                        ResumedAsync();
                    }
                }
                else if (message.Command == "slept")
                {
                    if (Device.RuntimePlatform == Device.iOS)
                    {
                        await SleptAsync();
                    }
                }
                else if (message.Command == "migrated")
                {
                    await Task.Delay(1000);
                    await SetMainPageAsync();
                }
                else if (message.Command == "popAllAndGoToTabGenerator" ||
                         message.Command == "popAllAndGoToTabMyVault")
                {
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        if (Current.MainPage is TabsPage tabsPage)
                        {
                            while (tabsPage.Navigation.ModalStack.Count > 0)
                            {
                                await tabsPage.Navigation.PopModalAsync(false);
                            }
                            if (message.Command == "popAllAndGoToTabMyVault")
                            {
                                _appOptions.MyVaultTile = false;
                                tabsPage.ResetToVaultPage();
                            }
                            else
                            {
                                _appOptions.GeneratorTile = false;
                                tabsPage.ResetToGeneratorPage();
                            }
                        }
                    });
                }
            });
        }
示例#6
0
 private async void Lock_Clicked(object sender, EventArgs e)
 {
     await _lockService.LockAsync(true, true);
 }
 public async Task LockAsync()
 {
     await _lockService.LockAsync(true, true);
 }
示例#8
0
 public Task Lock(bool allowSoftLock = false, bool userInitiated = false)
 {
     return(_lockService.LockAsync(allowSoftLock, userInitiated));
 }
示例#9
0
        public App(AppOptions appOptions)
        {
            _appOptions                = appOptions ?? new AppOptions();
            _userService               = ServiceContainer.Resolve <IUserService>("userService");
            _broadcasterService        = ServiceContainer.Resolve <IBroadcasterService>("broadcasterService");
            _messagingService          = ServiceContainer.Resolve <IMessagingService>("messagingService");
            _stateService              = ServiceContainer.Resolve <IStateService>("stateService");
            _lockService               = ServiceContainer.Resolve <ILockService>("lockService");
            _syncService               = ServiceContainer.Resolve <ISyncService>("syncService");
            _tokenService              = ServiceContainer.Resolve <ITokenService>("tokenService");
            _cryptoService             = ServiceContainer.Resolve <ICryptoService>("cryptoService");
            _cipherService             = ServiceContainer.Resolve <ICipherService>("cipherService");
            _folderService             = ServiceContainer.Resolve <IFolderService>("folderService");
            _settingsService           = ServiceContainer.Resolve <ISettingsService>("settingsService");
            _collectionService         = ServiceContainer.Resolve <ICollectionService>("collectionService");
            _searchService             = ServiceContainer.Resolve <ISearchService>("searchService");
            _authService               = ServiceContainer.Resolve <IAuthService>("authService");
            _platformUtilsService      = ServiceContainer.Resolve <IPlatformUtilsService>("platformUtilsService");
            _storageService            = ServiceContainer.Resolve <IStorageService>("storageService");
            _passwordGenerationService = ServiceContainer.Resolve <IPasswordGenerationService>(
                "passwordGenerationService");
            _i18nService         = ServiceContainer.Resolve <II18nService>("i18nService") as MobileI18nService;
            _deviceActionService = ServiceContainer.Resolve <IDeviceActionService>("deviceActionService");

            InitializeComponent();
            SetCulture();
            ThemeManager.SetThemeStyle("light");
            MainPage = new HomePage();
            var mainPageTask = SetMainPageAsync();

            ServiceContainer.Resolve <MobilePlatformUtilsService>("platformUtilsService").Init();
            _broadcasterService.Subscribe(nameof(App), async(message) =>
            {
                if (message.Command == "showDialog")
                {
                    var details     = message.Data as DialogDetails;
                    var confirmed   = true;
                    var confirmText = string.IsNullOrWhiteSpace(details.ConfirmText) ?
                                      AppResources.Ok : details.ConfirmText;
                    if (!string.IsNullOrWhiteSpace(details.CancelText))
                    {
                        confirmed = await MainPage.DisplayAlert(details.Title, details.Text, confirmText,
                                                                details.CancelText);
                    }
                    else
                    {
                        await MainPage.DisplayAlert(details.Title, details.Text, confirmText);
                    }
                    _messagingService.Send("showDialogResolve", new Tuple <int, bool>(details.DialogId, confirmed));
                }
                else if (message.Command == "locked")
                {
                    await _stateService.PurgeAsync();
                    MainPage = new NavigationPage(new LockPage());
                }
                else if (message.Command == "lockVault")
                {
                    await _lockService.LockAsync(true);
                }
                else if (message.Command == "logout")
                {
                    await LogOutAsync(false);
                }
                else if (message.Command == "loggedOut")
                {
                    // TODO
                }
                else if (message.Command == "unlocked" || message.Command == "loggedIn")
                {
                    // TODO
                }
            });
        }