private static void ReadCreateObjectBlock(Packet packet, WowGuid guid, uint map, object index) { ObjectType objType = ObjectTypeConverter.Convert(packet.ReadByteE <ObjectTypeLegacy>("Object Type", index)); var moves = ReadMovementUpdateBlock(packet, guid, index); var updates = CoreParsers.UpdateHandler.ReadValuesUpdateBlockOnCreate(packet, objType, index); var dynamicUpdates = CoreParsers.UpdateHandler.ReadDynamicValuesUpdateBlockOnCreate(packet, objType, index); WoWObject obj; switch (objType) { case ObjectType.Unit: obj = new Unit(); break; case ObjectType.GameObject: obj = new GameObject(); break; case ObjectType.Item: obj = new Item(); break; case ObjectType.Player: obj = new Player(); break; default: obj = new WoWObject(); break; } obj.Type = objType; obj.Movement = moves; obj.UpdateFields = updates; obj.DynamicUpdateFields = dynamicUpdates; obj.Map = map; obj.Area = CoreParsers.WorldStateHandler.CurrentAreaId; obj.Zone = CoreParsers.WorldStateHandler.CurrentZoneId; obj.PhaseMask = (uint)CoreParsers.MovementHandler.CurrentPhaseMask; obj.Phases = new HashSet <ushort>(V6_0_2_19033.Parsers.MovementHandler.ActivePhases.Keys); obj.DifficultyID = CoreParsers.MovementHandler.CurrentDifficultyID; // If this is the second time we see the same object (same guid, // same position) update its phasemask if (Storage.Objects.ContainsKey(guid)) { var existObj = Storage.Objects[guid].Item1; CoreParsers.UpdateHandler.ProcessExistingObject(ref existObj, obj, guid); // can't do "ref Storage.Objects[guid].Item1 directly } else { Storage.Objects.Add(guid, obj, packet.TimeSpan); } if (guid.HasEntry() && (objType == ObjectType.Unit || objType == ObjectType.GameObject)) { packet.AddSniffData(Utilities.ObjectTypeToStore(objType), (int)guid.GetEntry(), "SPAWN"); } }
private static void ReadCreateObjectBlock(Packet packet, CreateObject createObject, WowGuid guid, uint map, object index) { ObjectType objType = ObjectTypeConverter.Convert(packet.ReadByteE <ObjectTypeLegacy>("Object Type", index)); WoWObject obj = CoreParsers.UpdateHandler.CreateObject(objType, guid, map); obj.Movement = ReadMovementUpdateBlock(packet, guid, index); obj.UpdateFields = CoreParsers.UpdateHandler.ReadValuesUpdateBlockOnCreate(packet, createObject.Values.Legacy, objType, index); obj.DynamicUpdateFields = CoreParsers.UpdateHandler.ReadDynamicValuesUpdateBlockOnCreate(packet, objType, index); // If this is the second time we see the same object (same guid, // same position) update its phasemask if (Storage.Objects.ContainsKey(guid)) { var existObj = Storage.Objects[guid].Item1; CoreParsers.UpdateHandler.ProcessExistingObject(ref existObj, obj, guid); // can't do "ref Storage.Objects[guid].Item1 directly } else { Storage.Objects.Add(guid, obj, packet.TimeSpan); } if (guid.HasEntry() && (objType == ObjectType.Unit || objType == ObjectType.GameObject)) { packet.AddSniffData(Utilities.ObjectTypeToStore(objType), (int)guid.GetEntry(), "SPAWN"); } }
public List <MenuItemDTO> GetMenuItemsByRestaurantID(int RestaurantID, int?page, int pageSize) { List <MenuItemDTO> MenuItems = default(List <MenuItemDTO>); try { using (IEateryDbContext context = _unitOfWork.GetEateryDbContext()) { var MenuItemList = this._MenuItemRepository.GetAllQuery(context) .OrderByDescending(x => x.ID) .Where(x => x.RestaurantID == RestaurantID) .Skip((page ?? 0) * pageSize) .Take(pageSize) .ToList(); if (MenuItemList != null && MenuItemList.Any()) { MenuItems = ObjectTypeConverter.ConvertList <MenuItem, MenuItemDTO>(MenuItemList).ToList(); } } } catch (Exception) { throw; } return(MenuItems); }
private IEnumerable <ObjectType> ProcessArgumentTypes(IEnumerable <ObjectType> argumentTypes) { foreach (var argumentType in argumentTypes) { yield return(ObjectTypeConverter.Convert(ClassMapping, argumentType, EntityType)); } }
public void TrueShouldBeReturned() { // Although an exlicit type converter exists for enums, ObjectTypeConverter should not discriminate against any type. // This is so we don't have to modify it to ignore types for which there is a specific converter. var typeConverter = new ObjectTypeConverter(); Assert.True(typeConverter.CanConvert(typeof(Status))); }
public void AnArgumentNullExceptionShouldBeThrown() { var typeConverter = new ObjectTypeConverter(); var exception = Assert.Throws <ArgumentNullException>( () => typeConverter.ConvertFromDbValue(1, null)); Assert.Equal("type", exception.ParamName); }
/// <summary> /// Converts data type... Most of the time. /// </summary> /// <param name="value">The value.</param> /// <param name="targetType">Type of the target.</param> /// <returns></returns> public static object SafeConvert(object value, Type targetType) { try { return(ObjectTypeConverter.Convert(value, targetType)); } catch (InvalidCastException) { } return(targetType.Default()); }
public RestaurantDTO Register(RestaurantDTO restaurantDTO, int userID) { if (restaurantDTO != null) { using (IEateryDbContext context = _unitOfWork.GetEateryDbContext()) { using (var dbContextTransaction = ((IDbContext)context).GetDataBase().BeginTransaction()) { try { if (userID > 0) { Restaurant restaurant = ObjectTypeConverter.Convert <RestaurantDTO, Restaurant>(restaurantDTO); restaurant.UserID = userID; restaurant.CreatedBy = userID; restaurant.CreatedDate = DateTime.Now; this._RestaurantRepository.Add(context, restaurant); _unitOfWork.Commit(context); if (restaurant.ID > 0) { foreach (var operationTimingsDTO in restaurantDTO.OperationTimings) { OperationTiming operationTiming = ObjectTypeConverter.Convert <OperationTimingDTO, OperationTiming>(operationTimingsDTO); operationTiming.RestaurantID = restaurant.ID; operationTiming.CreatedBy = userID; operationTiming.CreatedDate = DateTime.Now; this._OperationTimingRepository.Add(context, operationTiming); _unitOfWork.Commit(context); } dbContextTransaction.Commit(); restaurantDTO = ObjectTypeConverter.Convert <Restaurant, RestaurantDTO>(restaurant); } else { dbContextTransaction.Rollback(); } } else { dbContextTransaction.Rollback(); } } catch (Exception ex) { dbContextTransaction.Rollback(); } } } } return(restaurantDTO); }
public RegisterOwnerWithRestaurantDTO RegisterOwnerWithRestaurant(RegisterOwnerWithRestaurantDTO RestaurantRegistrationDTO) { if (RestaurantRegistrationDTO != null) { using (IEateryDbContext context = _unitOfWork.GetEateryDbContext()) { using (var dbContextTransaction = ((IDbContext)context).GetDataBase().BeginTransaction()) { try { User user = ObjectTypeConverter.Convert <UserDTO, User>(RestaurantRegistrationDTO.UserDTO); this._userRepository.Add(context, user); _unitOfWork.Commit(context); if (user.ID > 0) { Restaurant Restaurant = ObjectTypeConverter.Convert <RestaurantDTO, Restaurant>(RestaurantRegistrationDTO.RestaurantDTO); Restaurant.UserID = user.ID; this._RestaurantRepository.Add(context, Restaurant); _unitOfWork.Commit(context); if (Restaurant.ID > 0) { foreach (var MenuItemDTO in RestaurantRegistrationDTO.RestaurantDTO.MenuItemList) { MenuItem MenuItem = ObjectTypeConverter.Convert <MenuItemDTO, MenuItem>(MenuItemDTO); this._MenuItemRepository.Add(context, MenuItem); _unitOfWork.Commit(context); } dbContextTransaction.Commit(); } else { dbContextTransaction.Rollback(); } } else { dbContextTransaction.Rollback(); } } catch (Exception) { dbContextTransaction.Rollback(); } } } } return(RestaurantRegistrationDTO); }
private static void ReadCreateObjectBlock(Packet packet, CreateObject createObject, WowGuid guid, uint map, object index) { var objType = ObjectTypeConverter.Convert(packet.ReadByteE <ObjectType251>("ObjectType", index)); var obj = objType switch { ObjectType.Unit => new Unit(), ObjectType.GameObject => new GameObject(), ObjectType.Player => new Player(), ObjectType.AreaTrigger => new SpellAreaTrigger(), ObjectType.Conversation => new ConversationTemplate(), _ => new WoWObject(), }; packet.ReadInt32("HeirFlags", index); var moves = ReadMovementUpdateBlock(packet, createObject, guid, obj, index); var updates = CoreParsers.UpdateHandler.ReadValuesUpdateBlockOnCreate(packet, createObject.Values, objType, index); var dynamicUpdates = CoreParsers.UpdateHandler.ReadDynamicValuesUpdateBlockOnCreate(packet, objType, index); obj.UpdateFields = updates; obj.DynamicUpdateFields = dynamicUpdates; obj.Type = objType; obj.Movement = moves; obj.Map = map; obj.Area = CoreParsers.WorldStateHandler.CurrentAreaId; obj.Zone = CoreParsers.WorldStateHandler.CurrentZoneId; obj.PhaseMask = (uint)CoreParsers.MovementHandler.CurrentPhaseMask; obj.Phases = new HashSet <ushort>(CoreParsers.MovementHandler.ActivePhases.Keys); obj.DifficultyID = CoreParsers.MovementHandler.CurrentDifficultyID; // If this is the second time we see the same object (same guid, // same position) update its phasemask if (Storage.Objects.ContainsKey(guid)) { var existObj = Storage.Objects[guid].Item1; CoreParsers.UpdateHandler.ProcessExistingObject(ref existObj, obj, guid); // can't do "ref Storage.Objects[guid].Item1 directly } else { Storage.Objects.Add(guid, obj, packet.TimeSpan); } if (guid.HasEntry() && (objType == ObjectType.Unit || objType == ObjectType.GameObject)) { packet.AddSniffData(Utilities.ObjectTypeToStore(objType), (int)guid.GetEntry(), "SPAWN"); } }
public bool Remove(MenuItemRatingDTO ratingDTO) { if (ratingDTO != null) { using (IEateryDbContext context = _unitOfWork.GetEateryDbContext()) { MenuItemRating rating = ObjectTypeConverter.Convert <MenuItemRatingDTO, MenuItemRating>(ratingDTO); this._menuItemRatingRepository.Delete(context, rating); _unitOfWork.Commit(context); return(true); } } return(false); }
public UserDTO CreateNewUser(UserDTO userDTO) { if (userDTO != null && userDTO.ID == 0) { using (IEateryDbContext context = _unitOfWork.GetEateryDbContext()) { User user = ObjectTypeConverter.Convert <UserDTO, User>(userDTO); this._userRepository.Add(context, user); _unitOfWork.Commit(context); return(ObjectTypeConverter.Convert <User, UserDTO>(user)); } } return(default(UserDTO)); }
public List <RestaurantDTO> SearchRestaurants(SearchCriteriaDTO searchCriteria) { List <RestaurantDTO> Restaurants = default(List <RestaurantDTO>); if (searchCriteria != null) { using (IEateryDbContext context = _unitOfWork.GetEateryDbContext()) { List <Restaurant> RestaurantList = this._RestaurantRepository.GetAllQuery(context).ToList(); if (RestaurantList != null && RestaurantList.Any()) { Restaurants = ObjectTypeConverter.ConvertList <Restaurant, RestaurantDTO>(RestaurantList).ToList(); } } } return(Restaurants); }
public UserDTO Update(UserDTO userDTO, int userID) { using (IEateryDbContext context = _unitOfWork.GetEateryDbContext()) { User user = ObjectTypeConverter.Convert <UserDTO, User>(userDTO); user.UpdatedDate = DateTime.Now; user.UpdatedBy = userID; user = this._userRepository.Update(context, user); _unitOfWork.Commit(context); if (user != null) { return(ObjectTypeConverter.Convert <User, UserDTO>(user)); } } return(default(UserDTO)); }
protected ObjectType ConvertReturnType(ObjectType newObjectType) { var expression = objectType.Obj as LambdaExpression; var returnType = expression.ReturnType; var newReturnType = ObjectTypeConverter.Convert(returnType, targetType); if (returnType == newReturnType) { return(newObjectType); } var typeOfVisitor = typeof(ReturnTypeVisitor); var visitor = (ExpressionVisitor)Activator.CreateInstance(typeOfVisitor, expression.Parameters.Select(q => q.Type), newReturnType); var newExpression = visitor.Visit(expression); return(new ObjectType(newExpression)); }
private static string ConvertUnit(object value, string unit, int prefixUnit, params string[] prefixes) { var v = ObjectTypeConverter.Convert <decimal>(value); int prefixIndex = 0; for (; prefixIndex < prefixes.Length - 1; prefixIndex++) { if (v < prefixUnit) { break; } v /= prefixUnit; } var cultureInfo = CultureInfo.GetCultureInfo(CommonLocale.Language); var literal = string.Format(cultureInfo, "{0:#,#0.##} {1}{2}", Math.Round(v, 2), prefixes[prefixIndex], unit); return(literal); }
public bool Add(MenuItemDTO MenuItemDTO, int userID) { if (MenuItemDTO != null) { using (IEateryDbContext context = _unitOfWork.GetEateryDbContext()) { MenuItem MenuItem = ObjectTypeConverter.Convert <MenuItemDTO, MenuItem>(MenuItemDTO); MenuItem.CreatedBy = userID; MenuItem.CreatedDate = DateTime.Now; this._MenuItemRepository.Add(context, MenuItem); _unitOfWork.Commit(context); return(true); } } return(false); }
public bool Add(MenuItemRatingDTO ratingDTO) { if (ratingDTO != null) { using (IEateryDbContext context = _unitOfWork.GetEateryDbContext()) { MenuItemRating rating = ObjectTypeConverter.Convert <MenuItemRatingDTO, MenuItemRating>(ratingDTO); //rating.CreatedBy = ratingDTO.userID; //rating.CreatedDate = DateTime.Now; this._menuItemRatingRepository.Add(context, rating); _unitOfWork.Commit(context); return(true); } } return(false); }
public bool Add(OperationTimingDTO operationTimingDTO, int userID) { if (operationTimingDTO != null) { using (IEateryDbContext context = _unitOfWork.GetEateryDbContext()) { OperationTiming operationTiming = ObjectTypeConverter.Convert <OperationTimingDTO, OperationTiming>(operationTimingDTO); operationTiming.CreatedBy = userID; operationTiming.CreatedDate = DateTime.Now; this._operationTimingRepository.Add(context, operationTiming); _unitOfWork.Commit(context); return(true); } } return(false); }
public MenuItemDTO Update(MenuItemDTO menuItemDTO, int?userID) { using (IEateryDbContext context = _unitOfWork.GetEateryDbContext()) { MenuItem menuItem = this._MenuItemRepository.GetById(context, menuItemDTO.ID); if (menuItem != null) { menuItem.IsPublished = menuItemDTO.IsPublished; menuItem.UpdatedDate = DateTime.Now; menuItem.UpdatedBy = userID; menuItem = this._MenuItemRepository.Update(context, menuItem); _unitOfWork.Commit(context); if (menuItem != null) { return(ObjectTypeConverter.Convert <MenuItem, MenuItemDTO>(menuItem)); } } } return(default(MenuItemDTO)); }
protected ObjectType ConvertParamenter(ParameterExpression parameter, ObjectType newObjectType) { var type = parameter.Type; var newType = ObjectTypeConverter.Convert(type, targetType); if (type == newType) { return(newObjectType); } var newParameter = Expression.Parameter(newType, parameter.Name); var typeOfVisitor = typeof(ParameterVisitor); var visitor = (ExpressionVisitor)Activator.CreateInstance(typeOfVisitor, newParameter); var expression = objectType.Obj as LambdaExpression; var newExpressionBody = visitor.Visit(expression.Body); var newExpression = Expression.Lambda(newExpressionBody, newParameter); return(new ObjectType(newExpression)); }
public MenuItemDTO GetMenuItemById(int MenuItemID) { MenuItemDTO MenuItemDto = default(MenuItemDTO); using (IEateryDbContext context = _unitOfWork.GetEateryDbContext()) { try { MenuItem MenuItem = this._MenuItemRepository.GetAllQuery(context).FirstOrDefault(x => x.ID == MenuItemID); if (MenuItem != null) { MenuItemDto = ObjectTypeConverter.Convert <MenuItem, MenuItemDTO>(MenuItem); return(MenuItemDto); } } catch (Exception ex) { //AppLogManager.LogError(ex); throw ex; } } return(MenuItemDto); }
public UserDTO GetUserByEmailPassword(string email, string password) { UserDTO userDto = default(UserDTO); using (IEateryDbContext context = _unitOfWork.GetEateryDbContext()) { try { User user = this._userRepository.GetAllQuery(context).FirstOrDefault(x => x.Email == email && x.Password == password); if (user != null) { userDto = ObjectTypeConverter.Convert <User, UserDTO>(user); return(userDto); } } catch (Exception ex) { //AppLogManager.LogError(ex); throw ex; } } return(userDto); }
public RestaurantDTO GetRestaurantById(int RestaurantID) { RestaurantDTO RestaurantDto = default(RestaurantDTO); using (IEateryDbContext context = _unitOfWork.GetEateryDbContext()) { try { var Restaurant = this._RestaurantRepository.GetAllQuery(context).FirstOrDefault(x => x.ID == RestaurantID); if (Restaurant != null) { RestaurantDto = ObjectTypeConverter.Convert <Restaurant, RestaurantDTO>(Restaurant); return(RestaurantDto); } } catch (Exception ex) { //AppLogManager.LogError(ex); throw ex; } } return(RestaurantDto); }
public UserDTO GetUserById(int userID) { UserDTO userDto = default(UserDTO); using (IEateryDbContext context = _unitOfWork.GetEateryDbContext()) { try { User user = this._userRepository.GetAllQuery(context).FirstOrDefault(x => x.ID == userID); if (user != null) { userDto = ObjectTypeConverter.Convert <User, UserDTO>(user); return(userDto); } } catch (Exception ex) { //AppLogManager.LogError(ex); throw ex; } } return(userDto); }
public RestaurantDTO GetRestaurantByUserID(int userID) { RestaurantDTO RestaurantDTO = default(RestaurantDTO); try { using (IEateryDbContext context = _unitOfWork.GetEateryDbContext()) { var Restaurant = (from Restaurants in this._RestaurantRepository.GetAllQuery(context) join users in this._userRepository.GetAllQuery(context) on Restaurants.UserID equals users.ID where users.ID == userID select Restaurants).FirstOrDefault(); if (Restaurant != null) { RestaurantDTO = ObjectTypeConverter.Convert <Restaurant, RestaurantDTO>(Restaurant); } } } catch (Exception) { throw; } return(RestaurantDTO); }
public void TrueShouldBeReturned() { var typeConverter = new ObjectTypeConverter(); Assert.True(typeConverter.CanConvert(typeof(int?))); }
private static void ReadCreateObjectBlock(Packet packet, WowGuid guid, uint map, object index) { ObjectType objType = ObjectTypeConverter.Convert(packet.ReadByteE <ObjectType801>("Object Type", index)); if (ClientVersion.RemovedInVersion(ClientVersionBuild.V8_1_0_28724)) { packet.ReadInt32("HeirFlags", index); } WoWObject obj; switch (objType) { case ObjectType.Unit: obj = new Unit(); break; case ObjectType.GameObject: obj = new GameObject(); break; case ObjectType.Player: obj = new Player(); break; case ObjectType.AreaTrigger: obj = new SpellAreaTrigger(); break; case ObjectType.Conversation: obj = new ConversationTemplate(); break; default: obj = new WoWObject(); break; } var moves = ReadMovementUpdateBlock(packet, guid, obj, index); if (ClientVersion.AddedInVersion(ClientVersionBuild.V8_1_0_28724)) { var updatefieldSize = packet.ReadUInt32(); using (var fieldsData = new Packet(packet.ReadBytes((int)updatefieldSize), packet.Opcode, packet.Time, packet.Direction, packet.Number, packet.Writer, packet.FileName)) { var flags = fieldsData.ReadByteE <UpdateFieldFlag>("FieldFlags", index); var handler = CoreFields.UpdateFields.GetHandler(); obj.ObjectData = handler.ReadCreateObjectData(fieldsData, flags, index); switch (objType) { case ObjectType.Item: handler.ReadCreateItemData(fieldsData, flags, index); break; case ObjectType.Container: handler.ReadCreateItemData(fieldsData, flags, index); handler.ReadCreateContainerData(fieldsData, flags, index); break; case ObjectType.AzeriteEmpoweredItem: handler.ReadCreateItemData(fieldsData, flags, index); handler.ReadCreateAzeriteEmpoweredItemData(fieldsData, flags, index); break; case ObjectType.AzeriteItem: handler.ReadCreateItemData(fieldsData, flags, index); handler.ReadCreateAzeriteItemData(fieldsData, flags, index); break; case ObjectType.Unit: (obj as Unit).UnitData = handler.ReadCreateUnitData(fieldsData, flags, index); break; case ObjectType.Player: handler.ReadCreateUnitData(fieldsData, flags, index); handler.ReadCreatePlayerData(fieldsData, flags, index); break; case ObjectType.ActivePlayer: handler.ReadCreateUnitData(fieldsData, flags, index); handler.ReadCreatePlayerData(fieldsData, flags, index); handler.ReadCreateActivePlayerData(fieldsData, flags, index); break; case ObjectType.GameObject: (obj as GameObject).GameObjectData = handler.ReadCreateGameObjectData(fieldsData, flags, index); break; case ObjectType.DynamicObject: handler.ReadCreateDynamicObjectData(fieldsData, flags, index); break; case ObjectType.Corpse: handler.ReadCreateCorpseData(fieldsData, flags, index); break; case ObjectType.AreaTrigger: (obj as SpellAreaTrigger).AreaTriggerData = handler.ReadCreateAreaTriggerData(fieldsData, flags, index); break; case ObjectType.SceneObject: handler.ReadCreateSceneObjectData(fieldsData, flags, index); break; case ObjectType.Conversation: (obj as ConversationTemplate).ConversationData = handler.ReadCreateConversationData(fieldsData, flags, index); break; } } } else { var updates = CoreParsers.UpdateHandler.ReadValuesUpdateBlockOnCreate(packet, objType, index); var dynamicUpdates = CoreParsers.UpdateHandler.ReadDynamicValuesUpdateBlockOnCreate(packet, objType, index); obj.UpdateFields = updates; obj.DynamicUpdateFields = dynamicUpdates; } obj.Type = objType; obj.Movement = moves; obj.Map = map; obj.Area = CoreParsers.WorldStateHandler.CurrentAreaId; obj.Zone = CoreParsers.WorldStateHandler.CurrentZoneId; obj.PhaseMask = (uint)CoreParsers.MovementHandler.CurrentPhaseMask; obj.Phases = new HashSet <ushort>(CoreParsers.MovementHandler.ActivePhases.Keys); obj.DifficultyID = CoreParsers.MovementHandler.CurrentDifficultyID; // If this is the second time we see the same object (same guid, // same position) update its phasemask if (Storage.Objects.ContainsKey(guid)) { var existObj = Storage.Objects[guid].Item1; CoreParsers.UpdateHandler.ProcessExistingObject(ref existObj, obj, guid); // can't do "ref Storage.Objects[guid].Item1 directly } else { Storage.Objects.Add(guid, obj, packet.TimeSpan); } if (guid.HasEntry() && (objType == ObjectType.Unit || objType == ObjectType.GameObject)) { packet.AddSniffData(Utilities.ObjectTypeToStore(objType), (int)guid.GetEntry(), "SPAWN"); } }