コード例 #1
0
        public async Task Subscribe(AlgorithmId algorithmId, ResultSubscriptionType resultSubscriptionType)
        {
            if (_subscriptions.TryGetValue(algorithmId, out ResultSubscriptionType newSubscription))
            {
                // This is an existing subscription. Add requested data
                newSubscription &= resultSubscriptionType;
            }
            else
            {
                // This is a new subscription.
                newSubscription = resultSubscriptionType;

                // When subscribed, we expect the user wants to see data fast.
                // Therefore, we get data from cache, send it, and immediately refresh from the server
                // After subscribing, the polling mechanism will update data further.

                var result = await _cache.GetObject <AlgorithmResult>(algorithmId.DeployId);

                if (result != null)
                {
                    OnAlgorithmResultUpdated(new AlgorithmResultEventArgs(result));
                }
            }

            // Save the subscription
            _subscriptions[algorithmId] = newSubscription;
        }
コード例 #2
0
        private async Task PollAlgorithm(AlgorithmId algorithmId, ResultSubscriptionType subscription)
        {
            if (subscription == 0)
            {
                throw new ArgumentOutOfRangeException(nameof(subscription), "No data has been subscribed");
            }

            var result = await _cache.GetOrCreateObject(algorithmId.DeployId, () => new AlgorithmResult
            {
                AlgorithmId = algorithmId,
            });

            // Check whether we need to update live results
            if ((subscription & ResultSubscriptionType.LiveResults) != 0)
            {
                try
                {
                    var remoteLiveAlgorithmResults = await _apiService.Api.GetLiveAlgorithmResultsAsync(algorithmId.ProjectId, algorithmId.DeployId);

                    _apiResultParser.ProcessLiveResult(result, remoteLiveAlgorithmResults);
                }
                catch (Exception ex)
                {
                    // TODO: Log
                }
            }

            // Check whether we need to update the log
            if ((subscription & ResultSubscriptionType.Log) != 0)
            {
                try
                {
                    // var logResults = await _apiService.Api.GetLiveAlgorithmLogs(algorithmId.ProjectId, algorithmId.DeployId);
                    // _apiResultParser.ProcessLogResult(result, logResults);
                }
                catch
                {
                    // TODO: Log
                }
            }

            // Fire the result event
            OnAlgorithmResultUpdated(new AlgorithmResultEventArgs(result));

            // Cache the result
            await _cache.InsertObject(algorithmId.DeployId, result);
        }
コード例 #3
0
 public void Subscribe(AlgorithmId algorithmId, ResultSubscriptionType resultSubscriptionType) => _algorithmResultProvider.Subscribe(algorithmId, resultSubscriptionType);