internal void DispatchRealData(Msg msg) { int cmd = msg.Cmd; if (cmdCallbackMap.ContainsKey(cmd)) { CmdCallback callback = cmdCallbackMap [cmd]; if (callback != null) { callback(msg); } cmdCallbackMap.Remove(cmd); } else if (cmdCallbackWraperMap.ContainsKey(cmd)) { CmdCallbackWraper cmdCallbackWraper = cmdCallbackWraperMap[cmd]; if (cmdCallbackWraper != null) { cmdCallbackWraper.proc(msg); cmdCallbackWraperMap.Remove(cmd); } } else { if (onMsgPush != null) { onMsgPush(msg); } } }
public void Cmd(string c, CmdCallback cb = null) { StreamWriter sw = p.StandardInput; queue.Add(new CmdQueue(c, cb)); // ;?e is a hackaround to bypass the imposibility to read byte-per-byte sw.WriteLine(c + ";?e"); }
public void VerifiyCode(string mobilePhone, string verificationCode, CmdCallback callback) { Msg msg = new Msg(AccountSrvCodeMap.Cmd.CMD_ACCOUNT_VERIFY_CODE); msg.AddParam(AccountSrvCodeMap.Param.ACCOUNT_OPEN_ID, mobilePhone); msg.AddParam(AccountSrvCodeMap.Param.ACCOUNT_VERIFICATION_CODE, verificationCode); sendHttpMessage(appCfg.LoginUrl, msg, callback); }
public void registAuthAccount(String userName, String pwd, CmdCallback onRegistReturn) { Msg msg = new Msg(AccountSrvCodeMap.Cmd.CMD_ACCOUNT_REGIST); msg.AddParam(AccountSrvCodeMap.Param.ACCOUNT_OPEN_ID, userName); msg.AddParam(AccountSrvCodeMap.Param.ACCOUNT_PWD, pwd); sendHttpMessage(appCfg.LoginUrl, msg, onRegistReturn); }
public void registAuthAccount(String userName, String pwd, CmdCallback onRegistReturn) { Msg msg = new Msg(AccountSrvCodeMap.Cmd.CMD_ACCOUNT_REGIST); msg.AddParam(AccountSrvCodeMap.Param.ACCOUNT_OPEN_ID, userName); msg.AddParam(AccountSrvCodeMap.Param.ACCOUNT_PWD, pwd); msg.AddParam(AccountSrvCodeMap.Param.ACCOUNT_SDK_CODE, SDKCode.ACCOUNT_AUTH); msg.AddParam(AccountSrvCodeMap.Param.ACCOUNT_SRV_VERSION, appCfg.PkgVersion); sendHttpMessage(appCfg.LoginUrl, msg, onRegistReturn, AccountSrvTimeOut); }
public virtual void Unregister(int commandName, CmdCallback commandType) { lock (SyncMsgMap) { if (MsgMap.ContainsKey(commandName)) { // ReSharper disable once DelegateSubtraction MsgMap[commandName] -= commandType; } } }
/* * public static ManualResetEvent allDone = new ManualResetEvent(false); * List<CmdQueue> queue; * const int BUFFER_SIZE = 1024; * private static void ReadCallBack(IAsyncResult asyncResult) { * // Get the RequestState object from AsyncResult. * RequestState rs = (RequestState)asyncResult.AsyncState; * * // Retrieve the ResponseStream that was set in RespCallback. * Stream responseStream = rs.ResponseStream; * * // Read rs.BufferRead to verify that it contains data. * int read = responseStream.EndRead( asyncResult ); * if (read > 0) { * // Prepare a Char array buffer for converting to Unicode. * Char[] charBuffer = new Char[BUFFER_SIZE]; * * // Convert byte stream to Char array and then to String. * // len contains the number of characters converted to Unicode. * int len = * rs.StreamDecode.GetChars(rs.BufferRead, 0, read, charBuffer, 0); * * String s = new String(charBuffer, 0, len); * System.Console.WriteLine("_____ "+s); * * // Append the recently read data to the RequestData stringbuilder * // object contained in RequestState. * rs.RequestData.Append( * Encoding.ASCII.GetString(rs.BufferRead, 0, read)); * * // Continue reading data until * // responseStream.EndRead returns –1. * IAsyncResult ar = responseStream.BeginRead( * rs.BufferRead, 0, BUFFER_SIZE, * new AsyncCallback(ReadCallBack), rs); * } else { * if(rs.RequestData.Length>0) * { * // Display data to the console. * string strContent; * strContent = rs.RequestData.ToString(); * } * // Close down the response stream. * responseStream.Close(); * // Set the ManualResetEvent so the main thread can exit. * //allDone.Set(); * } * return; * } * private static void RespCallback(IAsyncResult ar) { * // Get the RequestState object from the async result. * RequestState rs = (RequestState) ar.AsyncState; * // Get the WebRequest from RequestState. * WebRequest req = rs.Request; * // Call EndGetResponse, which produces the WebResponse object * // that came from the request issued above. * WebResponse resp = req.EndGetResponse(ar); * * // Start reading data from the response stream. * Stream ResponseStream = resp.GetResponseStream(); * * // Store the response stream in RequestState to read * // the stream asynchronously. * rs.ResponseStream = ResponseStream; * * // Pass rs.BufferRead to BeginRead. Read data into rs.BufferRead * IAsyncResult iarRead = ResponseStream.BeginRead(rs.BufferRead, 0, * BUFFER_SIZE, new AsyncCallback(ReadCallBack), rs); * } * public async Task<string> CmdAsync(string cmd, CmdCallback cb = null) { #if 0 * if (System.Net.Http) * var client = new System.Net.Http.HttpClient(); * Task<string> getstringTask = client.GetStringAsync (uri+cmd); * queue.Add (new CmdQueue (cmd, cb)); * string data = await getstringTask; * cb (data); * return getstringTask; #endif * WebRequest request = WebRequest.Create(uri+cmd); * RequestState rs = new RequestState (); * queue.Add (new CmdQueue (cmd, cb)); * rs.Request = request; * IAsyncResult r = (IAsyncResult) request.BeginGetResponse( * new AsyncCallback (RespCallback), rs); * } * * public void WaitAll() { * Task.WaitAll (tasks.ToArray ()); * } */ public void Cmd(string cmd, CmdCallback cb = null) { WebRequest request = WebRequest.Create(uri + cmd); WebResponse response = request.GetResponse(); Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd(); response.Close(); cb(responseFromServer); }
public bool sendMessage(int clientKey, Msg msg, CmdCallback callback) { if (!otherClients.ContainsKey(clientKey)) { logReport.OnWarningReport("send:" + msg.ToString() + " fail,invalide clientKey:" + clientKey); return(false); } bool rs = otherClients[clientKey].Send(msg, callback); logReport.OnLogReport("send:" + msg.ToString() + ",time:" + gameSrvClient.Runtime); return(rs); }
/// <summary> /// Parse the input command /// </summary> /// <param name="cmd"></param> private static void ParseInputCmd(String cmd) { CmdCallback cb = null; if (CmdDict.TryGetValue(cmd, out cb) && null != cb) { cb(cmd); } else { System.Console.WriteLine("Unknown command, enter help to view the specific command information"); } }
public virtual void Register(int commandName, CmdCallback command) { lock (SyncMsgMap) { if (!MsgMap.ContainsKey(commandName)) { MsgMap[commandName] = new CmdCallback(command); } else { MsgMap[commandName] += new CmdCallback(command); } } }
public void Send(Msg msg, CmdCallback callback) { if (callback != null) { DateTime now = DateTime.Now; msg.SendTime = now; } //实例委托 AsyncEventHandler asy = new AsyncEventHandler(HttpAsyncEvent); cmdDelegate.AddCmdCallbackMap(msg, callback); //异步调用开始,没有回调函数和AsyncState,都为null asy.BeginInvoke(msg, null, asy); }
public string Cmd(string c, CmdCallback cb = null) { if (this.doAsync) { StreamWriter sw = p.StandardInput; queue.Add(new CmdQueue(c, cb)); // ;?e is a hackaround to bypass the imposibility to read byte-per-byte sw.WriteLine(c + ";?e"); return(null); } string str = CmdSync(c); cb(str); return(str); }
public void sendHttpMessage(string url, Msg msg, CmdCallback callback) { HttpClient httpClient = null; if (httpClients.ContainsKey(url)) { httpClient = httpClients [url]; } if (httpClient == null) { httpClient = new HttpClient(url); httpClient.Decoder = httpDecoder; httpClient.Encoder = httpEncoder; httpClients.Add(url, httpClient); } httpClient.Send(msg, callback); }
public void BindAuthAccount(int sdkCode, String openId, string verifyCode, string pwd, CmdCallback onBindReturn) { Msg msg = new Msg(AccountSrvCodeMap.Cmd.CMD_ACCOUNT_RELACCOUNT_BIND); msg.AddParam(AccountSrvCodeMap.Param.ACCOUNT_SDK_CODE, sdkCode); msg.AddParam(AccountSrvCodeMap.Param.ACCOUNT_OPEN_ID, openId); msg.AddParam(AccountSrvCodeMap.Param.ACCOUNT_UID, uid); msg.AddParam(AccountSrvCodeMap.Param.ACCOUNT_VERIFICATION_CODE, verifyCode); msg.AddParam(AccountSrvCodeMap.Param.ACCOUNT_PWD, pwd); sendHttpMessage2(appCfg.LoginUrl, msg, new BindReturnWraper(onBindReturn), AccountSrvTimeOut); }
public CmdQueue(string cmd, CmdCallback cb) { this.Command = cmd; this.Callback = cb; }
public void RegistAuthAccount(string userName, string pwd, int sdkCode, string verificationCode, CmdCallback onRegistReturn) { Msg msg = new Msg(AccountSrvCodeMap.Cmd.CMD_ACCOUNT_REGIST); msg.AddParam(AccountSrvCodeMap.Param.ACCOUNT_OPEN_ID, userName); msg.AddParam(AccountSrvCodeMap.Param.ACCOUNT_PWD, pwd); msg.AddParam(AccountSrvCodeMap.Param.ACCOUNT_SDK_CODE, sdkCode); msg.AddParam(AccountSrvCodeMap.Param.ACCOUNT_VERIFICATION_CODE, verificationCode); msg.AddParam(AccountSrvCodeMap.Param.ACCOUNT_SRV_VERSION, appCfg.PkgVersion); sendHttpMessage(appCfg.LoginUrl, msg, onRegistReturn, AccountSrvTimeOut); }
public NetServiceCmdCallbackWraper(NetService netService, CmdCallback cmdCallback) : base(cmdCallback) { this.netService = netService; }
public bool sendMessage(Msg msg, CmdCallback callback) { bool rs = gameSrvClient.Send(msg, callback); return(rs); }
public bool sendMessage(Msg msg, CmdCallback callback) { bool rs = gameSrvClient.Send(msg, new NetServiceCmdCallbackWraper(this, callback)); return(rs); }
public void sendHttpMessage(string url, Msg msg, CmdCallback callback, common.net.http.OnTimeOut onTimeOut) { sendHttpMessage2(url, msg, callback, onTimeOut); }
public OnNoticePaySuccessReturnWraper(int sdkCode, OnNoticePaySuccessReturn onNoticePaySuccessReturn, CmdCallback cmdCallback) : base(cmdCallback) { this.sdkCode = sdkCode; this.onNoticePaySuccessReturn = onNoticePaySuccessReturn; }
public void sendHttpMessage(string url, Msg msg, CmdCallback callback) { sendHttpMessage(url, msg, callback, null); }
public CmdCallbackWraper(CmdCallback cmdCallback) { this.cmdCallback = cmdCallback; }
public BindReturnWraper(CmdCallback cmdCallback) : base(cmdCallback) { CmdCallback = cmdCallback; }
public PaymentCmdCallbackWraper(PaymentService paymentService, int sdkCode, int productId, string sdkProductId, int productNum, float price, string currency, SDKHandler sdkHandler, ReqPayOrderReturn reqPayOrderReturn, CmdCallback cmdCallback) : base(cmdCallback) { this.paymentService = paymentService; this.sdkCode = sdkCode; this.productId = productId; this.sdkProductId = sdkProductId; this.productNum = productNum; this.price = price; this.currency = currency; this.sdkHandler = sdkHandler; this.reqPayOrderReturn = reqPayOrderReturn; }