/// <summary> /// Adds a string format annotation to the property. /// </summary> /// <param name="property"></param> /// <param name="provider"></param> /// <returns></returns> public static PropertyBuilder HasStringFormat( this PropertyBuilder property, IStringFormatProvider provider ) { property.Metadata.SetAnnotation(StringFormatAnnotation, provider); return(property); }
/// <summary> /// Adds a string format annotation to the property. /// </summary> /// <param name="property"></param> /// <param name="provider"></param> /// <returns></returns> public static IMutableProperty HasStringFormat( this IMutableProperty property, IStringFormatProvider provider ) { property.SetAnnotation(StringFormatAnnotation, provider); return(property); }
/// <summary> /// Applies a string-format on a raw-type expression if required /// </summary> /// <param name="typeExpression">the type-expression found in the a configuration</param> /// <param name="formatter">the formatter that is used to format strings inside the calling factory</param> /// <returns>a re-formatted string that provides a type expression</returns> public static string ApplyFormat(this string typeExpression, IStringFormatProvider formatter) { var retVal = typeExpression; if (formatter != null && typeExpression.StartsWith("$")) { retVal = formatter.ProcessLiteral(typeExpression.Substring(1)); } return(retVal); }
/// <summary> /// parses the constructorparameter string for a LogAdapter /// </summary> /// <param name="constructor">the constructorparameter string</param> /// <param name="formatProvider">a Plugin-instance that is capable for formatting custom strings (i.e. decrypting passwords, or buffering sql-server instance names)</param> /// <returns>an object array containing the parsed objects</returns> private static PluginParameterElement[] ParseConstructor(string constructor, IStringFormatProvider formatProvider) { List <PluginParameterElement> ls = new List <PluginParameterElement>(); List <string> strings = new List <string>(); if (constructor != string.Empty) { constructor = StringRecognizer.Replace(constructor, (m) => { int id = strings.Count; var tmp = Unescape(m.Groups["string"].Value); if (m.Groups["formatIndicator"].Value == "$" && formatProvider != null) { LogEnvironment.LogDebugEvent($"Resolving {tmp} using {formatProvider}...", LogSeverity.Report); tmp = formatProvider.ProcessLiteral(tmp); LogEnvironment.LogDebugEvent($"Resulted to {tmp}", LogSeverity.Report); } strings.Add(tmp); return(string.Format("#STRING##{0}##", id)); }); string[] args = constructor.Split(new[] { "," }, StringSplitOptions.None); foreach (string arg in args) { if (!arg.StartsWith("#")) { AddConstructorVal(arg.ToUpper()[0], arg.Substring(1), ls); } else { string tmpValue = strings[int.Parse(arg.Substring(9, arg.Length - 11))]; AddConstructorVal((!tmpValue.StartsWith("^^")) ? 'S' : 'O', tmpValue, ls); } } } return(ls.ToArray()); }
/// <summary> /// Fills the generic Type-Arguments with the appropriate values /// </summary> /// <param name="uniqueName">the unique-name for which to get the generic arguments</param> /// <param name="genericTypeArguments">get generic arguments defined in the plugin-type</param> public void GetGenericParams(string uniqueName, List <GenericTypeArgument> genericTypeArguments, IStringFormatProvider formatter) { if (!string.IsNullOrEmpty(genericParamTableName)) { using (database.AcquireConnection(false, out var db)) { var data = db.GetNativeResults($"Select a.* from {tableName} p inner join {genericParamTableName} a on a.PlugInId = p.PlugInId where p.UniqueName = @uniqueName and isnull(disabled,0)=0" , null, db.GetParameter("uniqueName", uniqueName)); var joined = from t in genericTypeArguments join d in data on t.GenericTypeName equals d["GenericTypeName"] select new { Target = t, Type = (string)d["TypeExpression"] }; Dictionary <string, object> dic = new Dictionary <string, object>(); foreach (var j in joined) { j.Target.TypeResult = (Type)ExpressionParser.Parse(j.Type.ApplyFormat(formatter), dic); } } } }
/// <summary> /// Parses a constructor hint for a Plugin /// </summary> /// <param name="constructorString">the constructor hint</param> /// <param name="formatProvider">a Plugin-instance that is capable for formatting custom strings (i.e. decrypting passwords, or buffering sql-server instance names)</param> public static PluginConstructionElement ParsePluginString(string constructorString, IStringFormatProvider formatProvider) { Match splitted = ConstructorParser.Match(constructorString); string filename = splitted.Groups["Path"].Value; string className = splitted.Groups["Type"].Value; PluginParameterElement[] constructor = ParseConstructor(splitted.Groups["Parameters"].Value, formatProvider); return(new PluginConstructionElement { AssemblyName = filename, TypeName = className, Parameters = constructor }); }