Ejemplo n.º 1
0
 private void OnExperimentStarted(IExperimentRunner dispatcher)
 {
     if (ExperimentStarted != null)
     {
         ExperimentStarted(this, new ExperimentEventArgs(dispatcher));
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates the experiment.
        /// </summary>
        /// <param name="experiment">The experiment.</param>
        /// <param name="baseline">The baseline - if baseline is different than null it is going to be written into workspace before executing the experiment
        /// with the Unitname BASELINE.</param>
        /// <returns></returns>
        private IExperimentRunner CreateExperimentRunner(Workspace workspace, ComponentsLibrary library, TraceLabSDK.Types.Contests.TLExperimentResults baseline)
        {
            RunnableExperimentBase graph = null;

            var experimentWorkspaceWrapper = WorkspaceWrapperFactory.CreateExperimentWorkspaceWrapper(workspace, ExperimentInfo.Id);

            RunnableNodeFactory templateGraphNodesFactory = new RunnableNodeFactory(experimentWorkspaceWrapper);

            graph = GraphAdapter.Adapt(this, templateGraphNodesFactory, library, experimentWorkspaceWrapper.TypeDirectories);

            //clear Workspace
            experimentWorkspaceWrapper.DeleteExperimentUnits();

            //if baseline has been provided write it into the workspace before returning the dispatcher
            if (baseline != null)
            {
                experimentWorkspaceWrapper.Store("BASELINE", baseline);
            }

            IExperimentRunner dispatcher = ExperimentRunnerFactory.CreateExperimentRunner(graph);

            dispatcher.NodeExecuting      += dispatcher_NodeExecuting;
            dispatcher.NodeFinished       += dispatcher_NodeFinished;
            dispatcher.NodeHasError       += dispatcher_NodeHasError;
            dispatcher.ExperimentFinished += dispatcher_ExperimentFinished;
            dispatcher.ExperimentStarted  += dispatcher_ExperimentStarted;

            m_dispatcher = dispatcher;

            return(dispatcher);
        }
        public override void RunInternal()
        {
            Setup();

            var subGraph = m_compositeComponentMetadata.ComponentGraph;

            Action method = () =>
            {
                using (IExperimentRunner dispatcher = ExperimentRunnerFactory.CreateExperimentRunnerForSubLevelExperiment(m_subLevelExperiment))
                {
                    dispatcher.NodeExecuting      += subGraph.dispatcher_NodeExecuting;
                    dispatcher.NodeFinished       += subGraph.dispatcher_NodeFinished;
                    dispatcher.NodeHasError       += subGraph.dispatcher_NodeHasError;
                    dispatcher.ExperimentFinished += (s, a) =>
                    {
                        dispatcher.NodeExecuting -= subGraph.dispatcher_NodeExecuting;
                        dispatcher.NodeFinished  -= subGraph.dispatcher_NodeFinished;
                        dispatcher.NodeHasError  -= subGraph.dispatcher_NodeHasError;
                    };

                    dispatcher.ExecuteExperiment(null);
                }
            };

            Thread dispatchThread = ThreadFactory.CreateThread(new System.Threading.ThreadStart(method));

            dispatchThread.IsBackground = true;
            dispatchThread.Name         = "SubExperimentRunner";
            dispatchThread.SetApartmentState(System.Threading.ApartmentState.STA);
            dispatchThread.Start();
            dispatchThread.Join();

            TearDown();
        }
Ejemplo n.º 4
0
        private static IExperimentRunner CreateExperiment(Experiment experiment, Workspace workspace, ComponentsLibrary library)
        {
            RunnableExperimentBase graph = null;

            ExperimentWorkspaceWrapper experimentWorkspaceWrapper = WorkspaceWrapperFactory.CreateExperimentWorkspaceWrapper(workspace, experiment.ExperimentInfo.Id);
            RunnableNodeFactory        templateGraphNodesFactory  = new RunnableNodeFactory(experimentWorkspaceWrapper);

            graph = GraphAdapter.Adapt(experiment, templateGraphNodesFactory, library, workspace.TypeDirectories);

            //clear Workspace
            workspace.DeleteUnits(experiment.ExperimentInfo.Id);

            IExperimentRunner dispatcher = ExperimentRunnerFactory.CreateExperimentRunner(graph);

            return(dispatcher);
        }
Ejemplo n.º 5
0
        void dispatcher_ExperimentFinished(object sender, EventArgs e)
        {
            IExperimentRunner dispatcher = sender as IExperimentRunner;

            if (dispatcher != null)
            {
                dispatcher.NodeExecuting      -= dispatcher_NodeExecuting;
                dispatcher.NodeFinished       -= dispatcher_NodeFinished;
                dispatcher.ExperimentFinished -= dispatcher_ExperimentFinished;
            }

            //Reset terminate event at this moment, so that all running experiment runners (for all composite components sub level experiments can complete too)
            dispatcher.ResetExperimentExecutionTerminateEvent();

            IsExperimentRunning = false;
            OnExperimentCompleted(dispatcher);
        }
Ejemplo n.º 6
0
 internal ExperimentEventArgs(IExperimentRunner dispatcher)
 {
     Dispatcher = dispatcher;
 }