public ITypedStream AsReadOnly() { AssertNotDisposed(); lock (Inner) { if (mode == OpenMode.Write) { throw new InvalidOperationException("Write-only stream does not have read privilegies."); } return(container.Create(OpenMode.Read)); } }
/// <summary> /// Helper; creates cached TS. /// </summary> private ManagedTypedStream GetCachedTypedStream(string t, OpenMode mode) { // First update all unused typed streams containers. typedStreams.RemoveAll(delegate(TypedStreamContainer c) { if (!c.IsAlive) { return(true); } return(false); }); // Foreach stream. foreach (TypedStreamContainer c in typedStreams) { if (c.Type == t) { ManagedTypedStream stream = c.Create(mode); if (stream != null) { return(stream); } break; } } // We have to create it. // We ask node to provide TS. IDriverTypedStream s = node.GetTypedStream(OpenMode.ReadWrite, t); if (s == null) { return(null); } TypedStreamContainer cont = new TypedStreamContainer(t, s); // We add it in front, to make sure we first check this new type. typedStreams.Insert(0, cont); return(cont.Create(mode)); }