private void saveData() { //save data to chitietHDN ChiTietHDN ctHDN = new ChiTietHDN(); ctHDN.IDHDN = mIDHDN; ctHDN.IDSP = (long)cboSanPham.EditValue; ctHDN.SoLuong = Convert.ToDouble(txtSoLuong.Text.Trim()); ctHDN.Dongia = Convert.ToDouble(txtDonGia.Text.Trim()); ctHDN.VAT = Convert.ToDouble(txtVAT.Text.Trim()); //save data to SanPham: so luong nhap va gia nhap. SanPham sp = db.SanPhams.FirstOrDefault(x => x.ID == ctHDN.IDSP); sp.SoLuong = sp.SoLuong + ctHDN.SoLuong; sp.GiaNhap = ctHDN.Dongia * (1 + ctHDN.VAT / 100); //save data to HDN HoaDonNhap hd = db.HoaDonNhaps.FirstOrDefault(x => x.ID == ctHDN.IDHDN); hd.TongTien = hd.TongTien + sp.GiaNhap * ctHDN.SoLuong; db.ChiTietHDNs.Add(ctHDN); db.SaveChanges(); loadDatatoGridView(); MsgUtil.MessageThemSuccess(); }
private void btnThem_Click(object sender, EventArgs e) { try { QuanLyBanHangEntities db = new QuanLyBanHangEntities(); if (validate.CheckTextBoxisEmpty(txtMaHDX) && checkExistMaHDX(db)) { HoaDonXuat hdx = new HoaDonXuat(); hdx.IDTK = MsgUtil.userID; hdx.MaHDX = txtMaHDX.Text.Trim(); hdx.NgayXuat = dtNgayXuat.Value; if (txtKhachHang.Text.Length > 0) { hdx.TenKhachHang = txtKhachHang.Text.Trim(); } if (txtDienThoai.Text.Length > 0) { hdx.DienThoai = txtDienThoai.Text.Trim(); } db.HoaDonXuats.Add(hdx); db.SaveChanges(); loadDatatoGrid(); MsgUtil.MessageThemSuccess(); } } catch (Exception v_e) { MsgUtil.MessageThongBao("Lỗi " + v_e); } }
private void saveData() { //save data to chitietHDN ChiTietHDX ctHDX = new ChiTietHDX(); ctHDX.IDHDX = mIDHDX; ctHDX.IDSP = (long)cboSanPham.EditValue; ctHDX.SoLuong = Convert.ToDouble(txtSoLuong.Text.Trim()); ctHDX.DonGia = Convert.ToDouble(txtDonGia.Text.Trim()); ctHDX.VAT = Convert.ToDouble(txtVAT.Text.Trim()); //save data to SanPham: so luong nhap va gia nhap. SanPham sp = db.SanPhams.FirstOrDefault(x => x.ID == ctHDX.IDSP); sp.SoLuong = sp.SoLuong - ctHDX.SoLuong; if (sp.SoLuong < 0) { MsgUtil.MessageThongBao("Số lượng sản phẩm này trong kho không đủ để xuất! Vui lòng kiểm tra lại."); return; } sp.GiaBan = ctHDX.DonGia * (1 + (Double)ctHDX.VAT / 100); //save data to HDN HoaDonXuat hd = db.HoaDonXuats.FirstOrDefault(x => x.ID == ctHDX.IDHDX); hd.TongTien = hd.TongTien + sp.GiaBan * ctHDX.SoLuong; db.ChiTietHDXes.Add(ctHDX); db.SaveChanges(); loadDatatoGrid(); MsgUtil.MessageThemSuccess(); }
static ISteamSerializableHeader ReadHeader(uint rawEMsg, Stream stream) { ISteamSerializableHeader header; if (MsgUtil.IsProtoBuf(rawEMsg)) { header = new MsgHdrProtoBuf(); } else { switch (rawEMsg) { case (uint)EMsg.ChannelEncryptRequest: case (uint)EMsg.ChannelEncryptResponse: case (uint)EMsg.ChannelEncryptResult: header = new MsgHdr(); break; default: header = new ExtendedClientMsgHdr(); break; } } header.Deserialize(stream); return(header); }
static public FilteredMsgTypeList Filtered(GameObject inGameObject, MsgFlags inAll, MsgFlags inAny = MsgFlags.None) { if (inGameObject == null && (inAll == MsgFlags.None && inAny == MsgFlags.None)) { return(All()); } Initialize(); List <MsgType> types = null; MsgUtil.GetAvailableMsgTypes(inGameObject, ref types); List <Metadata> metadatas = new List <Metadata>(types.Count); for (int i = 0; i < types.Count; ++i) { Metadata metadata = Manager.Get().Database.Find(types[i]); if (metadata == null) { continue; } if ((inAll == MsgFlags.None || metadata.HasFlags(inAll)) && (inAny == MsgFlags.None || metadata.HasAnyFlags(inAny)) && !metadatas.Contains(metadata)) { metadatas.Add(metadata); } } metadatas.Sort(); return(new FilteredMsgTypeList(metadatas)); }
static object ReadBody(uint rawEMsg, Stream stream, ISteamSerializableHeader header) { var eMsg = MsgUtil.GetMsg(rawEMsg); var isProto = MsgUtil.IsProtoBuf(rawEMsg); var targetJobName = new Lazy <string>(() => ((MsgHdrProtoBuf)header).Proto.target_job_name); object body; switch (eMsg) { case EMsg.ServiceMethod: case EMsg.ServiceMethodCallFromClient: body = UnifiedMessagingHelpers.ReadServiceMethodBody(targetJobName.Value, stream, x => x.GetParameters().First().ParameterType); break; case EMsg.ServiceMethodResponse: body = UnifiedMessagingHelpers.ReadServiceMethodBody(targetJobName.Value, stream, x => x.ReturnType); break; default: body = ReadMessageBody(rawEMsg, stream); break; } return(body); }
static object ReadMessageBody(uint rawEMsg, Stream stream, uint gcAppId) { foreach (var type in MessageTypeFinder.GetGCMessageBodyTypeCandidates(rawEMsg, gcAppId)) { var streamPos = stream.Position; try { return(RuntimeTypeModel.Default.Deserialize(stream, null, type)); } catch (Exception) { stream.Position = streamPos; } } // Last resort for protobufs if (MsgUtil.IsProtoBuf(rawEMsg)) { try { var asFieldDictionary = ProtoBufFieldReader.ReadProtobuf(stream); return(asFieldDictionary); } catch (ProtoException) { return("Invalid protobuf data."); } catch (EndOfStreamException ex) { return("Error parsing SO data: " + ex.Message); } } return(null); }
internal static IPacketMsg GetPacketMsg(byte[] data) { uint rawEMsg = BitConverter.ToUInt32(data, 0); EMsg eMsg = MsgUtil.GetMsg(rawEMsg); switch (eMsg) { // certain message types are always MsgHdr case EMsg.ChannelEncryptRequest: case EMsg.ChannelEncryptResponse: case EMsg.ChannelEncryptResult: return(new PacketMsg(eMsg, data)); } try { if (MsgUtil.IsProtoBuf(rawEMsg)) { // if the emsg is flagged, we're a proto message return(new PacketClientMsgProtobuf(eMsg, data)); } else { // otherwise we're a struct message return(new PacketClientMsg(eMsg, data)); } } catch (Exception ex) { DebugLog.WriteLine("CMClient", "Exception deserializing emsg {0} ({1}).\n{2}", eMsg, MsgUtil.IsProtoBuf(rawEMsg), ex.ToString()); return(null); } }
public void Test001_ls_Win7_Calc() { Process calc = bringupApp(path_win7_calc); /* create an input "ls_l" and execute it */ Sinter sinter_ls_req = new Sinter { HeaderNode = MsgUtil.BuildHeader(scraper.serviceCodes["ls_req"]), EntityNodes = null, }; cmdhlr.CommandExecSinter(sinter_ls_req); /* get ls_res */ Sinter sinter_ls_res = conn.GetSinterFromFile(conn.filepath); /* parse ls_res and find calculator */ string calcProcess = null; foreach (Entity proc in sinter_ls_res.EntityNodes) { Console.WriteLine(proc.Name + " " + proc.Process); if (proc.Name.IndexOf("calc", StringComparison.OrdinalIgnoreCase) >= 0) { calcProcess = proc.Process; break; } } Assert.IsTrue(calcProcess != null); //to check if calc is in the "ls_res" result. killProcess(calc); }
Type GetMessageBodyType(uint realEMsg) { EMsg eMsg = MsgUtil.GetMsg(realEMsg); if (MessageTypeOverrides.BodyMap.ContainsKey(eMsg)) { return(MessageTypeOverrides.BodyMap[eMsg]); } var protomsgType = typeof(CMClient).Assembly.GetTypes().ToList().Find(type => { if (type.GetInterfaces().ToList().Find(inter => inter == typeof(IExtensible)) == null) { return(false); } if (type.Name.EndsWith(eMsg.ToString(), StringComparison.OrdinalIgnoreCase)) { return(true); } return(false); }); return(protomsgType); }
private void Control_Click(object sender, EventArgs e) { if (isSent) { return; } Button button = (Button)sender; Entity entity = (Entity)button.Tag; if (entity == null) { return; } Point center = GetCenter(entity); Sinter sinter = new Sinter { HeaderNode = MsgUtil.BuildHeader( serviceCodes["mouse"], serviceCodes["mouse_click_left"], "", "0", center.X.ToString(), center.Y.ToString() ), }; Console.WriteLine(sinter.HeaderNode.ParamsInfo.ToString()); execute_mouse(sinter); isSent = true; timer.Enabled = true; }
static IPacketMsg GetPacketMsg(byte[] data) { uint rawEMsg = BitConverter.ToUInt32(data, 0); EMsg eMsg = MsgUtil.GetMsg(rawEMsg); switch (eMsg) { // certain message types are always MsgHdr case EMsg.ChannelEncryptRequest: case EMsg.ChannelEncryptResponse: case EMsg.ChannelEncryptResult: return(new PacketMsg(eMsg, data)); } if (MsgUtil.IsProtoBuf(rawEMsg)) { // if the emsg is flagged, we're a proto message return(new PacketClientMsgProtobuf(eMsg, data)); } else { // otherwise we're a struct message return(new PacketClientMsg(eMsg, data)); } }
public override void ExecuteCommand(ChatSession session, StringRequestInfo requestInfo) { var frame = MsgFrame.Parse(requestInfo.Body); session.Logger.DebugFormat("{0} {1} {2}", session.UserName ?? "--", requestInfo.Key, requestInfo.Body); MsgUtil.SendAll(session, frame); }
public static IEnumerable <Type> GetGCMessageBodyTypeCandidates(uint rawEMsg, uint gcAppid) { var gcMsg = MsgUtil.GetGCMsg(rawEMsg); if (MessageTypeOverrides.GCBodyMap.ContainsKey(gcMsg)) { return(Enumerable.Repeat(MessageTypeOverrides.GCBodyMap[gcMsg], 1)); } var gcMsgName = EMsgExtensions.GetGCMessageName(rawEMsg); var typeMsgName = gcMsgName .Replace("k_", string.Empty) .Replace("ESOMsg", string.Empty) .TrimStart('_') .Replace("EMsg", string.Empty) .TrimStart("GC"); var possibleTypes = from type in typeof(CMClient).Assembly.GetTypes() from typePrefix in GetPossibleGCTypePrefixes(gcAppid) where type.GetInterfaces().Contains(typeof(IExtensible)) where type.FullName.StartsWith(typePrefix) && type.FullName.EndsWith(typeMsgName) select type; return(possibleTypes); }
public void execute_ls_l_req(Sinter _) { Sinter sinter = new Sinter() { HeaderNode = MsgUtil.BuildHeader(serviceCodes["ls_l_req"]), }; connection.SendMessage(sinter); }
private bool checkPassNewisEqualPassNewRepeat() { if (txtPassNew.Text.Trim() == txtPassNewRepeat.Text.Trim()) { return(true); } MsgUtil.MessageThongBao("Mật khẩu mới nhập lại không chính xác"); return(false); }
static TreeNode BuildInfoNode(uint rawEMsg) { var eMsg = MsgUtil.GetMsg(rawEMsg); return(new TreeNode("Info", new[] { CreateNode("EMsg", string.Format("{0} ({1})", eMsg.ToString(), (long)eMsg)), CreateNode("Is ProtoBuf", MsgUtil.IsProtoBuf(rawEMsg).ToString()), })); }
private bool checkPassOldisTrue() { tk = db.TaiKhoans.FirstOrDefault(x => x.ID == MsgUtil.userID); if (tk.MatKhau == txtPassOld.Text.Trim()) { return(true); } MsgUtil.MessageThongBao("Mật khẩu cũ của bạn không chính xác!"); return(false); }
private static IPacketGCMsg GetPacketGCMsg(uint eMsg, byte[] data) { // strip off the protobuf flag uint realEMsg = MsgUtil.GetGCMsg(eMsg); if (MsgUtil.IsProtoBuf(eMsg)) { return(new PacketClientGCMsgProtobuf(realEMsg, data)); } return(new PacketClientGCMsg(realEMsg, data)); }
/// <summary> /// Sends a game coordinator message for a specific appid. /// </summary> /// <param name="msg">The GC message to send.</param> /// <param name="appId">The app id of the game coordinator to send to.</param> public void Send(IClientGCMsg msg, uint appId) { var clientMsg = new ClientMsgProtobuf <CMsgGCClient>(EMsg.ClientToGC); clientMsg.Body.msgtype = MsgUtil.MakeGCMsg(msg.MsgType, msg.IsProto); clientMsg.Body.appid = appId; clientMsg.Body.payload = msg.Serialize(); Client.Send(clientMsg); }
private bool checkExistMaHDN(QuanLyBanHangEntities db) { HoaDonNhap dhn = db.HoaDonNhaps.FirstOrDefault(x => x.MaHDN == txtMaHDN.Text.Trim()); if (dhn == null) { return(true); } MsgUtil.MessageThongBao("Mã đơn hóa đơn đã tồn tại!"); return(false); }
static TreeNode BuildInfoNode(uint rawEMsg) { var eMsg = MsgUtil.GetMsg(rawEMsg); var eMsgName = $"EMsg {eMsg:G} ({eMsg:D})"; if (MsgUtil.IsProtoBuf(rawEMsg)) { return(new TreeNode(eMsgName)); } return(new TreeNode($"{eMsgName} (Non-Protobuf)")); }
static TreeNode BuildInfoNode(uint rawEMsg) { var eMsg = MsgUtil.GetMsg(rawEMsg); var eMsgExplorer = new TreeNodeObjectExplorer("EMsg", eMsg); return(new TreeNode("Info", new[] { eMsgExplorer.TreeNode, new TreeNodeObjectExplorer("Is Protobuf", MsgUtil.IsProtoBuf(rawEMsg)).TreeNode })); }
public void GetPacketMsgReturnsPacketClientMsgForOtherMessages() { var msg = MsgUtil.MakeMsg(EMsg.ClientLogOnResponse, protobuf: false); var msgHdr = new ExtendedClientMsgHdr { Msg = msg }; var data = Serialize(msgHdr); var packetMsg = CMClient.GetPacketMsg(data); Assert.IsAssignableFrom <PacketClientMsg>(packetMsg); }
public void GetPacketMsgReturnsPacketClientMsgProtobufForMessagesWithProtomask() { var msg = MsgUtil.MakeMsg(EMsg.ClientLogOnResponse, protobuf: true); var msgHdr = new MsgHdrProtoBuf { Msg = msg }; var data = Serialize(msgHdr); var packetMsg = CMClient.GetPacketMsg(data); Assert.IsAssignableFrom <PacketClientMsgProtobuf>(packetMsg); }
public static Type GetProtobufMessageBodyType(uint realEMsg) { EMsg eMsg = MsgUtil.GetMsg(realEMsg); if (MessageTypeOverrides.BodyMap.TryGetValue(eMsg, out var wellKnownType)) { return(wellKnownType); } var protomsgType = SteamKit2Assembly.GetTypes().ToList().Find(t => FilterProtobufMessageBodyType(t, eMsg)); return(protomsgType); }
public static Type GetProtobufMessageBodyType(uint realEMsg) { EMsg eMsg = MsgUtil.GetMsg(realEMsg); if (MessageTypeOverrides.BodyMap.ContainsKey(eMsg)) { return(MessageTypeOverrides.BodyMap[eMsg]); } var protomsgType = SteamKit2Assembly.GetTypes().ToList().Find(t => FilterProtobufMessageBodyType(t, eMsg)); return(protomsgType); }
public void ProcessKeyPress(string keypresses) { Sinter sinter = new Sinter { HeaderNode = MsgUtil.BuildHeader(serviceCodes["kbd"]), }; sinter.HeaderNode.ParamsInfo = new Params() { TargetId = "", Data1 = keypresses, }; execute_kbd(sinter); }
public void GetPacketMsgFailsWithNull() { var msg = MsgUtil.MakeMsg(EMsg.ClientLogOnResponse, protobuf: true); var msgHdr = new MsgHdrProtoBuf { Msg = msg }; var data = Serialize(msgHdr); Array.Copy(BitConverter.GetBytes(-1), 0, data, 4, 4); var packetMsg = CMClient.GetPacketMsg(data); Assert.Null(packetMsg); }
public void ClientMsgProtobufAssertsInitializedWithProtoMsg() { var packetMsgData = new ClientMsg <MsgClientLogon>().Serialize(); var packetMsg = new PacketClientMsg(MsgUtil.MakeMsg(EMsg.ClientLogon, protobuf: false), packetMsgData); var exception = Record.Exception(() => new ClientMsgProtobuf <CMsgClientLogon>(packetMsg)); Assert.NotNull(exception); Assert.IsType <TraceAssertException>(exception); var tae = (TraceAssertException)exception; // Can't nameof(ClientMsgProtobuf) - nameof doesn't support open generic types (yet). Assert.Contains($"ClientMsgProtobuf<{typeof( CMsgClientLogon ).FullName}>", tae.AssertMessage); }