/// <summary> /// Releases any resources held by an open reader. /// </summary> /// <param name="writer">The writer of the value.</param> protected override void CloseWriter( ITextWriter writer ) { var valueNode = new DataStoreTextValue(this.currentValueNodeName, this.textWriter.ToString()); this.currentValueNodeName = null; this.textWriter.Clear(); this.AddChild(valueNode); }
/// <summary> /// Creates a new empty file, and opens it for writing. /// </summary> /// <param name="dataStorePath">The data store path specifying the file to open.</param> /// <param name="overwriteIfExists"><c>true</c> to overwrite the file in case it already exists (like <see cref="System.IO.FileMode.Create"/>); or <c>false</c> to throw an exception (like <see cref="System.IO.FileMode.CreateNew"/>).</param> /// <returns>An <see cref="ITextWriter"/> representing the file opened.</returns> public ITextWriter CreateNewText( string dataStorePath, bool overwriteIfExists ) { try { if( dataStorePath.NullOrEmpty() || !DataStore.IsValidPath(dataStorePath) ) throw new ArgumentException("Invalid data store path!").StoreFileLine(); lock( this.syncLock ) { // create parent var parentNodes = this.GetOrCreateParentNodes(dataStorePath); // get or create value var textValue = this.GetNodeAt(dataStorePath) as IDataStoreTextValue; if( textValue.NullReference() ) { textValue = new DataStoreTextValue(DataStore.GetNodeName(dataStorePath), Substring.Empty); this.SetValueForExistingParent(parentNodes, textValue); } return new DataStoreTextValueWriter(textValue); } } catch( Exception ex ) { ex.Store("dataStorePath", dataStorePath); ex.Store("overwriteIfExists", overwriteIfExists); throw; } }