Exemple #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();
                }
            }
Exemple #2
0
        public async Task OnConnected(IRemoteClient remoteClient)
        {
            if (_remoteClientAssetFsLayer == null)
            {
                return;
            }

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

            try
            {
                outbound.Writer.Write("list-assets");
                outbound.Writer.Flush();
                var assetCount = outbound.Reader.ReadInt32();
                var assets     = new RemoteAssetFsFile[assetCount];
                for (var i = 0; i < assetCount; i++)
                {
                    assets[i] = ReadRemoteAssetFsFileFromStream(remoteClient, outbound.Reader);
                }
                var assetsByName = assets.ToDictionary(k => k.Name, v => v);
                foreach (var kv in assetsByName)
                {
                    _remoteClientAssetFsLayer.SetCachedFile(kv.Key, kv.Value);
                }
                foreach (var name in _remoteClientAssetFsLayer.GetCachedFileKeys())
                {
                    if (!assetsByName.ContainsKey(name))
                    {
                        _remoteClientAssetFsLayer.RemoveCachedFile(name);
                    }
                }
            }
            finally
            {
                remoteClient.ReleaseOutboundReaderWriter();
            }
        }