예제 #1
0
        public override void RunCommand(object sender)
        {
            var engine = (AutomationEngineInstance)sender;
            var format = v_ToStringFormat.ConvertUserVariableToString(engine);

            Stopwatch stopwatch;

            switch (v_StopwatchAction)
            {
            case "Start Stopwatch":
                //start a new stopwatch
                stopwatch = new Stopwatch();
                stopwatch.AddAppInstance(engine, v_InstanceName);
                stopwatch.Start();
                break;

            case "Stop Stopwatch":
                //stop existing stopwatch
                stopwatch = (Stopwatch)engine.AppInstances[v_InstanceName];
                stopwatch.Stop();
                break;

            case "Restart Stopwatch":
                //restart which sets to 0 and automatically starts
                stopwatch = (Stopwatch)engine.AppInstances[v_InstanceName];
                stopwatch.Restart();
                break;

            case "Reset Stopwatch":
                //reset which sets to 0
                stopwatch = (Stopwatch)engine.AppInstances[v_InstanceName];
                stopwatch.Reset();
                break;

            case "Measure Stopwatch":
                //check elapsed which gives measure
                stopwatch = (Stopwatch)engine.AppInstances[v_InstanceName];
                string elapsedTime;
                if (string.IsNullOrEmpty(format))
                {
                    elapsedTime = stopwatch.Elapsed.ToString();
                }
                else
                {
                    elapsedTime = stopwatch.Elapsed.ToString(format);
                }

                elapsedTime.StoreInUserVariable(engine, v_OutputUserVariableName);
                break;

            default:
                throw new NotImplementedException("Stopwatch Action '" + v_StopwatchAction + "' not implemented");
            }
        }