Ejemplo n.º 1
0
        void m_vworks_PostVWorksCommandEvent(object sender, WaveGuideEvents.VWorksCommandEventArgs e)
        {
            VWORKS_COMMAND       command        = e.Command;
            int                  param1         = e.Param1;
            string               name           = e.Name;
            string               desc           = e.Description;
            int                  sequenceNumber = m_imager.GetSequenceCount();
            bool                 success;
            EventMarkerContainer eventMarker;

            switch (command)
            {
            case VWORKS_COMMAND.Protocol_Aborted:
                PostMessage("VWorks - Protocol Aborted");

                m_dispatcher.Invoke((Action)(() =>
                {
                    m_timer.Stop();
                    VM.DelayText = "";
                    m_tokenSource.Cancel();      // stops the imaging task
                    VM.RunState = RunExperiment_ViewModel.RUN_STATE.ABORTED;
                    SetButton(VM.RunState);
                }));

                break;

            case VWORKS_COMMAND.Protocol_Resumed:
                PostMessage("VWorks - Protocol Resumed");
                m_dispatcher.Invoke((Action)(() =>
                {
                    m_timer.Stop();
                    VM.DelayText = "";
                    VM.DelayHeaderVisible = false;
                }));
                break;

            case VWORKS_COMMAND.Protocol_Complete:
                PostMessage("VWorks - Protocol Complete");

                m_dispatcher.Invoke((Action)(() =>
                {
                    m_timer.Stop();
                    VM.DelayText = "";
                    VM.DelayHeaderVisible = false;
                    m_tokenSource.Cancel();         // make sure the imaging task stops
                    VM.RunState = RunExperiment_ViewModel.RUN_STATE.FINISHED;
                    SetButton(VM.RunState);

                    ReportDialog dlg = new ReportDialog(m_project, m_experiment, m_indicatorList);
                    dlg.ShowDialog();
                }));


                break;

            case VWORKS_COMMAND.Protocol_Paused:
                PostMessage("VWorks - Protocol Paused");

                m_dispatcher.Invoke((Action)(() =>
                {
                    m_delayTime = param1;
                    VM.DelayHeaderVisible = true;
                    m_timer.Start();
                }));

                break;

            case VWORKS_COMMAND.Event_Marker:
                PostMessage("VWorks - Event Marker");

                m_dispatcher.Invoke((Action)(() =>
                {
                    ChartArray.AddEventMarker(sequenceNumber, desc);
                    eventMarker = new EventMarkerContainer();
                    eventMarker.Description = desc;
                    eventMarker.ExperimentID = m_experiment.ExperimentID;
                    eventMarker.Name = name;
                    eventMarker.SequenceNumber = sequenceNumber;
                    eventMarker.TimeStamp = DateTime.Now;
                    success = m_wgDB.InsertEventMarker(ref eventMarker);
                    if (!success)
                    {
                        PostMessage("Database Error in InsertEventMarker: " + m_wgDB.GetLastErrorMsg());
                    }
                }));


                break;

            case VWORKS_COMMAND.Initialization_Complete:
                PostMessage("VWorks Initialization Complete");

                m_dispatcher.Invoke((Action)(() =>
                {
                    BringWindowToFront();
                }));

                break;

            case VWORKS_COMMAND.Pause_Until:
                //PostMessage("VWorks - Pause Until");

                m_dispatcher.Invoke((Action)(() =>
                {
                    m_delayTime = param1;
                    VM.DelayHeaderVisible = true;
                    VM.DelayText = ((int)(m_delayTime / 1000)).ToString();
                    m_timer.Start();
                }));


                break;

            case VWORKS_COMMAND.Set_Time_Marker:
                //PostMessage("VWorks - Set Time Marker");
                break;

            case VWORKS_COMMAND.Start_Imaging:
                PostMessage("VWorks - Start Imaging");

                /////////////////////////////////////////////////////////////////////////////////

                /// Start Imaging Task
                m_dispatcher.Invoke((Action)(() =>
                {
                    BringWindowToFront();
                }));

                StartImaging_2(10000);

                ////////////////////////////////////////////////////////////////////////////////


                break;

            case VWORKS_COMMAND.Stop_Imaging:
                PostMessage("VWorks - Stop Imaging");

                m_dispatcher.Invoke((Action)(() =>
                {
                    StopImaging();
                }));

                break;

            case VWORKS_COMMAND.Unrecoverable_Error:
                PostMessage("VWorks - Unrecoverable Error" + ", " + name + ", " + desc);

                m_dispatcher.Invoke((Action)(() =>
                {
                    m_timer.Stop();
                    VM.DelayText = "";
                    m_tokenSource.Cancel();      // stops the imaging task
                    VM.RunState = RunExperiment_ViewModel.RUN_STATE.ERROR;
                    SetButton(VM.RunState);
                }));

                break;

            case VWORKS_COMMAND.Error:
                PostMessage("VWorks - Error" + ", " + name + ", " + desc);

                m_dispatcher.Invoke((Action)(() =>
                {
                    m_timer.Stop();
                    VM.DelayText = "";
                    VM.DelayHeaderVisible = false;
                    m_tokenSource.Cancel();      // stops the imaging task
                    VM.RunState = RunExperiment_ViewModel.RUN_STATE.ERROR;
                    SetButton(VM.RunState);
                }));

                break;

            case VWORKS_COMMAND.Message:
                PostMessage("VWorks - Message, " + name + ", " + desc);
                break;

            default:
                break;
            }
        }