/// <summary> /// Attempts to cancel execution of this task. /// </summary> /// <param name="mayInterruptIfRunning"></param> /// <returns>false if the task was canceled or /// ran before the call on this method. true in otherwise.</returns> public virtual bool Cancel(bool mayInterruptIfRunning) { lock (this) { if (RanOrCancelled(state)) { return(false); } state = StateTask.Canceled; if (mayInterruptIfRunning) { try { if (runner != null) { runner.Interrupt(); } } catch (ThreadInterruptedException) { //Do nothing } releaseShared(); } } Done(); return(true); }
public async Task When_Task_Wants_To_Prev_State_And_It_Exit_Should_Go_Next_State() { var taskId = Guid.NewGuid(); var taskCurrentState = Guid.NewGuid(); var taskPrevState = Guid.NewGuid(); var flowId = Guid.NewGuid(); StateTask task = new StateTask(); var mockUnitOfWork = new Mock <IUnitOfWork>(); mockUnitOfWork.Setup(x => x.TaskRepository.Get(It.Is <Guid>(t => t == taskId))). Returns(Task.FromResult(new StateTask { FlowId = flowId, StateId = taskCurrentState, State = new State { FlowId = flowId, Id = taskCurrentState, NextStateId = null, PrevStateId = taskPrevState } })); mockUnitOfWork.Setup(x => x.TaskRepository.Update(It.IsAny <StateTask>())).Callback <StateTask>((state) => task = state); var taskService = new TaskService(mockUnitOfWork.Object); await taskService.ToPrevStage(taskId); Assert.AreEqual(taskPrevState, task.StateId); }
public void When_Task_Wants_To_Next_State_And_It_Does_Not_Exit_Should_Throw_Error() { var taskId = Guid.NewGuid(); var taskCurrentState = Guid.NewGuid(); var flowId = Guid.NewGuid(); StateTask task = new StateTask(); var mockUnitOfWork = new Mock <IUnitOfWork>(); mockUnitOfWork.Setup(x => x.TaskRepository.Get(It.Is <Guid>(t => t == taskId))). Returns(Task.FromResult(new StateTask { FlowId = flowId, StateId = taskCurrentState, State = new State { FlowId = flowId, Id = taskCurrentState, NextStateId = null } })); mockUnitOfWork.Setup(x => x.TaskRepository.Update(It.IsAny <StateTask>())).Callback <StateTask>((state) => task = state); var taskService = new TaskService(mockUnitOfWork.Object); Assert.ThrowsAsync <TaskStateUpdateException>(async() => await taskService.ToNextStage(taskId)); }
public Task() { Id = Guid.Empty; Title = string.Empty; Description = string.Empty; State = StateTask.Open; }
public async Task <StateTask> Create(StateTask task) { var firstState = await _unitOfWork.StateRepository.GetFirstStateByFlowId(task.FlowId); task.Id = Guid.NewGuid(); task.StateId = firstState.Id; await _unitOfWork.TaskRepository.Create(task); await _unitOfWork.SaveChangesAsync(); return(task); }
public async Task <StateTask> Update(StateTask task) { var gonnaUpdateTask = await _unitOfWork.TaskRepository.Get(task.Id); if (gonnaUpdateTask == null) { return(null); } gonnaUpdateTask.Title = task.Title; gonnaUpdateTask = _unitOfWork.TaskRepository.Update(gonnaUpdateTask); await _unitOfWork.SaveChangesAsync(); return(gonnaUpdateTask); }
/// <summary> /// Sets the result of this Future to the given value unless this future /// has already been set or has been cancelled. /// </summary> /// <param name="obj"></param> protected virtual void Set(T obj) { lock (this) { if (state == StateTask.Ran) { return; } if (state == StateTask.Canceled) { releaseShared(); return; } state = StateTask.Ran; result = obj; releaseShared(); } Done(); }
/// <summary> /// When an object implementing interface Runnable is used to create a thread, /// starting the thread causes the object's run method to be called in that /// separately executing thread. /// </summary> public virtual void Run() { lock (this) { if (state != 0) { return; } state = StateTask.Running; runner = Thread.CurrentThread; } try { Set(callable.Call()); } catch (System.Exception ex) { SetException(ex); } }
protected virtual void SetException(System.Exception ex) { lock (this) { if (state == StateTask.Ran) { return; } if (state == StateTask.Canceled) { releaseShared(); return; } state = StateTask.Ran; // the task it's over exception = ex; result = default(T); releaseShared(); } Done(); //subclasses must override this member in order to use it. }
protected override BehaviorTask createTask() { StateTask pTask = new StateTask(); return(pTask); }
/// <summary> /// Was ran or were Canceled ? /// </summary> /// <param name="aState">State to evaluate</param> /// <returns></returns> public static bool RanOrCancelled(StateTask aState) { return(aState == StateTask.Ran || aState == StateTask.Canceled); }
protected override BehaviorTask createTask() { StateTask pTask = new StateTask(); return pTask; }
public StateWebTask() { _StateTask = new StateTask(); }
public TaskStateUpdateException(string message, StateTask task) : base(message) { Task = task; }
private void GetPNR(object item) { String StartMonth = DateTime.Now.AddDays(DateTime.Now.Day * -1).ToString("dd-MM-yyyy"); StateTask State = (StateTask)item; SQLCollection param = new SQLCollection("@code", DbType.String, State.DB); param.ANDBetween("TICKET_DATE", "ticket_date", StartMonth, null, DbType.Date); switch (State.Type) { case Business.B2C: State.DB = new DB("travoxb2b_global", State.DNS, "travox").GetField("SELECT name FROM db_initial WHERE wholesale_code = @code ", param); break; case Business.B2B: State.DB = "travoxb2b"; break; } DB GD = new DB(State.DB, State.DNS, "travox"); //foreach (DataRow PNR in GD.GetTable(base.GetResource("GetPNR(view_header).sql"), param).Rows) //{ //param.Add("@booking_info_id", DbType.String ,PNR["ref_id"].ToString()); //String booking_pnr_id = GD.Execute("", WithBookingPNR(PNR)); //param.Add("@booking_pnr_id", DbType.String, booking_pnr_id); // PR_view_header_Item.airline_code = PNR["airline_code"].ToString(); // PR_view_header_Item.airline_name = PNR["airline_name"].ToString(); // PR_view_header_Item.gds = PNR["gds"].ToString(); // PR_view_header_Item.client_deadline = PNR["client_deadline"].ToString(); // PR_view_header_Item.airline_deadline = PNR["airline_deadline"].ToString(); // PR_view_header_Item.ticket_date = PNR["ticket_date"].ToString(); // PR_view_header_Item.operate_by_code = PNR["operate_by_code"].ToString(); // PR_view_header_Item.pnr = PNR["pnr"].ToString(); // PR_view_header_Item.ad_cost = PNR["ad_cost") // PR_view_header_Item.ch_cost = PNR["ch_cost") // PR_view_header_Item.inf_cost = loopHeader // PR_view_header_Item.ad_price = PNR["ad_price") // PR_view_header_Item.ch_price = PNR["ch_price") // PR_view_header_Item.inf_price = loopHeader // PR_view_header_Item.ad_tax = PNR["ad_tax") // PR_view_header_Item.ch_tax = PNR["ch_tax") // PR_view_header_Item.inf_tax = loopHeader // PR_view_header_Item.currency = PNR["currency"].ToString(); // PR_view_header_Item.credit_card_success = PNR["credit_card_success"].ToString(); // PR_view_header_Item.service_charge = PNR["service_charge") // PR_view_header_Item.invoice_name = PNR["invoice_name"].ToString(); // PR_view_header_Item.invoice_address = PNR["invoice_address"].ToString(); // PR_view_header_Item.invoice_district = PNR["invoice_district"].ToString(); // PR_view_header_Item.invoice_province = PNR["invoice_province"].ToString(); // PR_view_header_Item.invoice_postcode = PNR["invoice_postcode"].ToString(); // PR_view_header_Item.invoice_country = PNR["invoice_country"].ToString(); // PR_view_header_Item.invoice_tel = PNR["invoice_tel"].ToString(); // PR_view_header_Item.invoice_fax = PNR["invoice_fax"].ToString(); // PR_view_header_Item.invoice_email = PNR["invoice_email"].ToString(); // PR_view_header_Item.payment_type = PNR["payment_type"] // PR_view_header_Item.agent_name = PNR["agent_name"].ToString(); // PR_view_header_Item.agent_address = PNR["agent_address"].ToString(); // PR_view_header_Item.insurance_code = PNR["insurance_code"].ToString(); // PR_view_header_Item.insurance_price = PNR["insurance_price"].ToString(); // PR_view_header_Item.import_by = schema_name.ToString() // 'PR_view_header.Add(PR_view_header_Item) // iReturn = dtReturn.Rows(0)("ref_id") //} mres[State.ID].Set(); }