private async Task InitRoamingSettingsHelperAsync()
        {
            switch (ProviderManager.Instance?.GlobalProvider?.State)
            {
            case ProviderState.SignedIn:
                if (_remoteFileStorage == null)
                {
                    _remoteFileStorage = await OneDriveStorageHelper.CreateForCurrentUserAsync(_serializer);
                }
                if (_remoteSettingsStorage == null)
                {
                    _remoteSettingsStorage = await UserExtensionStorageHelper.CreateForCurrentUserAsync("ContosoNotes.json", _serializer);
                }
                break;

            case ProviderState.SignedOut:
                _remoteFileStorage     = null;
                _remoteSettingsStorage = null;
                break;
            }
        }
        private async Task <NotesListModel> GetNotesListAsync(IFileStorageHelper storageHelper)
        {
            if (storageHelper == null)
            {
                return(null);
            }

            // Get the list of stored notes.
            string notesListFileName = "notesList.json";

            try
            {
                NotesListModel notesList = await storageHelper.ReadFileAsync <NotesListModel>(notesListFileName);

                return(notesList);
            }
            catch (System.Exception e)
            {
                return(null);
            }
        }
        private async Task <NotePageModel> GetCurrentNotePage(ISettingsStorageHelper <string> settingsStorage, IFileStorageHelper fileStorage, NotesListModel notesList)
        {
            if (fileStorage == null || settingsStorage == null)
            {
                return(null);
            }

            if (settingsStorage.TryRead <string>("currentNotePageId", out string currentNotePageId) && currentNotePageId != null)
            {
                foreach (var notesListItem in notesList.Items)
                {
                    if (currentNotePageId == notesListItem.NotePageId)
                    {
                        string notePageFileName = GetNotePageFileName(notesListItem);
                        return(await fileStorage.ReadFileAsync <NotePageModel>(notePageFileName));
                    }
                }
            }

            return(null);
        }
Example #4
0
 public GetFileHandler(IFileService fileService, IFileStorageHelper fileStorageHelper)
 {
     _fileService       = fileService;
     _fileStorageHelper = fileStorageHelper;
 }