public static ParameterDic Combine(params ParameterDic[] dics) { ParameterDic retDic = dics.First(); foreach (var d in dics.Skip(1)) { retDic = combine(retDic, d); } return(retDic); }
private static ParameterDic combine(ParameterDic orginalDic, ParameterDic newDic) { ParameterDic retDic = orginalDic.Clone(); if (newDic != null) { foreach (var v in newDic.VariableNames) { retDic.SetValue(v, newDic.GetValue(v), true); } } return(retDic); }
/// <summary> /// Get an IEntryModel[] from ParameterDic[entryKey], /// If it's an IEntryModel[], return directly. /// If it's an IEntryModel, convert to array and return. /// If it's a string, parse from profileKey, convert to IEntryModel and then IEntryModel[] and return. /// Throw exception if neither. /// </summary> /// <param name="paramDic"></param> /// <returns></returns> public static async Task <IEntryModel[]> GetValueAsEntryModelArrayAsync(this ParameterDic paramDic, string entryKey, string profileKey = null) { object value = paramDic.GetValue <object>(entryKey); if (value is IEnumerable) { return((value as IEnumerable).Cast <IEntryModel>().ToArray()); } if (value is IEntryModel[]) { return((IEntryModel[])value); } return(new IEntryModel[] { await GetValueAsEntryModelAsync(paramDic, entryKey, profileKey) }); throw new ArgumentException(entryKey); }
public static string ReplaceVariableInsideBracketed(this ParameterDic pd, string variableKey) { if (variableKey == null) { return(null); } Regex regex = new Regex("{(?<TextInsideBrackets>[^}]+)}"); string value = variableKey; Match match = regex.Match(value); while (!value.StartsWith("::") && match.Success) { string key = "{" + match.Groups["TextInsideBrackets"].Value + "}"; object val = pd.GetValue(key); value = value.Replace(key, val == null ? "" : val.ToString()); match = regex.Match(value); } return(value); }
/// <summary> /// Get an IEntryModel from ParameterDic[entryKey], /// If it's an IEntryModel, convert to array and return. /// If it's a string, parse from profileKey, convert to IEntryModel and then IEntryModel[] and return. /// Throw exception if neither. /// </summary> /// <param name="paramDic"></param> /// <param name="entryKey"></param> /// <param name="profileKey"></param> /// <returns></returns> public static async Task <IEntryModel> GetValueAsEntryModelAsync(this ParameterDic paramDic, string entryKey, string profileKey = null) { object value = paramDic.GetValue <object>(entryKey); if (value is IEntryModel) { return((IEntryModel)value); } if (value is string) { string path = (string)value; if (profileKey != null) { IProfile profile = paramDic.GetValue <IProfile>(profileKey); if (profile == null) { throw new ArgumentException(profileKey); } return(await profile.ParseAsync(path)); } } throw new ArgumentException(entryKey); }
public static ParameterPair FromVariable(string variable, object value) { return(new ParameterPair(ParameterDic.GetVariable(variable), value)); }
public static ParameterDic ConvertAndMerge(this IParameterDicConverter converter, ParameterDic pd, object parameter = null, params object[] additionalParameters) { var convertedPd = converter.Convert(parameter, additionalParameters); return(ParameterDic.Combine(convertedPd, pd)); }
public static async Task RunAsync(this IScriptRunner scriptRunner, ParameterDic initialParameters, params IScriptCommand[] cmds) { await scriptRunner.RunAsync(new Queue <IScriptCommand>(cmds), initialParameters); }
public static void Run(this IScriptRunner scriptRunner, ParameterDic initialParameters, params IScriptCommand[] cmds) { scriptRunner.Run(new Queue <IScriptCommand>(cmds), initialParameters); }