private void UpdateShipmentQueuingAtStation(object sender, StationShipmentEventArgs e) { try { _synchronizationContext.Post((evnt) => { try { var evntargs = (evnt as StationShipmentEventArgs); if (evnt != null && tvwStations != null) { foreach (TreeNode node in tvwStations.Nodes[0].Nodes) { if (node.Text.Equals("Station" + e.SourceStationNumber)) { TreeNode newChildNode = new TreeNode(evntargs.Message); newChildNode.Tag = evntargs.DeliveredShipment.ShipmentIdentifier; node.Nodes.Add(newChildNode); } } } tvwStations.ExpandAll(); } catch (Exception exp) { MessageBox.Show(exp.Message); } }, e); } catch (Exception exp) { MessageBox.Show(exp.Message); } }
public void ProcessQueuedShipment() { try { if (_queueShipment.Count() > 0) { while (_queueShipment.Count() > 0) { Shipment shipment = _queueShipment.Dequeue(); var station = LookupCache.GetInstance().GetStation(shipment.SourceStation.StationId); station.DeliverShipmentToStation(shipment); StationShipmentEventArgs args = new StationShipmentEventArgs(shipment.SourceStation.StationId, shipment.DestinationStation.StationId); args.Message = shipment + " Shipment queued at " + shipment.SourceStation; args.DeliveredShipment = shipment; OnShipmentQueued(this, args); } } _queueShipmentSynchronizer.WaitOne(); ProcessQueuedShipment(); } catch (Exception) { throw; } }
public void OnShipmentQueued(object sender, StationShipmentEventArgs eventArgs) { var shipmentQueuedAtStation = ShipmentQueuedAtStation; if (shipmentQueuedAtStation != null) { shipmentQueuedAtStation(sender, eventArgs); } }
private void QueueArrivedShipment(object sender, StationShipmentEventArgs eventArgs) { try { Station sourceStation = LookupCache.GetInstance().GetStation(eventArgs.SourceStationNumber); Station destinationStation = LookupCache.GetInstance().GetStation(eventArgs.DestinationStationNumber); Shipment shipment = new Shipment(sourceStation, destinationStation); _queueShipment.Enqueue(shipment); _queueShipmentSynchronizer.Set(); } catch (Exception) { throw; } }
private void UpdateShipmentDequeueFromStation(object sender, StationShipmentEventArgs e) { try { _synchronizationContext.Post((evnt) => { try { var evntargs = (evnt as StationShipmentEventArgs); if (evnt != null && tvwTrains != null) { foreach (TreeNode node in tvwStations.Nodes[0].Nodes) { if (node.Text.Contains("Station" + evntargs.SourceStationNumber)) { if (node.Nodes.Count > 0) { TreeNode nodeToRemove = null; foreach (TreeNode shipmentNode in node.Nodes) { if (shipmentNode.Tag.ToString().Contains(evntargs.DeliveredShipment.ShipmentIdentifier.ToString())) { nodeToRemove = shipmentNode; break; } } if (nodeToRemove != null) { node.Nodes.Remove(nodeToRemove); } } } } } tvwStations.ExpandAll(); } catch (Exception exp) { MessageBox.Show(exp.Message); } }, e); } catch (Exception exp) { MessageBox.Show(exp.Message); } }