/// <inheritdoc/> protected override void OnStart() { base.OnStart(); Ioc.Reset(); Startup.InitializeApplication(this); INavigationService navigation = Ioc.GetOrCreate <INavigationService>(); IStoryBoardService storyBoardService = Ioc.GetOrCreate <IStoryBoardService>(); if (IsStartedBySendIntent()) { // Another app sent content to SilentNotes navigation.Navigate(ControllerNames.Note, ControllerParameters.SendToSilentnotesText, GetSendIntentText()); } else if (IsStartedByOAuthRedirectIndent(storyBoardService)) { if (storyBoardService.ActiveStory is SynchronizationStoryBoard synchronizationStory) { // Create a copy of the active story, which uses the Ioc of this new process storyBoardService.ActiveStory = new SynchronizationStoryBoard(synchronizationStory); storyBoardService.ActiveStory.ContinueWith(SynchronizationStoryStepId.HandleOAuthRedirect.ToInt()); } } else { // Normal startup navigation.Navigate(ControllerNames.NoteRepository); IAutoSynchronizationService syncService = Ioc.GetOrCreate <IAutoSynchronizationService>(); syncService.SynchronizeAtStartup(); // no awaiting, run in background } }
/// <inheritdoc/> public override void ShowInView(IHtmlView htmlView, KeyValueList <string, string> variables, Navigation redirectedFrom) { base.ShowInView(htmlView, variables, redirectedFrom); IStoryBoardService storyBoardService = Ioc.GetOrCreate <IStoryBoardService>(); SerializeableCloudStorageCredentials credentials = storyBoardService.ActiveStory.LoadFromSession <SerializeableCloudStorageCredentials>(SynchronizationStorySessionKey.CloudStorageCredentials); _viewModel = new CloudStorageAccountViewModel( Ioc.GetOrCreate <INavigationService>(), Ioc.GetOrCreate <ILanguageService>(), Ioc.GetOrCreate <ISvgIconService>(), Ioc.GetOrCreate <IThemeService>(), Ioc.GetOrCreate <IBaseUrlService>(), storyBoardService, Ioc.GetOrCreate <IFeedbackService>(), Ioc.GetOrCreate <ICloudStorageClientFactory>(), credentials); VueBindingShortcut[] shortcuts = new[] { new VueBindingShortcut(VueBindingShortcut.KeyEscape, nameof(CloudStorageAccountViewModel.CancelCommand)), new VueBindingShortcut(VueBindingShortcut.KeyEnter, nameof(CloudStorageAccountViewModel.OkCommand)), }; VueBindings = new VueDataBinding(_viewModel, View, shortcuts); _viewModel.VueDataBindingScript = VueBindings.BuildVueScript(); VueBindings.StartListening(); string html = _viewService.GenerateHtml(_viewModel); View.LoadHtml(html); }
/// <summary> /// OpenAuth2 requires the usage of an external browser, where the user can login to his /// service. Then the website will redirect to a given url, which can be intercepted by the /// application. Here we handle this intercepted url. /// </summary> /// <param name="args">The event arguments of <see cref="OnActivated(IActivatedEventArgs)"/>.</param> /// <returns>Returns true if the url is a redirect and has been handled, otherwise false.</returns> private bool TryHandleOauthRedirect(IActivatedEventArgs args) { if (args.Kind != ActivationKind.Protocol) { return(false); } Uri redirectUri = (args as ProtocolActivatedEventArgs)?.Uri; string url = redirectUri?.AbsoluteUri; if (string.IsNullOrEmpty(url) || (!url.Contains("ch.martinstoeckli.silentnotes:"))) { return(false); } // Bring application back to front Window.Current.Activate(); // Reenter the synchronization story IStoryBoardService storyBoardService = Ioc.GetOrCreate <IStoryBoardService>(); if (storyBoardService.ActiveStory is SynchronizationStoryBoard) { storyBoardService.ActiveStory.StoreToSession(SynchronizationStorySessionKey.OauthRedirectUrl, url); storyBoardService.ActiveStory.ContinueWith(SynchronizationStoryStepId.HandleOAuthRedirect); } return(true); }
/// <summary> /// Initializes a new instance of the <see cref="SettingsViewModel"/> class. /// </summary> public SettingsViewModel( INavigationService navigationService, ILanguageService languageService, ISvgIconService svgIconService, IThemeService themeService, IBaseUrlService webviewBaseUrl, ISettingsService settingsService, IStoryBoardService storyBoardService, IFeedbackService feedbackService, ICloudStorageClientFactory cloudStorageClientFactory, IFilePickerService filePickerService) : base(navigationService, languageService, svgIconService, themeService, webviewBaseUrl) { _settingsService = settingsService; _storyBoardService = storyBoardService; _feedbackService = feedbackService; _cloudStorageClientFactory = cloudStorageClientFactory; _filePickerService = filePickerService; _fontSizeConverter = new SliderStepConverter(ReferenceFontSize, 1.0); _noteMaxHeightConverter = new SliderStepConverter(ReferenceNoteMaxSize, 20.0); Model = _settingsService.LoadSettingsOrDefault(); EncryptionAlgorithms = new List <DropdownItemViewModel>(); FillAlgorithmList(EncryptionAlgorithms); // Initialize commands GoBackCommand = new RelayCommand(GoBack); ChangeCloudSettingsCommand = new RelayCommand(ChangeCloudSettings); ClearCloudSettingsCommand = new RelayCommand(ClearCloudSettings); TestNewLocalizationCommand = new RelayCommand(TestNewLocalization); }
/// <inheritdoc/> public override void ShowInView(IHtmlView htmlView, KeyValueList <string, string> variables, Navigation redirectedFrom) { base.ShowInView(htmlView, variables, redirectedFrom); IStoryBoardService storyBoardService = Ioc.GetOrCreate <IStoryBoardService>(); SerializeableCloudStorageCredentials credentials = storyBoardService.ActiveStory.LoadFromSession <SerializeableCloudStorageCredentials>(SynchronizationStorySessionKey.CloudStorageCredentials); _viewModel = new CloudStorageAccountViewModel( Ioc.GetOrCreate <INavigationService>(), Ioc.GetOrCreate <ILanguageService>(), Ioc.GetOrCreate <ISvgIconService>(), Ioc.GetOrCreate <IThemeService>(), Ioc.GetOrCreate <IBaseUrlService>(), storyBoardService, Ioc.GetOrCreate <IFeedbackService>(), Ioc.GetOrCreate <ICloudStorageClientFactory>(), credentials); Bindings.BindCommand("GoBack", _viewModel.GoBackCommand); Bindings.BindCommand("OkCommand", _viewModel.OkCommand); Bindings.BindCommand("CancelCommand", _viewModel.CancelCommand); Bindings.BindText("Url", null, (v) => _viewModel.Url = v, null, null, HtmlViewBindingMode.OneWayToViewmodel); Bindings.BindText("Username", null, (v) => _viewModel.Username = v, null, null, HtmlViewBindingMode.OneWayToViewmodel); Bindings.BindText("Password", () => SecureStringExtensions.SecureStringToString(_viewModel.Password), (v) => _viewModel.Password = SecureStringExtensions.StringToSecureString(v), _viewModel, nameof(_viewModel.Password), HtmlViewBindingMode.TwoWayPlusOneTimeToView); Bindings.BindCheckbox("Secure", null, (v) => _viewModel.Secure = v, null, null, HtmlViewBindingMode.OneWayToViewmodel); string html = _viewService.GenerateHtml(_viewModel); View.LoadHtml(html); }
/// <summary> /// The OnStart() and OnNewIntent() methods have no guaranteed order, so we do all the /// work for starting up the app here, this is guaranteed to be called after them. /// </summary> protected override void OnResume() { base.OnResume(); // Turn on the view again, see OnPause(). if (_webView.Visibility != ViewStates.Visible) { _webView.Visibility = ViewStates.Visible; } INavigationService navigationService = Ioc.GetOrCreate <INavigationService>(); IStoryBoardService storyBoardService = Ioc.GetOrCreate <IStoryBoardService>(); if (!string.IsNullOrEmpty(_actionSendParameter)) { // Create new note and show it IRepositoryStorageService repositoryStorageService = Ioc.GetOrCreate <IRepositoryStorageService>(); ISettingsService settingsService = Ioc.GetOrCreate <ISettingsService>(); repositoryStorageService.LoadRepositoryOrDefault(out NoteRepositoryModel noteRepository); NoteModel note = new NoteModel { BackgroundColorHex = settingsService.LoadSettingsOrDefault().DefaultNoteColorHex, HtmlContent = _actionSendParameter, }; noteRepository.Notes.Insert(0, note); repositoryStorageService.TrySaveRepository(noteRepository); _actionSendParameter = null; // create the note only once navigationService.Navigate(new Navigation(ControllerNames.Note, ControllerParameters.NoteId, note.Id.ToString())); } else if (IsStartedByOAuthRedirectIndent(storyBoardService)) { if (storyBoardService.ActiveStory is SynchronizationStoryBoard synchronizationStory) { // Create a copy of the active story, which uses the Ioc of this new process storyBoardService.ActiveStory = new SynchronizationStoryBoard(synchronizationStory); storyBoardService.ActiveStory.ContinueWith(SynchronizationStoryStepId.HandleOAuthRedirect); } } else { // Normal startup if (CanStartupWithLastNavigation(_lastNavigation)) { navigationService.Navigate(_lastNavigation); } else { navigationService.Navigate(new Navigation(ControllerNames.NoteRepository)); } IAutoSynchronizationService syncService = Ioc.GetOrCreate <IAutoSynchronizationService>(); syncService.SynchronizeAtStartup(); // no awaiting, run in background } }
public StopAndShowRepositoryStep( int stepId, IStoryBoard storyBoard, IFeedbackService feedbackService, INavigationService navigationService, IStoryBoardService storyBoardService) : base(stepId, storyBoard) { _feedbackService = feedbackService; _navigationService = navigationService; _storyBoardService = storyBoardService; }
public FirstTimeSyncViewModel( INavigationService navigationService, ILanguageService languageService, ISvgIconService svgIconService, IBaseUrlService webviewBaseUrl, IStoryBoardService storyBoardService) : base(navigationService, languageService, svgIconService, webviewBaseUrl) { _storyBoardService = storyBoardService; GoBackCommand = new RelayCommand(GoBack); ContinueCommand = new RelayCommand(Continue); }
/// <summary> /// Initializes a new instance of the <see cref="NoteRepositoryViewModel"/> class. /// </summary> public NoteRepositoryViewModel( INavigationService navigationService, ILanguageService languageService, ISvgIconService svgIconService, IThemeService themeService, IBaseUrlService webviewBaseUrl, IStoryBoardService storyBoardService, IFeedbackService feedbackService, ISettingsService settingsService, IEnvironmentService environmentService, ICryptoRandomSource randomSource, IRepositoryStorageService repositoryService) : base(navigationService, languageService, svgIconService, themeService, webviewBaseUrl) { _storyBoardService = storyBoardService; _repositoryService = repositoryService; _feedbackService = feedbackService; _settingsService = settingsService; _environmentService = environmentService; _noteCryptor = new Cryptor(NoteModel.CryptorPackageName, randomSource); _searchableTextConverter = new SearchableHtmlConverter(); AllNotes = new List <NoteViewModel>(); FilteredNotes = new ObservableCollection <NoteViewModel>(); _repositoryService.LoadRepositoryOrDefault(out NoteRepositoryModel noteRepository); Model = noteRepository; // Initialize commands and events ShowNoteCommand = new RelayCommand <object>(ShowNote); NewNoteCommand = new RelayCommand(NewNote); NewChecklistCommand = new RelayCommand(NewChecklist); DeleteNoteCommand = new RelayCommand <object>(DeleteNote); ClearFilterCommand = new RelayCommand(ClearFilter); SynchronizeCommand = new RelayCommand(Synchronize); ShowTransferCodeCommand = new RelayCommand(ShowTransferCode); ShowSettingsCommand = new RelayCommand(ShowSettings); ShowRecycleBinCommand = new RelayCommand(ShowRecycleBin); ShowExportCommand = new RelayCommand(ShowExport); ShowInfoCommand = new RelayCommand(ShowInfo); OpenSafeCommand = new RelayCommand(OpenSafe); CloseSafeCommand = new RelayCommand(CloseSafe); ChangeSafePasswordCommand = new RelayCommand(ChangeSafePassword); Modified = false; // If a filter was set before e.g. opening a note, set the same filter again. if (!string.IsNullOrEmpty(_lastFilter)) { Filter = _lastFilter; } }
public CloudStorageOauthWaitingViewModel( INavigationService navigationService, ILanguageService languageService, ISvgIconService svgIconService, IBaseUrlService webviewBaseUrl, IStoryBoardService storyBoardService, IFeedbackService feedbackService) : base(navigationService, languageService, svgIconService, webviewBaseUrl) { _storyBoardService = storyBoardService; feedbackService.ShowBusyIndicator(true); GoBackCommand = new RelayCommand(GoBack); }
public MergeChoiceViewModel( INavigationService navigationService, ILanguageService languageService, ISvgIconService svgIconService, IBaseUrlService webviewBaseUrl, IStoryBoardService storyBoardService) : base(navigationService, languageService, svgIconService, webviewBaseUrl) { _storyBoardService = storyBoardService; UseMergedRepositoryCommand = new RelayCommand(UseMergedRepository); UseLocalRepositoryCommand = new RelayCommand(UseLocalRepository); UseCloudRepositoryCommand = new RelayCommand(UseCloudRepository); GoBackCommand = new RelayCommand(GoBack); CancelCommand = new RelayCommand(Cancel); }
public NoteRepositoryViewModel( INavigationService navigationService, ILanguageService languageService, ISvgIconService svgIconService, IThemeService themeService, IBaseUrlService webviewBaseUrl, IStoryBoardService storyBoardService, IFeedbackService feedbackService, ISettingsService settingsService, IEnvironmentService environmentService, ICryptoRandomSource randomSource, IRepositoryStorageService repositoryService) : base(navigationService, languageService, svgIconService, themeService, webviewBaseUrl) { _storyBoardService = storyBoardService; _repositoryService = repositoryService; _feedbackService = feedbackService; _settingsService = settingsService; _environmentService = environmentService; _noteCryptor = new Cryptor(NoteModel.CryptorPackageName, randomSource); _searchableTextConverter = new SearchableHtmlConverter(); AllNotes = new List <NoteViewModel>(); FilteredNotes = new ObservableCollection <NoteViewModel>(); _repositoryService.LoadRepositoryOrDefault(out NoteRepositoryModel noteRepository); Model = noteRepository; // Initialize commands and events ShowNoteCommand = new RelayCommand <Guid>(ShowNote); NewNoteCommand = new RelayCommand(NewNote); NewChecklistCommand = new RelayCommand(NewChecklist); DeleteNoteCommand = new RelayCommand <Guid>(DeleteNote); ClearFilterCommand = new RelayCommand(ClearFilter); SynchronizeCommand = new RelayCommand(Synchronize); ShowTransferCodeCommand = new RelayCommand(ShowTransferCode); ShowSettingsCommand = new RelayCommand(ShowSettings); ShowRecycleBinCommand = new RelayCommand(ShowRecycleBin); ShowInfoCommand = new RelayCommand(ShowInfo); OpenSafeCommand = new RelayCommand(OpenSafe); CloseSafeCommand = new RelayCommand(CloseSafe); ChangeSafePasswordCommand = new RelayCommand(ChangeSafePassword); OnPropertyChanged(nameof(FilterButtonMagnifierVisible)); OnPropertyChanged(nameof(FilterButtonCancelVisible)); Modified = false; }
public TransferCodeViewModel( INavigationService navigationService, ILanguageService languageService, ISvgIconService svgIconService, IBaseUrlService webviewBaseUrl, IStoryBoardService storyBoardService, IFeedbackService feedbackService) : base(navigationService, languageService, svgIconService, webviewBaseUrl) { _storyBoardService = storyBoardService; _feedbackService = feedbackService; // Initialize commands OkCommand = new RelayCommand(Ok); GoBackCommand = new RelayCommand(GoBack); CancelCommand = new RelayCommand(Cancel); }
public CloudStorageChoiceViewModel( INavigationService navigationService, ILanguageService languageService, ISvgIconService svgIconService, IBaseUrlService webviewBaseUrl, IStoryBoardService storyBoardService, ICloudStorageClientFactory cloudStorageClientFactory) : base(navigationService, languageService, svgIconService, webviewBaseUrl) { _storyBoardService = storyBoardService; _cloudStorageClientFactory = cloudStorageClientFactory; ServiceChoices = new List <CloudStorageChoiceItemViewModel>(); GoBackCommand = new RelayCommand(GoBack); ChooseCommand = new RelayCommand <string>(Choose); ListChoices(ServiceChoices); }
public SettingsViewModel( INavigationService navigationService, ILanguageService languageService, ISvgIconService svgIconService, IThemeService themeService, IBaseUrlService webviewBaseUrl, ISettingsService settingsService, IStoryBoardService storyBoardService) : base(navigationService, languageService, svgIconService, themeService, webviewBaseUrl) { _settingsService = settingsService; _storyBoardService = storyBoardService; Model = _settingsService.LoadSettingsOrDefault(); EncryptionAlgorithms = new List <DropdownItemViewModel>(); FillAlgorithmList(EncryptionAlgorithms); // Initialize commands GoBackCommand = new RelayCommand(GoBack); ChangeCloudSettingsCommand = new RelayCommand(ChangeCloudSettings); ClearCloudSettingsCommand = new RelayCommand(ClearCloudSettings); }
public CloudStorageAccountViewModel( INavigationService navigationService, ILanguageService languageService, ISvgIconService svgIconService, IBaseUrlService webviewBaseUrl, IStoryBoardService storyBoardService, IFeedbackService feedbackService, ICloudStorageClientFactory cloudStorageClientFactory, SerializeableCloudStorageCredentials model) : base(navigationService, languageService, svgIconService, webviewBaseUrl) { _storyBoardService = storyBoardService ?? throw new ArgumentNullException(nameof(storyBoardService)); _feedbackService = feedbackService ?? throw new ArgumentNullException(nameof(feedbackService)); Model = model; _credentialsRequirements = cloudStorageClientFactory.GetOrCreate(Model.CloudStorageId).CredentialsRequirements; CloudServiceName = cloudStorageClientFactory.GetCloudStorageMetadata(Model.CloudStorageId).Title; GoBackCommand = new RelayCommand(GoBack); CancelCommand = new RelayCommand(Cancel); OkCommand = new RelayCommand(Ok); }
private bool IsStartedByOAuthRedirectIndent(IStoryBoardService storyBoardService) { return((storyBoardService.ActiveStory != null) && storyBoardService.ActiveStory.TryLoadFromSession(SynchronizationStorySessionKey.OauthRedirectUrl.ToInt(), out string _)); }