private MyDebugNode CreateDebugNode(IMyExecutable executable) { MyDebugNode result; if (executable is MyTask) { result = new MyDebugTaskNode(executable as MyTask); } else { result = new MyDebugNode(executable); } if (executable is MyExecutionBlock) { foreach (IMyExecutable child in (executable as MyExecutionBlock).Children) { if (child is MySignalTask) { if (showSignalsButton.Checked) { result.Nodes.Add(CreateDebugNode(child)); } } else if (showDisabledTasksButton.Checked || child.Enabled) { result.Nodes.Add(CreateDebugNode(child)); } } } return(result); }
/// Executes current IMyExecutable children and moves to next one public virtual MyExecutionBlock ExecuteStep() { if (m_childIterator < m_children.Length) { IMyExecutable currentChild = m_children[m_childIterator]; m_childIterator++; if (currentChild is MyExecutionBlock) { MyExecutionBlock childList = currentChild as MyExecutionBlock; childList.Reset(); return(childList); } else { if (currentChild.Enabled) { MyLog.DEBUG.WriteLine("Executing: " + currentChild.Name); currentChild.SimulationStep = SimulationStep; currentChild.Execute(); } return(this); } } else { return(Parent); } }
private MyDebugNode CreateDebugNode(IMyExecutable executable) { MyDebugNode result; if (executable is MyTask) { result = new MyDebugTaskNode(executable as MyTask); } else { result = new MyDebugNode(executable); } if (executable is MyExecutionBlock) { foreach (IMyExecutable child in (executable as MyExecutionBlock).Children) { if (child is MySignalTask) { if (showSignalsButton.Checked) { result.Nodes.Add(CreateDebugNode(child)); } } else if (showDisabledTasksButton.Checked || child.Enabled) { result.Nodes.Add(CreateDebugNode(child)); } } } return result; }
private void ProfilingExecute(IMyExecutable child) { m_profilingStopwatch.Restart(); try { child.Execute(); } finally { EndMeasuring(child); } }
public MyExecutionBlock CreateCustomExecutionPlan(MyExecutionBlock defaultPlan) { //get rid of signal tasks IMyExecutable[] content = new IMyExecutable[defaultPlan.Children.Length - 2]; Array.Copy(defaultPlan.Children, 1, content, 0, defaultPlan.Children.Length - 2); //place if block inside return new MyExecutionBlock( defaultPlan.Children[0], new MyIfBlock(IsActive, content), defaultPlan.Children.Last()) { Name = defaultPlan.Name }; }
/// Executes all children elements public virtual void Execute() { for (int i = 0; i < m_children.Length; i++) { IMyExecutable child = m_children[i]; if (child.Enabled) { child.SimulationStep = SimulationStep; child.Execute(); } } }
/// Executes current IMyExecutable children and moves to next one public virtual MyExecutionBlock ExecuteStep() { if (m_childIterator < m_children.Length) { IMyExecutable currentChild = m_children[m_childIterator]; m_childIterator++; var childList = currentChild as MyExecutionBlock; if (childList != null) { childList.Reset(); // Profiling an inner block. if (IsProfiling) { m_profilingStopwatch.Restart(); } return(childList); } else { if (currentChild.Enabled) { MyLog.DEBUG.WriteLine("Executing: " + currentChild.Name); currentChild.SimulationStep = SimulationStep; if (IsProfiling) { ProfilingExecute(currentChild); } else { currentChild.Execute(); } } return(this); } } else { // Control goes back to parent, en its measurement of this block. if (IsProfiling && Parent != null) { Parent.EndChildBlockMeasuring(this); } return(Parent); } }
public MyExecutionBlock CreateCustomExecutionPlan(MyExecutionBlock defaultPlan) { //get rid of signal tasks IMyExecutable[] content = new IMyExecutable[defaultPlan.Children.Length - 2]; Array.Copy(defaultPlan.Children, 1, content, 0, defaultPlan.Children.Length - 2); //place if block inside return(new MyExecutionBlock( defaultPlan.Children[0], new MyIfBlock(IsActive, content), defaultPlan.Children.Last()) { Name = defaultPlan.Name }); }
private static void AlterText(DrawTextEventArgs e) { if (e.Node.Tag is MyDebugNode) { IMyExecutable executable = (e.Node.Tag as MyDebugNode).Executable; if (executable is MyExecutionBlock) { e.Font = new Font(e.Font, FontStyle.Bold); } if (!executable.Enabled) { e.TextColor = SystemColors.GrayText; } } }
public MyDebugNode(IMyExecutable executable) : base(executable.Name) { Executable = executable; if (Executable is MyIncomingSignalTask) { Icon = Properties.Resources.signal_in; } else if (Executable is MyOutgoingSignalTask) { Icon = Properties.Resources.signal_out; } else { Icon = Properties.Resources.gear_16xLG; } }
public MyDebugNode(IMyExecutable executable) : base(executable.Name ?? string.Empty) { BackgroundColor = Color.White; Executable = executable; if (Executable is MyIncomingSignalTask) { Icon = Properties.Resources.signal_in; } else if (Executable is MyOutgoingSignalTask) { Icon = Properties.Resources.signal_out; } else { Icon = Properties.Resources.gear_16xLG; } }
/// Executes all children elements public virtual void Execute() { // ReSharper disable once ForCanBeConvertedToForeach -- Performance critical loop. for (int i = 0; i < m_children.Length; i++) { IMyExecutable child = m_children[i]; if (child.Enabled) { child.SimulationStep = SimulationStep; if (IsProfiling) { ProfilingExecute(child); } else { child.Execute(); } } } }
private MyDebugNode CreateDebugNode(IMyExecutable executable) { MyDebugNode result; if (executable is MyTask) { result = new MyDebugTaskNode(executable as MyTask, () => m_mainForm.TaskView.RefreshView()); } else { result = new MyDebugNode(executable); } var executableBlock = executable as MyExecutionBlock; if (executableBlock != null) { foreach (IMyExecutable child in executableBlock.Children) { if (child is MySignalTask) { if (showSignalsButton.Checked) { result.Nodes.Add(CreateDebugNode(child)); } } else if (showDisabledTasksButton.Checked || child.Enabled) { result.Nodes.Add(CreateDebugNode(child)); } } } result.BreakpointStateChanged += OnBreakpointStateChanged; return(result); }
private void ProfilingExecute(IMyExecutable child) { m_profilingStopwatch.Restart(); try { child.Execute(); } finally { EndMeasuring(child); } }
public MyDebugNode(IMyExecutable executable) : base(executable.Name) { Executable = executable; if (Executable is MyIncomingSignalTask) { Icon = Properties.Resources.signal_in; } else if (Executable is MyOutgoingSignalTask) { Icon = Properties.Resources.signal_out; } else { Icon = Properties.Resources.gear_16xLG; } }
public ParseResult Parse(ParseMode mode, out byte[] Instructions) { byte[] MagicBytes = new byte[4]; // Open the file as read only. using (FileStream Reader = TargetFile.Open(FileMode.Open)) { if (mode == ParseMode.AUTO) { // There must be no less than 4 bytes in the file in order to determine its magic bytes. This is not necessarily true for // every file type. If there are only 3 bytes in the read file, the user probably chose the wrong file anyway. // Reader.Read() returns the number of bytes read. if (Reader.Read(MagicBytes, 0, 4) != 4) { Logger.Log(LogCode.IO_INVALIDFILE, "File must be no less than 4 bytes in length"); Instructions = null; return(ParseResult.INVALID); } // Order the bytes in big endian(because was read from a file) to form the signature of magic bytes. // Most magic byte signatures are 4 bytes, especially for the purposes of this program. int Signature = MagicBytes[3] + (MagicBytes[2] << 8) + (MagicBytes[1] << 16) + (MagicBytes[0] << 24); // Check if the file type can be inferred from the magic byte signature from the signatures registered in the SignatureTable. MagicDelegate ResultDel; if (SignatureTable.TryGetValue(Signature, out ResultDel)) { IMyExecutable Result = ResultDel(Reader); // If $Result is null after parsing, there was an error in doing so. if (Result == null) { Instructions = null; return(ParseResult.INVALID); } else { Instructions = ResultDel(Reader).Instructions; return(ParseResult.SUCCESS); } } else { // If the file type cannot be inferred, Instructions = null; return(ParseResult.NOT_INFERRED); } } // Other parse modes for forcing files to be interpreted as a particular format. else if (mode == ParseMode.BIN) { Instructions = BIN.Parse(Reader).Instructions; return(ParseResult.SUCCESS); } else if (mode == ParseMode.TXT) { TXT Result = TXT.Parse(Reader); // If $Result is null after parsing, there was an error in doing so. if (Result == null) { Instructions = null; return(ParseResult.INVALID); } else { Instructions = Result.Instructions; return(ParseResult.SUCCESS); } } } // This should never be reached. throw new System.Exception(); }
private MyDebugNode CreateDebugNode(IMyExecutable executable) { MyDebugNode result; if (executable is MyTask) { result = new MyDebugTaskNode(executable as MyTask); } else { result = new MyDebugNode(executable); } var executableBlock = executable as MyExecutionBlock; if (executableBlock != null) { foreach (IMyExecutable child in executableBlock.Children) { if (child is MySignalTask) { if (showSignalsButton.Checked) { result.Nodes.Add(CreateDebugNode(child)); } } else if (showDisabledTasksButton.Checked || child.Enabled) { result.Nodes.Add(CreateDebugNode(child)); } } } result.BreakpointStateChanged += OnBreakpointStateChanged; return result; }
private void EndMeasuring(IMyExecutable childBlock) { m_profilingStopwatch.Stop(); ProfilingInfo[childBlock] = m_profilingStopwatch.Elapsed; }
private void EndMeasuring(IMyExecutable childBlock) { m_profilingStopwatch.Stop(); ProfilingInfo[childBlock] = m_profilingStopwatch.Elapsed; }