public async Task Commit() { try { // For some odd reasons, current LiteDB version does not support transaction using (LiteRepository _liteRepo = new LiteRepository(LiteDBLocation)) { if (ToSave.Any() || ToModify.Any()) { IList <T> _combinedList = ToSave.Concat(ToModify).ToList(); _liteRepo.Upsert <T>(_combinedList, CollectionName); } if (ToRemove.Any()) { _liteRepo.Delete <T>(Query.Where("_id", id => ToRemove.Contains(id)), CollectionName); } } await Task.Run(() => { ToSave.Clear(); ToModify.Clear(); ToRemove.Clear(); }); } catch (Exception ex) { throw ex; } }
/// <summary>Commit changes made to the collection.</summary> async Task ICollectionRef <T> .Commit() { try { using LiteRepository _liteRepo = new LiteRepository(RefConfig.Location); if (ToSave.Any() || ToModify.Any()) { IList <T> _combinedList = ToSave.Concat(ToModify).ToList(); _liteRepo.Upsert <T>(_combinedList, RefConfig.Collection); } if (ToRemove.Any()) { BsonValue[] _bsonValues = ToRemove.Select(_id => new BsonValue(_id)).ToArray(); _liteRepo.DeleteMany <T>(Query.In("_id", _bsonValues), RefConfig.Collection); } await Task.Run(() => { ToSave.Clear(); ToModify.Clear(); ToRemove.Clear(); }); } catch (Exception ex) { throw ex; } }
public void Load() { string input = ""; input = File.ReadAllText(System.IO.Path.Combine(Application.persistentDataPath, "SavedDetails.json")); loadedDetails = JsonUtility.FromJson <ToSave>(input); Debug.Log("LOADED " + input); }
private void PB_TextBox_Click(object sender, EventArgs e) { SaveFileDialog sfd = new SaveFileDialog(); Image ToSave; if ((e as MouseEventArgs).Button == MouseButtons.Right) { if (Prompt(MessageBoxButtons.YesNo, "Save the current conversation?") != DialogResult.Yes) { return; } sfd.FileName = "FE_Conversation.png"; List <Image> Images = new List <Image>(); int stored = CUR_INDEX; ResetParameters(); for (CUR_INDEX = 0; CUR_INDEX < Messages.Count; CUR_INDEX++) { string parsed = UpdateParse(Messages[CUR_INDEX]); if (!string.IsNullOrWhiteSpace(parsed) && !string.IsNullOrEmpty(parsed)) { Images.Add(RenderBox(parsed)); } } CUR_INDEX = stored; ResetParameters(); for (int i = 0; i <= CUR_INDEX; i++) { UpdateParse(Messages[i]); } Bitmap bmp = new Bitmap(Images.Max(i => i.Width), Images.Sum(i => i.Height)); using (Graphics g = Graphics.FromImage(bmp)) { int h = 0; foreach (Image img in Images) { g.DrawImage(img, new Point(0, h)); h += img.Height; } } ToSave = bmp; } else { if (Prompt(MessageBoxButtons.YesNo, "Save the current image?") != DialogResult.Yes) { return; } ToSave = PB_TextBox.Image; sfd.FileName = "FE_Conversation_" + CUR_INDEX + ".png"; } if (sfd.ShowDialog() == DialogResult.OK) { ToSave.Save(sfd.FileName, ImageFormat.Png); } }
public void SaveGameState(ToSave template) { BinaryFormatter bf = new BinaryFormatter(); FileStream file; file = File.Create(Application.dataPath + filePath); ToSave savefile = template; bf.Serialize(file, savefile); file.Close(); }
private void Awake() { myModel = GetComponent <Kennith_Model>(); myHealth = GetComponent <Health>(); myEnergy = GetComponent <Energy>(); myDetails = new ToSave(); myDetails.charName = myModel.characterName; myDetails.health = myHealth.Amount; myDetails.energy = myEnergy.Amount; }
public void LoadGameState() { if (File.Exists(Application.dataPath + filePath)) { print("load"); ChangeScene(1); BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.dataPath + filePath, FileMode.Open); ToSave savefile = (ToSave)bf.Deserialize(file); currentData = savefile; file.Close(); } else { ChangeScene(1); } }
void Start() { if (GameManager.gm.currentData.finishedPath.Length != 0) { template = GameManager.gm.currentData; finishedPathSave = template.finishedPath; } else { template = new ToSave(); finishedPathSave = new bool[2]; } currentLivesSave = template.currentLives; maxLivesSave = template.maxLives; coinsSave = template.coins; milkSave = template.milk; bonesSave = template.bones; hasKeySave = template.hasKey; playerMovement = FindObjectOfType <PlayerMovement>(); }
/// <summary>Insert a list of objects to the referenced collection.</summary> void ICollectionRef <T> .Insert(IList <T> objs) => ToSave = ToSave.Concat(objs).ToList();
/// <summary>Insert an object to the referenced collection.</summary> void ICollectionRef <T> .Insert(T obj) => ToSave.Add(obj);
public void Add(T obj) => ToSave.Add(obj);