Ejemplo n.º 1
0
        /// <inheritdoc />
        public override void OnStoringUnsavedData()
        {
            bool pinStateChanged = Model.IsPinned != _originalWasPinned;

            if (Modified || pinStateChanged)
            {
                if (IsUnlocked)
                {
                    Model.HtmlContent = Lock(_unlockedContent);
                }
                else
                {
                    Model.HtmlContent = XmlUtils.SanitizeXmlString(_unlockedContent);
                }

                _repositoryService.LoadRepositoryOrDefault(out NoteRepositoryModel noteRepository);

                if (pinStateChanged)
                {
                    RepositionNoteBecausePinStateChanged(noteRepository);
                }

                _repositoryService.TrySaveRepository(noteRepository);
                Modified = false;
            }
        }
Ejemplo n.º 2
0
 /// <inheritdoc/>
 public override void OnStoringUnsavedData()
 {
     if (Modified)
     {
         _repositoryService.TrySaveRepository(Model);
         Modified = false;
     }
 }
Ejemplo n.º 3
0
 /// <inheritdoc />
 public override void OnStoringUnsavedData()
 {
     if (Modified)
     {
         _repositoryService.LoadRepositoryOrDefault(out NoteRepositoryModel noteRepository);
         _repositoryService.TrySaveRepository(noteRepository);
         Modified = false;
     }
 }
Ejemplo n.º 4
0
        /// <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
            }
        }
Ejemplo n.º 5
0
        /// <inheritdoc />
        public override void OnStoringUnsavedData()
        {
            if (Modified)
            {
                Model.HtmlContent = XmlUtils.SanitizeXmlString(Model.HtmlContent);

                _repositoryService.LoadRepositoryOrDefault(out NoteRepositoryModel noteRepository);
                _repositoryService.TrySaveRepository(noteRepository);
                Modified = false;
            }
        }
        /// <inheritdoc/>
        public override void OnStoringUnsavedData()
        {
            // If there was an error reading the existing repository, we do not overwrite it, to
            // prevent further damage.
            if (Model == null)
            {
                return;
            }

            if (Modified)
            {
                _repositoryService.TrySaveRepository(Model);
                Modified = false;
            }
        }
        /// <inheritdoc/>
        public override async Task Run()
        {
            try
            {
                NoteRepositoryModel cloudRepository = StoryBoard.LoadFromSession <NoteRepositoryModel>(SynchronizationStorySessionKey.CloudRepository);
                _repositoryStorageService.TrySaveRepository(cloudRepository);
                await StoryBoard.ContinueWith(SynchronizationStoryStepId.StopAndShowRepository);

                _feedbackService.ShowToast(_languageService["sync_success"]);
            }
            catch (Exception ex)
            {
                // Keep the current page open and show the error message
                ShowExceptionMessage(ex, _feedbackService, _languageService);
            }
        }
Ejemplo n.º 8
0
        /// <inheritdoc/>
        public override async Task Run()
        {
            try
            {
                NoteRepositoryModel cloudRepository = StoryBoard.LoadFromSession <NoteRepositoryModel>(SynchronizationStorySessionKey.CloudRepository.ToInt());
                SerializeableCloudStorageCredentials credentials = StoryBoard.LoadFromSession <SerializeableCloudStorageCredentials>(SynchronizationStorySessionKey.CloudStorageCredentials.ToInt());
                _repositoryStorageService.LoadRepositoryOrDefault(out NoteRepositoryModel localRepository);
                SettingsModel settings = _settingsService.LoadSettingsOrDefault();

                // Merge repositories
                NoteRepositoryMerger merger           = new NoteRepositoryMerger();
                NoteRepositoryModel  mergedRepository = merger.Merge(localRepository, cloudRepository);

                // Store merged repository locally when different
                if (!RepositoriesAreEqual(mergedRepository, localRepository))
                {
                    _repositoryStorageService.TrySaveRepository(mergedRepository);
                }

                // Store merged repository to the cloud when different, otherwise spare the slow upload
                if (!RepositoriesAreEqual(mergedRepository, cloudRepository))
                {
                    byte[] encryptedRepository = EncryptRepository(
                        mergedRepository, settings.TransferCode, _cryptoRandomService, settings.SelectedEncryptionAlgorithm);

                    ICloudStorageClient cloudStorageClient = _cloudStorageClientFactory.GetOrCreate(credentials.CloudStorageId);
                    await cloudStorageClient.UploadFileAsync(Config.RepositoryFileName, encryptedRepository, credentials);
                }

                await StoryBoard.ContinueWith(SynchronizationStoryStepId.StopAndShowRepository.ToInt());

                _feedbackService.ShowToast(_languageService["sync_success"]);
            }
            catch (Exception ex)
            {
                // Keep the current page open and show the error message
                ShowExceptionMessage(ex, _feedbackService, _languageService);
            }
        }