Ejemplo n.º 1
0
            protected override object OnFromString(FromStringArgs args)
            {
                string el  = args.Text.Trim();
                var    res = args.Core.Groups.FirstOrDefault(z => z.Id == el);

                if (res == null)
                {
                    args.Error = $"There is no group with the name {{{el}}}";
                }

                return(res);
            }
Ejemplo n.º 2
0
            protected override object OnFromString(FromStringArgs args)
            {
                var x = args.Core.Clusterers.FirstOrDefault(z => z.DisplayName == args.Text);

                if (x == null)
                {
                    args.Error = $"There is no clusterer with the name {{{args.Text}}}.";
                    return(null);
                }

                return(new WeakReference <ConfigurationClusterer>(x));
            }
Ejemplo n.º 3
0
            protected override object OnFromString(FromStringArgs args)
            {
                string peakName = args.Text;

                Peak peak = args.Core.Peaks.FirstOrDefault(z => z.DisplayName == peakName);

                if (peak != null)
                {
                    return(new WeakReference <Peak>(peak));
                }
                else
                {
                    args.Error = $"There is no peak with the name {{{peakName}}}.";
                    return(null);
                }
            }
Ejemplo n.º 4
0
            protected override object OnFromString(FromStringArgs args)
            {
                string[] elems = InternalConvertor.ReadFields(args.Text);

                WeakReference <Cluster>[] r = new WeakReference <Cluster> [elems.Length];

                for (int n = 0; n < elems.Length; ++n)
                {
                    Cluster c = args.Core.Clusters.FirstOrDefault(z => z.DisplayName == elems[n]);

                    if (c == null)
                    {
                        args.Error = $"There is no cluster with the name {{{elems[n]}}}.";
                        return(null);
                    }

                    r[n] = new WeakReference <Cluster>(c);
                }

                return(r);
            }
Ejemplo n.º 5
0
            protected override object OnFromString(FromStringArgs args)
            {
                string[] e2 = InternalConvertor.ReadFields(args.Text);

                WeakReference <ConfigurationStatistic>[] r = new WeakReference <ConfigurationStatistic> [e2.Length];
                var opts = args.Core.Statistics;

                for (int n = 0; n < e2.Length; n++)
                {
                    var x = opts.FirstOrDefault(z => z.DisplayName == e2[n]);

                    if (x == null)
                    {
                        args.Error = $"There is no statistic with the name {{{e2[n]}}}.";
                        return(null);
                    }

                    r[n] = new WeakReference <ConfigurationStatistic>(x);
                }

                return(r);
            }
Ejemplo n.º 6
0
            protected override object OnFromString(FromStringArgs args)
            {
                double vd;

                if (args.Text == "MAX")
                {
                    return(double.MaxValue);
                }
                else if (args.Text == "MIN")
                {
                    return(double.MinValue);
                }
                else if (double.TryParse(args.Text, out vd))
                {
                    return(vd);
                }
                else
                {
                    args.Error = $"{{{args.Text}}} is not a valid number.";
                    return(null);
                }
            }
Ejemplo n.º 7
0
            protected override object OnFromString(FromStringArgs args)
            {
                int vi;

                if (args.Text == "MAX")
                {
                    return(int.MaxValue);
                }
                else if (args.Text == "MIN")
                {
                    return(int.MinValue);
                }
                else if (int.TryParse(args.Text, out vi))
                {
                    return(vi);
                }
                else
                {
                    args.Error = $"{{{args.Text}}} is not a valid integer.";
                    return(null);
                }
            }
Ejemplo n.º 8
0
            protected override object OnFromString(FromStringArgs args)
            {
                switch (args.Text.Trim().ToUpper())
                {
                case "1":
                case "YES":
                case "Y":
                case "TRUE":
                case "T":
                    return(true);

                case "0":
                case "NO":
                case "N":
                case "FALSE":
                case "F":
                    return(false);

                default:
                    return(null);
                }
            }
Ejemplo n.º 9
0
        /// <summary>
        /// Converts the specified string to a customisable parameter set.
        /// </summary>
        /// <param name="core">Required</param>
        /// <param name="text">Text to convert</param>
        /// <returns>Parameters or NULL on failure.</returns>
        public object[] TryStringToParams(Core core, string text, out string error)
        {
            if (!HasCustomisableParams)
            {
                // Any input is valid if there are no parameters
                // This way we don't get errors from leftover text when inputs are hidden because
                // there are no parameters
                error = null;
                return(new object[0]);
            }

            string[] elements = AlgoParameterTypes.ExternalConvertor.ReadFields(text);

            if (elements.Length != _parameters.Length)
            {
                // Count mismatch
                error = $"This algorithm takes {{{_parameters.Length}}} parameters but {{{elements.Length}}} were provided.";
                return(null);
            }

            object[] result = new object[_parameters.Length];

            for (int i = 0; i < _parameters.Length; i++)
            {
                var x = new FromStringArgs(core, elements[i]);
                result[i] = _parameters[i].Type.FromString(x);

                if (result[i] == null)
                {
                    // Couldn't read parameter
                    error = $"Error in parameter #{i + 1}: {x.Error}";
                    return(null);
                }
            }

            error = null;
            return(result);
        }
Ejemplo n.º 10
0
 public object FromString(FromStringArgs args)
 {
     return(OnFromString(args));
 }
Ejemplo n.º 11
0
 protected abstract object OnFromString(FromStringArgs args);