Exemplo n.º 1
0
        public void Update(string playerID)
        {
            Data.Clear();

            PlayerData playerData = null;

            Match[] recentMatches = null;

            CTSource?.Cancel();
            CTSource = new CancellationTokenSource();

            CancellationToken cancelToken = CTSource.Token;

            RetrievalStarted?.Invoke(this, null);

            Task.Factory.StartNew(() =>
            {
                if (!cancelToken.IsCancellationRequested)
                {
                    playerData = OpenDotaAPI.GetPlayerData(playerID);
                }
                if (!cancelToken.IsCancellationRequested)
                {
                    recentMatches = OpenDotaAPI.GetPlayerMatches(playerID, 20, Settings.Instance.GetDaysLimit(), Settings.Instance.GetLobbyType());
                }

                if (!cancelToken.IsCancellationRequested)
                {
                    Data.ConsumeData(playerID, playerData, recentMatches);
                }
            }, cancelToken).ContinueWith((t) =>
            {
                RetrievalCompleted?.Invoke(this, null);
            });
        }
Exemplo n.º 2
0
        public async Task UpdateAsync(string playerId, int lobby)
        {
            Data.Clear();
            Match[] recentMatches = null;

            CtSource?.Cancel();
            CtSource = new CancellationTokenSource();

            var cancelToken = CtSource.Token;

            RetrievalStarted?.Invoke(this, null);

            await Task.Factory.StartNew(() =>
            {
                if (!cancelToken.IsCancellationRequested)
                {
                    recentMatches = OpenDotaApi.GetPlayerMatches(playerId, lobby);
                }

                if (!cancelToken.IsCancellationRequested)
                {
                    Data.ConsumeRecentMatches(recentMatches);
                }
            }, cancelToken).ContinueWith(t => RetrievalCompleted?.Invoke(this, null), cancelToken);
        }