[C++ CONNECT] What happened to mdlSystem_expandCfgVar() ?

I'm having my first try at porting existing V8i apps to CONNECT. The first problem I've encountered is that much of my code will do things like this:

valueP = mdlSystem_expandCfgVar ( "$(MSDIR)config\\mslocal.cfg" );

If the string might contain a UNC path I also use mdlSystem_extExpandCfgVarNoFmt() to expand a string with embedded configuration variables. These two functions are no longer available in the SDK.

I get that the Connect SDK now automatically does an expansion of the variable as part of mdlSystem_getCfgVar(), however I need to expand a user-defined string that may or may not have one or more embedded configuration variables in it. I assume that mdlSystem_getCfgVar() would fail on such a string, since it won't match an existing variable.

Is there a workaround for this, and why were these functions removed? The ConfigurationManager structure does not seem to have this missing functionality either. I just want to expand a string that may contain one or more nested variables.

Cheers.

Parents
  • How about the following replaced code ?

    WString cfgValue;
    ConfigurationManager::GetVariable(cfgValue, L"MSDIR");
    cfgValue.AppendA("config\\mslocal.cfg");
    mdlDialog_dmsgsPrint(cfgValue.GetWCharCP());



  • Hi Yongan, that should work when it is me, the programmer, creating the string to expand. But in my program, it can also be the user who has entered a string to expand, and I won't know in advance which variables may be embedded, nor what they may be. Should I write my own recursive code to expand a string containing macros? E.g. search for all "$(" with a matching ")"?

    If so, then I will be doing exactly what the API used to do for me, and it makes me wonder why was it removed in the first place?

    --
    Piers Porter
    Altiva Software

  • MDL V8i

    We have two or three functions that expand a configuration variable...

    FunctionComment
    mdlSystem_getExpandedCfgVar ("var-name") Expands (gets the value of) a single variable
    mdlSystem_getCfgVar (value, "var-name", maxlength) An older version of the above; less useful
    mdlSystem_extExpandCfgVarNoFmt ("string that may contain $(var-name)",  immediate) Expands CfgVars embedded in a string
    mdlSystem_extExpandCfgVar ("string that may contain $(var-name)") Expands CfgVars embedded in a string

    CONNECT API

    There are several methods of ConfigurationManager that deal with CfgVars, but only one ConfigurationManager::GetVariable() that Piers and I can see that gets the value of a CfgVar.

    Pier's question is this: given a string that includes embedded CfgVars, how do I get its expanded value in CONNECT?

    Example 1: "$(MSDIR)config/appl/"

    Using mdlSystem_extExpandCfgVarNoFmt() that would expand to something like "C:\Program FIles(x86)\Bentley\MicroStation\config\appl\". That is, the function has substituted the expanded CfgVar into the string, retaining the literal text.

    Example 2: "$(MSDIR)/config/database/$(MS_SERVER).cfg"

    Using mdlSystem_extExpandCfgVarNoFmt() that would expand to something like "C:\Program FIles(x86)\Bentley\MicroStation\config\database\oracle.cfg".  That is, the function has made two substitutions of expanded CfgVar values.

    How do we do that in CONNECT?  Has that functionality been lost in the new API?

     
    Regards, Jon Summers
    LA Solutions

  • Thanks Jon, you put it more eloquently than I.

    To further confound us, this could get a lot more complex if we consider the differences between variables that use ${VAR} instead of $(VAR). Processing these correctly manually requires knowing how MicroStation has resolved these variables with subsequent values set (i.e. whether to use the fully resolved variable or the immediate value).

    Then we have all of the other macro commands that are fully supported in CONNECT, such as:
    dev(MSDIR)
    dir(MSDIR)
    parentdir(MSDIR)
    ...etc

    There are many more commands supported by the configuration file parser, as documented under the chapter:
    Home > Setting Up the Environment > Configuration > Configuration Concepts > Configuration Variables > Configuration File Syntax > Operators.

    I really don't want to have to write my own configuration file parser to get back this basic functionality.

    --
    Piers Porter
    Altiva Software

  • Hi Piers and Jon,
    I am asking Bentley expert about this. If I get answer I will post it here ASAP.
    Thanks, YongAn



  • What we determined in looking at our own code was that there was huge confusion regarding the differences between mdlSystem_getCfgVar and mdlSystem_expandCfgVar. Most callers to mdlSystem_getCfgVar really wanted the functionality of mdlSystem_expandCfgVar, and many callers of mdlSystem_expandCfgVar forgot to call mdlSystem_freeCfgVarBuffer. So we simplified the public API greatly by providing only ConfigurationManager::GetVariable.

    If you really need the functionality of mdlSystem_expandCfgVarxxx, you can declare this function and call it. We did not include it in the public API because it is rarely needed.

    MSCORE_EXPORT StatusInt msMacro_expandMacroExpression (WStringR expansion, WCharCP expression, bool immediate, bool fmtExpansion);


    Barry



    Answer Verified By: Piers Porter 

  • Hello Piers,

    I have a good solution for this. You can firstly assign your string to a temporary configVar (such as MS_FOO) and then call GetVariable to expand it. Actually GetVariable can expand a string which contains some macros. Pls see my below test code:

    WString cfgValue;
    ConfigurationManager::DefineVariable(L"MS_FOO", L"$(MSDIR)config\\mslocal.cfg");
    ConfigurationManager::GetVariable(cfgValue, L"MS_FOO");
    mdlDialog_dmsgsPrint(cfgValue.GetWCharCP());



  • I just found out this function does not handle UNC paths, as it truncates "\\" into "\".Some testing has revealed that the last argument "fmtExpansion" prevents this truncation. So anyone looking for an equivalent to V8i's mdlSystem_extExpandCfgVarNoFmt() can use msMacro_expandMacroExpression() with the last bool set to FALSE.

    --
    Piers Porter
    Altiva Software

Reply Children
No Data