Exemple #1
0
		public async Task<bool> RunBackroundSync (int gymID, ProgressClass progressClass)
		{
			bool returnValue = true;
			if (CrossConnectivity.Current.IsConnected) {
				try {

					//Sync template created on the device but not on the server
					await WorkoutTemplateDAL.SyncServerTemplates (gymID);
					progressClass.FireEvent (1, 7);
					//Syn dirty exercise templates with the server
					await FeedbackSubmissionDAL.ResubmitFailtFeedbackSubmissionPosts (gymID);
					progressClass.FireEvent (3, 7);

					//Sync templates witht the server
					progressClass.FireEvent (4, 7);
					await WorkoutTemplateDAL.LoadTemplates (gymID);

//					//Sync local user assigned templates with server
//					await UserDAL.SyncLocalUserAssignedTemplateWithServer (gymID);
                	
					//Sync local UserExerciseGroups and UserWorkoutTemplateMappings with the server
					await Manager.Instance.UserExerciseGroup.SyncLocalUserExerciseGroupsAndUserWorkoutTemplateMappingsWithServer (gymID);
					//progressClass.FireEvent(7, 7);

					//Sync users and exercises mapped to users
					progressClass.FireEvent (5.5, 7);
					await UserDAL.LoadUsers (gymID);
					progressClass.FireEvent (7, 7);
					//Replace current exercises if its been over 1 day since last replace
					await ExerciseDAL.CreateExercises (gymID);

					//Send errors back to the server
					await ErrorLogDAL.SendErrorLogToServer (gymID);

					//Send local engagement notes not added to the API
					returnValue = await SyncEngagementNotes (gymID, returnValue);

					//Send member goals not added to the API
					returnValue = await SyncMemberGoals (gymID, returnValue);

					//Delete member goals not deleted in the API
					returnValue = await SyncMemberGoalsDeletion (gymID, returnValue);

					//Send member barriers not added to the API
					returnValue = await SyncMemberBarriers (gymID, returnValue);

					//Delete member barriers not deleted in the API
					returnValue = await SyncMemberBarriersDeletion (gymID, returnValue);

				} catch (Exception e) {
					returnValue = false;
					Manager.Instance.ErrorLog.AddErrorLogRecord (e, DateTime.UtcNow, gymID, "RunBackroundSync", "", e.Message, e.StackTrace);
				}
			}
			return returnValue;
		}
		public PrimaryOptionsPage (Task taskResponder = null, ProgressClass progressClass = null)
		{
			InitializeComponent ();
			_viewModel = new PrimaryOptionsViewModel (Manager.Instance.StaffMember, App.WorkoutCreatorContext);

            //Subscribe to messages to check need to display feedback outbox
            MessagingCenter.Subscribe<ModalWorkoutCreationPage>(this, "Check for dirty feedback", (sender) =>
            {
                this.ProcessFeedbackOutbox();
            });

            MessagingCenter.Subscribe<FeedbackOutboxPage>(this, "Check for dirty feedback", (sender) =>
            {
                this.ProcessFeedbackOutbox();
            });
					
			if (taskResponder != null) {
                progressClass.ProgressEvent += ((sender, args) =>
                {
                    DependencyService.Get<ICustomLoader>().UpdateProgress((float)progressClass.CurrentPercentage);
                });

                Device.BeginInvokeOnMainThread(() =>
                {
                    DependencyService.Get<ICustomLoader>().Display("Loading branch inventory...");
                });
                

				createTemplateButton.IsVisible = false;
                assignTemplateButton.IsVisible = false;
                viewMemberTemplateButton.IsVisible = false;
               
				Action<Task> action =
					(str) =>
					Device.BeginInvokeOnMainThread ( () => {
                        createTemplateButton.IsVisible = true;
                        assignTemplateButton.IsVisible = true;
                        viewMemberTemplateButton.IsVisible = true;
                        DependencyService.Get<ICustomLoader>().Hide();
					});
				taskResponder.ContinueWith(action);
			}

			createTemplateButton.Clicked += async (sender2, args2) =>
			{
				//Uses session tracking
				Insights.Track("Record Workout Clicked", new Dictionary<string, string>()
					{
					});
				await Navigation.PushAsync (new ExerciseContainerPage ());
			};

			assignTemplateButton.Clicked += async (sender2, args2) => {
				//Uses session tracking
				Insights.Track("Assign Workout Clicked", new Dictionary<string, string>()
					{
					});
				await Navigation.PushAsync (new TemplateListPage ());
			};

			viewMemberTemplateButton.Clicked += async (sender2, args2) =>
			{
				//Uses session tracking
				Insights.Track("Review Workout Clicked", new Dictionary<string, string>()
					{
					});
				await Navigation.PushAsync (new MemberTemplatesListPage ());
			};

            ProcessFeedbackOutbox();
		}