/// <summary> /// Save the configuration. /// </summary> public void Save(Act <Configuration> onSave = null) { _lock.Take(); if (State.Is(AssetState.Loaded) || State.Is(AssetState.Unloaded)) { State = AssetState.Saving; if (onSave == null) { // get the connection ConnectionLocal connection = ManagerConnections.Get <ConnectionLocal>(_path); // ensure the file modes are right connection.FileMode = System.IO.FileMode.Truncate; connection.FileAccess = System.IO.FileAccess.Write; connection.FileShare = System.IO.FileShare.Read; // get the stream Teple <LockShared, ByteBuffer> resource; connection.Get(out resource); // run save logic OnSave(resource.ArgB); resource.ArgA.Release(); } else { onSave.ArgA = this; // get the connection ConnectionLocal connection = ManagerConnections.Get <ConnectionLocal>(_path); // ensure the file modes are right connection.FileMode = System.IO.FileMode.Create; connection.FileAccess = System.IO.FileAccess.Write; // callback save connection.Get(new Act <ByteBuffer>(new ActionPair <ByteBuffer>(OnSave, s => onSave.Run()))); } } else { _lock.Release(); } }