Exemplo n.º 1
0
 private void RecalculateRoute(PlatformItem item, IPlatformModule module)
 {
     if (!RouteCalculator.CalculateSingleItemRouting(item, module))
     {
         module.RemoveItemRouting(item);
     }
 }
Exemplo n.º 2
0
        private void OnPlatformItemEvent(PlatformItemEvent itemEvent)
        {
            if (!IsInitialized)
            {
                return;
            }

            var module = itemEvent.AssosiatedModule;
            var itemId = itemEvent.ItemId;

            if (!RouteCalculator.GraphContainsModule(module))
            {
                return;
            }

            if (itemEvent.EventType == PlatformItemEventType.NewItemCreated)
            {
                var item = itemEvent.NewItem;

                if (item == null)
                {
                    throw new InvalidOperationException(module.Name + " created a new PlatformItem but was not set as a reference to event args!");
                }

                var previousModule = (from m in ModuleRepository.Modules
                                      where m.ContainsItem(itemEvent.ItemId) &&
                                      m != module
                                      select m).FirstOrDefault();

                if (previousModule != null)
                {
                    Logger.Warn("Duplicate item-id detected.");
                    item.AddLog("Duplicate item-id detected.");
                    previousModule.RemoveItem(itemId);
                }

                module.AddItem(item);
                UpdateRouteIndex(item, module);
                RecalculateRoute(item, module);
            }
            else if (itemEvent.EventType == PlatformItemEventType.ItemDetected)
            {
                var previousModule = (from m in ModuleRepository.Modules
                                      where m.ContainsItem(itemId) &&
                                      m != module
                                      select m).FirstOrDefault();

                if (previousModule != null)
                {
                    var originalItem = previousModule.GetItem(itemId);
                    previousModule.MoveItem(itemId, module);
                    UpdateRouteIndex(originalItem, module);
                }
                else
                {
                    if (!module.ContainsItem(itemId))
                    {
                        var item = module.CreateNewPlatformItem();
                        item.ItemId = itemId;

                        module.AddItem(item);
                    }
                }

                RecalculateRoute(module.GetItem(itemId), module);
            }
            else if (itemEvent.EventType == PlatformItemEventType.ItemLeft)
            {
                var targetModule = RouteCalculator.GetTargetModule(itemEvent.ReleasePort, module);

                // sink, finished
                if (targetModule == null)
                {
                    module.RemoveItem(itemId);
                    Logger.Info("Item " + (ulong)itemId + " lost in " + module.Name + ". Is in nirvana now.");
                }
                // move to next
                else
                {
                    var item = module.GetItem(itemId);
                    module.MoveItem(itemId, targetModule);

                    UpdateRouteIndex(item, targetModule);
                    RecalculateRoute(item, targetModule);
                }
            }
        }
Exemplo n.º 3
0
 public bool IsRoutePossible(IPlatformModule sourceModule, IPlatformModule targetModule)
 {
     return(RouteCalculator.IsRoutePossible(sourceModule, targetModule));
 }