/// <summary>
        /// Creates an instruction view model for the given instruction model.
        /// </summary>
        /// <param name="instructionModel">The instruction model to make the view model from.</param>
        /// <returns>An instruction view model derived from BaseInstructionViewModel.</returns>
        public override BaseInstructionViewModel CreateInstructionViewModel(IBaseInstructionModel instructionModel)
        {
            if (instructionModel is XICInstructionModel)
            {
                return(new XICViewModel(instructionModel));
            }
            if (instructionModel is XIOInstructionModel)
            {
                return(new XIOViewModel(instructionModel));
            }
            if (instructionModel is OTEInstructionModel)
            {
                return(new OTEViewModel(instructionModel));
            }

            // If the instruction type did not exist, throw argument exception
            throw new ArgumentException($"The {instructionModel.ShortName} instruction is not in the {nameof(InstructionViewModelFactory)} factory");
        }
예제 #2
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="instructionModel">The instruction model linked to the instruction view model.</param>
 public OTEViewModel(IBaseInstructionModel instructionModel) : base(instructionModel)
 {
 }
 public RungInstructionsLinkedListNode(IBaseInstructionModel instruction)
 {
     Instruction = instruction;
     NodeID      = Instruction.ID;
 }
        public void InsertInstruction(IBaseInstructionModel instruction, int index)
        {
            RungInstructionsLinkedListNode node         = Head;
            RungInstructionsLinkedListNode previousNode = null;
            RungInstructionsLinkedListNode nextNode     = null;
            RungInstructionsLinkedListNode newNode      = new RungInstructionsLinkedListNode(instruction);

            int tracker = 0;

            //try
            //{
            //    File.AppendAllText(@"C:\Temp\Debug.txt", $"{DateTime.Now.ToString("HH:mm:ss")} - In InsertInstruction trying to insert {newNode.Instruction.ASCIIName}.{newNode.ID} instruction at index {index} {Environment.NewLine}");
            //    File.AppendAllText(@"C:\Temp\Debug.txt", $"{DateTime.Now.ToString("HH:mm:ss")} - Current Head: {node.Instruction.ASCIIName}.{node.ID} {Environment.NewLine}");
            //}
            //catch(Exception) { }


            // Head
            if (index == 0)
            {
                if (Head is null)
                {
                    Head = newNode;
                    return;
                }
                Head.Previous = newNode;
                newNode.Next  = Head;
                Head          = newNode;
                //try
                //{
                //    File.AppendAllText(@"C:\Temp\Debug.txt", $"{DateTime.Now.ToString("HH:mm:ss")} - Changed Head to: {Head.Instruction.ASCIIName}.{Head.ID} {Environment.NewLine}");
                //    File.AppendAllText(@"C:\Temp\Debug.txt", $"{DateTime.Now.ToString("HH:mm:ss")} - RungInstructionLinkedList.Count: {this.GetNumberOfInstructions()} {Environment.NewLine}");
                //}
                //catch(Exception) { }

                return;
            }

            // For other nodes, traverse the linked list to the index
            while (tracker != index)
            {
                previousNode = node;
                node         = node.Next;
                nextNode     = node.Next;
                tracker++;

                //try { File.AppendAllText(@"C:\Temp\Debug.txt", $"{DateTime.Now.ToString("HH:mm:ss")} - Node {tracker} is: {node.Instruction.ASCIIName}.{node.ID} {Environment.NewLine}"); } catch(Exception) { }
            }

            // Join the preceding and following nodes.
            previousNode.Next = newNode;
            node.Previous     = newNode;

            //try
            //{
            //    File.AppendAllText(@"C:\Temp\Debug.txt", $"{DateTime.Now.ToString("HH:mm:ss")} - Changed Node {tracker} to: {node.Instruction.ASCIIName}.{node.ID} {Environment.NewLine}");
            //    File.AppendAllText(@"C:\Temp\Debug.txt", $"{DateTime.Now.ToString("HH:mm:ss")} - Node {tracker}.Previous: {previousNode.Instruction.ASCIIName}.{node.ID}{Environment.NewLine}");
            //    File.AppendAllText(@"C:\Temp\Debug.txt", $"{DateTime.Now.ToString("HH:mm:ss")} - Node {tracker}.Next : {nextNode.Instruction.ASCIIName}.{node.ID} {Environment.NewLine}");
            //}
            //catch(Exception){ }
        }
 /// <summary>
 /// Creates an instruction viewmodel from an instruction model.
 /// </summary>
 /// <param name="InstructionModel">The instruction model to create an instruction viewmodel from.</param>
 /// <returns>An instruction viewmodel.</returns>
 public abstract BaseInstructionViewModel CreateInstructionViewModel(IBaseInstructionModel InstructionModel);