public Promise Start(Student student, Activity activity, bool resetActivityState = false)
		{
			Promise promise = new Promise();

			try
			{
				ActivityState activityState = null;

				activityService.LoadActivityState(student.Id, activity.Id, true).ThenAs<ActivityState>((ActivityState state) =>
				{
					activityState = state;
					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));
//					}	

					promise.Resolve(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";
//					}));

					return true;
				})
				.Catch((Exception e) => 
				{
					promise.Reject(e);
				});                 
			}
			catch (Exception e)
			{
				promise.Reject(e);
			}

			return promise;
		}
Esempio n. 2
0
		public void OnClicked(Activity activity)
		{
			ViewModel.StartActivity(activity);
		}
		public void StartActivity(Activity activity)
		{
			try
			{
				Contract.ArgumentNotNull("activity", activity);
				
				DebugLog.Info("Started Activity {0}", activity.Name);

                navigator.Reveal<ProgressIndicatorViewModel>().ThenAs<ProgressIndicatorViewModel>((ProgressIndicatorViewModel progressIndicatorViewModel) =>
                {
                    ProgressIndicatorViewModel.ProgressInfo busyIndicator = progressIndicatorViewModel.Begin("Starting...");
                    activityLauncher.Start(sessionState.Student, activity, false)
                    .ThenAs<ViewModel>((ViewModel activityViewModel) =>
                    {
                        navigator.Transition(this, activityViewModel);
                        return true;
                    })
                    .Catch((Exception e) =>
                           {
                               navigator.Reveal<AlertViewModel>(alert =>
                                                                {
                                                                    alert.Title = "Unable to start activity";
                                                                    alert.Message = e.Message;
                                                                    alert.Error = e;
                                                                    alert.AlertDismissed += ((int index) => DebugLog.Info("Button {0} pressed", index));
                                                                });

                           }).Finally(() =>
                           {
                               busyIndicator.Dispose();
                           });
                    return true;
                });
			}
			catch (Exception e)
			{
				navigator.Reveal<AlertViewModel>(alert => 
				                                 {
					alert.Title = "Unable to start activity";
					alert.Message = e.Message;
					alert.Error = e;
				});
			}
		}