Esempio n. 1
0
            /// <summary>
            /// this is callback from remote host side to get asset associated with checksum from VS.
            /// </summary>
            public async Task RequestAssetAsync(int sessionId, byte[][] checksums, string streamName)
            {
                try
                {
                    Contract.ThrowIfFalse(_owner._currentSessionId == sessionId);

                    using (Logger.LogBlock(FunctionId.JsonRpcSession_RequestAssetAsync, streamName, _source.Token))
                        using (var stream = await DirectStream.GetAsync(streamName, _source.Token).ConfigureAwait(false))
                        {
                            using (var writer = new StreamObjectWriter(stream))
                            {
                                writer.WriteInt32(sessionId);

                                await WriteAssetAsync(writer, checksums).ConfigureAwait(false);
                            }

                            await stream.FlushAsync(_source.Token).ConfigureAwait(false);
                        }
                }
                catch (IOException)
                {
                    // remote host side is cancelled (client stream connection is closed)
                    // can happen if pinned solution scope is disposed
                }
                catch (OperationCanceledException)
                {
                    // rpc connection is closed.
                    // can happen if pinned solution scope is disposed
                }
            }
Esempio n. 2
0
            /// <summary>
            /// this is callback from remote host side to get asset associated with checksum from VS.
            /// </summary>
            public async Task RequestAssetAsync(int scopeId, Checksum[] checksums, string streamName)
            {
                try
                {
                    using (Logger.LogBlock(FunctionId.JsonRpcSession_RequestAssetAsync, streamName, _source.Token))
                        using (var stream = await DirectStream.GetAsync(streamName, _source.Token).ConfigureAwait(false))
                        {
                            var scope = _owner.PinnedRemotableDataScope;
                            using (var writer = new ObjectWriter(stream))
                            {
                                writer.WriteInt32(scopeId);

                                await WriteAssetAsync(writer, scope, checksums).ConfigureAwait(false);
                            }

                            await stream.FlushAsync(_source.Token).ConfigureAwait(false);
                        }
                }
                catch (IOException)
                {
                    // remote host side is cancelled (client stream connection is closed)
                    // can happen if pinned solution scope is disposed
                }
                catch (OperationCanceledException)
                {
                    // rpc connection is closed.
                    // can happen if pinned solution scope is disposed
                }
            }
                /// <summary>
                /// this is callback from remote host side to get asset associated with checksum from VS.
                /// </summary>
                public async Task RequestAssetAsync(int serviceId, byte[][] checksums, string streamName)
                {
                    try
                    {
                        using (var stream = await DirectStream.GetAsync(streamName, _source.Token).ConfigureAwait(false))
                        {
                            using (var writer = new ObjectWriter(stream))
                            {
                                writer.WriteInt32(serviceId);

                                await WriteAssetAsync(writer, checksums).ConfigureAwait(false);
                            }

                            await stream.FlushAsync(_source.Token).ConfigureAwait(false);
                        }
                    }
                    catch (IOException)
                    {
                        // remote host side is cancelled (client stream connection is closed)
                        // can happen if pinned solution scope is disposed
                    }
                    catch (OperationCanceledException)
                    {
                        // rpc connection is closed.
                        // can happen if pinned solution scope is disposed
                    }
                }
Esempio n. 4
0
        /// <summary>
        /// this is callback from remote host side to get asset associated with checksum from VS.
        /// </summary>
        public async Task RequestAssetAsync(int scopeId, Checksum[] checksums, string streamName, CancellationToken cancellationToken)
        {
            try
            {
                using (var source = CancellationTokenSource.CreateLinkedTokenSource(_shutdownCancellationSource.Token, cancellationToken))
                    using (Logger.LogBlock(FunctionId.JsonRpcSession_RequestAssetAsync, streamName, source.Token))
                        using (var stream = await DirectStream.GetAsync(streamName, source.Token).ConfigureAwait(false))
                        {
                            using (var writer = new ObjectWriter(stream, source.Token))
                            {
                                writer.WriteInt32(scopeId);

                                await WriteAssetAsync(writer, scopeId, checksums, source.Token).ConfigureAwait(false);
                            }

                            await stream.FlushAsync(source.Token).ConfigureAwait(false);
                        }
            }
            catch (IOException)
            {
                // direct stream can throw if cancellation happens since direct stream still uses
                // disconnection for cancellation
            }
            catch (OperationCanceledException)
            {
                // this can happen if connection got shutdown
            }
        }
Esempio n. 5
0
                /// <summary>
                /// this is callback from remote host side to get asset associated with checksum from VS.
                /// </summary>
                public async Task RequestAssetAsync(int serviceId, byte[] checksum, string streamName)
                {
                    try
                    {
                        var service = ChecksumScope.Workspace.Services.GetRequiredService <ISolutionChecksumService>();

                        using (var stream = await DirectStream.GetAsync(streamName, _source.Token).ConfigureAwait(false))
                        {
                            using (var writer = new ObjectWriter(stream))
                            {
                                writer.WriteInt32(serviceId);
                                writer.WriteArray(checksum);

                                var checksumObject = service.GetChecksumObject(new Checksum(checksum), _source.Token);
                                writer.WriteString(checksumObject.Kind);

                                await checksumObject.WriteToAsync(writer, _source.Token).ConfigureAwait(false);
                            }

                            await stream.FlushAsync(_source.Token).ConfigureAwait(false);
                        }
                    }
                    catch (IOException)
                    {
                        // remote host side is cancelled (client stream connection is closed)
                        // can happen if pinned solution scope is disposed
                    }
                    catch (OperationCanceledException)
                    {
                        // rpc connection is closed.
                        // can happen if pinned solution scope is disposed
                    }
                }
Esempio n. 6
0
        /// <summary>
        /// this is callback from remote host side to get asset associated with checksum from VS.
        /// </summary>
        public async Task RequestAssetAsync(int scopeId, Checksum[] checksums, string streamName, CancellationToken cancellationToken)
        {
            try
            {
                using (var combinedCancellationToken = _shutdownCancellationSource.Token.CombineWith(cancellationToken))
                    using (Logger.LogBlock(FunctionId.JsonRpcSession_RequestAssetAsync, streamName, combinedCancellationToken.Token))
                        using (var stream = await DirectStream.GetAsync(streamName, combinedCancellationToken.Token).ConfigureAwait(false))
                        {
                            using (var writer = new ObjectWriter(stream, combinedCancellationToken.Token))
                            {
                                writer.WriteInt32(scopeId);

                                await WriteAssetAsync(writer, scopeId, checksums, combinedCancellationToken.Token).ConfigureAwait(false);
                            }

                            await stream.FlushAsync(combinedCancellationToken.Token).ConfigureAwait(false);
                        }
            }
            catch (Exception ex) when(ReportUnlessCanceled(ex, cancellationToken))
            {
                // only expected exception will be catched. otherwise, NFW and let it propagate
                Debug.Assert(cancellationToken.IsCancellationRequested || ex is IOException);
            }
        }