void ConvertWatchModelToDataArry() { globalWatchModelHold = ConvertRestNumberCellToRestStar(globalWatchModelHold); DataArrayModel convertedFromWatch = new DataArrayModel(); convertedFromWatch.DataArray = new List <List <string> >(); List <string> WeekAndDay = new List <string>(); WeekAndDay.Add(globalWatchModelHold.Week); WeekAndDay.Add(globalWatchModelHold.Day); convertedFromWatch.DataArray.Add(WeekAndDay); List <string> tmpWeights = new List <string>(); // starts at workout string list index 2 to get past workout name and rep int index = 2; while (index < globalWatchModelHold.Workouts.Count) { tmpWeights.AddRange(globalWatchModelHold.Workouts.GetRange(index, globalWatchModelHold.Sets.Count)); convertedFromWatch.DataArray.Add(tmpWeights); tmpWeights = new List <string>(); // skips to next set count plus 2 because of name and rep index = index + globalWatchModelHold.Sets.Count + 2; } ApplyJsonToSheet(convertedFromWatch); }
// for when i receive watch json and show to list view // last watch received json function processed before manually pressing send to sheet WatchModel ConvertWatchJsonToWatchModel(List <string> WorkoutNames, List <string> RepCount, List <List <string> > MasterArray) { WatchModel watchModel = new WatchModel(); watchModel.Week = MasterArray[0][0]; watchModel.Day = MasterArray[0][1]; watchModel.Sets = new List <string>(); watchModel.Workouts = new List <string>(); // populate set count based on first workout amount for (int i = 0; i < MasterArray[1].Count; i++) { watchModel.Sets.Add("Set " + (i + 1)); } // populate workout list past the first array which is week and day info for (int i = 1; i < MasterArray.Count; i++) { watchModel.Workouts.Add(WorkoutNames[i - 1]); watchModel.Workouts.Add(RepCount[i - 1]); watchModel.Workouts.AddRange(MasterArray[i]); } ListViewHeaderMessage("Received from watch: " + watchModel.Week + ", " + watchModel.Day, 3); return(watchModel); }
/// <summary> /// Constructor. /// </summary> public WatchViewModel() { MainWindowTitle = "Watch CAD"; _watchModel = new WatchModel(); InitWatchData(); BuildCommand = new Command(arg => BuildMethod()); }
// make object from json sent from watch void MakeObjectFromJson() { DataArrayModel dataArrayModel; // filter the received watch json empty 8888 to * string filterEmpty = ReceivedMsg.Replace("8888", "*"); dataArrayModel = JsonConvert.DeserializeObject <DataArrayModel>(filterEmpty); // get workout name and reps then removes from DataArrayModel List <string> watchWorkoutTitle = dataArrayModel.DataArray[dataArrayModel.DataArray.Count - 1]; dataArrayModel.DataArray.RemoveAt(dataArrayModel.DataArray.Count - 1); List <string> watchReps = dataArrayModel.DataArray[dataArrayModel.DataArray.Count - 1]; dataArrayModel.DataArray.RemoveAt(dataArrayModel.DataArray.Count - 1); WatchModel watchModel = ConvertWatchJsonToWatchModel(watchWorkoutTitle, watchReps, dataArrayModel.DataArray); globalWatchModelHold = watchModel; ListViewWorkouts(watchModel); UploadButtonBool = true; }
public void WatchModelRoundtrips() { var watchModel = new WatchModel { Duration = TimeSpan.FromSeconds(1.5) }; var jsonString = JsonConvert.SerializeObject(watchModel); var deserialised = JsonConvert.DeserializeObject <WatchModel>(jsonString); Assert.Equal(watchModel.Duration, deserialised.Duration); }
public void WatchDurationsSerialiseAsDates() { var watchModel = new WatchModel { Duration = TimeSpan.FromSeconds(1.5) }; var jsonString = watchModel.Serialise(); var jObject = JObject.Parse(jsonString); var serialisedDuration = jObject.GetValue(nameof(WatchModel.Duration), StringComparison.OrdinalIgnoreCase); Assert.Equal(JTokenType.Float, serialisedDuration.Type); Assert.Equal(1.5, serialisedDuration.Value <double>()); }
// first method for the process of sending to watch void PackageForWatch() { if (globalWatchModelHold == null) { ListViewHeaderMessage("Connect to watch first", 2); return; } ; globalWatchModelHold = ConvertStarCellToRestNumber(globalWatchModelHold); var jsonString = JsonConvert.SerializeObject(globalWatchModelHold); SendMessage(jsonString); }
List <string> LoadSave() { string SavedListJson = Preferences.Get("SavedList", ""); string SavedWatchJson = Preferences.Get("WatchObject", ""); List <string> SavedList = JsonConvert.DeserializeObject <List <string> >(SavedListJson); WatchModel SavedWatch = JsonConvert.DeserializeObject <WatchModel>(SavedWatchJson); watch.WatchObject = SavedWatch; if (watch.WatchObject != null) { PopulatePreviousWorkInfo(); } return(SavedList); }
public void Send(WatchModel watchModel) { UdpClient tmpClient = new UdpClient(); IPEndPoint broadcastIp = new IPEndPoint(IPAddress.Broadcast, PORT_NUMBER); // Can send on broadcast watchModel.Counter += 1; // Update "TimeStamp" to check for changes on remote watches ! string json = JsonService.Serialize(watchModel); byte[] buffer = Encoding.ASCII.GetBytes(json); tmpClient.Send(buffer, buffer.Length, broadcastIp); tmpClient.Close(); }
public ActionResult Watch(int threadId) { if (Request.Cookies["LogOnCookie"] == null) { var result = new { IsAuthenticated = false }; return(Json(result)); } var scope = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions() { IsolationLevel = IsolationLevel.ReadCommitted }); try { int totalWatchByUser = 0; using (scope) { var threadModel = _unitOfWork.ThreadRepository.GetById(threadId); threadModel.Watch = threadModel.Watch + 1; totalWatchByUser = threadModel.Watch; _unitOfWork.ThreadRepository.Update(threadModel); _unitOfWork.Save(); var watchModel = new WatchModel { ThreadId = threadId, WatchedBy = Request.Cookies["LogOnCookie"].Values["username"], WatchedOn = DateTime.Now, IpAddress = GetIp(), Browser = Request.Browser.Browser }; _unitOfWork.WatchRepository.Insert(watchModel); _unitOfWork.Save(); CacheImplementation.UpdateCacheItem(CacheImplementation.RecentThreads, threadId, "Watch", null); scope.Complete(); } return(Json(new { Result = "Success", IsAuthenticated = true, totalWatch = totalWatchByUser }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { scope.Dispose(); Elmah.ErrorSignal.FromCurrentContext().Raise(ex); return(Json(new { Result = "Failed" }, JsonRequestBehavior.AllowGet)); } }
public CartController() { _db = new WatchModel(); }
public WatchController() { _db = new WatchModel(); }