public void SaveNotes(IEnumerable <DomainNote> notes) { var data = new NotebookData { Notes = NoteMapper.Convert(notes.ToList()), TimeStamp = timeProvider.Now }; string json = JsonConvert.SerializeObject(data); // for now, possible exceptions will be handled on the application-level File.WriteAllText(filePath, json); }
private void Start() { // Load the notebook from save, or create a new one if save data doesn't exist data = GameManager.Instance.LoadNotebook() ?? new NotebookData(config); // Set the configuration of the notebook data data.SetConfig(config); // Add the current level data.OnLevelEncountered(LevelID.Current()); // Try to get an instance of the game manager GameManager instance = GameManager.Instance; // If the instance exists then unlock all item id's that exist in the list of items if (instance) { foreach (LevelData.ItemData item in instance.LevelData.ItemQuantities) { data.UnlockItem(item.itemObject.ItemID); } } // Setup the tab picker first of all children tabPicker.Setup(); // Get the resource request editor manually resourceRequestEditor = GetComponentInChildren <ResourceRequestEditor>(true); // Setup all children, ensuring correct initialization order NotebookUIChild[] children = GetComponentsInChildren <NotebookUIChild>(true); foreach (NotebookUIChild child in children) { child.Setup(); } // Map all bookmark targets to their corresponding game object names BookmarkTarget[] allBookmarkTargets = GetComponentsInChildren <BookmarkTarget>(true); foreach (BookmarkTarget bookmarkTarget in allBookmarkTargets) { nameTargetMap.Add(bookmarkTarget.name, bookmarkTarget); } // Setup sound events after all children are set up soundManager.SetupSoundEvents(); // This line of code prevents the notebook from turning off the first time that it is turned on, // while also making sure it is turned off at the start if (!isOpen) { SetIsOpen(false); } }
public void SaveNotebook(NotebookData data) { string name = "sz.notebook"; string fullPath = Path.Combine(Application.persistentDataPath, name); try { string json = JsonUtility.ToJson(data); File.WriteAllText(Path.Combine(Application.persistentDataPath, name), json); } catch { Debug.LogError("Serialization error, NOT saved to protect existing saves"); return; } }
public NotebookData LoadNotebook() { string name = "sz.notebook"; string fullPath = Path.Combine(Application.persistentDataPath, name); try { string json = File.ReadAllText(fullPath); NotebookData data = new NotebookData(NotebookUI.Config); JsonUtility.FromJsonOverwrite(json, data); return(data); } catch (System.Exception e) { Debug.Log("No save data or error loading notebook data, creating new data"); return(null); } }
private async Task <IActionResult> PerformSearch(FindNotesViewModel findNotesViewModel) { ApplicationUser user = await ControllerHelpers.GetCurrentUserAsync(_userManager, _dataAccess, HttpContext.User.GetUserId()); if (user.EvernoteCredentials == null) { return(View("MustAuthoriseEvernote")); } if (ModelState.IsValid) { findNotesViewModel.SearchPerformed = true; IEvernoteService evernoteService = new EvernoteServiceSDK1(user.EvernoteCredentials); try { ISearchResults searchResults = evernoteService.GetNotesMetaList( findNotesViewModel.SearchField, (Evernote.EDAM.Type.NoteSortOrder)findNotesViewModel.SortOrder, findNotesViewModel.SortAscending, findNotesViewModel.CurrentResultsPage, findNotesViewModel.PageSize); findNotesViewModel.NumberUnfilteredResults = searchResults.NotesMetadata.Count; if (findNotesViewModel.ExcludeShortNotes) { searchResults.NotesMetadata.RemoveAll(metadata => metadata.ContentLength < (1024 * 3)); } // now we populate with tags and notebook name foreach (INoteMetadata noteMetadata in searchResults.NotesMetadata) { if (noteMetadata.TagGuids != null) { List <TagData> tags = _dataAccess.GetCachedTagData(user.Id, noteMetadata.TagGuids); noteMetadata.TagNames = new List <string>(); foreach (string tagGuid in noteMetadata.TagGuids) { TagData tag = tags.FirstOrDefault(t => t.Guid == tagGuid); if (tag == null) { // save tag Tag evernoteTag = evernoteService.GetTag(tagGuid); tag = new TagData { Guid = tagGuid, Name = evernoteTag.Name, UserId = user.Id }; _dataAccess.SaveTag(tag); } noteMetadata.TagNames.Add(tag.Name); } } noteMetadata.NotebookName = _dataAccess.GetCachedNotebookName(user.Id, noteMetadata.NotebookGuid); if (noteMetadata.NotebookName == null) { Notebook notebook = evernoteService.GetNotebook(noteMetadata.NotebookGuid); noteMetadata.NotebookName = notebook.Name; NotebookData notebookData = new NotebookData() { UserId = user.Id, Guid = noteMetadata.NotebookGuid, Name = notebook.Name }; _dataAccess.SaveNotebook(notebookData); } } findNotesViewModel.SearchResults = searchResults.NotesMetadata.ConvertAll(noteMeta => new EverReaderNodeMetadataFormatter(noteMeta)); findNotesViewModel.TotalResultsForSearch = searchResults.TotalResults; } catch (EvernoteServiceSDK1AuthorisationException) { return(View("EvernoteAuthorisationError")); } } return(View("FindNotes", findNotesViewModel)); }
public void SaveNotebook(NotebookData notebook) { _dbContext.Notebooks.Add(notebook); _dbContext.SaveChanges(); }
public string GetCachedNotebookName(string userId, string notebookGuid) { NotebookData notebookData = _dbContext.Notebooks.Where(n => n.UserId == userId && n.Guid == notebookGuid).FirstOrDefault(); return((notebookData == null) ? null : notebookData.Name); }