public AsyncTask Start(Student student, Activity activity, bool resetActivityState = false) { return(activityService.LoadActivityState(student.Id, activity.Id, true) .Then((prevResult, onCompleted, onError) => { ActivityState activityState = prevResult.ResultAs <ActivityState>(); if (resetActivityState || !activityState.CanResume) { // Generate a new trace ID for restarts or new games that don't have saved state activityState.TraceId = Guid.NewGuid().ToString(); } DebugLog.Info("Start activity!"); // startedEntry = TraceLog.Player(TraceLog.Action.Started, "Activity", // "Name", activity.Name, // "ActivityUri", activity.Uri, // "IsComplete", activityState.IsComplete, // "CanResume", activityState.CanResume, // "Restart", resetActivityState, // "StartDate", activityState.ModifiedDate.ToIso8601(), // "Username", student.Username, // "SubjectId", student.SubjectId, // "TraceId", activityState.TraceId); // // if (activity.Uri.Contains("episode")) // { // LaunchEpisode(activityState, activity.Name, activity.Uri, resetActivityState); // } // else if (activity.Uri.Contains("assessment")) // { // LaunchAssessment(activityState, activity.Name, activity.Uri); // } // else if (activity.Uri.Contains("http")) // { // LaunchUrl(activityState, activity.Name, activity.Uri); // } // else // { // throw new Exception(String.Format("{0} has an unknown URI type: ", activity.Name, activity.Uri)); // } onCompleted(viewModelFactory.Resolve <ActivityViewModel>(Resolve(activity.Uri), vm => { vm.Activity = activity; vm.ActivityState = activityState; })); // promise.Resolve(viewModelFactory.Resolve<WebActivityViewModel>(web => // { // web.Title = "Web Browser Launched"; // web.Message = "Complete web viewer action for " + activity.Name; // web.URL = "http://www.google.com"; // })); })); }
public AsyncTask SaveActivityState(ActivityState activityState) { Contract.ArgumentNotNull("activityState", activityState); return(new AsyncTask((prevResult, onCompleted, onError) => { try { Uri serverUri = new Uri(appSettings.ServerURI, UriKind.RelativeOrAbsolute); Uri restUri = new Uri(serverUri, "rest/"); ActivityStateRepository repo = new ActivityStateRepository(restUri); if (repo == null) { throw new Exception("ActivityStateRepository is not initialized."); } // Load ActivityState (if it exists) repo.Update(activityState, (ActivityStateRepository.Response response) => { try { if (response.Success) { onCompleted(response.Item); } else { onError(new Exception(response.Error)); } } catch (Exception e) { onError(e); } }); } catch (Exception e) { onError(e); } })); }
private void LaunchEpisode(ActivityState activityState, string activityName, string episodeUrn, bool restart = false) { // Episode episode = Episode.All.FirstOrDefault(e => String.Compare(e.Urn, episodeUrn, StringComparison.CurrentCultureIgnoreCase) == 0); // if (episode != null) // { // Action startGameAction = () => // { // if (restart) // { // // Clear previous save data // activityState.Restart(); // } // // activityState.RecordLaunch(); // // SaveActivityState("Launching", false, activityState, // (bool success, ActivityState savedActivityState, string error) => // { // GameViewModel.Instance.StartGame(episode, activityName, savedActivityState, ActivityEnded); // }); // }; // // // TODO rgtaylor 2015-12-16 Refactor //// if (EyeTrackingService.Instance.IsEnabled) //// { //// EyeTrackingService.Instance.Initialize(); //// EyeTrackingService.Instance.Calibrate(startGameAction); //// } //// else // { // startGameAction(); // } // } // else // { // throw new Exception(String.Format("The '{0}' activity is not supported.", activityName)); // } }
public Promise SaveActivityState(ActivityState activityState) { Contract.ArgumentNotNull("activityState", activityState); Promise promise = new Promise(); try { Uri serverUri = new Uri(appSettings.ServerURI, UriKind.RelativeOrAbsolute); Uri restUri = new Uri(serverUri, "rest/"); ActivityStateRepository repo = new ActivityStateRepository(restUri); if (repo == null) { throw new Exception("ActivityStateRepository is not initialized."); } // Load ActivityState (if it exists) repo.Update(activityState, (ActivityStateRepository.Response response) => { try { if (response.Success) { promise.Resolve(response.Item); } else { promise.Reject(new Exception(response.Error)); } } catch (Exception e) { promise.Reject(e); } }); } catch (Exception e) { promise.Reject(e); } return promise; }
public Promise LoadActivityState(string studentId, string activityId, bool createNewIfDoesNotExit = false) { Promise promise = new Promise(); try { Uri serverUri = new Uri(appSettings.ServerURI, UriKind.RelativeOrAbsolute); Uri restUri = new Uri(serverUri, "rest/"); ActivityStateRepository repo = new ActivityStateRepository(restUri); if (repo == null) { throw new Exception("ActivityStateRepository is not initialized."); } // Load ActivityState (if it exists) repo.GetActivityStates(studentId, new string[] { activityId }, (ActivityStateRepository.Response loadResponse) => { try { if (loadResponse.Success) { if (loadResponse.Items != null && loadResponse.Items.Count > 0) { promise.Resolve(loadResponse.Items.OrderByDescending(s => s.ModifiedDate).First()); } else { // Create ActivityState ActivityState newState = new ActivityState() { ActivityId = activityId, StudentId = studentId }; repo.Insert(newState, (ActivityStateRepository.Response insertResponse) => { if (insertResponse.Success) { promise.Resolve(insertResponse.Item); } else { promise.Reject(new Exception(insertResponse.Error)); } }); } } else { promise.Reject(new Exception(loadResponse.Error)); } } catch (Exception e) { promise.Reject(e); } }); } catch (Exception e) { promise.Reject(e); } return promise; }
public AsyncTask LoadActivityState(string studentId, string activityId, bool createNewIfDoesNotExit = false) { return(new AsyncTask((prevResult, onCompleted, onError) => { try { Uri serverUri = new Uri(appSettings.ServerURI, UriKind.RelativeOrAbsolute); Uri restUri = new Uri(serverUri, "rest/"); ActivityStateRepository repo = new ActivityStateRepository(restUri); if (repo == null) { throw new Exception("ActivityStateRepository is not initialized."); } // Load ActivityState (if it exists) repo.GetActivityStates(studentId, new string[] { activityId }, (ActivityStateRepository.Response loadResponse) => { try { if (loadResponse.Success) { if (loadResponse.Items != null && loadResponse.Items.Count > 0) { onCompleted(loadResponse.Items.OrderByDescending(s => s.ModifiedDate).First()); } else { // Create ActivityState ActivityState newState = new ActivityState() { ActivityId = activityId, StudentId = studentId }; repo.Insert(newState, (ActivityStateRepository.Response insertResponse) => { if (insertResponse.Success) { onCompleted(insertResponse.Item); } else { onError(new Exception(insertResponse.Error)); } }); } } else { onError(new Exception(loadResponse.Error)); } } catch (Exception e) { onError(e); } }); } catch (Exception e) { onError(e); } })); }