/// <summary> /// 获取用户登陆凭证 /// </summary> void wxLogin() { var rsp = wc.GetStr(redirecturl + "&fun=new&version=v2"); outLog("login->" + Serialize.ToJson(rsp)); if (rsp.err) { if (rsp.err) { throw new Exception("登陆失败->" + Serialize.ToJson(rsp)); } } Regex reg = new Regex(@"<skey>(\S+?)</skey><wxsid>(\S+?)</wxsid><wxuin>(\d+)</wxuin><pass_ticket>(\S+?)</pass_ticket>"); passticket = String.Empty; baseRequest = new BaseRequest(); var m = reg.Match(rsp.data + ""); baseRequest.Skey = m.Groups[1].Value; baseRequest.Sid = m.Groups[2].Value; passticket = HttpUtility.UrlDecode(m.Groups[4].Value, Encoding.UTF8); lg.uin = baseRequest.Uin = Convert.ToInt64(m.Groups[3].Value); db.SubmitChanges(); outLog("loged->" + lg.uin); Loged?.Invoke(this); }
public bool Send(byte[] buffer) { if (buffer.Length == 0) { return(true); } var stream = _stream; if (stream.Any() == false) { return(false); } var message = new Message { Body = buffer, }; try { stream .ForEach(o => o.WriteMessage(message)); } catch (Exception e) { Loged?.Invoke(this, new LogEventArgs(e.Message)); return(false); } return(true); }
public bool StartClient(string hostName, int port) { Stop(); _cd = new CompositeDisposable(); TcpClient tcpClient; try { tcpClient = new TcpClient(hostName, port); } catch (SocketException e) { Loged?.Invoke(this, new LogEventArgs(e.Message)); return(false); } ReceiveMessage(tcpClient) .Catch((IOException e) => { Loged?.Invoke(this, new LogEventArgs(e.Message)); return(Observable.Empty <Message>()); }) .Subscribe() .AddTo(_cd); return(true); }
public static void Stop() { Loged?.Invoke("Stop...."); if (_host != null) { _host.Stop(); } }
/// <summary> /// /// </summary> //public static Dictionary<string, Dictionary<string, MethodInfo>> ActionDict = new Dictionary<string, Dictionary<string, MethodInfo>>(); public static void Start() { Loged?.Invoke("Start...."); string hostUri = $"http://localhost:{ConfModel.Port}"; _host = new NancyHost(new Uri(hostUri)); _host.Start(); }
public static void ReStart() { Loged?.Invoke("ReStart...."); try { Stop(); } catch (Exception) { // ignored } System.Threading.Thread.Sleep(3000); Start(); }
/// <summary> /// 登陆后初始化 /// </summary> void wxInit() { string url = String.Format("{0}/cgi-bin/mmwebwx-bin/webwxinit?pass_ticket={1}&skey={2}&r={3}", gateway, passticket, baseRequest.Skey, getcurrentseconds()); var rsp = wc.PostStr(url, Serialize.ToJson(new { BaseRequest = baseRequest })); outLog("init->" + Serialize.ToJson(rsp)); if (rsp.err) { throw new Exception("初始化失败->" + Serialize.ToJson(rsp)); } user = Serialize.FromJson <Contact>(rsp.data + "", "User"); _syncKey = Serialize.FromJson <SyncKey>(rsp.data + "", "SyncKey"); //lg.nickname = user.NickName; //db.SubmitChanges(); Loged?.Invoke(user); }
public bool StartListener(string ipAddress, int port) { Stop(); try { _tcpListener = new TcpListener(IPAddress.Parse(ipAddress), port); _tcpListener.Start(); } catch (SocketException e) { Loged?.Invoke(this, new LogEventArgs(e.Message)); return(false); } _cd = new CompositeDisposable(); Observable.Create <TcpClient>(async observer => { var tcpClient = await _tcpListener.AcceptTcpClientAsync(); observer.OnNext(tcpClient); observer.OnCompleted(); return(Disposable.Empty); }) .Repeat() .Select(o => ReceiveMessage(o).Catch((IOException e) => { Loged?.Invoke(this, new LogEventArgs(e.Message)); return(Observable.Empty <Message>()); })) .Merge() .Subscribe() .AddTo(_cd); return(true); }
public void OnLoged(string msg) { Loged?.Invoke($"[{ServiceName}]{msg}"); }
public static void OnLoged(string obj) { Loged?.Invoke(obj); }
private static void OnLoged(string obj) { Loged?.Invoke(obj); }