private async Task Split(char fx, string msg, bool fillEnd = false) { try { if (fx == 'N' || fx == 'n') { foreach (var el in JsonConvert.DeserializeObject <TimeModel[]>(msg).Where(el => ListStartPoint.IndexOf(el) < 0)) { if (fillEnd) { ListEndPoint.Add(el); } else { ListStartPoint.Add(el); } } } if (fx == 'M' || fx == 'm') { TripModel = (JsonConvert.DeserializeObject <TripAdvisorModel[]>(msg)).FirstOrDefault(o => o.DID.Equals(CarId)); } //foreach (var el in JsonConvert.DeserializeObject<TripAdvisorModel[]>(msg)) //{ // ListTrip.Add(new TripAdvisorViewModel(el)); //} if (fx == 'H' || fx == 'h') { var res = JsonConvert.DeserializeObject <DrivingStyle[]>(msg); _styleDriver = res.FirstOrDefault(o => o.DID.Equals(CarId)); } } catch (Exception) { } }
private async Task UpdateSourceAsync(string property = "") { ListTrip.Clear(); #region DesignMode if (DesignMode.DesignModeEnabled) { ListTrip.Add(new TripAdvisorViewModel(new TripAdvisorModel { DID = "1", CurrentDistance = 150, TripTime = 256, MedianSpeed = 65, })); ListTrip.Add(new TripAdvisorViewModel(new TripAdvisorModel { DID = "1", CurrentDistance = 180, TripTime = 298, MedianSpeed = 78, })); ListTrip.Add(new TripAdvisorViewModel(new TripAdvisorModel { DID = "1", CurrentDistance = 150, TripTime = 256, MedianSpeed = 65, })); ListTrip.Add(new TripAdvisorViewModel(new TripAdvisorModel { DID = "1", CurrentDistance = 180, TripTime = 298, MedianSpeed = 78, })); _styleDriver = new DrivingStyle { DID = "1", CurrentDrivingStyle = 67, CurrentEcoStyle = 89, TodayDrivingScore = 58, TodayEcoScore = 68, TotalDrivingScore = 68, TotalEcoScore = 98 }; } #endregion ReciveMessageModel res = null; var request = string.Empty; switch (property) { case "StartDate": ListStartPoint.Clear(); request = JsonConvert.SerializeObject(new PointsRequestModel { Date = new DateDataModel(StartDate), DevID = CarId }); res = await TcpConnection.Send("BN" + request); break; case "EndDate": ListEndPoint.Clear(); request = JsonConvert.SerializeObject(new PointsRequestModel { Date = new DateDataModel(EndDate), DevID = CarId }); res = await TcpConnection.Send("BN" + request); break; default: request = JsonConvert.SerializeObject(new TripRequestModel { Start = new DateTimeDataModel(_starTime), Stop = new DateTimeDataModel(_endTime), devID = CarId }); res = await TcpConnection.Send("BM" + request); break; } if (res == null) { return; } if (!string.IsNullOrEmpty(res.Msg)) { await Split(res.Fx, res.Msg, property.Equals("EndDate")); } OnSourceChenged(property); }