public void Test_1_Post() { // Arrange var c = new QuestController(); c.Request = new HttpRequestMessage(); c.Configuration = new HttpConfiguration(); var pr = new ProgressRequest() { PlayerId = player_name, PlayerLevel = 1, ChipAmountBet = 233 }; // Act var r = c.Post(pr); var cr = r as OkNegotiatedContentResult <ProgressResponse>; // Assert Assert.IsNotNull(r); Assert.IsNotNull(cr); Assert.IsNotNull(cr.Content); Assert.IsTrue(cr.Content.QuestPointsEarned > 0); }
/*public void Progress() * { * var fileProgressReporter = CreateFileProgressReporter(); * WindowRequest.Raise(new FileTransferProgressViewModel * { * Title = "Progress", * ProgressReporter = fileProgressReporter * }); * }*/ public void Progress() { /*var fileProgressReporter = CreateFileProgressReporter(); * ProgressRequest.Raise(new FileTransferProgressViewModel * { * Title = "Progress", * ProgressReporter = fileProgressReporter * });*/ ProgressRequest.Raise(new FileTransferProgressTestViewModel()); }
public IHttpActionResult Post([FromBody] ProgressRequest pr) { try { var prc = QuestHandler.Instance.GetProgress(pr); return(Ok(prc)); } catch (Exception ex) { return(InternalServerError(ex)); } }
private ProgressResponse GetProgress(string name) { // Arrange var qh = QuestHandler.Instance; var pq = new ProgressRequest() { PlayerId = name, PlayerLevel = 1, ChipAmountBet = 233 }; // Act var pr = qh.GetProgress(pq); // Assert Assert.IsTrue(pr.QuestPointsEarned > 0); Assert.IsTrue(pr.TotalQuestPercentCompleted > 0.0); return(pr); }
private void CompleteAfterDelay(string token, ProgressRequest request) { CancellationTokenSource linkedCTS; lock (request.RequestLock) { CancelAndDisposeToken(request.TimeoutCancellationTokenSource); request.TimeoutCancellationTokenSource = new CancellationTokenSource(); linkedCTS = CancellationTokenSource.CreateLinkedTokenSource( request.TimeoutCancellationTokenSource.Token, request.HandlerCancellationToken); } _ = CompleteAfterDelayAsync(token, request.TimeoutAfterLastNotify, linkedCTS); // Fire and forget async Task CompleteAfterDelayAsync(string token, TimeSpan delay, CancellationTokenSource cts) { try { await Task.Delay(delay, cts.Token).ConfigureAwait(false); } catch (TaskCanceledException) { // Task cancelled, new progress notification received. // Don't allow handler to return return; } finally { // Dispose of the Linked Cancellation Token Source // Note: The component TimeoutCancellationTokenSource & HandlerCancellationToken // should not be impacted. Their lifecycle is managed using CancelAndDisposeToken // and the platform handler, respectively. cts.Dispose(); } ProgressCompleted(token); } }
public ProgressResponse GetProgress(ProgressRequest pr) { // calculate points for this round long qpa = GetQuestPoint(pr.ChipAmountBet, pr.PlayerLevel); // get player data var pp = pdm.GetOrCreatePlayer(pr.PlayerId); // add qpa to total player saved long qpe = qpa + pp.PointsEarned; pp.PointsEarned = qpe; // update total points earned // get player current quest Quest qq = qcm.GetQuest(pp.QuestIndex).Value; // calc total quest % complete double qpc = GetTotalQuestPercentCompleted(qpe, qq.PointsCompleted); // calc milestone completed var ms = GetMileStoneCompleted(qq, pp); // update & save player latest info pp.MilestoneIndex = ms == null ? pp.MilestoneIndex : ms.MilestoneIndex; pdm.Save(pp); // determine if quest leveled up to new quest! LeveledUpQuest(qq, pp); var prc = new ProgressResponse() { QuestPointsEarned = qpe, TotalQuestPercentCompleted = qpc, MilestonesCompleted = ms }; return(prc); }
public override bool TryListenForProgress( string token, Func <JToken, CancellationToken, Task> onProgressNotifyAsync, TimeSpan timeoutAfterLastNotify, CancellationToken handlerCancellationToken, out Task onCompleted) { var onCompletedSource = new TaskCompletionSource <bool>(); var request = new ProgressRequest( onProgressNotifyAsync, timeoutAfterLastNotify, handlerCancellationToken, onCompletedSource); if (!_activeRequests.TryAdd(token, request)) { onCompleted = null; return(false); } CompleteAfterDelay(token, request); onCompleted = onCompletedSource.Task; return(true); }
public Wizard GetProgress(ProgressRequest request) { var proxy = _planningService.CreateProxy(); return(proxy.GetProgress(request)); }
public Wizard GetProgress(ProgressRequest request) { var wizardId = request.PlanningWizardID; var userId = request.UserID; var wizard = _planningRepository.FindBy <Wizard>(w => w.PlanningWizardID == wizardId) .Include("Phases") .Include("Phases.Steps") .Include("Phases.Steps.ActionItems") .FirstOrDefault(); if (wizard == null) { throw new Exception("Invalid Planning Wizard Id: " + wizardId); } var progress = _planningRepository.FindBy <Progress>(p => p.UserID == userId && p.PlanningWizardID == wizardId).FirstOrDefault(); if (progress == null) { progress = new Progress() { PlanningWizardID = wizardId, UserID = userId, CreateDate = DateTime.Now, CreateDateUtc = DateTime.UtcNow, ModifyDate = DateTime.Now, ModifyDateUtc = DateTime.UtcNow, CreateUserID = userId, ModifyUserID = userId, CurrentPlanningWizardPhaseID = wizard.Phases.First().PlanningWizardPhaseID, PercentComplete = 0, ProgressXml = wizard.Phases.ToXml() }; _planningRepository.Add(progress); _planningRepository.Save(); } // Re-hydrate progress.Phases = progress.ProgressXml.FromXml <List <Phase> >(); // Set progress as property wizard.Progress = progress; // Merge with Wizard data foreach (var progressPhase in progress.Phases) { var phase = wizard.Phases.First(p => p.PlanningWizardPhaseID == progressPhase.PlanningWizardPhaseID); phase.IsSelected = phase.PlanningWizardPhaseID.Equals(progress.CurrentPlanningWizardPhaseID); foreach (var progressStep in progressPhase.Steps) { var step = phase.Steps.First(s => s.PlanningWizardStepID == progressStep.PlanningWizardStepID); step.Notes = progressStep.Notes; step.IsSelected = progressStep.IsSelected; foreach (var progressActionItem in progressStep.ActionItems) { var actionItem = step.ActionItems.First(a => a.PlanningWizardActionItemID == progressActionItem.PlanningWizardActionItemID); actionItem.IsComplete = progressActionItem.IsComplete; actionItem.CompleteDate = progressActionItem.CompleteDate; actionItem.CompleteDateUtc = progressActionItem.CompleteDateUtc; } } } return(wizard); }
public void Send_And_Receive_Continuous_Request_With_Error() { ResonanceTransporter t1 = new ResonanceTransporter(new InMemoryAdapter("TST")); ResonanceTransporter t2 = new ResonanceTransporter(new InMemoryAdapter("TST")); t1.Connect(); t2.Connect(); t2.RequestReceived += (s, e) => { ProgressRequest receivedRequest = e.Message.Object as ProgressRequest; Task.Factory.StartNew(() => { for (int i = 0; i < receivedRequest.Count; i++) { t2.SendResponse(new ProgressResponse() { Value = i }, e.Message.Token); Thread.Sleep(receivedRequest.Interval); } t2.SendErrorResponse("Test Exception", e.Message.Token); Thread.Sleep(receivedRequest.Interval); t2.SendResponse(new ProgressResponse() { Value = receivedRequest.Count }, e.Message.Token, new ResonanceResponseConfig() { Completed = true }); }); }; int currentValue = -1; bool isCompleted = false; bool hasError = false; var request = new ProgressRequest() { Count = 100, Interval = TimeSpan.FromMilliseconds(30) }; var subscription = t1.SendContinuousRequest <ProgressRequest, ProgressResponse>(request).Subscribe((response) => { //Response Assert.IsTrue(response.Value == currentValue + 1); currentValue = response.Value; }, (ex) => { //Error hasError = true; Assert.AreEqual(ex.Message, "Test Exception"); }, () => { //Completed isCompleted = true; }); Assert.ThrowsException <ResonanceResponseException>(() => { subscription.Wait(); }, "Test Exception"); Assert.AreEqual(currentValue, request.Count - 1); Assert.IsFalse(isCompleted); Assert.IsTrue(hasError); t1.Dispose(true); t2.Dispose(true); }