private void Initialize() { AddStateToContextCommand = new DelegateCommand(OnAddState, CanAddState); RemoveStateCommand = new DelegateCommand <State>(OnRemoveStateCommand, CanRemoveState); SelectedStates = CollectionHelper.EmptyListCollectionView <State>(); EventAggregator = ServiceLocator.Current.GetInstance <IEventAggregator>(); StateCollection = Context.HospitalRegistryService .GetStates() .Select(state => new KeyValuePair <string, State>(state.Abbreviation, state)) .Concat(new[] { new KeyValuePair <string, State>(SELECT_STATE, null) }) .OrderBy(item => item.Value != null) .ThenBy(item => item.Key).ToListCollectionView(); var defaultStates = HospitalRegion.Default.DefaultStates.OfType <string>().ToList(); defaultStates.ForEach(s => { var toRemove = StateCollection.OfType <KeyValuePair <string, State> >().First(kvp => kvp.Key == s); StateCollection.Remove(toRemove); SelectedStates.AddNewItem(toRemove.Value); }); SelectedStates.CommitNew(); StateCollection.CommitEdit(); StateCollection.MoveCurrentToFirst(); /*Regions for combo box, Object type return "SELECT" on display, and NULL on return using */ RegionTypes = (new[] { typeof(object), typeof(HealthReferralRegion), typeof(HospitalServiceArea) }).ToListCollectionView(); SelectedRegionType = HospitalRegion.Default.SelectedRegionType; }
private StateCollection CreateParserStates(CGTContent content) { rules = CreateRules(content); StateCollection states = new StateCollection(); foreach (LALRStateRecord record in content.LALRStateTable) { State state = new State(record.Index); states.Add(state); } foreach (LALRStateRecord record in content.LALRStateTable) { State state = states[record.Index]; foreach (ActionSubRecord subRecord in record.ActionSubRecords) { Action action = ActionFactory.CreateAction(subRecord, states, symbols, rules); state.Actions.Add(action); } } return states; }
/// <summary> /// 获得分页列表,无论是否是缓存实体都从数据库直接拿取数据 /// </summary> /// <param name="pPageIndex">页数</param> /// <param name="pPageSize">每页列表</param> /// <param name="pOrderBy">排序</param> /// <param name="pSortExpression">排序字段</param> /// <param name="pRecordCount">列表行数</param> /// <returns>数据分页</returns> public static List <StateInfo> GetPagedList(int pPageIndex, int pPageSize, SortDirection pOrderBy, string pSortExpression, out int pRecordCount) { if (pPageIndex <= 1) { pPageIndex = 1; } List <StateInfo> list = new List <StateInfo>(); Query q = State.CreateQuery(); q.PageIndex = pPageIndex; q.PageSize = pPageSize; q.ORDER_BY(pSortExpression, pOrderBy.ToString()); StateCollection collection = new StateCollection(); collection.LoadAndCloseReader(q.ExecuteReader()); foreach (State state in collection) { StateInfo stateInfo = new StateInfo(); LoadFromDAL(stateInfo, state); list.Add(stateInfo); } pRecordCount = q.GetRecordCount(); return(list); }
public void CompositeStateTest() { var sm = new StateMachine(); var s0 = CreateState("0"); var s0States = new StateCollection(); s0.ParallelSubStates.Add(s0States); sm.States.Add(s0); var s00 = CreateState("00"); s0States.Add(s00); var s01 = CreateState("01"); s0States.Add(s01); var t0 = new Transition { SourceState = s0, TargetState = s0, }; t0.Action += (s, e) => _events = _events + "A0"; sm.Update(TimeSpan.FromSeconds(1)); sm.Update(TimeSpan.FromSeconds(1)); t0.Fire(); sm.Update(TimeSpan.FromSeconds(1)); sm.Update(TimeSpan.FromSeconds(1)); Assert.AreEqual("E0E00U00U0U00U0X00X0A0E0E00U00U0U00U0", _events); }
public void Test_Count() { string group = "TestGroup"; StateCollection <string> collection = new StateCollection <string>(StateScope.Application, group); string zero = "Zero"; string one = "One"; collection.Add(zero); string key = collection.GetStateKey(); StateAccess.State.SetApplication(key, collection); StateCollection <string> foundCollection0 = (StateCollection <string>)StateAccess.State.GetApplication(key); Assert.AreEqual(1, foundCollection0.Count); collection.Add(one); StateAccess.State.SetApplication(key, collection); StateCollection <string> foundCollection2 = (StateCollection <string>)StateAccess.State.GetApplication(key); Assert.AreEqual(2, foundCollection2.Count); Assert.AreEqual(2, collection.Count); }
public BattleData(BattleData other) { ID = other.ID; Element = other.Element; Category = other.Category; HitRate = other.HitRate; SkillStates = other.SkillStates.Clone(); copyEventList <BattleEvent>(ref BeforeTryActions, other.BeforeTryActions, true); copyEventList <BattleEvent>(ref BeforeActions, other.BeforeActions, true); copyEventList <BattleEvent>(ref OnActions, other.OnActions, true); copyEventList <BattleEvent>(ref BeforeExplosions, other.BeforeExplosions, true); copyEventList <BattleEvent>(ref BeforeHits, other.BeforeHits, true); copyEventList <BattleEvent>(ref OnHits, other.OnHits, true); copyEventList <BattleEvent>(ref OnHitTiles, other.OnHitTiles, true); copyEventList <BattleEvent>(ref AfterActions, other.AfterActions, true); copyEventList <ElementEffectEvent>(ref ElementEffects, other.ElementEffects, true); IntroFX = new List <BattleFX>(); foreach (BattleFX fx in other.IntroFX) { IntroFX.Add(new BattleFX(fx)); } HitFX = new BattleFX(other.HitFX); HitCharAction = other.HitCharAction.Clone(); }
public void Test_GetEnumerator() { string group = "TestGroup"; StateCollection <string> collection = new StateCollection <string>(StateScope.Application, group); string one = "One"; string two = "Two"; string[] values = new String[] { one, two }; collection.Add(one); collection.Add(two); int i = 0; foreach (string value in collection) { Assert.IsNotNull(value, "Value is null at index position " + i + "."); Assert.AreEqual(values[i], value, "Only value doesn't match what is expected."); i++; } }
/// <summary> /// 获得数据列表 /// </summary> /// <returns></returns> public static List <StateInfo> GetList() { string cacheKey = GetCacheKey(); //本实体已经注册成缓存实体,并且缓存存在的时候,直接从缓存取 if (CachedEntityCommander.IsTypeRegistered(typeof(StateInfo)) && CachedEntityCommander.GetCache(cacheKey) != null) { return(CachedEntityCommander.GetCache(cacheKey) as List <StateInfo>); } else { List <StateInfo> list = new List <StateInfo>(); StateCollection collection = new StateCollection(); Query qry = new Query(State.Schema); collection.LoadAndCloseReader(qry.ExecuteReader()); foreach (State state in collection) { StateInfo stateInfo = new StateInfo(); LoadFromDAL(stateInfo, state); list.Add(stateInfo); } //生成缓存 if (CachedEntityCommander.IsTypeRegistered(typeof(StateInfo))) { CachedEntityCommander.SetCache(cacheKey, list); } return(list); } }
public void CompositeStateTestWithInitialState() { var sm = new StateMachine(); var s0 = CreateState("0"); var s0States = new StateCollection(); s0.ParallelSubStates.Add(s0States); sm.States.Add(s0); var s00 = CreateState("00"); s0States.Add(s00); var s01 = CreateState("01"); s0States.Add(s01); var t0 = new Transition { SourceState = s0, TargetState = s0, }; t0.Action += (s, e) => _events = _events + "A0"; s0States.InitialState = s01; sm.Update(TimeSpan.FromSeconds(1)); sm.Update(TimeSpan.FromSeconds(1)); t0.Fire(); sm.Update(TimeSpan.FromSeconds(1)); sm.Update(TimeSpan.FromSeconds(1)); Assert.AreEqual("E0E01U01U0U01U0X01X0A0E0E01U01U0U01U0", _events); }
/// <summary> /// Reads a CGT and creates all the objects needed to create /// a tokenizer and parser at a later time. /// </summary> /// <param name="stream">The CGT stream.</param> private void ReadFile(Stream stream) { try { Reset(); this.stream = stream; CalithaBinReader reader = new CalithaBinReader(stream); string header = ""; try { header = reader.ReadUnicodeString(); if (! header.StartsWith("GOLD")) throw new CGTStructureException("File header is invalid"); } catch (EndOfStreamException e) { throw new CGTStructureException("File header is invalid",e); } RecordCollection records = new RecordCollection(); while (!(stream.Position == stream.Length)) { records.Add(ReadRecord(reader)); } structure = new CGTStructure(header,records); content = new CGTContent(structure); dfaStates = CreateDFAStates(content); parserStates = CreateParserStates(content); } finally { stream.Close(); } }
public static StateCollection GetCollection() { StateCollection tempList = null; using (SqlConnection myConnection = new SqlConnection(AppConfiguration.ConnectionString)) { using (SqlCommand myCommand = new SqlCommand("usp_GetState", myConnection)) { myCommand.CommandType = CommandType.StoredProcedure; myCommand.Parameters.AddWithValue("@QueryId", SelectTypeEnum.GetCollection); myConnection.Open(); using (SqlDataReader myReader = myCommand.ExecuteReader()) { if (myReader.HasRows) { tempList = new StateCollection(); while (myReader.Read()) { tempList.Add(FillDataRecord(myReader)); } } myReader.Close(); } } } return(tempList); }
public Get(IServiceProvider services) { this.statecollection = services.GetService <StateCollection>(); this.logger = services.GetService <Logger>(); this.agenda = services.GetService <Agenda>(); this.constants = services.GetService <Constants>(); }
public void DuplicatesNotAllowed() { var sc = new StateCollection(); var s = new State(); sc.Add(s); sc.Add(s); }
public void CompositeState() { var sm = new StateMachine(); var s0 = CreateState("0"); var s0States = new StateCollection(); s0.ParallelSubStates.Add(s0States); sm.States.Add(s0); var s00 = CreateState("00"); s0States.Add(s00); var t = new Transition { SourceState = s00, TargetState = s0, }; t.Action += (s, e) => _events = _events + "A"; sm.Update(TimeSpan.FromSeconds(1)); t.Fire(); sm.Update(TimeSpan.FromSeconds(1)); Assert.AreEqual("E0E00U00U0X00X0AE0E00U00U0", _events); }
public virtual void WriteWhenInState(IndentedTextWriter indentedTextWriter, StateCollection stateCollection, State state) { int stateId = stateCollection[state]; indentedTextWriter.WriteLine(AssertCharactersInStack(MainStateStackName, stateId)); indentedTextWriter.WriteLine(@"(?<-{0}>)", MainStateStackName); }
public PatternBuilder(IEnumerable<State> states, IStackStateWriter stackStateWriter) { _stateCollection = new StateCollection(states); _stringBuilder = new StringBuilder(); _textWriter = new StringWriter(_stringBuilder); _indentedTextWriter = new IndentedTextWriter(_textWriter); _stackStateWriter = stackStateWriter; }
public void Test_Remove_Empty() { string group = "TestGroup"; StateCollection <string> collection = StateCollection <string> .Current(StateScope.Application, group); collection.Remove("Test"); }
public Applications(IServiceProvider services) { agenda = services.GetService <Agenda>(); logger = services.GetService <Logger>(); statecollection = services.GetService <StateCollection>(); notifier = services.GetService <Notifier>(); constants = services.GetService <Constants>(); }
/// <summary> /// Creates a new LALR parser. /// </summary> /// <param name="tokenizer">A tokenizer.</param> /// <param name="states">The LALR states.</param> /// <param name="startState">The starting state.</param> /// <param name="symbols"></param> public LALRParser(IStringTokenizer tokenizer, StateCollection states, State startState, SymbolCollection symbols) { this.tokenizer = tokenizer; this.states = states; this.startState = startState; this.symbols = symbols; storeTokens = StoreTokensMode.NoUserObject; }
static void Main(string[] args) { var coll = new StateCollection(); var state = new SomeState(); coll.AddState(state); Console.ReadKey(); }
public static ExecutionStateCommand Apply(TestRecord test, DirectoryInfo testBinariesDirectory) { ExecutionStateCommand command = new ExecutionStateCommand(); ExecutionEventLog.RecordStatus("Applying Execution State."); StateCollection.ApplyDeployments(test.TestInfo.Deployments, testBinariesDirectory); return(command); }
private void BindStateList() { StateCollection stateList = new StateCollection(); stateList = StateDAL.GetCollection(); rptStateList.DataSource = stateList; rptStateList.DataBind(); }
public void WritePushState(IndentedTextWriter indentedTextWriter, StateCollection stateCollection, State state) { var stateId = stateCollection[state]; foreach (var bit in EnumerateBits(stateCollection.Count, stateId)) { string stackName = GetStackName(bit.Position); indentedTextWriter.WriteLine(SingleStackStateWriter.PushCharactersToStack(stackName, bit.Value)); } }
/// <summary> /// 批量装载 /// </summary> internal static void LoadFromDALPatch(List <StateInfo> pList, StateCollection pCollection) { foreach (State state in pCollection) { StateInfo stateInfo = new StateInfo(); LoadFromDAL(stateInfo, state); pList.Add(stateInfo); } }
public static RunStateCommand Apply(DirectoryInfo testBinariesDirectory) { ExecutionEventLog.RecordStatus("STARTED : ------------- Gac Test Infra Assemblies ------------- |"); StateCollection infraLibraries = StateCollection.LoadStateCollection(@"Infra\GacTestLibraries.deployment", testBinariesDirectory); infraLibraries.Push(StatePool.Run); ExecutionEventLog.RecordStatus("COMPLETED: ------------- Gac Test Infra Assemblies ------------- |"); return(new RunStateCommand()); }
public MapStatusData() { Name = new LocalText(); Desc = new LocalText(); Comment = ""; Emitter = new EmptySwitchOffEmitter(); StatusStates = new StateCollection <MapStatusState>(); }
private void Reset() { stream = null; structure = null; content = null; dfaStates = null; parserStates = null; symbols = null; rules = null; }
private bool CanAddState() { var selectStateBlank = StateCollection.GetItemAt(0); if (SelectedState.Value == null || selectStateBlank == null || SelectedState.Value.Equals(selectStateBlank)) { return(false); } return(true); }
public static string Serialize(StateCollection stateCollection) { using (MemoryStream stream = new MemoryStream()) { BinaryFormatter serializer = new BinaryFormatter(); serializer.Serialize(stream, stateCollection); stream.Flush(); stream.Position = 0; return Convert.ToBase64String(stream.ToArray()); } }
public static StateProvinceProtocol[] ConvertCollection(StateCollection states) { StateProvinceProtocol[] protoStates = new StateProvinceProtocol[states.Count]; for(int i = 0; i < states.Count; i++ ) { protoStates[i] = new StateProvinceProtocol( states[i] ); } return protoStates; }
public static StateProvinceProtocol[] ConvertCollection(StateCollection states) { StateProvinceProtocol[] protoStates = new StateProvinceProtocol[states.Count]; for (int i = 0; i < states.Count; i++) { protoStates[i] = new StateProvinceProtocol(states[i]); } return(protoStates); }
public void Setup(StateCollection stateCollection, InputCollection inputCollection) { foreach (string state in stateCollection.GetStates()) { var stateDictionary = new Dictionary <string, Transition>(); foreach (string input in inputCollection.GetInputs()) { stateDictionary.Add(input, null); } Transitions.Add(state, stateDictionary); } }
private State GetInitialState(StateCollection states, ParseStatistics stats) { // Get the initial state from the states collection and initialize it with items from // the start symbol var initialState = states.InitialState; foreach (var production in _startSymbol.Productions) { var initialItem = new Item(production, initialState, initialState); stats.CreatedItems++; initialState.Add(initialItem); } return initialState; }
public ItemData() { Name = new LocalText(); Desc = new LocalText(); Icon = -1; Comment = ""; ItemStates = new StateCollection <ItemState>(); UseAction = new AttackAction(); Explosion = new ExplosionData(); UseEvent = new BattleData(); ThrowAnim = new Content.AnimData(); }
/// <summary> /// Constructs new instance of <see cref="TenantContext"/>. /// </summary> /// <param name="services">Tenant rescricted <see cref="IServiceProvider"/></param> /// <param name="tenant">Tenant object which represents this context.</param> public TenantContext(IServiceProvider services, Tenant tenant) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (tenant == null) { throw new ArgumentNullException(nameof(tenant)); } Services = services; Tenant = tenant; States = new StateCollection(); }
/// <summary> /// Adds all states and transitions from some <see cref="StateCollection"/>. /// </summary> public void AddStates(StateCollection states) { var oldStateCount = this.states.Count; foreach (var state in states) { var stateBuilder = this.AddState(); stateBuilder.SetEndWeight(state.EndWeight); foreach (var transition in state.Transitions) { var updatedTransition = transition.With(destinationStateIndex: transition.DestinationStateIndex + oldStateCount); stateBuilder.AddTransition(updatedTransition); } } }
public StatusData() { Name = new LocalText(); Desc = new LocalText(); Comment = ""; Emoticon = -1; DropEmoticon = -1; FreeEmote = -1; DrawEffect = DrawEffect.None; StatusStates = new StateCollection <StatusState>(); OnSkillChanges = new PriorityList <SkillChangeEvent>(); TargetPassive = new PassiveData(); }
public void WriteWhenInState(IndentedTextWriter indentedTextWriter, StateCollection stateCollection, State state) { var stateId = stateCollection[state]; var bits = EnumerateBits(stateCollection.Count, stateId) .Select(b => new { Bit = b, StackName = GetStackName(b.Position) }) .ToList(); foreach (var bit in bits) { indentedTextWriter.WriteLine(SingleStackStateWriter.AssertCharactersInStack(bit.StackName, bit.Bit.Value)); } foreach (var bit in bits) { indentedTextWriter.WriteLine("(?<-{0}>)", bit.StackName); } }
void Start() { // Initialize from spawner var stateSpawner = transform.parent.GetComponent<StateSpawner>(); stateCollection = stateSpawner.stateCollection; stateId = stateSpawner.stateId; // Customize based on state settings stateSettings = stateCollection.GetStateSettings(stateId); if (stateSettings.disableAfter > 0.0f) { enabledObject.SetActive(false); enabledObject = delayedObject; enabledObject.SetActive(true); } if (stateSettings.statesToEnableOnEnable != null || stateSettings.statesToDisableOnEnable != null) { linkedStatue.SetActive(true); defaultStatue.SetActive(false); } UpdateState(); }
public virtual void WriteAssertStateStackIsEmpty(IndentedTextWriter indentedTextWriter, StateCollection stateCollection) { indentedTextWriter.WriteLine(@"(?({0})(?!))", MainStateStackName); }
public void TestParallelStates2() { var sm = new StateMachine(); var s0 = CreateState("0"); sm.States.Add(s0); var s0A = new StateCollection(); s0.ParallelSubStates.Add(s0A); var s0B = new StateCollection(); s0.ParallelSubStates.Add(s0B); var s0C = new StateCollection(); s0.ParallelSubStates.Add(s0C); var s1 = CreateState("1"); sm.States.Add(s1); var sa0 = CreateState("a0"); s0A.Add(sa0); var sa1 = CreateState("a1"); s0A.Add(sa1); var sb0 = CreateState("b0"); s0B.Add(sb0); var sb1 = CreateState("b1"); s0B.Add(sb1); var sb2 = CreateState("b2"); s0B.Add(sb2); var sc0 = CreateState("c0"); s0C.Add(sc0); var sc1 = CreateState("c1"); s0C.Add(sc1); s0C.InitialState = sc1; // Set final state s0A.FinalState = sa1; s0B.FinalState = sb2; s0C.FinalState = null; var t0 = new Transition { SourceState = s0, TargetState = s1, FireAlways = true, }; t0.Action += (s, e) => _events = _events + "A0"; var ta0a1 = new Transition { SourceState = sa0, TargetState = sa1, FireAlways = true, }; ta0a1.Action += (s, e) => _events = _events + "Aa0a1"; var tb0b1 = new Transition { SourceState = sb0, TargetState = sb1, FireAlways = true, }; tb0b1.Action += (s, e) => _events = _events + "Ab0b1"; var tb1b2 = new Transition { SourceState = sb1, TargetState = sb2, FireAlways = true, }; tb1b2.Action += (s, e) => _events = _events + "Ab1b2"; var tc0c1 = new Transition { SourceState = sc0, TargetState = sc1, FireAlways = true, }; tc0c1.Action += (s, e) => _events = _events + "Ac0c1"; var tc1c0 = new Transition { SourceState = sc1, TargetState = sc0, }; tc1c0.Action += (s, e) => _events = _events + "Ac1c0"; tc1c0.Fire(); sm.Update(TimeSpan.FromSeconds(1)); tc1c0.Fire(); sm.Update(TimeSpan.FromSeconds(1)); tc1c0.Fire(); sm.Update(TimeSpan.FromSeconds(1)); tc1c0.Fire(); // tc1c0 fires --> t0 must not fire. sm.Update(TimeSpan.FromSeconds(1)); Assert.AreEqual("E0Ea0Eb0Ec1Ua0Ub0Uc1U0Xa0Aa0a1Ea1Xb0Ab0b1Eb1Xc1Ac1c0Ec0Ua1Ub1Uc0U0Xb1Ab1b2Eb2Xc0Ac0c1Ec1Ua1Ub2Uc1U0Xc1Ac1c0Ec0Ua1Ub2Uc0U0", _events); }
public void NullNotAllowed() { var sc = new StateCollection(); sc.Add(null); }
/// <summary> /// Creates a new DFA. /// </summary> /// <param name="states">The states that are part of the DFA.</param> /// <param name="startState">The starting state</param> public DFA(StateCollection states, State startState) { this.states = states; this.startState = startState; currentState = startState; }
/// <summary> /// 批量装载 /// </summary> internal static void LoadFromDALPatch(List< StateInfo> pList, StateCollection pCollection) { foreach (State state in pCollection) { StateInfo stateInfo = new StateInfo(); LoadFromDAL(stateInfo, state ); pList.Add(stateInfo); } }
/// <summary> /// 获得分页列表,无论是否是缓存实体都从数据库直接拿取数据 /// </summary> /// <param name="pPageIndex">页数</param> /// <param name="pPageSize">每页列表</param> /// <param name="pOrderBy">排序</param> /// <param name="pSortExpression">排序字段</param> /// <param name="pRecordCount">列表行数</param> /// <returns>数据分页</returns> public static List<StateInfo> GetPagedList(int pPageIndex,int pPageSize,SortDirection pOrderBy,string pSortExpression,out int pRecordCount) { if(pPageIndex<=1) pPageIndex=1; List< StateInfo> list = new List< StateInfo>(); Query q = State .CreateQuery(); q.PageIndex = pPageIndex; q.PageSize = pPageSize; q.ORDER_BY(pSortExpression,pOrderBy.ToString()); StateCollection collection=new StateCollection(); collection.LoadAndCloseReader(q.ExecuteReader()); foreach (State state in collection) { StateInfo stateInfo = new StateInfo(); LoadFromDAL(stateInfo, state); list.Add(stateInfo); } pRecordCount=q.GetRecordCount(); return list; }
/// <summary> /// 获得数据列表 /// </summary> /// <returns></returns> public static List<StateInfo> GetList() { string cacheKey = GetCacheKey(); //本实体已经注册成缓存实体,并且缓存存在的时候,直接从缓存取 if (CachedEntityCommander.IsTypeRegistered(typeof(StateInfo)) && CachedEntityCommander.GetCache(cacheKey) != null) { return CachedEntityCommander.GetCache(cacheKey) as List< StateInfo>; } else { List< StateInfo> list =new List< StateInfo>(); StateCollection collection=new StateCollection(); Query qry = new Query(State.Schema); collection.LoadAndCloseReader(qry.ExecuteReader()); foreach(State state in collection) { StateInfo stateInfo= new StateInfo(); LoadFromDAL(stateInfo,state); list.Add(stateInfo); } //生成缓存 if (CachedEntityCommander.IsTypeRegistered(typeof(StateInfo))) { CachedEntityCommander.SetCache(cacheKey, list); } return list; } }
/// <summary> /// Function to retrieve state collection /// </summary> /// <param name="queryStates">states query</param> /// <returns>state collection</returns> private static StateCollection RetrieveStateCollection(IEnumerable<State> queryStates) { StateCollection stateCollection = new StateCollection(); foreach (State state in queryStates) { stateCollection.Add(state); } return stateCollection; }
public void TwoCompositeStates() { var sm = new StateMachine(); var s0 = CreateState("0"); var s0States = new StateCollection(); s0.ParallelSubStates.Add(s0States); sm.States.Add(s0); var s1 = CreateState("1"); var s1States = new StateCollection(); s1.ParallelSubStates.Add(s1States); sm.States.Add(s1); var s00 = CreateState("00"); s0States.Add(s00); var s01 = CreateState("01"); s0States.Add(s01); var s10 = CreateState("10"); s1States.Add(s10); var s11 = CreateState("11"); s1States.Add(s11); var t0001 = new Transition { SourceState = s00, TargetState = s01, }; t0001.Action += (s, e) => _events = _events + "A0001"; var t0111 = new Transition { SourceState = s01, TargetState = s11, }; t0111.Action += (s, e) => _events = _events + "A0111"; var t101 = new Transition { SourceState = s1, TargetState = s10, }; t101.Action += (s, e) => _events = _events + "A101"; sm.Update(TimeSpan.FromSeconds(1)); t0001.Fire(); sm.Update(TimeSpan.FromSeconds(1)); t0111.Fire(); sm.Update(TimeSpan.FromSeconds(1)); t101.Fire(null, null); sm.Update(TimeSpan.FromSeconds(1)); Assert.AreEqual("E0E00U00U0X00A0001E01U01U0X01X0A0111E1E11U11U1X11X1A101E1E10U10U1", _events); }
public void TestWithFinalState() { var sm = new StateMachine(); var s0 = CreateState("0"); var s0States = new StateCollection(); s0.ParallelSubStates.Add(s0States); sm.States.Add(s0); var s1 = CreateState("1"); sm.States.Add(s1); var s00 = CreateState("00"); s0States.Add(s00); var s01 = CreateState("01"); s0States.Add(s01); var s02 = CreateState("02"); s0States.Add(s02); // Set final state s0States.FinalState = s02; var t0 = new Transition { SourceState = s0, TargetState = s1, FireAlways = true, }; t0.Action += (s, e) => _events = _events + "A0"; var t0001 = new Transition { SourceState = s00, TargetState = s01, }; t0001.Action += (s, e) => _events = _events + "A0001"; var t0102 = new Transition { SourceState = s01, TargetState = s02, }; t0102.Action += (s, e) => _events = _events + "A0102"; sm.Update(TimeSpan.FromSeconds(1)); sm.Update(TimeSpan.FromSeconds(1)); t0001.Fire(); sm.Update(TimeSpan.FromSeconds(1)); sm.Update(TimeSpan.FromSeconds(1)); t0102.Fire(); sm.Update(TimeSpan.FromSeconds(1)); sm.Update(TimeSpan.FromSeconds(1)); Assert.AreEqual("E0E00U00U0U00U0X00A0001E01U01U0U01U0X01A0102E02U02U0X02X0A0E1U1", _events); }
public void GenerateState() { var oldStateCollection = stateCollection; stateCollection = new StateCollection(); if (oldStateCollection != null) { stateCollection.level = oldStateCollection.level + 1; } stateCollection.Generate(); }
/// <summary> /// Maps the states. /// </summary> /// <param name="dataReader">The data reader.</param> /// <returns>State collection.</returns> private static async Task<StateCollection> MapStates(SqlDataReader dataReader) { var stateCollection = new StateCollection(); if (dataReader != null) { while (await dataReader.ReadAsync()) { var state = new State { CountryId = dataReader.Int32Field(CountryId).ToString(), StateId = dataReader.Int32Field(StateId).ToString(), Name = dataReader.StringField(Name) }; stateCollection.Add(state); } } return stateCollection; }
private void SetupReferenceData() { var countries = new Country { CountryId = "1", Name = "USA", Code = "USA" }; var states = new State { StateId = "2", CountryId = "1", Name = "Florida" }; var ports = new Port { PortId = "1", City = "Florida", Name = "Miami", State = "Florida", StateId = "2", CountryId = "1" }; var brands = new Brand { BrandId = "1", Name = "Carnival" }; var personTypes = new PersonTypeEntity { PersonTypeId = "1001", Name = "Daniel" }; var loyaltyLevelTypes = new LoyaltyLevelType { LoyaltyLevelTypeId = "1001", Name = "abc", BrandId = "1", NoOfCruiseNights = 3, LogoImageAddress = "abc" }; var documentType = new DocumentType { CountryId = "232", Code = "USA", DocumentTypeId = "1", Name = "Passport" }; var brand = new BrandCollection(); var country = new CountryCollection(); country.Add(countries); var state = new StateCollection(); state.Add(states); var documentTypes = new DocumentTypeCollection(); documentTypes.Add(documentType); var port = new PortCollection(); port.Add(ports); var personTypeEntity = new PersonTypeEntityCollection(); personTypeEntity.Add(personTypes); var loyaltyLevelType = new LoyaltyLevelTypeCollection(); loyaltyLevelType.Add(loyaltyLevelTypes); this.referenceData.AssignBrands(brand); this.referenceData.AssignCountries(country); this.referenceData.AssignStates(state); this.referenceData.AssignDocumentTypes(documentTypes); this.referenceData.AssignLoyaltyLevelTypes(loyaltyLevelType); this.referenceData.AssignPersonTypes(personTypeEntity); this.referenceData.AssignPorts(port); }
public void IgnoredHistory() { var sm = new StateMachine(); var s0 = CreateState("0"); sm.States.Add(s0); var s1 = CreateState("1"); var s1States = new StateCollection(); s1States.SaveHistory = true; s1.ParallelSubStates.Add(s1States); sm.States.Add(s1); var s10 = CreateState("10"); s1States.Add(s10); var s11 = CreateState("11"); s1States.Add(s11); var s12 = CreateState("12"); s1States.Add(s12); s1States.InitialState = s11; var t0 = new Transition { SourceState = s0, TargetState = s12, }; t0.Action += (s, e) => _events = _events + "A0"; var t1211 = new Transition { SourceState = s12, TargetState = s11, }; t1211.Action += (s, e) => _events = _events + "A1211"; var t1 = new Transition { SourceState = s1, TargetState = s0, }; t1.Action += (s, e) => _events = _events + "A1"; var t010 = new Transition { SourceState = s0, TargetState = s10, }; t010.Action += (s, e) => _events = _events + "A010"; sm.Update(TimeSpan.FromSeconds(1)); t0.Fire(); sm.Update(TimeSpan.FromSeconds(1)); t1211.Fire(); sm.Update(TimeSpan.FromSeconds(1)); t1.Fire(); sm.Update(TimeSpan.FromSeconds(1)); t010.Fire(); sm.Update(TimeSpan.FromSeconds(1)); Assert.AreEqual("E0U0X0A0E1E12U12U1X12A1211E11U11U1X11X1A1E0U0X0A010E1E10U10U1", _events); }
public void TestNoFinalState() { var sm = new StateMachine(); var s0 = CreateState("0"); var s0States = new StateCollection(); s0.ParallelSubStates.Add(s0States); sm.States.Add(s0); var s1 = CreateState("1"); sm.States.Add(s1); var s00 = CreateState("00"); s0States.Add(s00); var s01 = CreateState("01"); s0States.Add(s01); var s02 = CreateState("02"); s0States.Add(s02); Assert.AreEqual(null, s0States.FinalState); var t0 = new Transition { SourceState = s0, TargetState = s1, FireAlways = true, }; t0.Action += (s, e) => _events = _events + "A0"; sm.Update(TimeSpan.FromSeconds(1)); sm.Update(TimeSpan.FromSeconds(1)); Assert.AreEqual("E0E00U00U0X00X0A0E1U1", _events); }
public virtual void WritePushState(IndentedTextWriter indentedTextWriter, StateCollection stateCollection, State state) { int stateId = stateCollection[state]; indentedTextWriter.WriteLine(PushCharactersToStack(MainStateStackName, stateId)); }
//-------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="StateMachine"/> class. /// </summary> public StateMachine() { States = new StateCollection(); //States.StateMachine = this; }