public Stateless(int eid) { List <WorkElement> cElement = DBconn.GetStateless(eid); if (cElement.Count == 0) { string orderTitle = "NewWorkElement" + DateTime.Now, orderDesc = ""; var nowdate = DateTime.Now; var res = DBconn.excuteQuery($"insert into element (ordertitle,orderdesc,laststate,requestdate,terminationdate) output Inserted.id values('','','{_state}','{nowdate}',null);"); if (!int.TryParse(res.ToString(), out eid)) { eid = 0; } _element = new WorkElement { Id = eid, OrderTitle = orderTitle, RequestedBy = "", EmailAddress = "", OrderDescription = orderDesc, RequestDate = nowdate, Transition = new List <Transition>() }; } else { _element = new WorkElement { Id = eid, OrderTitle = cElement[0].OrderTitle, RequestedBy = cElement[0].RequestedBy, EmailAddress = cElement[0].EmailAddress, OrderDescription = cElement[0].OrderDescription, RequestDate = cElement[0].RequestDate, Transition = cElement[0].Transition }; } ConfigStateless(); }
public Stateless() { string orderTitle = "NewWorkElement" + DateTime.Now, orderDesc = ""; int eid; var nowdate = DateTime.Now; var res = DBconn.excuteQuery($"insert into element (ordertitle,orderdesc,laststate,requestdate,terminationdate) output Inserted.id values('','','{_state}','{nowdate}',null);"); if (!int.TryParse(res.ToString(), out eid)) { eid = 0; } _element = new WorkElement { Id = eid, OrderTitle = orderTitle, OrderDescription = orderDesc, RequestDate = nowdate, Transition = new List <Transition>() }; ConfigStateless(); }
public WorkElement _element;//a request for creating a service order or work element release public Stateless(string requestedBy, string requestedMail, string orderTitle, string orderDesc) { int eid; var nowdate = DateTime.Now; int id = DBconn.insertAgent(requestedBy, requestedMail); var res = DBconn.excuteQuery($"insert into element (ordertitle,orderdesc,requestedby,laststate,requestdate,terminationdate) output Inserted.id values('{orderTitle}','{orderDesc}','{id}','{_state}','{nowdate}',null);"); if (!int.TryParse(res.ToString(), out eid)) { eid = 0; } _element = new WorkElement { Id = eid, OrderTitle = orderTitle, OrderDescription = orderDesc, RequestedBy = requestedBy, EmailAddress = requestedMail, RequestDate = nowdate, Transition = new List <Transition>() }; ConfigStateless(); }
private void ConfigStateless() { _machine = new StateMachine <State, Trigger>(() => _state, s => _state = s); _assignTrigger = _machine.SetTriggerParameters <int, string>(Trigger.Assign); _createTrigger = _machine.SetTriggerParameters <int, string>(Trigger.Create); _rejectTrigger = _machine.SetTriggerParameters <int, string>(Trigger.Reject); _reviewTrigger = _machine.SetTriggerParameters <int, string>(Trigger.Review); _approveTrigger = _machine.SetTriggerParameters <int, string>(Trigger.Approve); _machine.Configure(State.New) .Permit(Trigger.Assign, State.Designated); _machine.Configure(State.Designated) .Permit(Trigger.Create, State.Completed) .Permit(Trigger.Review, State.Reviewed) .Permit(Trigger.Reject, State.Rejected); _machine.Configure(State.Reviewed) .Permit(Trigger.Approve, State.Approved) .Permit(Trigger.Reject, State.Rejected); _machine.Configure(State.Approved) .Permit(Trigger.Assign, State.Designated); _machine.OnTransitioned( t => { var d = DateTime.Now; DBconn.excuteQuery($"insert into statelog (elementid,triggerid,triggeredby,triggereddate,sourcestate,destinationstate,comment) output Inserted.id values('{_element.Id}','{t.Trigger}','" + (t.Parameters.Length > 0 ? t.Parameters[0] : "0") + "','" + d + "','" + t.Source + "','" + t.Destination + "','" + (t.Parameters.Length > 1 ? t.Parameters[1] : "") + "');"); DBconn.excuteQuery($"update element set laststate='{t.Destination}',terminationdate='{d}' where id='{_element.Id}';"); Console.WriteLine( $"OnTransitioned: {t.Source} -> {t.Destination} via {t.Trigger}({string.Join(", ", t.Parameters)})" ); } ); }