public bool SetLocation(string boxId, string binId) { logger.Debug("calling SetLocation"); Context c = new Context(); wmsdbEntities entities = c.GetWMSEntities(); bool result = false; try { var query = from b in entities.Boxes where b.id == boxId select b; var boxes = query.ToList(); foreach (var box in boxes) // should be only one box in the list! { box.location_id = binId; entities.SaveChanges(); logger.Debug(string.Format("Location set! boxId = {0}, locationId = {1}", box.id, box.location_id)); result = true; break; } } catch (Exception ex) { logger.Error(ex.ToString()); result = false; } return(result); }
public bool UnReserveBin(string binId) { logger.Debug("calling UnReserveBin"); Context c = new Context(); wmsdbEntities entities = c.GetWMSEntities(); bool result = false; try { var query = from l in entities.Locations select l; var locations = query.ToList(); foreach (var location in locations) { if (location.id == binId) { location.reserved = false; entities.SaveChanges(); logger.Debug(string.Format("Bin with binId = {0} unreserved", binId)); result = true; break; } } } catch (Exception ex) { logger.Error(ex.ToString()); result = false; } return(result); }
public bool CreateTransportentry(string boxId, string binId) { logger.Debug("calling CreateTransportEntry"); Context c = new Context(); wmsdbEntities entities = c.GetWMSEntities(); bool result = false; try { Transportentry newTrEntry = new Transportentry() { box_id = boxId, bin_id = binId }; entities.AddToTransportentries(newTrEntry); entities.SaveChanges(); logger.Debug(string.Format("New transportentry created! box_id = {0}, bin_id = {1}", newTrEntry.box_id, newTrEntry.bin_id)); result = true; } catch (Exception ex) { logger.Error(ex.ToString()); result = false; } return(result); }
public bool CreateOrder(string orderId, string dockId, bool isUnloading, bool toBeCleaned) { logger.Debug("calling CreateOrder"); Context c = new Context(); wmsdbEntities entities = c.GetWMSEntities(); bool result = false; try { Order newOrder = new Order { orderId = orderId, dockId = dockId, isUnloading = isUnloading, toBeCleaned = toBeCleaned }; entities.AddToOrders(newOrder); entities.SaveChanges(); logger.Debug(string.Format("Order created! orderId = {0}", newOrder.orderId)); result = true; // sending the event about the creation to Monitoring TODO!!!!!!!!!! ?????????? } catch (Exception ex) { logger.Error(ex.ToString()); result = false; } return(result); }
public bool CreateLocation(string locId, string typeId, string rackId, bool reserved) { logger.Debug("calling CreateLocation"); Context c = new Context(); wmsdbEntities entities = c.GetWMSEntities(); bool result = false; try { Location newLocation = new Location { id = locId, type = typeId, rack_id = rackId, reserved = reserved }; entities.AddToLocations(newLocation); entities.SaveChanges(); logger.Debug(string.Format("New location created! id = {0}, typeId = {1}, rackId = {2} reserved = {3}", newLocation.id, newLocation.type, newLocation.rack_id, newLocation.reserved)); result = true; } catch (Exception ex) { logger.Error(ex.ToString()); result = false; } return(result); }
public bool InsertMaterial(string boxId, string materialId, int amount) { logger.Debug("calling InsertMaterial"); Context c = new Context(); wmsdbEntities entities = c.GetWMSEntities(); bool result = false; try { Position position = new Position { box_id = boxId, material_id = materialId, amount = amount }; entities.AddToPositions(position); entities.SaveChanges(); logger.Debug(string.Format("Material inserted! boxId = {0}, materialId= {1}, amount = {2}", position.box_id, position.material_id, position.amount)); result = true; } catch (Exception ex) { logger.Error(ex.ToString()); result = false; } return(result); }
public bool CreateMaterial(string materialNumber, string name, string description) { logger.Debug("calling CreateMaterial"); Context c = new Context(); wmsdbEntities entities = c.GetWMSEntities(); bool result = false; try { Material newMaterial = new Material { materialNumber = materialNumber, name = name, description = description }; entities.AddToMaterials(newMaterial); entities.SaveChanges(); logger.Debug(string.Format("New material created! materialNumber = {0}", newMaterial.materialNumber)); result = true; } catch (Exception ex) { logger.Error(ex.ToString()); result = false; } return(result); }
public wmsdbEntities GetWMSEntities() { string connectionString = GetConnectionString(); wmsdbEntities context = new wmsdbEntities(connectionString); context.ContextOptions.LazyLoadingEnabled = false; // to avoid circular references!! return(context); }
public List <Position> GetPositions() { Context c = new Context(); wmsdbEntities entities = c.GetWMSEntities(); var query = from p in entities.Positions select p; var positions = query.ToList(); return(positions); }
public List <Material> GetMaterials() { Context c = new Context(); wmsdbEntities entities = c.GetWMSEntities(); var query = from m in entities.Materials select m; var materials = query.ToList(); return(materials); }
public List <Locationtype> GetLocationTypes() { Context c = new Context(); wmsdbEntities entities = c.GetWMSEntities(); var query = from lt in entities.Locationtypes select lt; var locationTypes = query.ToList(); return(locationTypes); }
public List <Rack> GetRacks() { Context c = new Context(); wmsdbEntities entities = c.GetWMSEntities(); var query = from r in entities.Racks select r; var racks = query.ToList(); return(racks); }
public List <Transportentry> GetTransportentries() { Context c = new Context(); wmsdbEntities entities = c.GetWMSEntities(); var query = from r in entities.Transportentries select r; var trEntries = query.ToList(); return(trEntries); }
public List <Order> GetOrders() { Context c = new Context(); wmsdbEntities entities = c.GetWMSEntities(); var query = from o in entities.Orders select o; var orders = query.ToList(); return(orders); }
public bool DeleteBox(string boxId) { logger.Debug("calling DeleteBox"); try { Context c = new Context(); wmsdbEntities entities = c.GetWMSEntities(); var query0 = from p in entities.Positions select p; var positions = query0.ToList(); Position position = positions.Find( delegate(Position p) { return(p.box_id == boxId); } ); if (position != null) { entities.Positions.DeleteObject(position); entities.SaveChanges(); logger.Debug("position deleted"); } var query = from b in entities.Boxes select b; var boxes = query.ToList(); Box box = boxes.Find( delegate(Box b) { return(b.id == boxId); } ); if (box != null) { entities.Boxes.DeleteObject(box); entities.SaveChanges(); logger.Debug("box deleted"); return(true); } else { return(false); } } catch (Exception ex) { return(false); } }
public List <Box> GetBoxes() { Context c = new Context(); wmsdbEntities entities = c.GetWMSEntities(); var query = from b in entities.Boxes select b; var boxes = query.ToList(); return(boxes); }
public bool CreateBox(string boxId) { logger.Debug("calling CreateBox"); Context c = new Context(); wmsdbEntities entities = c.GetWMSEntities(); bool result = false; String abcCat = "C"; Random r = new Random(); int nextCat = r.Next(0, 2); if (nextCat == 0) { abcCat = "A"; } else if (nextCat == 1) { abcCat = "B"; } else { abcCat = "C"; } try{ Box newBox = new Box { id = boxId, location_id = "RS", abc_cat = abcCat }; entities.AddToBoxes(newBox); entities.SaveChanges(); logger.Debug(string.Format("New box created! boxId = {0}", newBox.id)); result = true; // sending the event about the creation TODO!!!!!!!!!! CustomEvent co = new CustomEvent(); co.LocationName = boxId; string eventAsString = Event.SerializeEvent(co); logger.Debug("box creation event was serialized: " + eventAsString); MonitoringMessagePublisher mpublisher = new MonitoringMessagePublisher(); mpublisher.SendMessage(eventAsString); logger.Debug("Event about the box creation was sent to a defined queue using Monitoring"); } catch (Exception ex) { logger.Error(ex.ToString()); result = false; } return(result); }
/// <summary> /// Identifies if WMS can handle an order or not /// </summary> /// <param name="unloading">bool - true for an unloading order, false for a loading order</param> /// <param name="numberOfBoxes">integer - number of boxes to be unloaded or loades</param> /// <param name="toBeCleaned">bool - true for track has to be cleaned after an unloading order</param> /// <returns>bool- true if WMS can handle the order, false if not</returns> public bool Ready(bool unloading, int numberOfBoxes, bool toBeCleaned) { // TODO: move to StorageBinSearch??? below is the same code like in SeachrNextFreeBin!!!!!! logger.Debug("calling Ready"); int numberOfFreeBins = 0; Context c = new Context(); wmsdbEntities entities = c.GetWMSEntities(); var queryBoxes = from b in entities.Boxes select b; var boxes = queryBoxes.ToList(); var queryLocations = from l in entities.Locations select l; var locations = queryLocations.ToList(); var queryLocationtypeId = from ln in entities.Locationtypes where ln.name == ConstantsLibrary.Constants.STORAGE_BIN select ln.id; var locationIds = queryLocationtypeId.ToList(); string storageBinTypeId = locationIds.First(); var queryLeftOuterJoin = from location in locations join box in boxes on location.id equals box.location_id into gj where location.type.Equals(storageBinTypeId) from o in gj.DefaultIfEmpty() select new { LocationID = location.id, Reserved = location.reserved, LocationType = location.type, BoxId = (o == null) ? "NULL" : o.id }; //http://smehrozalam.wordpress.com/2009/06/10/c-left-outer-joins-with-linq/ foreach (var location in queryLeftOuterJoin) { if (location.BoxId == "NULL" && location.Reserved != true) { //logger.Debug("empty and not reserved box was found. Id = " + location.LocationID); numberOfFreeBins++; } } if (numberOfFreeBins >= numberOfBoxes) { return(true); } else { return(false); } }
public List <Box> GetBoxesOnRS() { Context c = new Context(); wmsdbEntities entities = c.GetWMSEntities(); var query = from b in entities.Boxes where b.location_id == "RS" select b; //var storageBinsQuery = from l in entities.Locations where l.type == storageBinTypeId select l; var boxes = query.ToList(); return(boxes); }
public string GetRackIdByName(string rackName) { Context c = new Context(); wmsdbEntities entities = c.GetWMSEntities(); var query = from r in entities.Racks where r.name == rackName select r.id; var rackIds = query.ToList(); if (rackIds.Count > 0) { return(rackIds.First()); } return(null); }
public string GetLocationtypeIdByName(string locationName) { Context c = new Context(); wmsdbEntities entities = c.GetWMSEntities(); var query = from ln in entities.Locationtypes where ln.name == locationName select ln.id; var locationIds = query.ToList(); if (locationIds.Count > 0) { return(locationIds.First()); } return(null); }
public List <Location> GetStorageBins() { Context c = new Context(); wmsdbEntities entities = c.GetWMSEntities(); var queryLocationtypeId = from ln in entities.Locationtypes where ln.name == ConstantsLibrary.Constants.STORAGE_BIN select ln.id; var locationIds = queryLocationtypeId.ToList(); string storageBinTypeId = locationIds.First(); var storageBinsQuery = from l in entities.Locations where l.type == storageBinTypeId select l; var storageBins = storageBinsQuery.ToList(); return(storageBins); }
public bool CallCCSTransport(string boxId, string endDestId) { logger.Debug("calling CallCCSTransport"); // Getting Service Objects from Spring IApplicationContext ctx = ContextRegistry.GetContext(); IRoutingService routing = (IRoutingService)ctx.GetObject("routingServiceObjectWSBinding"); IMaterialMgtService materialMgt = (IMaterialMgtService)ctx.GetObject("materialMgtServiceObjectWSBinding"); //IConveyorControlService ccsService = (IConveyorControlService)ctx.GetObject("CCSServiceObjectWSBinding"); ICCSMockService ccsService = (ICCSMockService)ctx.GetObject("ccsMockServiceObjectWSBinding"); //duplex Context c = new Context(); wmsdbEntities entities = c.GetWMSEntities(); var query = from b in entities.Boxes where b.id == boxId select b; var boxes = query.ToList(); Box box = boxes.First(); string nextDestId = ""; string transportMedium = ""; nextDestId = routing.GetNextDestination(boxId, endDestId); if (string.IsNullOrEmpty(nextDestId)) { logger.Debug("the box is at location or error"); return(true); // null if error, empty if the box is already at the location } transportMedium = routing.GetNextTransportMedium(boxId); /* * ////////////////// EVENT-DRIVEN asynch call * CCSMockServiceClient cl = new CCSMockServiceClient(); // init client * cl.TransportCompleted += new EventHandler<TransportCompletedEventArgs>(TransportCallback); // add event handler to TransportCallback * cl.TransportAsync(boxId, transportMedium, box.location_id, nextDestId); // call Transport asynchronously * ////////////////// asynch call test end); */ ///////////////// CHANNEL FACTORY asynch call //// ccsService.Transport(boxId, box.location_id, nextDestId); //IAsyncResult arTransport = ccsService.BeginTransport(boxId, transportMedium, box.location_id, nextDestId, TransportCallback, ccsService); ccsService.Move(boxId, transportMedium, box.location_id, nextDestId); logger.Debug(string.Format("ASYNCHRONOUS CCS MOCK CALL! box_id = {0}, transportMedium = {1}; currentLocation = {2}, nextDestination = {3}", boxId, transportMedium, box.location_id, nextDestId)); //System.Threading.Thread.Sleep(2000); return(true); }
public bool DeleteOrder(string orderId) { logger.Debug("calling DeleteOrder"); Context c = new Context(); wmsdbEntities entities = c.GetWMSEntities(); var query = from o in entities.Orders select o; var orders = query.ToList(); Order order = orders.Find( delegate(Order o) { return(o.orderId == orderId); } ); entities.Orders.DeleteObject(order); entities.SaveChanges(); return(true); }
public bool DeleteTransportentry(string boxId) { logger.Debug("calling DeleteTransportentry"); Context c = new Context(); wmsdbEntities entities = c.GetWMSEntities(); var query = from t in entities.Transportentries select t; var transportentries = query.ToList(); Transportentry trEntry = transportentries.Find( delegate(Transportentry t) { return(t.box_id == boxId); } ); entities.Transportentries.DeleteObject(trEntry); entities.SaveChanges(); return(true); }
public string GetNextTransportMedium(string boxId) { logger.Debug("calling GetNextTransportMedium"); Context c = new Context(); wmsdbEntities entities = c.GetWMSEntities(); // get Box var query1 = from b in entities.Boxes where b.id == boxId select b; var boxes = query1.ToList(); Box box = boxes.First(); // get ReceptionStation var query3 = from l in entities.Locations join lt in entities.Locationtypes on l.type equals lt.id where lt.name == ConstantsLibrary.Constants.RECEPTION_STATION select l; Location receptionStation = query3.First(); // get TransferStation var query4 = from l in entities.Locations join lt in entities.Locationtypes on l.type equals lt.id where lt.name == ConstantsLibrary.Constants.TRANSFER_STATION select l; Location transferStation = query4.First(); // get Conveyor var query5 = from l in entities.Locations join lt in entities.Locationtypes on l.type equals lt.id where lt.name == ConstantsLibrary.Constants.CONVEYOR select l; Location conveyor = query5.First(); // get RackFeeder var query6 = from l in entities.Locations join lt in entities.Locationtypes on l.type equals lt.id where lt.name == ConstantsLibrary.Constants.RACK_FEEDER select l; Location rackFeeder = query6.First(); if (box.location_id == receptionStation.id) { return(conveyor.id); // transportMedium = Conveyor, with id = "C" } else if (box.location_id == transferStation.id) { return(rackFeeder.id); // destination = "RackFeeder" with id = RF1 } return(null); // box is not at RS or TS => null /* OLD * var query1 = from b in entities.Boxes where b.id == boxId select b; * var boxes = query1.ToList(); * Box box = boxes.First(); * * var query3 = from l in entities.Locations * join lt in entities.Locationtypes on l.type equals lt.id * where lt.name == ConstantsLibrary.Constants.CONVEYOR * select l; * Location conveyor = query3.First(); * * var query4 = from l in entities.Locations * join lt in entities.Locationtypes on l.type equals lt.id * where lt.name == ConstantsLibrary.Constants.RACK_FEEDER * select l; * Location rackFeeder = query4.First(); * * if (box.location_id == conveyor.id) * return conveyor.id; // transportMedium = Conveyor, with id = "C" * else if (box.location_id == rackFeeder.id) * return rackFeeder.id; // destination = "RackFeeder" with id = RF1 * return null; // box is not on the conveyor or rackfeeder => null * */ }
public string SearchNextFreeBin(string boxId) { logger.Debug("calling SearchNextFreeBin"); logger.Debug("SearchStrategy is " + this.Strategy); Context c = new Context(); wmsdbEntities entities = c.GetWMSEntities(); var queryBoxes = from b in entities.Boxes select b; var boxes = queryBoxes.ToList(); var queryLocations = from l in entities.Locations select l; var locations = queryLocations.ToList(); var queryLocationtypeId = from ln in entities.Locationtypes where ln.name == ConstantsLibrary.Constants.STORAGE_BIN select ln.id; var locationIds = queryLocationtypeId.ToList(); string storageBinTypeId = locationIds.First(); // AS: IMO, Location should not represent StorageBins and Transport Locations such as Conveyor or Picking Station at the same time // Hence, this code needs to be redesigned after refactoring Location any way. // Therefore, I basically just have duplicated the previous code that selects just any free storage location if (this.Strategy.Equals(StorageStrategy.Simple)) { // AS: this is just the copy of the previous code var queryLeftOuterJoin = from location in locations join box in boxes on location.id equals box.location_id into gj where location.type.Equals(storageBinTypeId) from o in gj.DefaultIfEmpty() select new { LocationID = location.id, Reserved = location.reserved, LocationType = location.type, BoxId = (o == null) ? "NULL" : o.id }; //http://smehrozalam.wordpress.com/2009/06/10/c-left-outer-joins-with-linq/ foreach (var location in queryLeftOuterJoin) { if (location.BoxId == "NULL" && location.Reserved != true) { //logger.Debug("empty and not reserved box was found. Id = " + location.LocationID); return(location.LocationID); } } return(null); } else if (this.Strategy.Equals(StorageStrategy.Abc)) { var boxCat = from box in boxes where box.id == boxId select box.abc_cat; var queryLeftOuterJoin = from location in locations join box in boxes on location.id equals box.location_id into gj where location.type.Equals(storageBinTypeId) && location.abc_cat == boxCat.First() from o in gj.DefaultIfEmpty() select new { LocationID = location.id, Reserved = location.reserved, LocationType = location.type, BoxId = (o == null) ? "NULL" : o.id }; ////http://smehrozalam.wordpress.com/2009/06/10/c-left-outer-joins-with-linq/ foreach (var location in queryLeftOuterJoin) { if (location.BoxId == "NULL" && location.Reserved != true) { //logger.Debug("empty and not reserved box was found. Id = " + location.LocationID); return(location.LocationID); } } return(null); } else { logger.Warn("A new type of StorageStrategy has been defined, but not implemented!"); return(null); } }
/// <summary> /// Determines the next destination for the box on the way to the endlocation /// </summary> /// <param name="boxId"> id of the box to be transported </param> /// <param name="binId"> end location </param> /// <returns> /// id of the next destination (location) if there is one /// "" if the box is already at the end location /// null else /// </returns> public string GetNextDestination(string boxId, string binId) { logger.Debug("calling GetNextDestination"); Context c = new Context(); wmsdbEntities entities = c.GetWMSEntities(); // get Box var query1 = from b in entities.Boxes where b.id == boxId select b; var boxes = query1.ToList(); Box box = boxes.First(); // get StorageBin var query2 = from l in entities.Locations where l.id == binId select l; var locations = query2.ToList(); Location storageBin = locations.First(); // get ReceptionStation var query3 = from l in entities.Locations join lt in entities.Locationtypes on l.type equals lt.id where lt.name == ConstantsLibrary.Constants.RECEPTION_STATION select l; Location receptionStation = query3.First(); // get TransferStation var query4 = from l in entities.Locations join lt in entities.Locationtypes on l.type equals lt.id where lt.name == ConstantsLibrary.Constants.TRANSFER_STATION select l; Location transferStation = query4.First(); // routing in 2 steps: 1) from RS to TS 2) from TS to SB if (box.location_id == storageBin.id) { return(""); // destination = no, with id = "" } else if (box.location_id == receptionStation.id) { return(transferStation.id); // destination = "transferStation" with id = TS } else if (box.location_id == transferStation.id) { return(binId); // destination = "StorageBin" with id = binId } /* OLD!! // routing in 2 steps: 1) from C to RF 2) from RF to SB * var query3 = from l in entities.Locations * join lt in entities.Locationtypes on l.type equals lt.id * where lt.name == ConstantsLibrary.Constants.CONVEYOR select l; * Location conveyor = query3.First(); * * var query4 = from l in entities.Locations * join lt in entities.Locationtypes on l.type equals lt.id * where lt.name == ConstantsLibrary.Constants.RACK_FEEDER select l; * Location rackFeeder = query4.First(); * * if (box.location_id == location.id) * return ""; // destination = no, with id = "" * else if (box.location_id == conveyor.id) * return rackFeeder.id; // destination = "RackFeeder" with id = RF1 * else if (box.location_id == rackFeeder.id) * return binId; // destination = "StorageBin" with id = binId * */ return(null); }