0

So, I am making a program designed to complete some automated process. I have a form that allows the user to build custom automation processes. The structure of this automation process is as follows:

    public class AutomationScript
    {
        public string FilePath;
        public List<AutomationEvent> Events;

        public AutomationScript()
        {
            Events = new List<AutomationEvent>();
        }
    }

    public class AutomationCommand
    {
        public AutomationCommandType Type;
        public int Parameter;

        public AutomationCommand(AutomationCommandType _type, int _parameter)
        {
            Type = _type;
            Parameter = _parameter;
        }
    }

    public struct AutomationEvent
    {
        public string Name;
        public bool LoopEnabled;
        public List<AutomationCommand> Commands;
    }

    public enum AutomationCommandType
    {
        WaitSecs,
        CollectSample,
        CollectBackGround,
        StopCollection,
        LoopStart,
        LoopEnd,
    }

Now, when the user initiates the process to run a thread is created and it iterates through the commands. The basic setup is as follows:

        private void runAutomationScript()
        {
            while (automationON)
            {
                foreach (AutomationEvent aEvent in fullAutomationScript.Events)
                {
                    int loopStartIndex = 0;
                    int loopEndIndex = 0;
                    foreach (AutomationCommand command in aEvent.Commands)
                    {
                        while (!CommandCompleted) { } //Will stay in loop until the hardware module is finished receiving spectra
                        switch (command.Type)
                        {
                            case AutomationCommandType.CollectBackGround:
                                RequestedBackgroundScans = command.Parameter;
                                spectralCollection.getBackGroundSpectra(RequestedBackgroundScans);
                                CommandCompleted = false;
                                break;
                            case AutomationCommandType.CollectSample:
                                RequestedSampleScans = command.Parameter;
                                spectralCollection.getSampleSpectra(RequestedSampleScans);
                                CommandCompleted = false;
                                break;
                            case AutomationCommandType.WaitSecs:
                                Thread.Sleep(command.Parameter * 1000);
                                break;
                            case AutomationCommandType.StopCollection:
                                automationON = false;
                                break;
                            case AutomationCommandType.LoopStart:
                                loopStartIndex = aEvent.Commands.IndexOf(command);
                                break;
                            case AutomationCommandType.LoopEnd:
                                loopEndIndex = aEvent.Commands.IndexOf(command);
                                //Wehn the loop end is reached it will get the index of the start and end and grab a sublist and iterate over that continuously.
                                int firstCommandIndex = loopStartIndex + 1;
                                List<AutomationCommand> loopedCommands = aEvent.Commands.GetRange(firstCommandIndex, loopEndIndex - firstCommandIndex );
                                break;

                        }
                    }
                }
            }
            OnAutomationFinished(EventArgs.Empty);
        }

Now, at this point it works fine. I am trying to allow the user to define a loop point for the process to loop through. As you can see there is an AutomationCommand called LoopStart and LoopEnd. I am trying to figure out how to loop through this second sub loop without copying code into another function. I am toying with the idea of making some recursive definition of this command loop. Any ideas will help.

6
  • The reason for the CommandCompletedis because the spectral collection is done by events. So, when the commands to get spectral data are initiated the loop must wait until these events are done firing. Commented Jun 11, 2014 at 18:24
  • This question got my attention because it has the TeeChart tag. I wonder how TeeChart fits in your application and if you have any doubts about its usage. Thanks in advance. Commented Jun 12, 2014 at 7:00
  • Teechart is great. I don't have any doubts about its usage but one. I am performing this automated process to do to do quantification analysis on an absorption plot to test for gas impurities. I am storing these results in a result stream (Queue). ANyway, the application is an MDI spectral collection service. Each mdi child contains a chart. The user can view concentration results per molcule or group. I am trying to keep everything simple by keeping all my chart series in one location and chart them wherever I need. Thing is when I apply a series to a chrt it gets taken away frm others Commented Jun 13, 2014 at 16:33
  • I want to be able to chart the sme series on multiple charts if I need to. Thing is, a series can only be assigned to one chart. Or at least that's what I believe. SO instead, I have to create copies of every fastline in every child and do consistancy checks and updates on the main stream as well as streams in each child. Commented Jun 13, 2014 at 16:35
  • TeeChart Series will always make internal x,y (& z if applicable) arrays for Series to be associated with a Chart or plotted. There are some effective ways of connecting to data of another Series, loading data into a dataset and Series with Series.Clone() method or Copy function, and using CheckDataSource() to verify consistency between Series. I also added your request to the bugzilla to be considered for inclusion in future releases: bugs.teechart.net/show_bug.cgi?id=801 Commented Jun 16, 2014 at 14:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.