public void ToStringTest() { var sc = new SimpleCommand( "git", new List <string> { "reset", "--hard" }); string expectedString = "git reset --hard"; string actualString = sc.ToString(); actualString.Should().Be(expectedString); }
public override void CreateAndSendTOTelegram(SimpleCommand cmd) { try { if (!(cmd is SimpleConveyorCommand)) { throw new ConveyorException(String.Format("{0} is not SimpleCoveyorCommand", cmd.ToString())); } SimpleConveyorCommand Cmd = cmd as SimpleConveyorCommand; MaterialID matID = Warehouse.DBService.FindMaterialID((int)cmd.Material, true); short task; switch (Cmd.Task) { case SimpleCommand.EnumTask.Move: task = TelegramTransportTO.ORDER_MOVE; break; case SimpleCommand.EnumTask.Delete: task = TelegramTransportTO.ORDER_PALETTEDELETE; break; case SimpleCommand.EnumTask.Create: task = TelegramTransportTO.ORDER_PALETTECREATE; break; case SimpleCommand.EnumTask.Cancel: throw new NotImplementedException(); default: throw new ConveyorException(String.Format("{0} has unknown Order", Cmd.ToString())); } if (Warehouse.Conveyor.ContainsKey(Cmd.Source)) { Communicator.AddSendTelegram(new TelegramTransportTO { MFCS_ID = Cmd.ID, Sender = Communicator.MFCS_ID, Receiver = Communicator.PLC_ID, Order = task, Palette = new Palette { Barcode = (UInt32)Cmd.Material, Type = (short)matID.Size, Weight = (ushort)matID.Weight }, SenderTransport = Warehouse.FindConveyorBasic(Cmd.Source).ConveyorAddress, Source = Warehouse.FindConveyorBasic(Cmd.Source).ConveyorAddress, Target = Warehouse.FindConveyorBasic(Cmd.Target).ConveyorAddress }); cmd.Status = SimpleCommand.EnumStatus.Written; Warehouse.DBService.UpdateSimpleCommand(cmd); Warehouse.AddEvent(Event.EnumSeverity.Event, Event.EnumType.Command, cmd.ToString()); if (cmd.Command_ID.HasValue) { Command command = Warehouse.DBService.FindCommandByID(cmd.Command_ID.Value); if (command == null) { throw new ConveyorException($"Command {command.ToString()} null."); } if (command.Status < Database.Command.EnumCommandStatus.Active) { command.Status = Database.Command.EnumCommandStatus.Active; Warehouse.DBService.UpdateCommand(command); Warehouse.OnCommandFinish?.Invoke(command); } } } } catch (Exception e) { Warehouse.AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, e.Message); throw new ConveyorException(String.Format("{0} Conveyor.CreateAndSendTOTelegram failed ({1}).", Name, cmd != null ? cmd.ToString() : "null")); } }
public override void FinishCommand(Int32 id, SimpleCommand cmd, SimpleCommand.EnumStatus s) { try { if (cmd == null) { Warehouse.AddEvent(Event.EnumSeverity.Event, Event.EnumType.Program, String.Format("Conveyor.FinishCommand ({0},{1},{2}) ", id, "null", s)); } SimpleConveyorCommand cOld = null; if (cmd == null || cmd.ID != id) { if (id != 0) { cOld = Warehouse.DBService.FindSimpleConveyorCommandByID(id); } } if (cmd == null) { cmd = cOld; } if (cmd != null) { cmd.Status = s; Warehouse.DBService.UpdateSimpleCommand(cmd); if (cmd.Status == SimpleCommand.EnumStatus.Finished || cmd.Status == SimpleCommand.EnumStatus.Canceled) { OnSimpleCommandFinish(cmd); } Warehouse.AddEvent(Event.EnumSeverity.Event, Event.EnumType.Command, cmd.ToString()); } if (cOld != null && cOld.Status < SimpleCommand.EnumStatus.Canceled) { cOld.Status = SimpleCommand.EnumStatus.Canceled; cOld.Reason = SimpleCommand.EnumReason.MFCS; Warehouse.DBService.UpdateSimpleCommand(cOld); OnSimpleCommandFinish(cOld); Warehouse.AddEvent(Event.EnumSeverity.Event, Event.EnumType.Command, cOld.ToString()); } if (cmd != null && cOld == null && cmd.ID != id && id != 0) { throw new ConveyorException("Can't find command by Id"); } } catch (Exception ex) { Warehouse.AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, ex.Message); throw new ConveyorException(String.Format("{0} Conveyor.FinishCommand failed ({1},{2},{3})", Name, id, cmd != null ? cmd.ToString() : "null", s)); } }
public override void CreateAndSendTOTelegram(SimpleCommand cmd) { try { if (!(cmd is SimpleCraneCommand)) { throw new CraneException(String.Format("{0} is not SimpleCraneCommand.", cmd.ToString())); } SimpleCraneCommand Cmd = cmd as SimpleCraneCommand; MaterialID matID = null; if (Cmd.Material.HasValue) { matID = Warehouse.DBService.FindMaterialID((int)Cmd.Material, true); } LPosition pos = LPosition.FromString(Cmd.Source); if (!pos.IsWarehouse()) { if (cmd.Task == SimpleCommand.EnumTask.Pick) { pos = FindInConveyor(cmd.Source).CraneAddress; } else if (cmd.Task == SimpleCommand.EnumTask.Drop) { pos = FindOutConveyor(cmd.Source).CraneAddress; } else if (cmd.Task == SimpleCommand.EnumTask.Move) { pos = FindInOutConveyor(cmd.Source).CraneAddress; } else if (cmd.Task == SimpleCommand.EnumTask.Cancel) { pos = CraneAddress; if (!cmd.CancelID.HasValue) { throw new CraneException(String.Format("{0} Parameter null", cmd != null ? cmd.ToString() : "null")); } } else if (cmd.Task >= SimpleCommand.EnumTask.Delete) { pos = CraneAddress; } } if (matID == null && cmd.Task != SimpleCommand.EnumTask.Move && cmd.Task != SimpleCommand.EnumTask.Cancel) { throw new CraneException(String.Format("Command validity fault ({0})", cmd.ToString())); } Communicator.AddSendTelegram( new Telegrams.TelegramCraneTO { Sender = Communicator.MFCS_ID, Receiver = Communicator.PLC_ID, MFCS_ID = cmd.ID, Order = (short)cmd.Task, Buffer_ID = (cmd.Task != SimpleCommand.EnumTask.Cancel) ? (matID != null ? matID.ID : 0) : cmd.CancelID.Value, Position = new Telegrams.Position { R = (short)pos.Shelve, X = (short)pos.Travel, Y = (short)pos.Height, Z = (short)pos.Depth }, Palette = new Telegrams.Palette { Barcode = Convert.ToUInt32(matID != null ? matID.ID : 0), Type = (Int16)(matID != null ? matID.Size : 0), Weight = (UInt16)(matID != null ? matID.Weight : 0) }, ID = PLC_ID }); cmd.Status = SimpleCommand.EnumStatus.Written; Warehouse.DBService.UpdateSimpleCommand(cmd); Warehouse.AddEvent(Event.EnumSeverity.Event, Event.EnumType.Command, cmd.ToString()); // check for blocked locations LPosition p = LPosition.FromString(cmd.Source); string frontLoc; if (p.Shelve > 0 && p.Depth == 2) { LPosition pOther = new LPosition { Shelve = p.Shelve, Travel = p.Travel, Height = p.Height, Depth = 1 }; frontLoc = pOther.ToString(); } else { frontLoc = cmd.Source; } if (Warehouse.DBService.FindPlaceID(cmd.Source) != null && (Warehouse.DBService.FindPlaceID(cmd.Source).Blocked || Warehouse.DBService.FindPlaceID(frontLoc).Blocked)) { Warehouse.Segment[Segment].AlarmRequest(0); Warehouse.AddEvent(Event.EnumSeverity.Error, Event.EnumType.Command, string.Format("Location blocked. Command: {0}", cmd.ToString())); } if (cmd.Command_ID.HasValue) { Command command = Warehouse.DBService.FindCommandByID(cmd.Command_ID.Value); if (command == null) { throw new ConveyorException($"Command {command.ToString()} null."); } if (command.Status < Database.Command.EnumCommandStatus.Active) { command.Status = Database.Command.EnumCommandStatus.Active; Warehouse.DBService.UpdateCommand(command); Warehouse.OnCommandFinish?.Invoke(command); } } } catch (Exception ex) { Warehouse.AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, ex.Message); throw new CraneException(String.Format("{0} Crane.CreateAndSendTOTelegram failed. ({1})", Name, cmd != null ? cmd.ToString() : "null")); } }
public void OnSimpleCommandFinish(SimpleCommand cmd) { try { // automatic mode if (cmd.Command_ID.HasValue) { Command Command = Warehouse.DBService.FindCommandByID(cmd.Command_ID.Value); if (Command == null) { throw new ConveyorBasicException(String.Format("{0} has no corresponding Command", cmd != null ? cmd.ToString() : "null")); } if (Command.Task == Database.Command.EnumCommandTask.Move) { Place p = Warehouse.DBService.FindMaterial((Command as CommandMaterial).Material.Value); if (p != null && p.Place1 == (Command as CommandMaterial).Target) { Command.Status = Database.Command.EnumCommandStatus.Finished; Warehouse.DBService.UpdateCommand(Command); Warehouse.OnCommandFinish?.Invoke(Command); } else { Conveyor conv = Warehouse.ConveyorList.FirstOrDefault(c => c.Name == (Command as CommandMaterial).Target); if (conv != null && conv is ConveyorOutputDefault) { Command.Status = Database.Command.EnumCommandStatus.Finished; Warehouse.DBService.UpdateCommand(Command); Warehouse.OnCommandFinish?.Invoke(Command); } } } else if (cmd.Status == SimpleCommand.EnumStatus.Finished && Warehouse.DBService.AllSimpleCommandWithCommandIDFinished(cmd.Command_ID.Value)) { Command.Status = Database.Command.EnumCommandStatus.Finished; Warehouse.DBService.UpdateCommand(Command); Warehouse.OnCommandFinish?.Invoke(Command); } else if (cmd.Status == SimpleCommand.EnumStatus.Canceled && (cmd.Task == SimpleCommand.EnumTask.Create || cmd.Task == SimpleCommand.EnumTask.Delete || (cmd.Task == SimpleCommand.EnumTask.Move && Command.Task == Command.EnumCommandTask.SegmentHome))) { if ((int)cmd.Reason > 100) { Command.Reason = Command.EnumCommandReason.PLC; } else { Command.Reason = Command.EnumCommandReason.MFCS; } Command.Status = Database.Command.EnumCommandStatus.Canceled; Warehouse.DBService.UpdateCommand(Command); Warehouse.OnCommandFinish?.Invoke(Command); } } } catch (Exception ex) { Warehouse.AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, ex.Message); throw new ConveyorBasicException(String.Format("{0} ConveyorBasic.OnSimpleCommandFinish ({1}) fault.", Name, cmd != null ? cmd.ToString() : "null")); } }