示例#1
0
 /// <summary>
 /// Returns the content of config node as terse laconic string capped at the specified max len (64 by default).
 /// Warning: the returned laconic is mostly used for logging and error reporting, it is not possible to
 /// read it back into config node as it is for info purposes only
 /// </summary>
 public static string AsTextSnippet(this IConfigSectionNode node, int len = 0, string ellipsis = null)
 {
     if (node == null || !node.Exists)
     {
         return(string.Empty);
     }
     if (len <= 0)
     {
         len = 64;
     }
     if (ellipsis == null)
     {
         ellipsis = "...";
     }
     return(node.ToLaconicString(CodeAnalysis.Laconfig.LaconfigWritingOptions.Compact)
            .TakeFirstChars(len, ellipsis));
 }
示例#2
0
            public ContractMapping(IConfigSectionNode config)
            {
                try
                {
                    var cname = config.AttrByName(CONFIG_MAP_CLIENT_CONTRACT_ATTR).Value;
                    if (cname.IsNullOrWhiteSpace())
                    {
                        throw new Clients.SkyClientException(CONFIG_MAP_CLIENT_CONTRACT_ATTR + " is unspecified");
                    }
                    m_Contract = Type.GetType(cname, true);

                    m_Local  = new Data(config, config[CONFIG_LOCAL_SECTION], false);
                    m_Global = new Data(config, config[CONFIG_GLOBAL_SECTION], true);
                }
                catch (Exception error)
                {
                    throw new Clients.SkyClientException(StringConsts.SKY_SVC_CLIENT_MAPPING_CTOR_ERROR.Args(
                                                             config.ToLaconicString(CodeAnalysis.Laconfig.LaconfigWritingOptions.Compact),
                                                             error.ToMessageWithType()), error);
                }
            }
示例#3
0
 /// <summary> Makes entity with descriptive error </summary>
 protected virtual T Make <T>(IConfigSectionNode parent, string section) where T : IConfigurable
 {
     try
     {
         return(FactoryUtils.MakeAndConfigure <T>(parent.NonNull(nameof(parent))[section.NonBlank(nameof(section))]));
     }
     catch (ConfigException error)
     {
         throw new ScriptingException("Expression `{0}` declaration error while trying to make `{1}` around:  ... {2} ...".Args(GetType().Name, section, parent.ToLaconicString(CodeAnalysis.Laconfig.LaconfigWritingOptions.Compact)), error);
     }
 }
示例#4
0
 /// <summary>
 /// Reads config sections into Type[]
 /// </summary>
 protected virtual Type[] ReadKnownTypes(IConfigSectionNode conf)
 {
     try
     {
         return(conf.Children.Where(cn => cn.IsSameName(CONFIG_KNOWN_TYPE_SECTION))
                .Select(cn => Type.GetType(cn.AttrByName(Configuration.CONFIG_NAME_ATTR).Value, true))
                .ToArray());       //force execution now
     }
     catch (Exception error)
     {
         throw new SerbenchException("{0} serializer config error in '{1}' section: {2}".Args(GetType().FullName,
                                                                                              conf.ToLaconicString(),
                                                                                              error.ToMessageWithType()), error);
     }
 }
示例#5
0
 /// <summary>
 /// Reads config sections into Type[]
 /// </summary>
 protected virtual Type[] ReadKnownTypes(IConfigSectionNode conf)
 {
     try
       {
     return conf.Children.Where(cn => cn.IsSameName(CONFIG_KNOWN_TYPE_SECTION))
                     .Select( cn => Type.GetType( cn.AttrByName(Configuration.CONFIG_NAME_ATTR).Value, true ))
                     .ToArray();   //force execution now
       }
       catch(Exception error)
       {
     throw new SerbenchException("{0} serializer config error in '{1}' section: {2}".Args(GetType().FullName,
                                                                                      conf.ToLaconicString(),
                                                                                      error.ToMessageWithType()), error);
       }
 }