public RunLogExplorerForm(RunLog log, string fileName)
            : this()
        {
            this.runLog = log;

            this.fileNameLabel.Text = fileName;

            if (log == null)
                return;

            string effectiveName;
            if (log.RunSequence.SequenceName == "" || log.RunSequence.SequenceName == null)
            {
                effectiveName = "Unnamed Sequence";
            }
            else
            {
                effectiveName = log.RunSequence.SequenceName;
            }

            this.Text = effectiveName + " Iteration #" + log.RunSequence.ListIterationNumber + "/" + log.RunSequence.Lists.iterationsCount() + " Time: " + log.RunTime.ToString() + " - Elgin";
            this.seqNameLabel.Text = log.RunSequence.SequenceName;
            this.seqDesc.Text = log.RunSequence.SequenceDescription;

            this.timeLabel.Text = log.RunTime.ToString();
            this.sequenceGrid.SelectedObject = log.RunSequence;
            this.settingsGrid.SelectedObject = log.RunSettings;
        }
        public static void runCicero(RunLog runLog)
        {
            try
            {
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
                Application.EnableVisualStyles();

                // Detect if Windows 7 or Vista is being used.
                OperatingSystem osInfo = System.Environment.OSVersion;
                if (osInfo.Version.Major == 6)
                {
                    WordGenerator.GlobalInfo.usingWindows7 = true;
                }

                try
                {

                    Application.SetCompatibleTextRenderingDefault(false);

                }
                catch (InvalidOperationException)
                {
                }

                MainClientForm mainForm;

                if (runLog == null)
                {
                    mainForm = new MainClientForm();
                }
                else
                {
                    mainForm =  new MainClientForm(runLog);
                }

                ClientRunner runner = new ClientRunner();

                runner.messageLog += new EventHandler<MessageEvent>(mainForm.addMessageLogText);
                Storage.registerMessageLogHandler(mainForm.handleMessageEvent);

                Application.Run(mainForm);

            }
            catch (Exception e)
            {
                display_unhandled_exception(e);
            }
        }
        public static void runCicero(RunLog runLog)
        {
            try
            {
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
                Application.EnableVisualStyles();

                // Detect if Windows 7 or Vista is being used.
                OperatingSystem osInfo = System.Environment.OSVersion;
                if (osInfo.Version.Major == 6)
                {
                    WordGenerator.GlobalInfo.usingWindows7 = true;
                }

                try
                {

                    Application.SetCompatibleTextRenderingDefault(false);

                }
                catch (InvalidOperationException)
                {
                }

                if (runLog == null)
                {
                    Application.Run(new mainClientForm());
                }
                else
                {
                    Application.Run(new mainClientForm(runLog));
                }
            }
            catch (Exception e)
            {
                display_unhandled_exception(e);
            }
        }
Beispiel #4
0
            public void addVariables(string fileName, RunLog log)
            {
                foreach (Variable var in log.RunSequence.Variables) {
                    MySqlCommand cmd = new MySqlCommand(@"INSERT INTO filelist_variablevalue
                       (name, value, runlog_id)
                       VALUES (@name, @value, @runlog)", this.conn);

                    cmd.Parameters.AddWithValue("@name", var.VariableName);
                    cmd.Parameters.AddWithValue("@value", var.VariableValue);
                    cmd.Parameters.AddWithValue("@runlog", fileName);

                    cmd.ExecuteNonQuery();
                }
            }
Beispiel #5
0
            public void addRunLog(string fileName, RunLog log)
            {
                MySqlCommand cmdq = new MySqlCommand(@"SELECT path FROM filelist_runloginfo WHERE path=@path", this.conn);
                cmdq.Parameters.AddWithValue("@path", fileName);

                object result = cmdq.ExecuteScalar();

                if (result == null)
                {
                    MySqlCommand cmd = new MySqlCommand(@"INSERT IGNORE INTO filelist_runloginfo
                         (path, loc_key, time, sequencepath, listiterationnumber, liststarttime, sequenceduration, description)
                         VALUES (@path, @loc_key, @time, @sequencepath, @listiterationnumber, @liststarttime, @sequenceduration, @description)", this.conn);

                    cmd.Parameters.AddWithValue("@path", fileName);
                    cmd.Parameters.AddWithValue("@loc_key", "default");
                    cmd.Parameters.AddWithValue("@time", log.RunTime);
                    cmd.Parameters.AddWithValue("@sequencepath", log.SequenceFileName);
                    cmd.Parameters.AddWithValue("@listiterationnumber", log.RunSequence.ListIterationNumber);
                    cmd.Parameters.AddWithValue("@liststarttime", log.ListStartTime);
                    cmd.Parameters.AddWithValue("@sequenceduration", log.RunSequence.SequenceDuration);
                    cmd.Parameters.AddWithValue("@description", log.RunSequence.SequenceDescription);

                    cmd.ExecuteNonQuery();

                    this.addVariables(fileName, log);
                }
            }
Beispiel #6
0
 private string getVariableString(DataGridViewColumn variableColumn, RunLog rlg)
 {
     if (variableSelections.ContainsKey(variableColumn))
     {
         if (variableSelections[variableColumn].usingName)
         {
             Variable var = rlg.RunSequence.getVariable(variableSelections[variableColumn].name);
             if (var != null)
             {
                 return var.VariableValue.ToString();
             }
             else return "Undefined";
         }
         else
         {
             Variable var = rlg.RunSequence.getVariable(variableSelections[variableColumn].id);
             if (var != null)
             {
                 return var.VariableValue.ToString();
             }
             else return "Undefined";
         }
     }
     else
     {
         return "Unassigned";
     }
 }
Beispiel #7
0
 private void closeLog(RunLog log)
 {
     if (log == null) return;
     if (openLogs.ContainsKey(log))
     {
         openLogs[log].Close();
         openLogs.Remove(log);
     }
 }
Beispiel #8
0
 private void addLogToDataGrid(RunLog rlg)
 {
     dataGridView1.Rows.Add(new object[] {
         null,                                   // close button
         rlg,                        // sequence name
         rlg.RunSequence.ListIterationNumber,    // seq iteration
         rlg.RunTime,                            // seq start time
         rlg.ListStartTime,                      // list start time
         rlg.RunSequence.SequenceDuration,       // seq duration
         rlg.RunSequence.CalibrationShot.ToString(), // calib shot?
         getVariableString(VarA, rlg),                // Variables A through G
         getVariableString(VarB, rlg),
         getVariableString(VarC, rlg),
         getVariableString(VarD, rlg),
         getVariableString(VarE, rlg),
         getVariableString(VarF, rlg),
         getVariableString(VarG, rlg)
     });
 }
 public Program(RunLog runLog)
 {
     this.runLog = runLog;
 }
        /// <summary>
        /// runLog will be null in general, when running Cicero as a standalone application. However, when Cicero is launched through Elgin,
        /// runLog will contain the log that we intent to browse.
        /// </summary>
        /// <param name="runLog"></param>
        public mainClientForm(RunLog runLog)
        {
            #region Singleton
            if (instance != null)
                throw new Exception("Word Generator is already running!");
            instance = this;
            #endregion

            try
            {
                string[] forts = WordGenerator.Properties.Resources.Fortunes.Split('\n');
                fortunes = new List<string>(forts);
            }
            catch { }

            if (runLog == null)
            {
                // Identify the clientStartupSettingsFile
                clientStartupSettingsFile = FileNameStrings.DefaultClientStartupSettingsFile;

                // Load all necessary data into Storage
                Storage.SaveAndLoad.LoadAllSubclasses(clientStartupSettingsFile);

            }
            else
            {
                Storage.clientStartupSettings = new ClientStartupSettings();
                Storage.sequenceData = runLog.RunSequence;
                Storage.settingsData = runLog.RunSettings;
            }

            InitializeComponent();

            CiceroSplashForm splash = new CiceroSplashForm();

            splash.Show();

            // bind F9 hotkey to run button:
            if (hotKeyBindings == null)
                hotKeyBindings = new List<object>();

            /*
            RegisterHotKey(Handle, hotKeyBindings.Count, KeyModifiers.None, Keys.F9);
            hotKeyBindings.Add(sequencePage1.runControl1.runZeroButton);
            */

            // bind F11 hotkey to server manager:
            RegisterHotKey(Handle, hotKeyBindings.Count, KeyModifiers.None, Keys.F11);
            hotKeyBindings.Add(this.serverManagerButton);

            // bind F1 to F8 to appropriate tab pages

            RegisterHotKey(Handle, hotKeyBindings.Count, KeyModifiers.None, Keys.F1);
            hotKeyBindings.Add(this.sequencePage);

            RegisterHotKey(Handle, hotKeyBindings.Count, KeyModifiers.None, Keys.F2);
            hotKeyBindings.Add(this.overrideTab);

            RegisterHotKey(Handle, hotKeyBindings.Count, KeyModifiers.None, Keys.F3);
            hotKeyBindings.Add(this.analogPage);

            RegisterHotKey(Handle, hotKeyBindings.Count, KeyModifiers.None, Keys.F4);
            hotKeyBindings.Add(this.gpibPage);

            RegisterHotKey(Handle, hotKeyBindings.Count, KeyModifiers.None, Keys.F5);
            hotKeyBindings.Add(this.rs232Tab);

            RegisterHotKey(Handle, hotKeyBindings.Count, KeyModifiers.None, Keys.F6);
            hotKeyBindings.Add(this.commonWaveformPage);

            RegisterHotKey(Handle, hotKeyBindings.Count, KeyModifiers.None, Keys.F7);
            hotKeyBindings.Add(this.variablesPage);

            RegisterHotKey(Handle, hotKeyBindings.Count, KeyModifiers.None, Keys.F8);
            hotKeyBindings.Add(this.pulsesTab);

            RefreshRecentFiles();
            this.RefreshSettingsDataToUI(Storage.settingsData);
            this.RefreshSequenceDataToUI(Storage.sequenceData);
        }
        /// <summary>
        /// runLog will be null in general, when running Cicero as a standalone application. However, when Cicero is launched through Elgin,
        /// runLog will contain the log that we intent to browse.
        /// </summary>
        /// <param name="runLog"></param>
        public MainClientForm(RunLog runLog)
        {
            #region Singleton
            if (instance != null)
                throw new Exception("Word Generator is already running!");
            instance = this;
            #endregion

            try
            {
                string[] forts = WordGenerator.Properties.Resources.Fortunes.Split('\n');
                fortunes = new List<string>(forts);
            }
            catch { }

            if (runLog == null)
            {
                // Identify the clientStartupSettingsFile
                clientStartupSettingsFile = FileNameStrings.DefaultClientStartupSettingsFile;

                // Load all necessary data into Storage
                Storage.SaveAndLoad.LoadAllSubclasses(clientStartupSettingsFile);

            }
            else
            {
                Storage.clientStartupSettings = new ClientStartupSettings();
                Storage.sequenceData = runLog.RunSequence;
                Storage.settingsData = runLog.RunSettings;
            }

            InitializeComponent();

            #if DEBUG
            debugToolStripMenuItem.Visible = true;
            #endif

            ToolStripMenuItem citationItem = new ToolStripMenuItem();
            citationItem.Text = "Citation";
            citationItem.Click += new EventHandler(citationItem_Click);
            aboutToolStripMenuItem.DropDownItems.Add(citationItem);

            if (hotKeyBindings == null)
                hotKeyBindings = new List<object>();

                try {

                /*
                RegisterHotKey(Handle, hotKeyBindings.Count, KeyModifiers.None, Keys.F9);
                hotKeyBindings.Add(sequencePage1.runControl1.runZeroButton);
                */

                // bind F11 hotkey to server manager:
                RegisterHotKey(Handle, hotKeyBindings.Count, KeyModifiers.None, Keys.F11);
                hotKeyBindings.Add(this.serverManagerButton);

                // bind F1 to F8 to appropriate tab pages

                RegisterHotKey(Handle, hotKeyBindings.Count, KeyModifiers.None, Keys.F1);
                hotKeyBindings.Add(this.sequenceTab);

                RegisterHotKey(Handle, hotKeyBindings.Count, KeyModifiers.None, Keys.F2);
                hotKeyBindings.Add(this.overrideTab);

                RegisterHotKey(Handle, hotKeyBindings.Count, KeyModifiers.None, Keys.F3);
                hotKeyBindings.Add(this.analogTab);

                RegisterHotKey(Handle, hotKeyBindings.Count, KeyModifiers.None, Keys.F4);
                hotKeyBindings.Add(this.gpibTab);

                RegisterHotKey(Handle, hotKeyBindings.Count, KeyModifiers.None, Keys.F5);
                hotKeyBindings.Add(this.rs232Tab);

                RegisterHotKey(Handle, hotKeyBindings.Count, KeyModifiers.None, Keys.F6);
                hotKeyBindings.Add(this.commonWaveformTab);

                RegisterHotKey(Handle, hotKeyBindings.Count, KeyModifiers.None, Keys.F7);
                hotKeyBindings.Add(this.variablesTab);

                RegisterHotKey(Handle, hotKeyBindings.Count, KeyModifiers.None, Keys.F8);
                hotKeyBindings.Add(this.pulsesTab);

                RegisterHotKey(Handle, hotKeyBindings.Count, KeyModifiers.Control, Keys.F9);
                hotKeyBindings.Add(this.sequencePage.runControl1.bgRunButton);
            }
            catch (Exception e) {
                addMessageLogText(this, new MessageEvent("Unable to add hotkeys due to error: " + e.Message,
                                                         0,
                                                         MessageEvent.MessageTypes.Error));
            }

            RefreshRecentFiles();
            this.RefreshSettingsDataToUI();
            this.RefreshSequenceDataToUI();

            if (!Storage.clientStartupSettings.HasShownCitationMessage)
            {
                CitationInfoForm cif = new CitationInfoForm(true);
                cif.ShowDialog();
                Storage.clientStartupSettings.HasShownCitationMessage = true;
            }
        }
        public bool do_run(int iterationNumber, SequenceData sequence, bool calibrationShot)
        {
            this.runningThread = Thread.CurrentThread;
            bool keepGoing = true;
            while (keepGoing)
            {
                MainClientForm.instance.CurrentlyOutputtingTimestep = null;

                setStatus(RunFormStatus.StartingRun);

                lic_chk();

                if (RunForm.backgroundIsRunning() && !this.isBackgroundRunform)
                {
                    addMessageLogText(this, new MessageEvent("A background run is still running. Waiting for it to terminate..."));
                    RunForm.abortAtEndOfNextBackgroundRun();
                    setStatus(RunFormStatus.ClosableOnly);
                    while (RunForm.backgroundIsRunning())
                    {
                        Thread.Sleep(50);
                    }

                    if (this.IsDisposed)
                    {
                        addMessageLogText(this, new MessageEvent("Foreground run form was closed before background run terminated. Aborting foreground run."));
                        return false;
                    }

                    setStatus(RunFormStatus.StartingRun);

                }

                addMessageLogText(this, new MessageEvent("Starting Run."));

                updateTitleBar(calibrationShot);

                // Begin section of undocumented Paris code that Aviv doesn't understand.
                bool wrongSavePath = false;
                try
                {
                    if (Storage.settingsData.SavePath != "")
                        System.IO.Directory.GetFiles(Storage.settingsData.SavePath);

                }
                catch
                {
                    wrongSavePath = true;
                }

                if (wrongSavePath)
                {
                    addMessageLogText(this, new MessageEvent("Unable to locate save path. Aborting run. See the SavePath setting (under Advanced->Settings Explorer)."));

                    setStatus(RunFormStatus.FinishedRun);
                    return false;
                }
                // End section of undocumented Paris code that Aviv doesn't understand

                if (!sequence.Lists.ListLocked)
                {
                    if (calibrationShot)
                    {
                        addMessageLogText(this, new MessageEvent("Calibration shot error -- Lists in the calibration shot are not locked. They must be locked manually. Please open your calibration sequence file, lock the lists, save your calibration sequence, and then re-import the calibration shot in this sequence."));
                        addMessageLogText(this, new MessageEvent("Skipping calibration shot and aborting run as a result of previous error."));
                        ErrorDetected = true;
                        setStatus(RunFormStatus.FinishedRun);
                        return false;
                    }

                    addMessageLogText(this, new MessageEvent("Lists not locked, attempting to lock them..."));

                    WordGenerator.MainClientForm.instance.variablesEditor.tryLockLists();

                    if (!sequence.Lists.ListLocked)
                    {
                        addMessageLogText(this, new MessageEvent("Unable to lock lists. Aborting run. See the Variables tab."));
                        ErrorDetected = true;

                        setStatus(RunFormStatus.FinishedRun);
                        return false;
                    }
                    addMessageLogText(this, new MessageEvent("Lists locked successfully."));
                }

                sequence.ListIterationNumber = iterationNumber;

                string listBoundVariableValues = "";

                foreach (Variable var in sequence.Variables)
                {
                    if (Storage.settingsData.PermanentVariables.ContainsKey(var.VariableName))
                    {
                        var.PermanentVariable = true;
                        var.PermanentValue = Storage.settingsData.PermanentVariables[var.VariableName];
                    }
                    else
                    {
                        var.PermanentVariable = false;
                    }
                }

                foreach (Variable var in sequence.Variables)
                {

                    if (var.ListDriven && !var.PermanentVariable)
                    {
                        if (listBoundVariableValues == "")
                        {
                            listBoundVariableValues = "List bound variable values: ";
                        }
                        listBoundVariableValues += var.VariableName + " = " + var.VariableValue.ToString() + ", ";
                    }
                }

                if (listBoundVariableValues != "")
                {
                    addMessageLogText(this, new MessageEvent(listBoundVariableValues));
                }

                foreach (Variable var in sequence.Variables)
                {
                    if (var.DerivedVariable)
                    {
                        if (var.parseVariableFormula(sequence.Variables) != null)
                        {
                            addMessageLogText(this, new MessageEvent("Warning! Derived variable " + var.ToString() + " has an an error. Will default to 0 for this run."));
                            ErrorDetected = true;
                        }
                    }
                }
                if (!calibrationShot)
                {
                    foreach (Variable var in sequence.Variables)
                    {
                        if (var.VariableName == "SeqMode")
                        {
                            addMessageLogText(this, new MessageEvent("Detected a variable with special name SeqMode. Nearest integer value " + (int)var.VariableValue + "."));
                            int i = (int)var.VariableValue;
                            if (i >= 0 && i < runningSequence.SequenceModes.Count)
                            {
                                SequenceMode mode = runningSequence.SequenceModes[i];
                                if (runningSequence == Storage.sequenceData)
                                {
                                    addMessageLogText(this, new MessageEvent("Settings sequence to sequence mode " + mode.ModeName + "."));
                                    WordGenerator.MainClientForm.instance.sequencePage.setMode(mode);
                                }
                                else
                                {
                                    addMessageLogText(this, new MessageEvent("Currently running sequence is either a calibration shot or background running sequence. Cannot change the sequence mode of a background sequence. Skipping mode change."));
                                }
                            }
                            else
                            {
                                addMessageLogText(this, new MessageEvent("Warning! Invalid sequence mode index. Ignoring the SeqMode variable."));
                                ErrorDetected = true;
                            }
                        }
                    }
                }

                if (variablePreviewForm != null)
                {
                    addMessageLogText(this, new MessageEvent("Updating variables according to variable preview window..."));
                    int nChanged = variablePreviewForm.refresh(sequence);
                    addMessageLogText(this, new MessageEvent("... " + nChanged + " variable values changed."));
                }

                // Create timestep "loop copies" if there are timestep loops in use
                bool useLoops = false;
                foreach (TimestepGroup tsg in sequence.TimestepGroups)
                {
                    if (tsg.LoopTimestepGroup && sequence.TimestepGroupIsLoopable(tsg) && tsg.LoopCountInt > 1)
                    {
                        useLoops = true;
                    }
                }
                if (useLoops)
                {
                    addMessageLogText(this, new MessageEvent("This sequence makes use of looping timestep groups. Creating temporary loop copies..."));
                    sequence.createLoopCopies();
                    addMessageLogText(this, new MessageEvent("...done"));
                }

                List<string> missingServers = Storage.settingsData.unconnectedRequiredServers();

                if (missingServers.Count != 0)
                {

                    string missingServerList = ServerManager.convertListOfServersToOneString(missingServers);

                    addMessageLogText(this, new MessageEvent("Unable to start run. The following required servers are not connected: " + missingServerList + "."));
                    ErrorDetected = true;
                    setStatus(RunFormStatus.FinishedRun);
                    return false;
                }

                List<LogicalChannel> overriddenDigitals = new List<LogicalChannel>();
                List<LogicalChannel> overriddenAnalogs = new List<LogicalChannel>();

                foreach (LogicalChannel lc in Storage.settingsData.logicalChannelManager.Digitals.Values)
                {
                    if (lc.overridden)
                        overriddenDigitals.Add(lc);
                }

                foreach (LogicalChannel lc in Storage.settingsData.logicalChannelManager.Analogs.Values)
                {
                    if (lc.overridden)
                        overriddenAnalogs.Add(lc);
                }

                if (overriddenDigitals.Count != 0)
                {
                    string list = "";
                    foreach (LogicalChannel lc in overriddenDigitals)
                    {
                        string actingName;
                        if (lc.Name != "" & lc.Name != null)
                        {
                            actingName = lc.Name;
                        }
                        else
                        {
                            actingName = "[Unnamed]";
                        }
                        list += actingName + ", ";
                    }
                    list = list.Remove(list.Length - 2);
                    list += ".";
                    addMessageLogText(this, new MessageEvent("Reminder. The following " + overriddenDigitals.Count + " digital channel(s) are being overridden: " + list));
                }

                if (overriddenAnalogs.Count != 0)
                {
                    string list = "";
                    foreach (LogicalChannel lc in overriddenAnalogs)
                    {
                        string actingName;
                        if (lc.Name != "" & lc.Name != null)
                        {
                            actingName = lc.Name;
                        }
                        else
                        {
                            actingName = "[Unnamed]";
                        }

                        list += actingName + ", ";
                    }
                    list = list.Remove(list.Length - 2);
                    list += ".";
                    addMessageLogText(this, new MessageEvent("Reminder. The following " + overriddenAnalogs.Count + " analog channel(s) are being overridden: " + list));
                }

                runStartTime = DateTime.Now;

                #region Sending camera instructions
                if (Storage.settingsData.UseCameras)
                {

                    byte[] msg;// = Encoding.ASCII.GetBytes(get_fileStamp(sequence));
                    string shot_name = NamingFunctions.get_fileStamp(sequence, Storage.settingsData, runStartTime);
                    string sequenceTime = sequence.SequenceDuration.ToString();
                    string FCamera;
                    string UCamera;

                    foreach (Socket theSocket in CameraPCsSocketList)
                    {
                        try
                        {
                            int index = CameraPCsSocketList.IndexOf(theSocket);
                            FCamera = connectedPCs[index].useFWCamera.ToString();
                            UCamera = connectedPCs[index].useUSBCamera.ToString();
                            msg = Encoding.ASCII.GetBytes(shot_name + "@" + sequenceTime + "@" + FCamera + "@" + UCamera + "@" + isCameraSaving.ToString() + "@\0");
                            theSocket.Send(msg, 0, msg.Length, SocketFlags.None);
                        }
                        catch { }
                    }
                }
                #endregion

                ServerManager.ServerActionStatus actionStatus;

                // send start timestamp
                addMessageLogText(this, new MessageEvent("Sending run start timestamp."));
                actionStatus = Storage.settingsData.serverManager.setNextRunTimestampOnConnectedServers(runStartTime, addMessageLogText);
                if (actionStatus != ServerManager.ServerActionStatus.Success)
                {
                    addMessageLogText(this, new MessageEvent("Unable to set start timestamp. " + actionStatus.ToString()));
                    ErrorDetected = true;
                    setStatus(RunFormStatus.FinishedRun);
                    return false;
                }

                // send settings data.
                addMessageLogText(this, new MessageEvent("Sending settings data."));
                actionStatus = Storage.settingsData.serverManager.setSettingsOnConnectedServers(Storage.settingsData, addMessageLogText);
                if (actionStatus != ServerManager.ServerActionStatus.Success)
                {
                    addMessageLogText(this, new MessageEvent("Unable to send settings data. " + actionStatus.ToString()));
                    ErrorDetected = true;
                    setStatus(RunFormStatus.FinishedRun);
                    return false;
                }

                // send sequence data.
                addMessageLogText(this, new MessageEvent("Sending sequence data."));
                actionStatus = Storage.settingsData.serverManager.setSequenceOnConnectedServers(sequence, addMessageLogText);
                if (actionStatus != ServerManager.ServerActionStatus.Success)
                {
                    addMessageLogText(this, new MessageEvent("Unable to send sequence data. " + actionStatus.ToString()));
                    ErrorDetected = true;
                    setStatus(RunFormStatus.FinishedRun);
                    return false;
                }

                // generate buffers.
                addMessageLogText(this, new MessageEvent("Generating buffers."));
                actionStatus = Storage.settingsData.serverManager.generateBuffersOnConnectedServers(iterationNumber, addMessageLogText);
                if (actionStatus != ServerManager.ServerActionStatus.Success)
                {
                    addMessageLogText(this, new MessageEvent("Unable to generate buffers. " + actionStatus.ToString()));
                    ErrorDetected = true;
                    setStatus(RunFormStatus.FinishedRun);
                    return false;
                }

                // arm tasks.

                Random rnd = new Random();
                clockID = (uint)rnd.Next();

                if (softwareClockProvider != null || networkClockProvider!=null)
                {
                    addMessageLogText(this, new MessageEvent("A software clock provider already exists, unexpectedly. Aborting."));
                    return false;
                }

                if (!Storage.settingsData.AlwaysUseNetworkClock)
                {
                    softwareClockProvider = new ComputerClockSoftwareClockProvider(10);
                    softwareClockProvider.addSubscriber(this, 41, 0);
                    softwareClockProvider.ArmClockProvider();
                }

                networkClockProvider = new NetworkClockProvider(clockID);
                networkClockProvider.addSubscriber(this, 41, 1);
                networkClockProvider.ArmClockProvider();

                currentSoftwareclockPriority = 0;

                addMessageLogText(this, new MessageEvent("Arming tasks."));
                actionStatus = Storage.settingsData.serverManager.armTasksOnConnectedServers(clockID, addMessageLogText);
                if (actionStatus != ServerManager.ServerActionStatus.Success)
                {
                    addMessageLogText(this, new MessageEvent("Unable to arm tasks. " + actionStatus.ToString()));
                    ErrorDetected = true;
                    setStatus(RunFormStatus.FinishedRun);
                    return false;
                }

                // generate triggers

                addMessageLogText(this, new MessageEvent("Generating triggers."));
                actionStatus = Storage.settingsData.serverManager.generateTriggersOnConnectedServers(addMessageLogText);
                if (actionStatus != ServerManager.ServerActionStatus.Success)
                {
                    addMessageLogText(this, new MessageEvent("Unable to generate triggers. " + actionStatus.ToString()));
                    ErrorDetected = true;
                    setStatus(RunFormStatus.FinishedRun);
                    return false;
                }

                setStatus(RunFormStatus.Running);

                // async call to progress bar initialization

                Action<double> initProgressBarAction = initializeProgressBar;
                Invoke(initProgressBarAction, new object[] { sequence.SequenceDuration });

                double duration = sequence.SequenceDuration;
                addMessageLogText(this, new MessageEvent("Sequence duration " + duration + " s. Running."));

                // start software clock
                if (softwareClockProvider!=null)
                    softwareClockProvider.StartClockProvider();
                networkClockProvider.StartClockProvider();

                while (true)
                {
                    if (currentSoftwareclockPriority == 0)
                    {
                        if (softwareClockProvider != null && (softwareClockProvider.getElapsedTime() >= (200 + duration * 1000.0)))
                            break;
                    }
                    else
                        if (networkClockProvider != null && (networkClockProvider.getElapsedTime() >= (duration * 1000.0)))
                            break;

                    Thread.Sleep(100);
                }

                if (softwareClockProvider!=null)
                    softwareClockProvider.AbortClockProvider();
                softwareClockProvider = null;
                networkClockProvider.AbortClockProvider();
                networkClockProvider = null;

                MainClientForm.instance.CurrentlyOutputtingTimestep = sequence.dwellWord();

                actionStatus = Storage.settingsData.serverManager.getRunSuccessOnConnectedServers(addMessageLogText);
                if (actionStatus != ServerManager.ServerActionStatus.Success)
                {
                    addMessageLogText(this, new MessageEvent("Run failed, possibly due to a buffer underrun. Please check the server event logs."));
                    ErrorDetected = true;
                    setStatus(RunFormStatus.FinishedRun);
                    return false;
                }

                if (useLoops)
                    sequence.cleanupLoopCopies();

                addMessageLogText(this, new MessageEvent("Finished run. Writing log file..."));
                RunLog runLog = new RunLog(runStartTime, formCreationTime, sequence, Storage.settingsData, WordGenerator.MainClientForm.instance.OpenSequenceFileName, WordGenerator.MainClientForm.instance.OpenSettingsFileName);
                string fileName = runLog.WriteLogFile();

                if (fileName != null)
                {
                    addMessageLogText(this, new MessageEvent("Log written to " + fileName));
                }
                else
                {
                    addMessageLogText(this, new MessageEvent("Log not written! Perhaps a file with this name already exists?"));
                    ErrorDetected = true;
                }

                foreach (RunLogDatabaseSettings rset in Storage.settingsData.RunlogDatabaseSettings)
                {

                    if (rset.Enabled)
                    {
                        RunlogDatabaseHandler handler = null;
                        try
                        {
                            handler = new RunlogDatabaseHandler(rset);
                            handler.addRunLog(fileName, runLog);
                            addMessageLogText(this, new MessageEvent("Run log added to mysql database at url " + rset.Url + " successfully."));
                        }
                        catch (RunLogDatabaseException e)
                        {
                            addMessageLogText(this, new MessageEvent("Caught exception when attempting to add runlog to mysqldatabase at " + rset.Url + "."));
                            if (rset.VerboseErrorReporting)
                            {
                                addMessageLogText(this, new MessageEvent("Displaying runlogdatabase exception. To disable this display, turn off verbose error reporting for this runlog database in Cicero settings (under Advanced->Settings Explorer)"));
                                ExceptionViewerDialog ev = new ExceptionViewerDialog(e);
                                ev.ShowDialog();
                            }
                            else
                            {
                                addMessageLogText(this, new MessageEvent("Exception was " + e.Message + ". For more detailed information, turn on verbose error reporting for this runlog database in Cicero settings (under Advanced->Settings Explorer)"));
                            }
                        }

                        if (handler != null)
                            handler.closeConnection();
                    }
                }

                if (runRepeat)
                    keepGoing = true;
                else
                    keepGoing = false;

                repeatCount++;

                if (abortAfterThis.Checked)
                {
                    userAborted = true;
                    setStatus(RunFormStatus.FinishedRun);
                    return false;
                }

                setStatus(RunFormStatus.FinishedRun);
            }

            return true;
        }