/// <summary> /// Adds an object to be tracked by this objecttype. /// </summary> /// <param name="existingObject">Object to track.</param> /// <param name="assumeNew">If false, ignores objects not ready to be saved (with id=-1). /// Else assign a new ID if the object has not been saved yet.</param> /// <returns>True on success. False if somehow the add failed.</returns> public virtual bool Add(ISaveable existingObject, bool assumeNew = true) { int id = existingObject.GetSaveID(); if (assumeNew && id == -1) { // SetSaveID is only called by two things: Loading, and this method. By locking here, this should be threadsafe. lock (this) { id = existingObject.GetSaveID(); if (id == -1) { id = NextFreeNumber(); //Note that this may get a lock on ItemDictionary also, and then the file stream. existingObject.SetSaveID(id); existingObject.Save(); } } } if (id >= 0) { Add(existingObject, id, false); return(true); } return(false); }
/// <inheritdoc/> public void SaveSaveable(ISaveable saveable) { if (IsIgnoringStateSynchronization) { return; } GameState.Set(saveable.Id, saveable.Save(), saveable.Context); }
private string TestSaveable(ISaveable saveable) { StringBuilder sb = new StringBuilder(); using (TextWriter tw = new StringWriter(sb)) { saveable.Save(tw); } return(sb.ToString()); }
public void SaveProject() { foreach (ItemsBase item in Items) { ISaveable saveable = item as ISaveable; if (saveable != null) { saveable.Save(_projectPath); } } }
private void Save() { ISaveable saveable = owner as ISaveable; if (saveable != null) { saveable.Save(); } else { (owner as ISubobject).Save(); } }
public static void UpdateAndSave <T>( this ISaveable instance, Expression <Func <T> > propertyExpression, T newValue) { // Gets the property name string propertyName = ((MemberExpression)propertyExpression.Body).Member.Name; // Updates its value PropertyInfo prop = instance.GetType().GetProperty(propertyName); prop.SetValue(instance, newValue, null); // Now call Save instance.Save(); }
private void perform_save() { if (_settingsSaver == null) { return; } if (_settingsHolder == null) { _settingsHolder = new List <string>(Items.Count); } else { _settingsHolder.Clear(); } _settingsHolder.AddRange(Items.Cast <object>().Select(o => o.ToString())); _settingsSaver.Save(); }
static void Main(string[] args) { var person = new Person(); person.Save(); ISaveable s = person; s.Save(); // note Load method is not available on interface instance IPersistable p = (IPersistable)person; Console.WriteLine(p.Save()); Console.WriteLine(p.Load()); // note Load method is not available on interface instance Console.ReadLine(); }
protected override void InnerRespond(string userString) { //No matter what the input is, we try to set it once, and then this prompt returns. //Avoids infinite loops of validation failure, allows empty strings and any other weird things. using (IDisposable mudLock = ThreadManager.GetMUDLock(1000)) { if (mudLock == null) { //Ideally this shouldn't happen, but in case it does notify the user. User.sendMessage("The MUD is currently paused. Wait until it is unpaused and try again."); } else { string error; if (!fieldParser.SetValue(objectToModify, userString, out error)) { if (error != null) { User.sendMessage("Error: " + error); } else { User.sendMessage("An unspecified error occurred. The value was not set."); } } else { ISaveable objectToSave = objectToModify as ISaveable; if (objectToSave != null) { objectToSave.Save(); } else { GlobalValues.GlobalsIsDirty = true; } User.sendMessage("Value set."); } } } Cancel(true); }
private void DeleteValue() { string error; using (IDisposable mudLock = ThreadManager.GetMUDLock(1000)) { if (mudLock == null) { //Ideally this shouldn't happen, but in case it does notify the user. User.sendMessage("The MUD is currently paused. Wait until it is unpaused and try again."); } else { if (!fieldParser.SetValue(objectToModify, null, out error)) { if (error != null) { User.sendMessage("Error: " + error); } else { User.sendMessage("An unspecified error occurred. The value was not deleted."); } } else { ISaveable objectToSave = objectToModify as ISaveable; if (objectToSave != null) { objectToSave.Save(); } else { GlobalValues.GlobalsIsDirty = true; } User.sendMessage("The value has been deleted."); } } } CheckOptions(); }
protected virtual void SaveItem(ISaveable obj, object saveItemParameter) { obj.Save(saveContext); }
public async void StartIoProcess(Args args) { var dest = Path.Combine(AppContext.BaseDirectory, args.Dest, DateTime.Now.ToString("HH-mm-ss")); if (!Directory.Exists(dest)) { Directory.CreateDirectory(dest); } var paths = Directory.GetFiles(args.Src); foreach (var path in paths) { var stream = await loader.Load(path); string name = Path.GetFileName(path); string target = $@"{args.Dest}\{name}.jpg"; using (var outStream = new FileStream(target, FileMode.Create)) await imageProcessor.ProcessImg(stream).ContinueWith(async(res) => await saver.Save(stream, args.Dest)); } }
// A shortcut for ISaveable objects since we know how to write them public void SaveAndMarkReference(ISaveable obj) { SaveAndMarkReference(obj, () => { obj.Save(this); }); }