示例#1
0
        string validateSweep(decimal Value)
        {   // Mostly copied from Run
            var props = AvailableParameters.ToArray();

            if (props.Length == 0)
            {
                return("");
            }
            if (isRunning)
            {
                return("");           // Avoid changing the value during run when the gui asks for validation errors.
            }
            if (!validateSweepMutex.WaitOne(0))
            {
                return("");
            }
            var originalValues = props.Select(set => set.GetValue(this)).ToArray();

            try
            {
                var str = StringConvertProvider.GetString(Value, CultureInfo.InvariantCulture);

                foreach (var set in props)
                {
                    var val = StringConvertProvider.FromString(str, set.TypeDescriptor, this, CultureInfo.InvariantCulture);
                    set.SetValue(this, val);
                }

                return("");
            }
            catch (TargetInvocationException e)
            {
                return(e.InnerException.Message);
            }
            finally
            {
                for (int i = 0; i < props.Length; i++)
                {
                    props[i].SetValue(this, originalValues[i]);
                }
                validateSweepMutex.ReleaseMutex();
            }
        }
示例#2
0
        public override void Run()
        {
            base.Run();

            var selected       = SelectedMembers.ToArray();
            var originalValues = selected.Select(set => set.GetValue(this)).ToArray();


            IEnumerable <decimal> range = LinearRange(SweepStart, SweepStop, (int)SweepPoints);

            if (SweepBehavior == SweepBehavior.Exponential)
            {
                range = ExponentialRange(SweepStart, SweepStop, (int)SweepPoints);
            }

            var    disps = selected.Select(x => x.GetDisplayAttribute()).ToList();
            string names = string.Join(", ", disps.Select(x => x.Name));

            if (disps.Count > 1)
            {
                names = string.Format("{{{0}}}", names);
            }

            foreach (var Value in range)
            {
                var val = StringConvertProvider.GetString(Value, CultureInfo.InvariantCulture);
                foreach (var set in selected)
                {
                    try
                    {
                        var value = StringConvertProvider.FromString(val, set.TypeDescriptor, this, CultureInfo.InvariantCulture);
                        set.SetValue(this, value);
                    }
                    catch (TargetInvocationException ex)
                    {
                        Log.Error("Unable to set '{0}' to value '{2}': {1}", set.GetDisplayAttribute().Name, ex.InnerException.Message, Value);
                        Log.Debug(ex.InnerException);
                    }
                }
                // Notify that values might have changes
                OnPropertyChanged("");

                var AdditionalParams = new ResultParameters();

                foreach (var disp in disps)
                {
                    AdditionalParams.Add(new ResultParameter(disp.Group.FirstOrDefault() ?? "", disp.Name, Value));
                }

                Log.Info("Running child steps with {0} = {1} ", names, Value);

                var runs = RunChildSteps(AdditionalParams, BreakLoopRequested).ToList();
                if (BreakLoopRequested.IsCancellationRequested)
                {
                    break;
                }
                runs.ForEach(r => r.WaitForCompletion());
            }
            for (int i = 0; i < selected.Length; i++)
            {
                selected[i].SetValue(this, originalValues[i]);
            }
        }