public async Task ContextLoadedStream(ContextDto request, IWritableChannel <ContextLoadingUpdate> responseStream, MethodCallContext callContext)
        {
            var context = _contextsSet.GetContext(request.Id);

            if (context == null)
            {
                throw new Exception($"There is no context with {request.Id} id");
            }

            await Observable.Return(Unit.Default)
            .Merge(context.ContextUpdatedEventStream)
            .ObserveOn(TaskPoolScheduler.Default)
            .Throttle(TimeSpan.FromMilliseconds(200))
            .Select(_ => new ContextLoadingUpdate
            {
                LoadedAppDescriptors =
                {
                    context.GetConnectedApps().Select(ConvertToProto)
                },
                Status = context.IsLoading ? ContextLoadingStatus.InProgress : ContextLoadingStatus.Finished,
            })
            .DistinctUntilChanged()
            .Do(update =>
            {
                Log.Debug(
                    $"Sending context linkage update for context {context.Id}: LoadedAppDescriptorsCount={update.LoadedAppDescriptors.Count}");
            })
            .PipeAsync(responseStream, callContext.CancellationToken);
        }
        public Task <InvocationsList> GetLinkedInvocations(ContextDto request, MethodCallContext callContext)
        {
            return(Task.Factory.StartNew(() =>
            {
                var context = _contextsSet.GetContext(request.Id);
                if (context == null)
                {
                    throw new Exception($"There is no context with {request.Id} id");
                }

                return CreateInvocationsList(context);
            }));
        }
 public Task <Empty> JoinContext(ContextDto request, MethodCallContext callContext)
 {
     return(Task.Factory.StartNew(() =>
     {
         var context = _contextsSet.GetContext(request.Id);
         if (context == null)
         {
             throw new Exception($"There is no context with {request.Id} id");
         }
         foreach (var appConnection in _appLifecycleManager.GetAppInstanceConnections(callContext.ConsumerApplicationInstanceId))
         {
             context.AppConnected(appConnection.Info);
         }
         return new Empty();
     }));
 }