Esempio n. 1
0
        /// <inheritdoc/>
        public async Task SynchronizeAtStartup()
        {
            if (!ShouldSynchronize())
            {
                return;
            }

            _repositoryStorageService.LoadRepositoryOrDefault(out NoteRepositoryModel localRepository);
            long oldFingerprint = localRepository.GetModificationFingerprint();

            // Do the synchronization with the cloud storage in a background thread
            await Task.Run(async() =>
            {
                SynchronizationStoryBoard syncStory = new SynchronizationStoryBoard(StoryBoardMode.ToastsOnly);
                await syncStory.Start();
            }).ConfigureAwait(true); // Come back to the UI thread

            // Memorize fingerprint of the synchronized respository
            _repositoryStorageService.LoadRepositoryOrDefault(out localRepository);
            long newFingerprint = localRepository.GetModificationFingerprint();

            LastSynchronizationFingerprint = newFingerprint;

            // Reload active page, but only if notes are visible and the repository differs
            if (oldFingerprint != newFingerprint)
            {
                _navigationService.RepeatNavigationIf(
                    new[] { ControllerNames.NoteRepository, ControllerNames.Note });
            }
        }
        /// <inheritdoc/>
        public override void ShowInView(IHtmlView htmlView, KeyValueList <string, string> variables, Navigation redirectedFrom)
        {
            base.ShowInView(htmlView, variables, redirectedFrom);
            IRepositoryStorageService repositoryService = Ioc.GetOrCreate <IRepositoryStorageService>();

            _scrollToNote = variables?.GetValueOrDefault(ControllerParameters.NoteId);

            RepositoryStorageLoadResult loadResult = repositoryService.LoadRepositoryOrDefault(out _);

            if (loadResult != RepositoryStorageLoadResult.InvalidRepository)
            {
                _viewModel = new NoteRepositoryViewModel(
                    Ioc.GetOrCreate <INavigationService>(),
                    Ioc.GetOrCreate <ILanguageService>(),
                    Ioc.GetOrCreate <ISvgIconService>(),
                    Ioc.GetOrCreate <IThemeService>(),
                    Ioc.GetOrCreate <IBaseUrlService>(),
                    Ioc.GetOrCreate <IStoryBoardService>(),
                    Ioc.GetOrCreate <IFeedbackService>(),
                    Ioc.GetOrCreate <ISettingsService>(),
                    Ioc.GetOrCreate <IEnvironmentService>(),
                    Ioc.GetOrCreate <ICryptoRandomService>(),
                    repositoryService);

                VueBindingShortcut[] shortcuts = new[]
                {
                    new VueBindingShortcut("s", nameof(_viewModel.SynchronizeCommand))
                    {
                        Ctrl = true
                    },
                    new VueBindingShortcut("n", nameof(_viewModel.NewNoteCommand))
                    {
                        Ctrl = true
                    },
                    new VueBindingShortcut("l", nameof(_viewModel.NewChecklistCommand))
                    {
                        Ctrl = true
                    },
                    new VueBindingShortcut("r", nameof(_viewModel.ShowRecycleBinCommand))
                    {
                        Ctrl = true
                    },
                    new VueBindingShortcut("i", nameof(_viewModel.ShowInfoCommand))
                    {
                        Ctrl = true
                    },
                    new VueBindingShortcut(VueBindingShortcut.KeyHome, "ScrollToTop")
                    {
                        Ctrl = true
                    },
                    new VueBindingShortcut(VueBindingShortcut.KeyEnd, "ScrollToBottom")
                    {
                        Ctrl = true
                    },
                };
                VueBindings = new VueDataBinding(_viewModel, View, shortcuts);
                VueBindings.DeclareAdditionalVueMethod("ScrollToTop", "scrollToTop();");
                VueBindings.DeclareAdditionalVueMethod("ScrollToBottom", "scrollToBottom();");
                _viewModel.VueDataBindingScript        = VueBindings.BuildVueScript();
                VueBindings.UnhandledViewBindingEvent += UnhandledViewBindingEventHandler;
                VueBindings.ViewLoadedEvent           += ViewLoadedEventHandler;
                VueBindings.StartListening();

                _viewModel.PropertyChanged += ViewmodelPropertyChangedEventHandler;

                string html = _viewService.GenerateHtml(_viewModel);
                View.LoadHtml(html);
            }
            else
            {
                // Show error message and stop loading the application
                _stopViewModel = new StopViewModel(
                    Ioc.GetOrCreate <INavigationService>(),
                    Ioc.GetOrCreate <ILanguageService>(),
                    Ioc.GetOrCreate <ISvgIconService>(),
                    Ioc.GetOrCreate <IThemeService>(),
                    Ioc.GetOrCreate <IBaseUrlService>());
                string html = _viewStop.GenerateHtml(_stopViewModel);
                View.LoadHtml(html);
            }
        }
        /// <inheritdoc/>
        public override void ShowInView(IHtmlView htmlView, KeyValueList <string, string> variables, Navigation redirectedFrom)
        {
            base.ShowInView(htmlView, variables, redirectedFrom);
            View.NavigationCompleted += NavigationCompletedEventHandler;
            IRepositoryStorageService repositoryService = Ioc.GetOrCreate <IRepositoryStorageService>();

            _scrollToNote = variables?.GetValueOrDefault(ControllerParameters.NoteId);

            RepositoryStorageLoadResult loadResult = repositoryService.LoadRepositoryOrDefault(out _);

            if (loadResult != RepositoryStorageLoadResult.InvalidRepository)
            {
                _viewModel = new NoteRepositoryViewModel(
                    Ioc.GetOrCreate <INavigationService>(),
                    Ioc.GetOrCreate <ILanguageService>(),
                    Ioc.GetOrCreate <ISvgIconService>(),
                    Ioc.GetOrCreate <IThemeService>(),
                    Ioc.GetOrCreate <IBaseUrlService>(),
                    Ioc.GetOrCreate <IStoryBoardService>(),
                    Ioc.GetOrCreate <IFeedbackService>(),
                    Ioc.GetOrCreate <ISettingsService>(),
                    Ioc.GetOrCreate <IEnvironmentService>(),
                    Ioc.GetOrCreate <ICryptoRandomService>(),
                    repositoryService);

                Bindings.BindCommand("NewNote", _viewModel.NewNoteCommand);
                Bindings.BindCommand("NewChecklist", _viewModel.NewChecklistCommand);
                Bindings.BindCommand("Synchronize", _viewModel.SynchronizeCommand);
                Bindings.BindCommand("ShowTransferCode", _viewModel.ShowTransferCodeCommand);
                Bindings.BindCommand("ShowRecycleBin", _viewModel.ShowRecycleBinCommand);
                Bindings.BindCommand("ShowSettings", _viewModel.ShowSettingsCommand);
                Bindings.BindCommand("ShowInfo", _viewModel.ShowInfoCommand);
                Bindings.BindCommand("OpenSafe", _viewModel.OpenSafeCommand);
                Bindings.BindCommand("CloseSafe", _viewModel.CloseSafeCommand);
                Bindings.BindCommand("ChangeSafePassword", _viewModel.ChangeSafePasswordCommand);
                Bindings.BindCommand("FilterButtonCancel", _viewModel.ClearFilterCommand);
                Bindings.BindText("TxtFilter", () => _viewModel.Filter, (value) => _viewModel.Filter = value, _viewModel, nameof(_viewModel.Filter), HtmlViewBindingMode.TwoWay);
                Bindings.BindVisibility("FilterButtonMagnifier", () => string.IsNullOrEmpty(_viewModel.Filter), _viewModel, nameof(_viewModel.FilterButtonMagnifierVisible), HtmlViewBindingMode.OneWayToView);
                Bindings.BindVisibility("FilterButtonCancel", () => !string.IsNullOrEmpty(_viewModel.Filter), _viewModel, nameof(_viewModel.FilterButtonCancelVisible), HtmlViewBindingMode.OneWayToView);
                Bindings.BindGeneric <object>(
                    NotesChangedEventHandler,
                    null,
                    null,
                    null,
                    new HtmlViewBindingViewmodelNotifier(_viewModel, "Notes"),
                    HtmlViewBindingMode.OneWayToView);
                Bindings.UnhandledViewBindingEvent += UnhandledViewBindingEventHandler;

                // Load html page and content (notes)
                string html      = _viewService.GenerateHtml(_viewModel);
                string htmlNotes = _viewContentService.GenerateHtml(_viewModel);
                html = html.Replace("<ul id=\"note-repository\"></ul>", htmlNotes); // Replace node "note-repository" with content
                View.LoadHtml(html);
            }
            else
            {
                // Show error message and stop loading the application
                _stopViewModel = new StopViewModel(
                    Ioc.GetOrCreate <INavigationService>(),
                    Ioc.GetOrCreate <ILanguageService>(),
                    Ioc.GetOrCreate <ISvgIconService>(),
                    Ioc.GetOrCreate <IThemeService>(),
                    Ioc.GetOrCreate <IBaseUrlService>());
                string html = _viewStop.GenerateHtml(_stopViewModel);
                View.LoadHtml(html);
            }
        }