/// <summary> /// Loads the shelvesets of the user which name is currently in the Codestriker Integration Window /// </summary> private async void RefreshExecute() { ErrorText = string.Empty; IsCreateTopicPending = true; FetchState state = await m_TfsHelper.FetchProjectsAsync(TfsUsername); IsCreateTopicPending = false; switch (state) { case FetchState.UserNotFound: Project = new ProjectData(); ErrorText = Resources.UserNotFound; break; case FetchState.UserNotLoggedIn: ErrorText = Resources.UserNotLoggedIn; break; case FetchState.NoProject: ErrorText = Resources.NoProjectsFound; break; case FetchState.Successful: // nothing to do here break; default: throw new ArgumentOutOfRangeException(); } }
private void HandleGetTocInfo(byte[] payload) { if (_useV2) { _nbrOfItems = BitConverter.ToUInt16(payload.Take(2).ToArray(), 0); payload = payload.Skip(2).ToArray(); } else { _nbrOfItems = payload[0]; payload = payload.Skip(1).ToArray(); } _crc = BitConverter.ToUInt32(payload, 0); _log.Debug($"Got TOC CRC, {_nbrOfItems} items and crc=0x{_crc.ToString("X")}"); var cached = _tocCache.GetByCrc(_crc); if (cached != null) { _toc.AddFromCache(cached); _log.Info($"TOC found in cache with crc {_crc} "); TocFetchFinished(); } else { _fetchState = FetchState.GET_TOC_ELEMENT; _requestedIndex = 0; RequestTocElement(_requestedIndex); } }
FetchResult Fetch(ReportingTask<FetchResult> taskContext, FetchState state) { // Get the charts taskContext.Description = "Fetching weekly charts list"; var chartsResponse = client.UserGetWeeklyChartList(state.User); if (chartsResponse.StatusCode == StatusCode.Failed) throw new InvalidOperationException("This user does not exist, or it doesn't have any weekly chart generated yet ('" + chartsResponse.Error.Message + "')"); // Get the tracks... taskContext.TotalItems = chartsResponse.Content.Charts.Length; // ...in parallel! Parallel.ForEach(chartsResponse.Content.Charts, () => { var thisWeek = new List<ScrobbledTrack>(); state.WeeklyTracks.Enqueue(thisWeek); return thisWeek; }, (range, index, parallelState) => { if (taskContext.Task.IsCanceled) // Allow mid-operation canceling parallelState.Stop(); taskContext.Description = "Fetching weekly chart starting " + range.From.ToShortDateString(); var tracksResponse = client.UserGetWeeklyTrackChart(state.User, range.From, range.To); if (tracksResponse.StatusCode == StatusCode.Failed) state.Errors.Enqueue(new QualifiedError(range.From.ToShortDateString() + " to " + range.To.ToShortDateString(), "'" + tracksResponse.Error.Message + "' (scrobbles from that week were ignored)")); else if (tracksResponse.Content.Tracks != null) // This does happen sometimes parallelState.ThreadLocalState.AddRange(from track in tracksResponse.Content.Tracks select new ScrobbledTrack(track.Artist.Name, track.Title, track.PlayCount, range.To)); taskContext.ReportItemCompleted(); }); // Early out if (taskContext.Task.IsCanceled) return null; // Compose results taskContext.Description = "Assembling charts"; var trackSet = new Dictionary<string, ScrobbledTrack>(); foreach (var track in state.WeeklyTracks.SelectMany(x => x)) { ScrobbledTrack contained; string key = track.Artist + track.Title; if (trackSet.TryGetValue(key, out contained)) { contained.PlayCount += track.PlayCount; if (track.WeekLastPlayed > contained.WeekLastPlayed) contained.WeekLastPlayed = track.WeekLastPlayed; } else trackSet.Add(key, track); } return new FetchResult(trackSet.Values.ToArray(), state.Errors.ToArray()); }
/// <summary> /// returns the toc which is asynchronously completed. /// </summary> internal Toc <T> Start() { _toc = new Toc <T>(); _fetchState = FetchState.GET_TOC_INFO; _communicator.RegisterEventHandler(_port, TocPacketReceived); SendTocInfoRequest(); return(_toc); }
public void RegFetchTexture2D(CTexture2D tex, FOnGpuFinished cb) { for (int i = 0; i < WaitGpuFinishResources.Count; i++) { if (WaitGpuFinishResources[i].Texture2D == tex) { return; } } var state = new FetchState(); state.Texture2D = tex; state.OnGpuFinished = cb; state.TickFrame = 4; WaitGpuFinishResources.Add(state); }
public void TestFetchSendsSuccessToCallbackAfterRedirect2() { ManualResetEvent completion = new ManualResetEvent(false); bool failed = false; _producerContext = new SettableProducerContext( ImageRequest.FromUri(SUCCESS_REDIRECT_URL2), SUCCESS_REDIRECT_URL2, _producerListener, new object(), RequestLevel.FULL_FETCH, false, true, Priority.MEDIUM); _fetchState = new FetchState(_consumer, _producerContext); _fetcher.Fetch( _fetchState, new NetworkFetcherCallbackImpl( (response, responseLength) => { Assert.IsTrue(response != null); Assert.IsTrue(responseLength == -1); completion.Set(); }, (throwable) => { failed = true; completion.Set(); }, () => { failed = true; completion.Set(); })); // Wait for callback completion.WaitOne(); Assert.IsFalse(failed); }
public void TestFetchSendsErrorToCallbackAfterHttpError() { ManualResetEvent completion = new ManualResetEvent(false); bool failed = false; _producerContext = new SettableProducerContext( ImageRequest.FromUri(FAILURE_URL), FAILURE_URL, _producerListener, new object(), RequestLevel.FULL_FETCH, false, true, Priority.MEDIUM); _fetchState = new FetchState(_consumer, _producerContext); _fetcher.Fetch( _fetchState, new NetworkFetcherCallbackImpl( (response, responseLength) => { failed = true; completion.Set(); }, (throwable) => { Assert.IsTrue(throwable.GetType() == typeof(IOException)); completion.Set(); }, () => { failed = true; completion.Set(); })); // Wait for callback completion.WaitOne(); Assert.IsFalse(failed); }
public FetchInfo(FetchInfo rhs) { this.State = rhs.State; this.Since = rhs.Since; this.RequestType = rhs.RequestType; }
public FetchInfo() { State = FetchState.New; Since = DateTime.Now; RequestType = String.Empty; }
public VirtualButton(PlayerInput input, FetchState fetcher) { this.input = input; this.fetcher = fetcher; }
FetchResult Fetch(ReportingTask <FetchResult> taskContext, FetchState state) { // Get the charts taskContext.Description = "Fetching weekly charts list"; var chartsResponse = client.UserGetWeeklyChartList(state.User); if (chartsResponse.StatusCode == StatusCode.Failed) { throw new InvalidOperationException("This user does not exist, or it doesn't have any weekly chart generated yet ('" + chartsResponse.Error.Message + "')"); } var lastWeekFetched = chartsResponse.Content.Charts.Max(x => x.From); // Get the tracks... taskContext.TotalItems = chartsResponse.Content.Charts.Length; // ...in parallel! Parallel.ForEach(chartsResponse.Content.Charts, () => { var thisWeek = new List <ScrobbledTrack>(); state.WeeklyTracks.Enqueue(thisWeek); return(thisWeek); }, (range, parallelState, output) => { // Allow mid-operation canceling if (taskContext.CancellationTokenSource.Token.IsCancellationRequested) { parallelState.Stop(); } // Skip weeks that have already been imported or fetched if (range.From > state.FirstWeek) { taskContext.Description = "Fetching weekly chart starting " + range.From.ToShortDateString(); var tracksResponse = client.UserGetWeeklyTrackChart(state.User, range.From, range.To); if (tracksResponse.StatusCode == StatusCode.Failed) { state.Errors.Enqueue(new QualifiedError(range.From.ToShortDateString() + " to " + range.To.ToShortDateString(), "'" + tracksResponse.Error.Message + "' (scrobbles from that week were ignored)")); } else if (tracksResponse.Content.Tracks != null) // This does happen sometimes { output.AddRange(from track in tracksResponse.Content.Tracks select new ScrobbledTrack(track.Artist, track.Title, track.PlayCount, range.To)); } } taskContext.ReportItemCompleted(); return(output); }, ActionUtil.NullAction); // Early out if (taskContext.CancellationTokenSource.Token.IsCancellationRequested) { taskContext.CancellationTokenSource.Token.ThrowIfCancellationRequested(); } // Compose results taskContext.Description = "Assembling charts"; var trackSet = new Dictionary <ScrobbledTrack, ScrobbledTrack>(); foreach (var track in state.WeeklyTracks.SelectMany(x => x)) { ScrobbledTrack contained; if (trackSet.TryGetValue(track, out contained)) { contained.PlayCount += track.PlayCount; if (track.WeekLastPlayed > contained.WeekLastPlayed) { contained.WeekLastPlayed = track.WeekLastPlayed; } } else { trackSet.Add(track, track); } } return(new FetchResult(trackSet.Values.ToList(), state.Errors.ToArray(), lastWeekFetched)); }