public async Task <bool> Update_MSTR_Drone() { try { using (FlightProcessorConnection cn = new FlightProcessorConnection()) { MSTR_Drone mSTR_Drone = await cn.MSTR_Drone.Where(w => w.DroneId == (int)_DroneFlight.DroneID).FirstOrDefaultAsync(); if (mSTR_Drone != null) { mSTR_Drone.LastFlightID = _DroneFlight.ID; mSTR_Drone.FlightTime = _DroneFlight.FlightDate; cn.Entry(mSTR_Drone).State = EntityState.Modified; await cn.SaveChangesAsync(); } } return(true); } catch (System.Data.Entity.Validation.DbEntityValidationException e) { OnDbEntityException?.Invoke(e); } catch (Exception ex) { OnTaskError?.Invoke(new TaskExceptionInfo { TaskException = ex, TaskName = "Task - Update_MSTR_Drone()" }); } return(false); }
/// <summary> /// 初始化一个任务 /// </summary> /// <param name="cfgFile">任务配置文件路径,如果已经初始化,则返回任务ID</param> /// <returns>返回任务对象</returns> public static Task InitTask(string cfgFile) { var fullPath = SnailCore.IO.PathUnity.GetFullPath(cfgFile); if (string.IsNullOrEmpty(fullPath)) { throw new Exception("could not find the file with path:" + cfgFile); } Task task = null; lock (LockObj) { if (!BufferTasks.ContainsKey(fullPath)) { task = new Task(fullPath); foreach (var kv in BufferTasks) { if (kv.Value.TaskId == task.TaskId) { throw new Exception(string.Format("任务id:{0},重复出现,请检查配置,并重新启动任务.", task.TaskId)); } } task.OnStart += (sender, e) => { try { OnTaskRunning?.Invoke(sender, e); } catch (Exception ex) { LoggerProxy.Error(LogSource, "invoke OnTaskRunning failed.", ex); } }; task.OnStop += (sender, e) => { try { OnTaskComplete?.Invoke(sender, e); } catch (Exception ex) { LoggerProxy.Error(LogSource, "invoke OnTaskComplete failed.", ex); } }; task.OnError += (sender, e) => { try { OnTaskError?.Invoke(sender, e); } catch (Exception ex) { LoggerProxy.Error(LogSource, "invoke OnTaskError failed.", ex); } }; BufferTasks.Add(fullPath, task); } } return(BufferTasks[fullPath]); }
} //public static void UpdateProximity() public async static Task <bool> UpdateFlightsToDB() { foreach (String FromKey in Keys()) { try { var Result = await Flight(FromKey).UpdateFlightsToDB(); } catch (Exception ex) { OnTaskError?.Invoke(new TaskExceptionInfo { TaskException = ex, TaskName = $"Update Flight: FromKey={FromKey} - UpdateFlightsToDB()" }); } } return(true); }
public async static void fnThreadUpdateDroneDataMain() { try { while (IsAppRunning) { var TheTask = await fnThreadUpdateDroneData(); } } catch (System.Data.Entity.Validation.DbEntityValidationException e) { OnDbEntityException?.Invoke(e); } catch (Exception ex) { OnTaskError?.Invoke(new TaskExceptionInfo { TaskException = ex, TaskName = "Update Drone Data - fnThreadUpdateDroneDataMain" }); } }
public async static void fnLoadPendingDataMain() { try { while (IsAppRunning) { var TheTask = await fnLoadPendingData(); await Task.Delay(10); } } catch (Exception ex) { OnTaskError?.Invoke(new TaskExceptionInfo { TaskException = ex, TaskName = "Load Pending Data - fnLoadPendingDataMain" }); } }
public void SetDroneData(DroneData ActiveDroneData) { _DroneData = ActiveDroneData; Decimal.TryParse(_DroneData.BBFlightID, out _BBFlightID); _DroneID = (int)_DroneData.DroneId; try { _ReadTime = DateTime.ParseExact(_DroneData.ReadTime, "dd/MM/yyyy-HH:mm:ss", null); _DroneFlight.FlightDate = _ReadTime; } catch (Exception ex) { OnTaskError?.Invoke(new TaskExceptionInfo { TaskException = ex, TaskName = "SetDroneData - _ReadTime Parse Error" }); } _SetFlightMapData(); }
public async static void fnThreadProcessingMain() { try { while (IsAppRunning) { var TheTask = await fnThreadProcessing(); await Task.Delay(10); } } catch (System.Data.Entity.Validation.DbEntityValidationException e) { OnDbEntityException?.Invoke(e); } catch (Exception ex) { OnTaskError?.Invoke(new TaskExceptionInfo { TaskException = ex, TaskName = "Main Thred Processing - fnThreadProcessingMain" }); } }
public async Task <bool> UpdateFlightsToDB() { try { _DroneFlight.MaxSpeed = (Decimal)SpeedSummary.Max; _DroneFlight.MaxAltitude = (Decimal)AltitudeSummary.Max; _DroneFlight.FlightHours = (int)_FlightMapData.TotalFlightTime; _DroneFlight.FlightDistance = (Decimal)Math.Round((Double)_FlightMapData.Distance, 0); using (var update = new FlightProcessorConnection()) { var entry = update.Entry(_DroneFlight); entry.State = EntityState.Modified; await update.SaveChangesAsync(); } return(true); } catch (System.Data.Entity.Validation.DbEntityValidationException e) { OnDbEntityException?.Invoke(e); } catch (Exception ex) { OnTaskError?.Invoke(new TaskExceptionInfo { TaskException = ex, TaskName = "UpdateFlightsToDB()" }); } return(false); }
public async Task <bool> UpdateFlight() { if (Proximities != null) { _FlightMapData.OtherFlightIDs = Newtonsoft.Json.JsonConvert.SerializeObject(GetSimpleProximity()); } try { using (FlightProcessorConnection cn = new FlightProcessorConnection()) { cn.FlightMapData.Add(_FlightMapData); cn.Entry(_DroneFlight).State = EntityState.Modified; await cn.SaveChangesAsync(); } return(true); } catch (System.Data.Entity.Validation.DbEntityValidationException e) { OnDbEntityException?.Invoke(e); } catch (Exception ex) { OnTaskError?.Invoke(new TaskExceptionInfo { TaskException = ex, TaskName = "Task - UpdateFlight()" }); } return(false); }
/// <summary> /// Callback when error thrown. /// </summary> /// <param name="task">The task where the exception thrown.</param> /// <param name="ex">The exception.</param> internal virtual void InternalErrorCallback(MTTask task, Exception ex) { OnTaskError?.Invoke(task, ex); }
private static void fnOnTaskError(TaskExceptionInfo exp) { OnTaskError?.Invoke(exp); }
internal void TriggerTaskError(TaskAgent sender, Exception ex) { OnTaskError?.Invoke(sender, ex); }