예제 #1
0
            public async Task <Stream> GetContentStream()
            {
                if (_cachedContent != null)
                {
                    return(new MemoryStream(_cachedContent));
                }

                await _remoteClient.WaitUntilConnected().ConfigureAwait(false);

                var outbound = await _remoteClient.ObtainOutboundReaderWriter().ConfigureAwait(false);

                try
                {
                    outbound.Writer.Write("get-asset-content");
                    outbound.Writer.Write(Name);
                    outbound.Writer.Flush();
                    if (outbound.Reader.ReadBoolean())
                    {
                        var contentLength = outbound.Reader.ReadInt32();
                        _cachedContent = outbound.Reader.ReadBytes(contentLength);
                        return(new MemoryStream(_cachedContent));
                    }
                    else
                    {
                        // TODO: Server was unable to provide content!
                        return(new MemoryStream());
                    }
                }
                finally
                {
                    _remoteClient.ReleaseOutboundReaderWriter();
                }
            }