/// <summary> /// Parameter to string /// </summary> /// <param name="param">Parameter value</param> /// <returns>Parameter as string</returns> internal static string ParamToString(object param) { return(AlgoParameterTypes.ToString(param)); }
/// <summary> /// Constructor. /// </summary> /// <param name="text">Script text</param> /// <param name="inputs">Input parameters</param> /// <param name="quickCalcCheck">If set then this corresponds to which input parameters must be set for the script to support QuickCalc mode. This should be a string of "0" and "1" the same length as the input parameter array.</param> public RScript(string text, string inputs, string fileName) { Dictionary <string, IAlgoParameterType> conv = AlgoParameterTypes.GetKeys(); int pos = 0; int lpos; this.FileName = fileName; RScriptMarkup markup = new RScriptMarkup(inputs); List <AlgoParameter> parameters = new List <AlgoParameter>(); while (true) { lpos = pos; string line = ReadLine(text, ref pos); if (line != null && line.StartsWith("##")) { string[] ee = line.Substring(2).Trim().Split(",".ToCharArray()); foreach (string e in ee) { string[] eee = e.Split("=".ToCharArray(), 3, StringSplitOptions.RemoveEmptyEntries); string name = eee[0]; string type = eee[1]; string desc = eee.Length >= 3 ? eee[2] : null; if (type != null) { name = name.Trim(); type = type.Trim().ToUpper(); IAlgoParameterType etype; if (conv.TryGetValue(type, out etype)) { parameters.Add(new AlgoParameter(name, desc, etype)); } else { int ssi = markup.Inputs.FindIndex(z => z.Key == type); if (ssi != -1) { markup.Inputs[ssi].Name = name; } else { Errors += $"Cannot parse script arguments: Parameter specification for [{type}] does not exist."; } } } } } else { break; } } string[] inputNamesA = markup.Inputs.Select(z => z.Name == "-" ? null : z.Name).ToArray(); this.Script = text; this.InputNames = inputNamesA; RequiredParameters = new AlgoParameterCollection(parameters.ToArray()); }