public async Task SaveDailyData(int pointId, List <Roc809DailyData> data, Action <int> onSuccess, Action <Exception> onException) { await Task.Factory.StartNew(() => { using (var repo = new DataRecordRepository <Roc809DailyData>(_connection)) { var lastData = repo.GetAll() .Where(d => d.Roc809MeasurePointId == pointId) .OrderByDescending(o => o.Period) .FirstOrDefault(); if (lastData != null) { var filtered = data.Where(d => d.Period > lastData.Period).ToList(); repo.Insert(filtered); return(filtered.Count); } repo.Insert(data); return(data.Count); } }, TaskCreationOptions.LongRunning) .ContinueWith(result => { if (result.Exception != null) { onException?.Invoke(result.Exception.InnerException); } else { onSuccess?.Invoke(result.Result); } }, TaskScheduler.FromCurrentSynchronizationContext()); }
public async Task SavePeriodicData(int pointId, List <Roc809PeriodicData> data, Action <int> onSuccess, Action <Exception> onException) { await Task.Factory.StartNew(() => { using (var repo = new DataRecordRepository <Roc809PeriodicData>(_connection)) { var existent = repo.GetAll().Where(d => d.Roc809MeasurePointId == pointId).Select(d => d.Period); var filtered = data.Where(d => !existent.Contains(d.Period)).ToList(); if (!filtered.Any()) { return(0); } repo.Insert(filtered); return(filtered.Count); } }, TaskCreationOptions.LongRunning) .ContinueWith(result => { if (result.Exception != null) { onException?.Invoke(result.Exception.InnerException); } else { onSuccess?.Invoke(result.Result); } }, TaskScheduler.FromCurrentSynchronizationContext()); }
public async Task SaveIdentData(FloutecIdentData data, Action <bool> onSuccess, Action <Exception> onException) { await Task.Factory.StartNew(() => { using (var repo = new DataRecordRepository <FloutecIdentData>(_connection)) { var lastData = repo.GetAll() .Where(d => d.FloutecMeasureLineId == data.FloutecMeasureLineId) .OrderByDescending(o => o.DateAdded) .FirstOrDefault(); if (lastData != null && lastData.IsEqual(data)) { return(false); } repo.Insert(data); return(true); } }, TaskCreationOptions.LongRunning) .ContinueWith(result => { if (result.Exception != null) { onException?.Invoke(result.Exception.InnerException); } else { onSuccess?.Invoke(result.Result); } }, TaskScheduler.FromCurrentSynchronizationContext()); }