Esempio n. 1
0
		//private static readonly AsyncLock Mutex = new AsyncLock ();

		public async static void AddModifyServerSyncTrackingRecord(APISyncTracking syncTrackingRecord)
		{



			var db = DependencyService.Get<ISQLite>().GetAsyncConnection();
			await db.CreateTableAsync<APISyncTracking>();
			if (syncTrackingRecord.Id == 0)
			{
				await db.InsertAsync(syncTrackingRecord);
			}
			else {
				await db.UpdateAsync(syncTrackingRecord);
			}


		}
Esempio n. 2
0
		private async static Task<bool> SyncTemplatesWithServer(int gymID, string getServiceType, string dateString)
		{
			bool returnValue = false;
			try
			{
				var workoutTemplateDTOList = await CoachServices.SyncTemplatesWithServer(gymID, dateString);

				if (workoutTemplateDTOList.Count > 0)
				{



					foreach (WorkoutTemplate workoutTemplateDTO in workoutTemplateDTOList)
					{
						DateTime lastTimeUpdateDateTime = DateTime.Parse(workoutTemplateDTO.LastUpdatedTime);

						WorkoutTemplate workoutTemplate = await WorkoutTemplateDAL.GetWorkoutTemplateByServerTemplateID(gymID, workoutTemplateDTO.WorkoutTemplateID);
						if (workoutTemplate == null)
						{
							workoutTemplate = new WorkoutTemplate();
						}
						//add workout template property values
						workoutTemplate.TemplateName = workoutTemplateDTO.TemplateName;
						workoutTemplate.TemplateDescription = workoutTemplateDTO.TemplateDescription;
						workoutTemplate.GymID = workoutTemplateDTO.GymID;
						workoutTemplate.LastUpdatedTimeDT = lastTimeUpdateDateTime;
						workoutTemplate.WorkoutTemplateID = workoutTemplateDTO.WorkoutTemplateID;

						//add or modify in the database
						await WorkoutTemplateDAL.AddModifyTemplate(workoutTemplate);

						//Determine if there are exercises that need to be mapped to the user. If so, map them
						var workoutTemplateExercises = workoutTemplateDTO.WorkoutTemplateExercises;
						if (workoutTemplateExercises != null)
						{
							if (workoutTemplateExercises.Count > 0)
							{
								List<WorkoutTemplateMapping> workoutTemplateMappingList = new List<WorkoutTemplateMapping>();
								foreach (var workoutExercise in workoutTemplateExercises)
								{
									string lastUpdatedTimeString = workoutExercise.LastUpdatedTime;
									DateTime lastUpdatedTime = DateTime.Parse(lastUpdatedTimeString);

									//Create a workouttemplatemapping model object
									WorkoutTemplateMapping workoutTemplateMapping = new WorkoutTemplateMapping();
									workoutTemplateMapping.ExerciseID = workoutExercise.ExerciseID;
									workoutTemplateMapping.Sets = workoutExercise.TargetSets;
									workoutTemplateMapping.Reps = workoutExercise.TargetReps;

									workoutTemplateMapping.TargetDurationMin = workoutExercise.TargetDurationMin;
									workoutTemplateMapping.TargetHRMin = workoutExercise.TargetHRMin;
									workoutTemplateMapping.TargetHRMax = workoutExercise.TargetHRMax;

									workoutTemplateMapping.ExerciseSequence = workoutExercise.ExerciseSequence;
									workoutTemplateMapping.LastUpdatedTime = lastUpdatedTime;
									workoutTemplateMapping.WorkoutTemplateID = workoutTemplate.Id;
									workoutTemplateMappingList.Add(workoutTemplateMapping);

								}
								//Insert created userworkouttemplatemapping model objects into the database
								await WorkoutTemplateMappingDAL.CreateWorkoutTemplateMapping(workoutTemplate.Id, workoutTemplateMappingList);

							}
						}


					}

					returnValue = true;
				}
				else {
					returnValue = false;
				}
			}
			catch (Exception e)
			{
				returnValue = false;
				Insights.Report(e);
				//ErrorLogDAL.AddErrorLogRecord (e, DateTime.UtcNow, gymID, "SyncTemplatesWithServer", "getServiceType : " + getServiceType + ", dateString: " + dateString, e.Message, e.StackTrace);
			}
			if (returnValue)
			{
				//Time stame the request by creating a serversynctracking object and writing to the database
				APISyncTracking serverSyncTrackingRecord = new APISyncTracking();
				serverSyncTrackingRecord.Date = DateTime.UtcNow;
				serverSyncTrackingRecord.DebugInfo = "";
				serverSyncTrackingRecord.GetServiceType = getServiceType;
				ServerSyncTrackingDAL.AddModifyServerSyncTrackingRecord(serverSyncTrackingRecord);
			}
			return returnValue;
		}
Esempio n. 3
0
		private async static Task<bool> RequestAndProcessAllExercisesByGymID(int gymID, string getServiceType)
		{
			bool returnValue = false;
			List<Exercise> exercises = new List<Exercise>();
			try
			{

				var exerciseDTOList = await CoachServices.RequestAndProcessExercises(gymID).ConfigureAwait(false);

				if (exerciseDTOList.Count > 0)
				{
					//Delete all exercise records in the current gym
					await ExerciseDAL.DeleteExercisesByGymID(gymID).ConfigureAwait(false);

					foreach (var exerciseDTO in exerciseDTOList)
					{
						Exercise exercise = new Exercise(exerciseDTO, gymID);
						exercises.Add(exercise);
					}
					if (exercises.Count > 0)
					{
						var db = DependencyService.Get<ISQLite>().GetAsyncConnection();
						await db.InsertAllAsync(exercises).ConfigureAwait(false);
					}
					returnValue = true;
				}
				else {
					returnValue = false;
				}
			}
			catch (Exception e)
			{
				returnValue = false;
				Insights.Report(e);
			}
			if (returnValue)
			{
				//Time stame the request by creating a serversynctracking object and writing to the database
				APISyncTracking serverSyncTrackingRecord = new APISyncTracking();
				serverSyncTrackingRecord.Date = DateTime.UtcNow;
				serverSyncTrackingRecord.DebugInfo = "";
				serverSyncTrackingRecord.GetServiceType = getServiceType;
				ServerSyncTrackingDAL.AddModifyServerSyncTrackingRecord(serverSyncTrackingRecord);
			}
			return returnValue;
		}
Esempio n. 4
0
		private async static Task<bool> SubmitAllErrorsToServerNotPreviouslySubmittedByGymID (int gymID, string serviceType, List<ErrorLog> errorLogRecords)
		{
			bool returnValue = true;
			try
			{
               
				foreach(ErrorLog errorLog in errorLogRecords)
				{

					var response = await CoachServices.PostErrorToServer(errorLog);

					if(!response.Contains("Created")){
						returnValue = false;
						throw new Exception("Not expected response in 'PostErrorToServer' web service method( serviceTypeParamenter: " + serviceType + ")");
					}else{
						//Write the serverErrorLogID back to the local database
                        //response format: "Created. ErrorlogId:420300"
                        string[] stringSeparators = new string[] {"ErrorlogId:"};
                        string[] responseSplitArray = response.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries);
                        string stringErrorLogID = responseSplitArray[1];
                        stringErrorLogID = stringErrorLogID.Replace("\"", "");
                        int errorLogID = int.Parse(stringErrorLogID);
						errorLog.ServerErrorLogID = errorLogID ;
						ErrorLogDAL.ModifyErrorLog(errorLog);

                        //Time stame the request by creating a serversynctracking object and writing to the database
                        APISyncTracking serverSyncTrackingRecord = new APISyncTracking();
                        serverSyncTrackingRecord.Date = DateTime.UtcNow;
                        serverSyncTrackingRecord.DebugInfo = "";
                        serverSyncTrackingRecord.GetServiceType = serviceType;
                        ServerSyncTrackingDAL.AddModifyServerSyncTrackingRecord(serverSyncTrackingRecord);
					}
				}

			}catch(Exception e) {


				returnValue = false;
				ErrorLogDAL.AddErrorLogRecord (e, DateTime.UtcNow, gymID, "SubmitAllErrorsToServerNotPreviouslySubmittedByGymID","serviceType: " + serviceType, e.Message, e.StackTrace);


			}
			return returnValue;
		}