Ejemplo n.º 1
0
        public void Start(IProjectionTrack track, DaemonLifecycle lifecycle, CancellationToken token = default(CancellationToken))
        {
            _track = track;

            if (_fetchingTask != null && !_fetchingTask.IsCompleted)
            {
                throw new InvalidOperationException("The Fetcher is already started!");
            }

            if (State == FetcherState.Active)
            {
                return;
            }

            _token = token;

            State = FetcherState.Active;

            if (track.LastEncountered > _lastEncountered)
            {
                _lastEncountered = track.LastEncountered;
            }

            _logger.FetchStarted(track);

            _fetchingTask =
                Task.Run(() => fetchEvents(track, lifecycle), token)
                .ContinueWith(t =>
            {
                _logger.FetchingStopped(track);
            }, token, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
        }
Ejemplo n.º 2
0
        public void Start(IProjectionTrack track, DaemonLifecycle lifecycle, CancellationToken token = default(CancellationToken))
        {
            _track = track;

            if (_fetchingTask != null && !_fetchingTask.IsCompleted)
            {
                throw new InvalidOperationException("The Fetcher is already started!");
            }

            if (State == FetcherState.Active)
            {
                return;
            }

            _token = token;

            State = FetcherState.Active;

            if (track.LastEncountered > _lastEncountered)
            {
                _lastEncountered = track.LastEncountered;
            }

            _logger.FetchStarted(track);

            _fetchingTask =
                Task.Factory.StartNew(async() =>
            {
                await fetchEvents(track, lifecycle).ConfigureAwait(false);
            },
                                      token, TaskCreationOptions.LongRunning, TaskScheduler.Default)
                .ContinueWith(t =>
            {
                _logger.FetchingStopped(track);
            }, token);
        }