public void UnRegisterReceiver() { #region Event EventDispatch.UnRegisterReceiver <int>(EventID.Ready_Request, OnReadyRequest); EventDispatch.UnRegisterReceiver <EventConnect>(EventID.Connect_Request, OnConnectRequest); EventDispatch.UnRegisterReceiver <Command>(EventID.AddCommand, OnAddCommand); #endregion #region Message MessageDispatch.UnRegisterReceiver <GM_Accept>(MessageID.GM_ACCEPT_SC, OnAccept); MessageDispatch.UnRegisterReceiver <GM_Connect>(MessageID.GM_CONNECT_SC, OnConnectReturn); MessageDispatch.UnRegisterReceiver <GM_Connect>(MessageID.GM_CONNECT_BC, OnConnectBC); MessageDispatch.UnRegisterReceiver <GM_Disconnect>(MessageID.GM_DISCONNECT_BC, OnDisconnectBC); MessageDispatch.UnRegisterReceiver <GM_Ready>(MessageID.GM_READY_BC, OnReadyBC); MessageDispatch.UnRegisterReceiver <GM_Begin>(MessageID.GM_BEGIN_BC, OnBeginBC); MessageDispatch.UnRegisterReceiver <GM_Frame_BC>(MessageID.GM_FRAME_BC, OnFrameBC); MessageDispatch.UnRegisterReceiver <GM_Return>(MessageID.GM_PING_SC, OnPingReturn); #endregion #region Command CommandDispatch.UnRegisterReceiver <CMD_ReleaseSkill>(CommandID.RELEASE_SKILL, OnCommandReleaseSkill); CommandDispatch.UnRegisterReceiver <CMD_MoveToPoint>(CommandID.MOVE_TO_POINT, OnCommandMoveToPoint); CommandDispatch.UnRegisterReceiver <CMD_CreateMonster>(CommandID.CREATE_MONSTER, OnCreateMonster); #endregion }
// Must be done in the derived classes. public override void Dispatch(CommandDispatch commandDispatch) { if (commandDispatch != null) { commandDispatch.DispatchCommand(this); } }
public void BindCommondCommand(CommandDispatch dispatch) { dispatch.bind("exit", exit, LANG_COMMANDS_EXIT); dispatch.bind("restart", restart, LANG_COMMANDS_RESTART); dispatch.bind("stop", stop, LANG_COMMANDS_STOP); dispatch.bind("start", start, LANG_COMMANDS_START); dispatch.bind("status", status, LANG_COMMANDS_STATUS); dispatch.bind("sourcemsg", sourcemsg, LANG_COMMANDS_SOURCEMSG); dispatch.bind("clientmsg", clientmsg, LANG_COMMANDS_CLIENTMSG); dispatch.bind("clientusermsg", chatuser, LANG_COMMANDS_CLIENTUSERMSG); dispatch.bind("disable", disable, LANG_COMMANDS_DISABLE); dispatch.bind("client", switchclient, LANG_COMMANDS_SWITCH_CLIENT); dispatch.bind("sourcelogin", sourcelogin, LANG_COMMANDS_SOURCELOGIN); dispatch.bind("clear", clear, LANG_COMMANDS_CLEAR); dispatch.bind("help", help, LANG_COMMANDS_HELP); dispatch.bind("listlang", languages, LANG_COMMANDS_LISTLANG); dispatch.bind("lang", language, LANG_COMMANDS_LANG); dispatch.bind("msgmgr", msgmgr, LANG_COMMANDS_MSGMGR); dispatch.bind("sources", listsource, LANG_COMMANDS_SOURCES); dispatch.bind("filters", filters, LANG_COMMANDS_FILTERS); }
public void TestCommandAttributeNameAliasFromCommandType() { var command = new CommandDispatch() { CommandType = CommandType.PotatoAddConnection }; Assert.AreEqual("PotatoAddConnection", command.Name); Assert.AreEqual(CommandType.PotatoAddConnection, command.CommandType); }
public CommandResult Execute(ICommandSpec command) { var json = Serializer.Encode(command); var submission = new CommandSubmission(command, increment(ref cmdid), json); var dispatch = new CommandDispatch(submission); return(Execute(dispatch)); }
/// <summary> /// 执行命令 /// </summary> /// <param name="cmd"></param> private void DoCommand(Command cmd) { CommandID id = (CommandID)cmd.type; if (Debuger.ENABLELOG) { Debug.Log("执行关键帧 = " + id.ToString() + ",frametime = " + cmd.time); } CommandDispatch.Dispatch(cmd); }
CommandResult DoExecute(CommandDispatch dispatch) { var command = dispatch.Spec; if (!PatternExists(command.CommandName)) { return(CommandResult.Failure(command, error($"Handler for command {command.CommandName} not found"))); } var exec = patterns[command.CommandName].TryExecute(command); return(new CommandResult(command, exec.Value, exec.IsSome, exec.Message, dispatch.SubmissionId, dispatch.CorrelationToken)); }
public static void WithCommandHandler(this IServiceCollection builder, [CanBeNull] IEnumerable <Assembly> assemblyContainingCommands) { builder.AddSingleton <ICommandHandler>(s => { var a = new CommandDispatch(); if (assemblyContainingCommands != null) { foreach (var asm in assemblyContainingCommands) { a.RegisterAssembly(asm); } } return(a); }); }
CommandResult <TSpec, TPayload> ICommandExecutor <TSpec, TPayload> .Execute(CommandDispatch <TSpec> dispatch) { try { var spec = dispatch.Spec; Notify(ExecutingCommand(spec)); var execution = Pattern.TryExecute(dispatch); var message = execution.Message; var payload = execution.ValueOrDefault(); var success = execution.Exists; var result = new CommandResult <TSpec, TPayload>(spec, payload, success, message, dispatch.SubmissionId, dispatch.CorrelationToken); Notify(CommandResultComputed(result)); return(result); } catch (Exception e) { var errorResult = new CommandResult <TSpec, TPayload> ( dispatch.Spec, default, false, AppMessage.Error(e),
public CommandDispatch(CommandDispatch <TSpec> src) : base(src) { this.ts = src.ts; }
public CommandDispatch(CommandDispatch src) : base(new CommandSubmission <TSpec>((TSpec)src.Spec, src.SubmissionId, src.CommandJson, src.CorrelationToken, src.EnqueuedTime)) { this.ts = src.DispatchTime; }
Option <TPayload> ICommandExecutionService <TSpec, TPayload> .TryExecute(CommandDispatch <TSpec> spec) => TryExecute(spec);
public CommandResult Execute(CommandDispatch dispatch) => Try(() => DoExecute(dispatch)). MapValueOrElse(x => x, message => CommandResult.Failure(dispatch.Spec, message));
public CommandCompletion(CommandDispatch <TSpec> src, CommandResult <TSpec> result, DateTime?ts = null) : base(src) { this.Result = result; this.ts = ts ?? now(); }
Option <object> ICommandExecutionService <TSpec> .TryExecute(CommandDispatch <TSpec> spec) => TryExecute(spec);
public void TestCommandAttributeParseInvalidCommandType() { ICommandDispatch command = new CommandDispatch().ParseCommandType("CustomCommand"); Assert.AreEqual("CustomCommand", command.Name); Assert.AreEqual(CommandType.None, command.CommandType); }
public void TestCommandAttributeParseValidCommandType() { ICommandDispatch command = new CommandDispatch().ParseCommandType("PotatoAddConnection"); Assert.AreEqual("PotatoAddConnection", command.Name); Assert.AreEqual(CommandType.PotatoAddConnection, command.CommandType); }
// Must be done in the derived classes. public override void Dispatch(CommandDispatch commandDispatch) { if(commandDispatch != null) commandDispatch.DispatchCommand(this); }
protected virtual Option <TPayload> TryExecute(CommandDispatch <TSpec> submission) => TryExecute(submission.Spec);