public List <TOrderItem> SyncOrderItem() { try { IEnumerable <OrderHistory> changedOrderIds; using (ThanhVanTranSysEntities context = new ThanhVanTranSysEntities()) using (OrderItemBusiness business = new OrderItemBusiness()) { changedOrderIds = context.OrderHistories .Where(i => i.date_time.Year == DateTime.Now.Year && i.date_time.Month == DateTime.Now.Month && i.date_time.Day == DateTime.Now.Day) .OrderBy(i => i.order_id).ThenBy(i => i.date_time); var orderItems = (from oi in business.GetAll() join co in changedOrderIds on oi.order_id equals co.order_id select ThriftUtil.ConvertToTOrderItem(oi, co.action == Constants.DELETE_ACTION)).ToList(); return(orderItems); } } catch (Exception exc) { ServerLogger.logError("[SyncOrderItem]", exc); return(new List <TOrderItem>()); } }
protected string InsertObject <T, E>(List <T> TObjectList) where T : TBase where E : EntityObject { string errorMessage = string.Empty; try { using (ThanhVanTranSysEntities context = new ThanhVanTranSysEntities()) { var objectSet = context.CreateObjectSet <E>(); foreach (var tobj in TObjectList) { objectSet.AddObject((E)ThriftUtil.ConvertToEntityObject(tobj)); } context.SaveChanges(); } } catch (Exception exc) { AppLogger.logError("InsertObject", exc); return(exc.Message); } return(errorMessage); }
public string InsertTicket(TTicket ticket, string userId) { try { //------------------------------------------------------------// // check a valid of Ticket //------------------------------------------------------------// TicketSaleDateBusiness saleDatebusines = new TicketSaleDateBusiness(); Ticket newTicket = ThriftUtil.ConvertToEntityObject(ticket) as Ticket; string errorMessage = CheckTicketInfo(newTicket); errorMessage += saleDatebusines.ValidateDateTime(newTicket.departure_time); if (string.IsNullOrEmpty(errorMessage) == false) { return(errorMessage); } TicketBusiness business = new TicketBusiness(); string resultMsg = business.Insert(newTicket); ////notify to the others client station //ticket.TicketId = ticketId; //BroadcastToClient(ClientAction.SellTicket,ticket); return(resultMsg); } catch (Exception exc) { ServerLogger.logError("[InsertTicket]", exc); return(exc.Message); } }
public TUser Login(string userName, string password, string senderIP, string senderPort) { try { ServerLogger.logInfo("Login", string.Format("User login [{0}] - [{1}] - [{2}] - [{3}]", userName, password, senderIP, senderPort), serverView); using (UserBusiness business = new UserBusiness()) { //bool loginSuccess = business.Users.Any(u => u.user_name == userName && u.password == password && u.active_status && !u.deleted); User user = business.ValidateUser(userName, password, Constants.UserRole.Staff.ToString()); if (user == null) { string failMessage = "Login Fail"; //if (user == null) failMessage = "Không tồn tại người dùng: " + userName; //else if (user.password != password) failMessage = "Nhập sai mật khẩu"; //else if (user.active_status == false) failMessage = "Người dùng này đã bị khóa."; ServerLogger.logInfo("Login", string.Format("login result: {0}", failMessage), serverView); return(new TUser()); } AddClientStation(userName, senderIP, int.Parse(senderPort)); return(ThriftUtil.ConvertToTUser(user)); } } catch (Exception exc) { ServerLogger.logError("[Login]", exc); return(new TUser()); } }
protected override User ExcuteLogin(string userName, string password, string role) { TUser tuser = ServerConnector.GetInstance().Login(userName, password, ClientRepository.GetInstance()._clientIp, ClientRepository.GetInstance()._clientPort); if (string.IsNullOrEmpty(tuser.Id) == false) { return(ThriftUtil.ConvertToUser(tuser)); } return(null); }
public List <TIrregularOrder> SyncIrregularOrder() { try { IEnumerable <OrderHistory> changedOrderIds; using (ThanhVanTranSysEntities context = new ThanhVanTranSysEntities()) using (IrregularOrderBusiness business = new IrregularOrderBusiness()) { //insert/update records changedOrderIds = context.OrderHistories .Where(i => i.date_time.Year == DateTime.Now.Year && i.date_time.Month == DateTime.Now.Month && i.date_time.Day == DateTime.Now.Day) .OrderBy(i => i.order_id).ThenBy(i => i.date_time); var orders = (from io in business.GetAll() join co in changedOrderIds on io.id equals co.order_id select ThriftUtil.ConvertToTIrregularOrder(io, co.action == Constants.DELETE_ACTION)).ToList(); //deleted records orders.AddRange((from o in changedOrderIds where o.action == Constants.DELETE_ACTION select new TIrregularOrder() { OrderId = o.order_id, IsDeleted = true, CloseDate = DateTime.Now.ToString(), CreateBy = string.Empty, CreateDate = DateTime.Now.ToString(), Destination = string.Empty, OrderStaus = string.Empty, PaymentStatus = string.Empty, RecipientIdNo = string.Empty, RecipientName = string.Empty, RecipientPhone = string.Empty, SenderIdNo = string.Empty, SenderName = string.Empty, SenderPhone = string.Empty, UserReponsitory = string.Empty, TotalCost = 0, TotalQuantity = 0, TotalValue = 0, })); return(orders); } } catch (Exception exc) { ServerLogger.logError("[LoadIrregularOrder]", exc); return(new List <TIrregularOrder>()); } }
public string CreateOrder(TOrder torder, List <TOrderItem> torderItems, string userId) { try { //Check Order string errorMessage = CheckOrder(torder); //check OrderItem List <OrderItem> orderItems = ThriftUtil.ConvertToOrderItemList(torderItems); errorMessage += CheckOrderItems(orderItems); if (string.IsNullOrEmpty(errorMessage) == false) { return(errorMessage); } string orderId = string.Empty; //Insert Order if (torder.Type == Constants.VALUE_ORDER_TYPE_REGULAR) { using (RegularOrderBusiness business = new RegularOrderBusiness()) { business.Insert(ThriftUtil.ConvertToRegualrOrder(torder)); } } else { using (IrregularOrderBusiness business = new IrregularOrderBusiness()) { business.Insert(ThriftUtil.ConvertToIrregularOrder(torder)); } } using (OrderItemBusiness business = new OrderItemBusiness()) { business.Insert(orderItems); } //notify to the others client station //torder.OrderId = orderId; //BroadcastToClient(ClientAction.CreateOrder,order,orderItems); return(""); } catch (Exception exc) { ServerLogger.logError("[CreateOrder]", exc); return(exc.Message); } }
public List <TOrderItem> LoadOrderItem() { try { using (OrderItemBusiness business = new OrderItemBusiness()) { return(business.GetAll().ToList().Select(i => ThriftUtil.ConvertToThriftObject(i) as TOrderItem).ToList()); } } catch (Exception exc) { ServerLogger.logError("[LoadOrderItem]", exc); return(new List <TOrderItem>()); } }
public List <TIrregularOrder> LoadIrregularOrder() { try { using (IrregularOrderBusiness business = new IrregularOrderBusiness()) { return(business.GetAll().ToList().Select(i => ThriftUtil.ConvertToThriftObject(i) as TIrregularOrder).ToList()); } } catch (Exception exc) { ServerLogger.logError("[LoadIrregularOrder]", exc); return(new List <TIrregularOrder>()); } }
public List <TCustomer> LoadCustomer() { try { using (CustomerBusiness business = new CustomerBusiness()) { return(business.GetAll().ToList().Select(i => ThriftUtil.ConvertToTCustomer(i)).ToList()); } } catch (Exception exc) { ServerLogger.logError("[LoadCustomer]", exc); return(new List <TCustomer>()); } }
public string UpdateOrderInfo(TOrder torder, List <TOrderItem> orderItems, string userId) { try { //Check Order string errorMessage = CheckOrder(torder, true); //check OrderItem errorMessage += orderItems.Count == 0 ? "Không có thông tin hàng hóa" : ""; if (string.IsNullOrEmpty(errorMessage) == false) { return(errorMessage); } if (torder.Type == Constants.VALUE_ORDER_TYPE_REGULAR) { using (RegularOrderBusiness business = new RegularOrderBusiness()) { business.Update(ThriftUtil.ConvertToEntityObject(torder) as RegularOrder); } } else { using (IrregularOrderBusiness business = new IrregularOrderBusiness()) { business.Update(ThriftUtil.ConvertToEntityObject(torder) as IrregularOrder); } } using (OrderItemBusiness business = new OrderItemBusiness()) { business.DeleteByOrderId(torder.OrderId); business.Insert(ThriftUtil.ConvertToOrderItemList(orderItems).Cast <OrderItem>()); } //notify to the others client station //BroadcastToClient(ClientAction.UpdateOrder,order,orderItems); return(""); } catch (Exception exc) { ServerLogger.logError("[UpdateOrderInfo]", exc); return(exc.Message); } }
public List <TTicket> SyncTicket() { try { IEnumerable <TicketHistory> changedTicketId; using (ThanhVanTranSysEntities context = new ThanhVanTranSysEntities()) using (TicketBusiness business = new TicketBusiness()) { changedTicketId = context.TicketHistories .Where(i => i.changed_date.Year == DateTime.Now.Year && i.changed_date.Month == DateTime.Now.Month && i.changed_date.Day == DateTime.Now.Day) .OrderBy(i => i.ticket_id).ThenBy(i => i.changed_date); //insert/update records var tickets = (from t in business.GetAll() join th in changedTicketId on t.id equals th.ticket_id where t.departure_time >= DateTime.Now select ThriftUtil.ConvertToTTicket(t, th.action == Constants.DELETE_ACTION)).ToList(); //deleted records tickets.AddRange((from th in changedTicketId where th.action == Constants.DELETE_ACTION select new TTicket { TicketId = th.ticket_id, BusId = string.Empty, CusIdNo = string.Empty, CusName = string.Empty, CusPhone = string.Empty, DepartTime = DateTime.Now.ToString(), IsDeleted = true, SeatNo = 0, SeatType = string.Empty, Status = string.Empty, TicketPrice = 0, TourId = string.Empty, UserId = string.Empty })); return(tickets); } } catch (Exception exc) { ServerLogger.logError("[LoadTicket]", exc); return(new List <TTicket>()); } }
public List <TTicket> LoadTicket() { try { using (TicketBusiness business = new TicketBusiness()) { return(business.GetAll().ToList() .Where(i => i.departure_time >= DateTime.Now) .Select(i => ThriftUtil.ConvertToTTicket(i)).ToList()); } } catch (Exception exc) { ServerLogger.logError("[LoadTicket]", exc); return(new List <TTicket>()); } }
protected string SyncObject <T, E>(List <T> TObjectList) where T : TBase where E : EntityObject { string errorMessage = string.Empty; try { using (ThanhVanTranSysEntities context = new ThanhVanTranSysEntities()) { var objectSet = context.CreateObjectSet <E>(); foreach (var tobj in TObjectList) { E changeObj = (E)ThriftUtil.ConvertToEntityObject(tobj); string id = typeof(E).GetProperty("id").GetValue(changeObj, null).ToString(); bool isDeleted = bool.Parse(typeof(T).GetProperty("IsDeleted").GetValue(tobj, null).ToString()); E existedEntity = objectSet.ToList().FirstOrDefault(e => typeof(E).GetProperty("id").GetValue(e, null).ToString().Equals(id)); if (existedEntity != null) { objectSet.DeleteObject(existedEntity); } if (isDeleted == false) { objectSet.AddObject(changeObj); } context.SaveChanges(); } } } catch (Exception exc) { AppLogger.logError("SyncObject", exc); return(exc.Message); } return(errorMessage); }
public string UpdateTicket(TTicket tticket, string userId) { try { using (ThanhVanTranSysEntities context = new ThanhVanTranSysEntities()) { DateTime departTime = DateTime.Parse(tticket.DepartTime); var existedTicket = context.Tickets.FirstOrDefault(t => t.bus_id == tticket.BusId && t.departure_time == departTime && t.seat_number == tticket.SeatNo && t.seat_class == tticket.SeatType && t.tour_id == tticket.TourId); if (existedTicket == null || (existedTicket != null && existedTicket.status == Constants.TicketStatus.Cancel.ToString())) { return(Constants.SERVER_ERROR_CODE_SINGLE_DATA_NOT_SYNC + " Vé đã bị xóa!"); } } if (CheckUserPermission(userId, tticket.UserId) == false) { return(Constants.Messages.MSG_TICKET_INSUFFICIENT_PERMISSION); } TicketBusiness business = new TicketBusiness(); Ticket ticket = ThriftUtil.ConvertToEntityObject(tticket) as Ticket; string resultMsg = business.Update(ticket); //notify to the others client station //BroadcastToClient(ClientAction.UpdateTicket,ticket); return(resultMsg); } catch (Exception exc) { ServerLogger.logError("[UpdateTicket]", exc); return(exc.Message); } }
public string UpdateSingleOrderInfo(TOrder torder, string userId) { try { //Check Order string errorMessage = CheckOrder(torder, true); if (string.IsNullOrEmpty(errorMessage) == false) { return(errorMessage); } if (torder.Type == Constants.VALUE_ORDER_TYPE_REGULAR) { using (RegularOrderBusiness business = new RegularOrderBusiness()) { business.Update(ThriftUtil.ConvertToEntityObject(torder) as RegularOrder); } } else { using (IrregularOrderBusiness business = new IrregularOrderBusiness()) { business.Update(ThriftUtil.ConvertToEntityObject(torder) as IrregularOrder); } } //notify to the others client station //BroadcastToClient(ClientAction.UpdateOrder,order,orderItems); return(""); } catch (Exception exc) { ServerLogger.logError("[UpdateSingleOrderInfo]", exc); return(exc.Message); } }
async Task <bool> Receive() { try { NetMQMessage msg = null; // NOTE: // After switching to async IO, when we close the socket in Dispose() the ReceiveMultipartMessage() wasn't returning. // So, we TryReceive() with a timeout. If it times out the receive loop will check if we retry or exit. // If we get an async-friendly version of NetMQ (or switch transports) we can probably go back to regular Receive(). if (socket.TryReceiveMultipartMessage(ReceiveTimeout, ref msg)) { if (msg == null || ZeroMQ.PubSubUtil.IsStoppingMessage(msg)) { PublisherLogger.Info("stopped by stpping message!"); return(false); } var topic = msg[0].ConvertToString(); var msgType = msg[1].ConvertToString(); if (MsgHandlers.TryGetValue(msgType, out Delegate mh)) { var respBytes = msg[2].Buffer; using (var proto = ThriftUtil.CreateReadProtocol(respBytes)) { Type t = GeneratedTypeCache.GetType(msgType); if (t == null) { throw new TargetInvocationException(new Exception("can't get type for: " + msgType)); } TBase ret = Activator.CreateInstance(t) as TBase; await ret.ReadAsync(proto, cts.Token); mh.DynamicInvoke(topic, ret); } } return(true); } else { // Receive timed out. Return true so receive loop can check if we should exit or try again. return(true); } } catch (Exception e) { if (e is TargetInvocationException ee) { Log($"invoke exception: {(ee).InnerException.Message} \n {ee.InnerException.StackTrace}", Logging.LogLevel.Warn); return(true); } if (e is TerminatingException) { Log($"terminated: {e.Message}", Logging.LogLevel.Info); return(false); } else { if (disposing) { Log("disposing exception: " + e.Message, Logging.LogLevel.Info); } else { Log($"receive exception: {e.Message} \n {e.StackTrace}", Logging.LogLevel.Error); } return(false); } } }
/// <remarks>must get config follow each role</remarks> public TSystemConfig LoadSystemConfig() { try { TSystemConfig systemConfig = new TSystemConfig(); using (ThanhVanTranSysEntities context = new ThanhVanTranSysEntities()) { systemConfig.Configurations = context.Configurations.ToList().Select(i => ThriftUtil.ConvertToTConfiguration(i)).ToList(); systemConfig.SaleTicketDates = context.TicketSaleDates.ToList().Select(i => ThriftUtil.ConvertToTSaleTicketDate(i)).ToList(); systemConfig.TicketPrices = context.TicketPriceConfigurations.ToList().Select(i => ThriftUtil.ConvertToTTicketPrice(i)).ToList(); systemConfig.TransportPrices = context.TransportPriceConfigurations.ToList().Select(i => ThriftUtil.ConvertToTTransportPrice(i)).ToList(); systemConfig.GuaranteeFees = context.GuaranteeFeeConfigurations.ToList().Select(i => ThriftUtil.ConvertToTGuaranteeFee(i)).ToList(); systemConfig.Buses = context.Buses.ToList().Select(i => ThriftUtil.ConvertToTBus(i)).ToList(); systemConfig.Tours = context.Tours.ToList().Select(i => ThriftUtil.ConvertToTTour(i)).ToList(); } return(systemConfig); } catch (Exception exc) { ServerLogger.logError("[LoadSystemConfig]", exc); return(new TSystemConfig()); } }