private static void TransferMoneyExample() { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("=============================================================================="); Console.WriteLine("TransferMoneyExample"); Console.WriteLine("=============================================================================="); Console.ForegroundColor = ConsoleColor.White; //先创建两个客户(银行账户所有者) Console.WriteLine("创建银行客户1"); var customer1 = Repository.Add(new Customer("customer1")); Console.WriteLine("创建银行客户2"); var customer2 = Repository.Add(new Customer("customer2")); //分别为这两个客户创建一个银行账户 Console.WriteLine("为银行客户1创建银行账户"); var bankAccount1 = Repository.Add(new BankAccount(customer1.Id)); Console.WriteLine("为银行客户2创建银行账户"); var bankAccount2 = Repository.Add(new BankAccount(customer2.Id)); //分别为每个账户增加5000元金额,以方便后面的转账操作 Console.WriteLine(Environment.NewLine + "为银行客户1的银行账户存入5000元金额,以方便后面的转账操作"); EventProcesser.ProcessEvent(new DepositAccountMoneyEvent(bankAccount1.Id, 5000)); Console.WriteLine("为银行客户2的银行账户存入5000元金额,以方便后面的转账操作"); EventProcesser.ProcessEvent(new DepositAccountMoneyEvent(bankAccount2.Id, 5000)); //查看账户1和账户2中的账户余额 Console.WriteLine(Environment.NewLine + "银行客户1的银行账户转账前的余额:{0}", bankAccount1.MoneyAmount); Console.WriteLine("银行客户2的银行账户转账前的余额:{0}", bankAccount2.MoneyAmount); //执行转账操作,从账户1转1000元金额到账户2中 Console.WriteLine(Environment.NewLine + "执行转账操作,从银行客户1的银行账户转1000元金额到银行客户2的银行账户中"); EventProcesser.ProcessEvent(new TransferEvent(bankAccount1.Id, bankAccount2.Id, 1000, DateTime.Now)); //查看账户1和账户2中的账户余额,以及转账记录 Console.WriteLine(Environment.NewLine + "银行客户1的银行账户转账后的余额:{0}", bankAccount1.MoneyAmount); Console.WriteLine("银行客户2的银行账户转账后的余额:{0}", bankAccount2.MoneyAmount); var transferHistoryOfAccount1 = bankAccount1.TransferHistories.ToList()[0]; var transferHistoryOfAccount2 = bankAccount2.TransferHistories.ToList()[0]; Console.WriteLine(Environment.NewLine + "银行客户1的银行账户的转账记录:"); Console.WriteLine( "源帐号:{0},目标帐号{1},转账金额:{2},转账金额:{3}", transferHistoryOfAccount1.FromAccountId, transferHistoryOfAccount1.ToAccountId, transferHistoryOfAccount1.MoneyAmount, transferHistoryOfAccount1.TransferDate); Console.WriteLine("银行客户2的银行账户的转账记录:"); Console.WriteLine( "源帐号:{0},目标帐号{1},转账金额:{2},转账金额:{3}", transferHistoryOfAccount2.FromAccountId, transferHistoryOfAccount2.ToAccountId, transferHistoryOfAccount2.MoneyAmount, transferHistoryOfAccount2.TransferDate); }
void Start() { BackMenuEvent = BackMenuEventProcesser; FSM GameFlowFSM = FSMManager.One.GetFSM((int)FSM_ID.GameFlowFSMState); if (!GameFlowFSM.IsEventRepeat("GameOverEvent")) { FSMManager.One.GetFSM((int)FSM_ID.GameFlowFSMState).AddEventProcesser("BackMenu", BackMenuEvent); } }
public BaseReply RemoveUserRole(RemoveUserRoleRequest request) { return(ProcessRequest( () => { EventProcesser.ProcessEvent(new RemoveUserRoleEvent { UserId = request.UserId, RoleId = request.RoleId }); })); }
public bool AddEventProcesser(int Type, EventProcesser EventProcesser) { if (this.EventMap.ContainsKey(Type) == true) { Debug.LogError("EventProcesser is repeated."); return(false); } this.EventMap.Add(Type, EventProcesser); return(true); }
public BaseReply RemoveSectionRoleUser(RemoveSectionRoleUserRequest request) { return(ProcessRequest( () => { EventProcesser.ProcessEvent(new RemoveSectionRoleUserEvent { SectionId = request.SectionId, RoleId = request.RoleId, UserId = request.UserId }); })); }
public BaseReply CloseThread(CloseThreadRequest request) { return(ProcessRequest( () => { EventProcesser.ProcessEvent(new CloseThreadEvent { ThreadId = request.ThreadId, PostAuthorMarks = request.PostAuthorMarks }); })); }
public bool AddEventProcesser(string Type, EventProcesser eventProcesser) { if (IsEventRepeat(Type)) { Debug.LogError("EventProcesser is repeated."); return(false); } this.EventMap.Add(Type, eventProcesser); return(true); }
void Start() { DifficultyValue = 1; OkEvent = OkEventProcesser; FSM GameFlowFSM = FSMManager.One.GetFSM((int)FSM_ID.GameFlowFSMState); if (!GameFlowFSM.IsEventRepeat("_selectDifficulty")) { FSMManager.One.GetFSM((int)FSM_ID.GameFlowFSMState).AddEventProcesser("_selectDifficulty", OkEvent); } }
public BaseReply UpdateGroup(UpdateGroupRequest request) { return(ProcessRequest( () => { var group = Repository.Get <Group, Guid>(request.Id); EventProcesser.ProcessEvent(new ChangeGroupSubjectEvent { GroupId = request.Id, NewSubject = request.Subject }); group.Enabled = request.Enabled; })); }
public BaseReply UpdateSection(UpdateSectionRequest request) { return(ProcessRequest( () => { var section = Repository.Get <Section, Guid>(request.Id); EventProcesser.ProcessEvent(new ChangeSectionSubjectEvent { SectionId = request.Id, NewSubject = request.Subject }); section.Enabled = request.Enabled; section.GroupId = request.GroupId; })); }
public void Handle(CloseThreadEvent evnt) { if (ReleaseStatus != ThreadReleaseStatus.Close) { if (evnt.PostAuthorMarks.Values.Sum() != Marks) { throw new ThreadCloseMarksNotMatchException(ForumValidationError.CloseThreadTotalMarksNotMatch.GetName(), evnt.PostAuthorMarks.Values.Sum(), Marks); } ReleaseStatus = ThreadReleaseStatus.Close; EventProcesser.ProcessEvent(new ThreadClosedEvent { Thread = this }); } }
static void Main(string[] argsArray) { var shell = new Shell(); var systemId = SystemGuidLoader.LoadOrCreateOrEmpty(); var sessionId = Guid.NewGuid(); var log = ReportFactory.GetReporter(systemId, sessionId, "UnoHost"); var descriptiveString = "UnoHost (" + argsArray.Select(a => "\"" + a + "\"").Join(" ") + ")"; try { AppDomain.CurrentDomain.ReportUnhandledExceptions(log); var dispatcher = new Dispatcher(Thread.CurrentThread); log.Info("Starting " + descriptiveString, ReportTo.LogAndUser); var argsList = argsArray.ToList(); var args = UnoHostArgs.RemoveFrom(argsList, shell); NSApplication.Init(); NSApplication.SharedApplication.Delegate = new AppDelegate(); AppDelegate.ThrowOnTerminate = false; Action exit = () => { log.Info("Stopping " + descriptiveString); NSApplication.SharedApplication.Terminate(NSApplication.SharedApplication); }; Console.CancelKeyPress += (sender, e) => exit(); NSApplication.CheckForIllegalCrossThreadCalls = false; // Load metadata var unoHostProject = UnoHostProject.Load(args.MetadataPath, shell); Action <Exception> onLostConnection = exception => { if (exception == null) { log.Info("CommunicationProtocol closed"); } else { log.Exception("CommunicationProtocol failed", exception); } exit(); }; var renderTarget = new IOSurfaceRenderTarget(); var glView = new UnoView.UnoView(dispatcher, log, renderTarget) { WantsBestResolutionOpenGLSurface = true }; glView.PrepareOpenGL(); // We have to call this method manually because the view isn't bound to a window var openGlVersion = new Subject <OpenGlVersion>(); var messagesTo = new Subject <IBinaryMessage>(); var output = Observable.Merge( messagesTo, openGlVersion.Select(OpenGlVersionMessage.Compose), renderTarget.SurfaceRendered.Select(NewSurfaceMessage.Compose)); if (!args.IsDebug) { args.OutputPipe.BeginWritingMessages( "Designer", ex => Console.WriteLine("UnoHost failed to write message to designer: " + ex), output.ObserveOn(new QueuedDispatcher())); } glView.Initialize(unoHostProject, openGlVersion); var messagesFrom = args.InputPipe .ReadMessages("Designer") .RefCount() .ObserveOn(dispatcher) .Publish(); messagesFrom.SelectSome(CocoaEventMessage.TryParse) .Subscribe(e => EventProcesser.SendEvent(glView, e), onLostConnection, () => onLostConnection(null)); // Fuselibs fails during construction if we don't get this, and we can't wait for it because we are dispatching responses on our queue glView.Resize(new SizeData(Size.Create <Points>(0, 0), 1.0)); messagesFrom.SelectSome(ResizeMessage.TryParse) .Subscribe(glView.Resize, onLostConnection, () => onLostConnection(null)); var size = glView.Size.Transpose(); // Run the uno entrypoints, this initializes Uno.Application.Current unoHostProject.ExecuteStartupCode(); var app = Uno.Application.Current as dynamic; // Init plugins FusionImplementation.Initialize(dispatcher, args.UserDataPath, app.Reflection); var overlay = PluginManager.Initialize(messagesFrom, messagesTo, dispatcher, glView.PerFrame, size); app.ResetEverything(true, overlay); // Ready to go messagesFrom.Connect(); messagesTo.OnNext(new Ready()); NSApplication.SharedApplication.Run(); } catch (Exception e) { log.Exception("Exception in " + descriptiveString, e); } }