예제 #1
0
		protected override State AccountFactory(Spacetime st, IHTimestamp stamp, int index)
		{
			var firstId = TStateId.DebugCreate(111ul);
			var secondId = TStateId.DebugCreate(222ul);
			var ret = new MonitoredAccount(TStateId.DebugCreate(111ul * ((ulong)index + 1)), stamp);
			if (index == 0)
			{
			ret.RegisterInlineTrigger((s) =>
				{
					StateRef from = new ScopedStateRef(firstId, typeof(MonitoredAccount).Name),
						to = new ScopedStateRef(secondId, typeof(MonitoredAccount).Name);

					WithIn.GetWithin().DeferExecute("Transfer", Utils.MakeArgList("fromAcc", from, "toAcc", to), 100.0f);
				},
				(s) =>  (s as MonitoredAccount).Balance > 100 );
			}
			else
			{
			ret.RegisterInlineTrigger((s) =>
				{
					StateRef from = new ScopedStateRef(secondId, typeof(MonitoredAccount).Name),
						to = new ScopedStateRef(firstId, typeof(MonitoredAccount).Name);

					WithIn.GetWithin().DeferExecute("Transfer", Utils.MakeArgList("fromAcc", from, "toAcc", to), 100.0f);
				},
				(s) =>  (s as MonitoredAccount).Balance > 100 );
			}
			return ret;
		}
예제 #2
0
		public void TwoTriggers()
		{
			Setup();

			var firstId = TStateId.DebugCreate(111ul);
			var secondId = TStateId.DebugCreate(222ul);

			using (new WithIn(m_spacetimes[0]))
				m_accountingInvoker.Deposit(m_accounts[0], 100.0f);

			using (new WithIn(m_spacetimes[1]))
				m_accountingInvoker.Deposit(m_accounts[1], 100.0f);

			m_spacetimes[1].PullAllFrom(m_spacetimes[0].Snapshot(m_spacetimes[1].LatestEvent));
			m_spacetimes[0].PullAllFrom(m_spacetimes[1].Snapshot(m_spacetimes[0].LatestEvent));

			m_accountStates[0].RegisterInlineTrigger((s) =>
				{
					StateRef from = new ScopedStateRef(firstId, typeof(MonitoredAccount).Name),
						to = new ScopedStateRef(secondId, typeof(MonitoredAccount).Name);

					WithIn.GetWithin().DeferExecute("Transfer", Utils.MakeArgList("fromAcc", from, "toAcc", to), 100.0f);
				},
				(s) => (s as MonitoredAccount).Balance > 100);

			m_accountStates[1].RegisterInlineTrigger((s) =>
				{
					StateRef from = new ScopedStateRef(secondId, typeof(MonitoredAccount).Name),
						to = new ScopedStateRef(firstId, typeof(MonitoredAccount).Name);

					WithIn.GetWithin().DeferExecute("Transfer", Utils.MakeArgList("fromAcc", from, "toAcc", to), 100.0f);
				},
				(s) => (s as MonitoredAccount).Balance > 100);

			using (new WithIn(m_spacetimes[0]))
				m_accountingInvoker.Deposit(m_accounts[0], 5.0f);
		}