예제 #1
0
        public ConveyorBasic FindDeviceByPLC_ID(int plc_id)
        {
            ConveyorBasic cb = null;

            cb = ConveyorList.Find(p => p.PLC_ID == plc_id);
            if (cb == null)
            {
                cb = CraneList.Find(p => p.PLC_ID == plc_id);
            }
            if (cb == null)
            {
                throw new BasicWarehouseException(String.Format("BasicWarehouse.FindDeviceByPLC_ID plc_id({0}) does not exist.", plc_id));
            }
            return(cb);
        }
예제 #2
0
파일: Graph.cs 프로젝트: II01/i2MFCSv2.TAI
        public bool RouteExists(string source, string target, bool isSimpleCommand)
        {
            try
            {
                ConveyorBasic deviceSource         = null;
                ConveyorBasic deviceTargetConveyor = null;
                List <Crane>  deviceTargetCrane    = null;

                if (source == null || target == null)
                {
                    return(false);
                }

                // define source
                // search for junction or first device
                if (ConveyorList.Exists(p => p.Name == source))
                {
                    deviceSource = Conveyor[source];
                    while (deviceSource.Route != null)
                    {
                        deviceSource = deviceSource.Route.Next;
                    }
                }
                else if (CraneList.Exists(p => p.Name == source))
                {
                    deviceSource = Crane[source];
                }
                else
                {
                    deviceSource = CraneList.Find(p => p.Shelve.Exists(s => source.StartsWith("W:" + s.ToString())));
                }
                if (deviceSource == null)
                {
                    return(false);
                }
                if (!(deviceSource is ConveyorJunction) && !(deviceSource is ConveyorOutput) && !(deviceSource is ConveyorOutputDefault) && !(deviceSource is Crane))
                {
                    return(false);
                }

                // define target
                if (ConveyorList.Exists(p => p.Name == target))
                {
                    deviceTargetConveyor = Conveyor[target];
                }
                else
                {
                    deviceTargetCrane = CraneList.FindAll(p => p.Shelve.Exists(s => target.StartsWith("W:" + s.ToString())));
                }
                if (deviceTargetConveyor == null && deviceTargetCrane == null)
                {
                    return(false);
                }

                // check if target is in the route
                List <Route> frc = null;
                if (deviceSource is ConveyorJunction)
                {
                    frc = (deviceSource as ConveyorJunction).RouteDef.FinalRouteCost;
                }
                else if (deviceSource is Crane)
                {
                    frc = (deviceSource as Crane).OutRouteDef.FinalRouteCost;
                }
                if (frc == null)
                {
                    return(false);
                }
                if (isSimpleCommand)
                {
                    if (deviceTargetConveyor != null && !frc.Exists(p => p.Items.Exists(s => s.Final.Name == deviceTargetConveyor.Name)))
                    {
                        return(false);
                    }
                    if (deviceTargetCrane != null && !frc.Exists(p => p.Items.Exists(s => deviceTargetCrane.Contains(s.Final as Crane))))
                    {
                        return(false);
                    }
                }
                else
                {
                    if (deviceTargetConveyor != null && !frc.Exists(p => p.Items[p.Items.Count - 1].Final.Name == deviceTargetConveyor.Name))
                    {
                        return(false);
                    }
                    if (deviceTargetCrane != null && !frc.Exists(p => deviceTargetCrane.Contains(p.Items[p.Items.Count - 1].Final as Crane)))
                    {
                        return(false);
                    }
                }

                return(true);
            }
            catch (Exception e)
            {
                AddEvent(Database.Event.EnumSeverity.Error, Database.Event.EnumType.Exception,
                         string.Format("{0}.{1}: {2}", this.GetType().Name, (new StackTrace()).GetFrame(0).GetMethod().Name, e.Message));
                return(false);
            }
        }