public static void AddCallBack <T>(ServerMethod method, Action <T> callback) { _hubProxy.On <T>($"{method}", (response) => { callback(response); }); }
/// <summary> /// 添加任务到调度 /// </summary> /// <param name="methodServerInfo"></param> private void AddJob(ServerInfo methodServerInfo) { try { RecurringJob.RemoveIfExists(methodServerInfo.TaskName); var type = typeof(ServerMethod); MethodInfo method = type.GetMethod(methodServerInfo.TaskMethod); if (method != null) { RecurringJob.AddOrUpdate(methodServerInfo.TaskName, () => ServerMethod.Execute(methodServerInfo.TaskMethod, methodServerInfo), methodServerInfo.ExecTime, TimeZoneInfo.Local); } else if (methodServerInfo.TaskMethod.ToLower().StartsWith("http://") || methodServerInfo.TaskMethod.ToLower().StartsWith("https://")) { RecurringJob.AddOrUpdate(methodServerInfo.TaskName, () => ServerMethod.ExcuteApi(methodServerInfo), methodServerInfo.ExecTime, TimeZoneInfo.Local); } else { LogHelper.WriteLog("加入任务队列失败,未查找到任务执行方法", methodServerInfo.TaskName); return; } LogHelper.WriteLog("加入任务队列成功", methodServerInfo.TaskName); } catch (Exception ex) { LogHelper.WriteLog("加入任务队列失败," + ex.Message, methodServerInfo.TaskName); } }
protected static ServermoduleID RegisterServermoduleByTargetType(TargetType target, ConnectionInfo connInfo) { if (null == connInfo) { throw new Exception("Does not allow null"); } ServerMethod method = null; if (TargetType.SlaveOwnerServermodule.Equals(target)) //TODO expand { method = new RegisterSlaveOwnerServermoduleMethod() { ConnectionInfo = connInfo }; } //socket only used for getting the servermodule ID var setupSocket = new RequestSocket(); setupSocket.Connect("tcp://" + net_mq_util.NetMqUtil.SERVER_MODULE_IP + ":" + net_mq_util.NetMqUtil.SERVER_MODULE_PORT); var localCallID = new Random().Next(); if (null == method) { throw new Exception(); } var encodedMethod = net_mq_encoder.NetMqEncoder.GenerateServerModuleMethodMessage(new ServermoduleID() { ID = ProtocolConstants.SERVERMODULE_ID_NOT_YET_ASSIGNED }, new CallID() { ID = localCallID }, method); setupSocket.SendMultipartMessage(encodedMethod); var response = setupSocket.ReceiveMultipartMessage(); setupSocket.Close(); var decodedReponse = net_mq_decoder.NetMqDecoder.DecodeResponse <ServermoduleID>(response); if ( ProtocolConstants.SERVERMODULE_ID_NOT_YET_ASSIGNED.Equals(decodedReponse.Item2.Item1.ID) && localCallID.Equals(decodedReponse.Item2.Item2.ID) ) { return(decodedReponse.Item1); } else { throw new MethodFailedException("The SlaveOwner Setup method failed"); } }
public override void ReadResponse(NetworkPacket packet) { method = (ServerMethod)packet.ReadByte(); switch (method) { case ServerMethod.CONNECT: response.connect.Read(packet); break; case ServerMethod.HEARTBEAT: break; } }
public override void Start() { base.Start(); /// make singleton based _instance = this; DontDestroyOnLoad(this.gameObject); /// set socket function List <string> methodList = ServerMethod.GetConnectMethod(); foreach (var methodName in methodList) { On(methodName, OnRequest); } }
public static Tuple <ServerMethod, Tuple <ServermoduleID, CallID> > DecodeServerModuleMethod(NetMQMessage message) { var splitMessage = SplitMessageInContentAndMetaData(message); var methodName = splitMessage.Item1.Pop().ConvertToString(); //var firstFrame = message.Pop(); //var methodName = GetFromFrameString(firstFrame); //var secondFrame = message.Pop(); //var methodId = GetFromFrameString(secondFrame); //validate the target type if (false == IsTargetTypeCorrect(methodName, TargetType.ServerModule)) { throw new WrongTargetException(); } ServerMethod result = null; //the first frame have already been "Pop'ed" off and the message will therefore have one frame less than you would normally expect if (HelloWorldMethod.METHOD_NAME.Equals(methodName)) { result = DecodeServerMethodHelloWorld(message); } else if (RegisterSlaveOwnerServermoduleMethod.METHOD_NAME.Equals(methodName)) { result = DecodeServerMethodRegisterSlaveOwnerServermodule(message); } //else if (RegisterFileServermoduleMethod.METHOD_NAME.Equals(methodName)) //{ // result = DecodeServerMethodRegisterFileServermodule(message); //} //else if (RegisterDatabaseServermoduleMethod.METHOD_NAME.Equals(methodName)) //{ // result = DecodeServerMethodRegisterDatabaseServermodule(message); //} return(new Tuple <ServerMethod, Tuple <ServermoduleID, CallID> >(result, new Tuple <ServermoduleID, CallID>(splitMessage.Item2.Item1, splitMessage.Item2.Item2))); }
public override void ExecuteServer(ConnectedPlayer subject) { ServerMethod.Invoke(); }
public override void ExecuteServer() { ServerMethod.Invoke(); }
public static async Task InvokeAsync <T>(ServerMethod method, T argument) { await _hubProxy.Invoke($"{method}", argument); }
public Grid ServerMethod(ServerMethod serverMethod) { _serverMethod = serverMethod; return(this); }
public Grid ServerMethod(ServerMethod serverMethod) { _serverMethod = serverMethod; return this; }
public static NetMQMessage GenerateServerModuleMethodMessage(ServermoduleID servermoduleID, CallID callID, ServerMethod method) { var baseMessage = GenerateBaseMessage(servermoduleID.ID, callID.ID); if (method is HelloWorldMethod) { return(GenerateHelloWorldMessage(baseMessage, (HelloWorldMethod)method)); } else if (method is RegisterServermoduleMethod) { return(GenerateRegisterServermoduleMessage(baseMessage, (RegisterSlaveOwnerServermoduleMethod)method)); } throw new MethodFailedException(); }