/// <summary> /// Initializes the LogicLayer /// </summary> /// <param name="args">Initialize parameters</param> /// <param name="ct">Cancels the initializion</param> /// <returns></returns> public async Task <bool> Initialize(StartArguments args, CancellationToken ct) { bool result = true; string errorMsg = string.Empty; const string fName = nameof(Initialize); _systemState = State.Initialize; Log.InfoEx(fName, "Initializing LogicLayer"); // TODO: Set settings from given arguments. // And set result based on that. // Set the idle-activity _activityQueue = args.IdleActivity != null ? new ActivityQueue(args.IdleActivity) : new ActivityQueue(new Activity(ActivityType.Idle)); // Load bottleshelf backup if provided, otherwise presume it's empty CurrentShelf = args.BackupShelf != null ? (_reservedShelf = args.BackupShelf) : (_reservedShelf = new Bottleshelf()); Queue = args.BacckupQueue ?? new OrderQueue(); // What services are available _beer = args.Beer; _drinks = args.Drinks; _sparkling = args.Sparkling; _currentTask = Task.Delay(1); // Additional arguments _partialOrderFullfill = args.FullfillOrdersPartially; // Initialize the robot, TODO: read port from cfg and throw if false switch (args.Mode) { case RunMode.Production: _robot.AddRobot("ABB", "COM3"); break; case RunMode.Simulation: _robot.AddRobot("SIMULATION", "SIM"); break; default: throw new ArgumentOutOfRangeException($"RunMode argument \"{args.Mode}\" out of range"); } if (result) { Log.InfoEx(fName, "Initialized LogicLayer successfully"); return(true); } else { _systemState = State.InitFailure; Log.ErrorEx(fName, $"Initializing LogicLayer failed:{Environment.NewLine}{errorMsg}"); return(false); } }
public void InitClasses() { ser = new ServiceLayer.ServiceLayer(); rob = new RobotCellLayer.RobotCellLayer(); da = new DataAccess.DataAccess(); rob.AddRobot("SIM", "SIM"); logic = new LogicLayer.LogicLayer(ser, rob, da); var shelf = new Bottleshelf(10, 0); shelf.AddBottle(new Bottle("Vodka")); shelf.AddBottle(new Bottle("Vesi")); shelf.AddBottle(new Bottle("Mehu")); var queue = new OrderQueue(); var kv = new Drink("Kossuvissy"); Assert.IsTrue(kv.AddPortion("Vodka", 4)); Assert.IsTrue(kv.AddPortion("Vesi", 10)); var mehu = new Drink("Mehu"); Assert.IsTrue(mehu.AddPortion("Mehu", 10)); queue.Add(new Tuple <Order, int>(new Order(OrderType.Drink, 1, 1, kv), 10)); queue.Add(new Tuple <Order, int>(new Order(OrderType.Drink, 2, 4, mehu), 10)); queue.Add(new Tuple <Order, int>(new Order(OrderType.Drink, 3, 3, kv), 10)); queue.Add(new Tuple <Order, int>(new Order(OrderType.Drink, 4, 1, kv), 10)); var startarg = new StartArguments(); startarg.BackupShelf = shelf; startarg.Mode = RunMode.Simulation; startarg.Beer = false; startarg.Drinks = true; startarg.Sparkling = false; startarg.IdleActivity = new Activity(ActivityType.ProcessOrders); startarg.BacckupQueue = queue; var init = Task.Run(() => logic.Initialize(startarg, new CancellationToken())); init.Wait(); Assert.IsTrue(init.Result); }