public void Load(int id, CellLocation place) { var toLoad = new Item(id, place.Rack == Side.Left ? Item.Destination.Left : Item.Destination.Right); toLoad.Place = place; toLoad.Moving = true; ItemDatabase.Instance().AddItem(toLoad); RInput.Items.Enqueue(toLoad); Emit(); }
public void Move(int id, CellLocation dst) { var item = ItemDatabase.Instance().GetItem(id); if (item.Moving) { Console.WriteLine("MOVE: item is already moving, ignoring request"); return; } ForkLoader current = item.Place.Rack == Side.Left ? LeftForkLoader : RightForkLoader; current.EnqueueUnloadRequest(new UnloadRequest(id, dst.Rack == Side.Left? Item.Destination.Left : Item.Destination.Right, dst)); }
public static void Route(HttpListenerRequest req, HttpListenerResponse resp) { string responseText = "Ok"; int responseCode = 200; try { var splitted = req.RawUrl.ToUpper().Split('/'); if (splitted[1] == "LOAD") { var id = Int32.Parse(splitted[2]); var dst = new CellLocation(splitted[3]); Controller.Load(id, dst); } else if (splitted[1] == "UNLOAD") { var id = Int32.Parse(splitted[2]); Controller.Unload(id); } else if (splitted[1] == "MOVE") { var id = Int32.Parse(splitted[2]); var dst = new CellLocation(splitted[3]); Controller.Move(id, dst); } else if (splitted[1] == "DATA") { responseText = ItemDatabase.Instance().GetJson(); } else { responseCode = 500; responseText = "{\"error\": \"Unknown endpoint\"}"; } } catch (Exception e) { Console.WriteLine(e); responseText = e.ToString(); responseCode = 500; } var buffer = Encoding.UTF8.GetBytes(responseText); resp.ContentEncoding = Encoding.UTF8; resp.StatusCode = responseCode; resp.ContentType = "application/json"; resp.OutputStream.Write(buffer, 0, buffer.Length); resp.Close(); }