public static YandexUserModel GetUser(HttpRequestBase request) { var model = new YandexUserModel { IsAutharization = false }; try { var userCookie = request.Cookies["yandex_token"]; if (userCookie != null) { var stream = HttpTools.PostStream(InfoUrl, string.Format("oauth_token={0}", userCookie.Value)); model = SerializeTools.Deserialize <YandexUserModel>(stream); model.IsAutharization = true; } } catch (Exception ex) { MonitorLog.WriteLog(ex.InnerException + ex.Message, MonitorLog.typelog.Error, true); model.IsAutharization = false; } return(model); }
/// <summary> 从byte加载对象 /// </summary> /// <param name="bytes"></param> /// <returns></returns> public static DownloadFile FromByte(byte[] bytes) { return(SerializeTools.BytesToObject(bytes) as DownloadFile); }
/// <summary> 吧对象转为byte[] /// </summary> public byte[] ToBytes() { return(SerializeTools.ObjectToBytes(this)); }
public override void Update(GameTime gameTime) { this._btnSurrender?.Update(gameTime); this._btnBack?.Update(gameTime); this._gameboard?.Update(gameTime); if (this._surrender) { this._surrender = false; RaiseSurrenderEvent(); } // 接收服务器传来的消息 NetIncomingMessage msg; while ((msg = this._client.NetClient.ReadMessage()) != null) { this._client.DecryptMessage(msg); switch (msg.MessageType) { case NetIncomingMessageType.DiscoveryResponse: Console.WriteLine("Found server at " + msg.SenderEndPoint + " name: " + msg.ReadString()); this._gameStatus = "已找到服务器,正在连接..."; this._client.Connect(msg.SenderEndPoint); break; case NetIncomingMessageType.VerboseDebugMessage: case NetIncomingMessageType.DebugMessage: case NetIncomingMessageType.WarningMessage: case NetIncomingMessageType.ErrorMessage: Console.WriteLine(msg.ReadString()); break; case NetIncomingMessageType.StatusChanged: NetConnectionStatus status = (NetConnectionStatus)msg.ReadByte(); if (status == NetConnectionStatus.Connected) { Console.WriteLine("connected to" + msg.SenderEndPoint); // 连接服务器成功,关闭监测线程 this._gameStatus = "连接服务器成功"; this._connected = true; this._connectTimer.Stop(); this._connectTime = 0; // 向服务器发送握手消息 SendClientJoinRequest(); } break; case NetIncomingMessageType.Data: var data = msg.Data; var message = SerializeTools.Deserialize <GameMessage>(data); Console.WriteLine(message.ClientId + "-" + message.Content + "-" + (Int32)message.MsgCode); OnMessage(message); //this._client.SendMessage(this._client.CreateGameMessage<HelloMessage>()); break; } this._client.NetClient.Recycle(msg); } base.Update(gameTime); }
public void OnMessage(Object peer) { var p = peer as NetPeer; NetIncomingMessage msg; while ((msg = p.ReadMessage()) != null) { msg.Decrypt(this._algo); switch (msg.MessageType) { case NetIncomingMessageType.DiscoveryRequest: ResponseDiscovery(msg.SenderEndPoint); break; case NetIncomingMessageType.ConnectionApproval: String s = msg.ReadString(); if (s == NetworkSetting.Encryptionkey) { msg.SenderConnection.Approve(); } else { msg.SenderConnection.Deny(); } break; case NetIncomingMessageType.VerboseDebugMessage: case NetIncomingMessageType.DebugMessage: case NetIncomingMessageType.WarningMessage: case NetIncomingMessageType.ErrorMessage: Console.WriteLine(msg.ReadString()); break; case NetIncomingMessageType.StatusChanged: NetConnectionStatus status = (NetConnectionStatus)msg.ReadByte(); if (status == NetConnectionStatus.Connected) { Console.WriteLine(NetUtility.ToHexString(msg.SenderConnection.RemoteUniqueIdentifier) + " connected!"); } else if (status == NetConnectionStatus.Disconnected) { Console.WriteLine(NetUtility.ToHexString(msg.SenderConnection.RemoteUniqueIdentifier) + " disconnected!"); } break; case NetIncomingMessageType.Data: try { var data = msg.Data; var message = SerializeTools.Deserialize <GameMessage>(data); Console.ForegroundColor = ConsoleColor.DarkMagenta; Console.WriteLine($"Receive Message From {NetUtility.ToHexString(message.ClientId)}::MsgCode:{(Int32)message.MsgCode},Content:{message.Content}"); Console.ResetColor(); OnGameMessage?.Invoke(message); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex); Console.ResetColor(); } break; } } p.Recycle(msg); }
public void SaveSecondNameJson(List <SecondName> secondNameTable) { string secondNameTableStr = SerializeTools.ListToJson <SecondName>(secondNameTable); File.WriteAllText(m_SecondNameTablePath, secondNameTableStr); }
public void SaveFirstNameJson(List <FirstName> firstNameTable) { string firstNameTableStr = SerializeTools.ListToJson <FirstName>(firstNameTable); File.WriteAllText(m_FirstNameTablePath, firstNameTableStr); }
public void SaveSpecialCustomerDataJson(List <CustomerData> specialCustomerDataTable) { string customerDataTableStr = SerializeTools.ListToJson <CustomerData>(specialCustomerDataTable); File.WriteAllText(m_SpecialCustomerTablePath, customerDataTableStr); }