/// <summary> /// Takes an object and a EDishType, turns every value of the object into a byte array of strings. /// The final byte array contains first 4 bytes = EDishtpye, 4 next bits = length of object array, rest of bits = object values /// </summary> /// <param name="myObj">An object matching a type in EDishType</param> /// <param name="type">What type of dish is it, (different types in the enum)</param> /// <returns>A byte array containing first 4 bits = EDishType, next 4 = length of object values in array, rest of bytes = object values</returns> static byte[] Serialize(Object myObj, EDishType type) { byte[] dishtypes = new byte[0]; byte[] arraylength = new byte[0]; byte[] finalobjectarray = new byte[0]; switch (type) { case EDishType.Dish: dishtypes = BitConverter.GetBytes(1); byte[] tempdishname = Encoding.UTF8.GetBytes(((Dish)myObj).Name + char.MinValue); byte[] tempdev = Encoding.UTF8.GetBytes(((Dish)myObj).Developer + char.MinValue); byte[] tempyear = Encoding.UTF8.GetBytes(((Dish)myObj).ReleaseYear.ToString() + char.MinValue); byte[] finalobjarray = new byte[tempdishname.Length + tempdev.Length + tempyear.Length]; tempdishname.CopyTo(finalobjarray, 0); tempdev.CopyTo(finalobjarray, tempdishname.Length); tempyear.CopyTo(finalobjarray, tempdishname.Length + tempdev.Length); finalobjectarray = finalobjarray; break; case EDishType.PremiumDish: dishtypes = BitConverter.GetBytes(2); break; default: break; } arraylength = BitConverter.GetBytes(finalobjectarray.Length); byte[] finalarray = new byte[dishtypes.Length + arraylength.Length + finalobjectarray.Length]; dishtypes.CopyTo(finalarray, 0); arraylength.CopyTo(finalarray, dishtypes.Length); finalobjectarray.CopyTo(finalarray, dishtypes.Length + arraylength.Length); return(finalarray); }
public Dish(Guid id, string name, EDishType type, ETimeOfDay timeOfDay, bool multipleOrders) { Id = id; Name = name; Type = type; TimeOfDay = timeOfDay; MultipleOrders = multipleOrders; }
public void SortTestNoError() { Order order = new Order(EOrderType.Morning); order.Dishes.AddRange(new List <Dish> { DishConstants.Cake, DishConstants.Coffee, DishConstants.Eggs, DishConstants.Potatoes, DishConstants.Steak, DishConstants.Toast, DishConstants.Wine }); _sorter.Sort(order); EDishType lastDishType = EDishType.Entree; foreach (var dish in order.Dishes) { Assert.IsTrue(dish.DishType >= lastDishType); lastDishType = dish.DishType; } }