[MSCE U17 C++] Create custom SrNoProvider for Report Definition Sr.No. column

In MicroStation Update17, we have introduced Sr.No. column functionality in report definition.

Sr.No. can be generated by using following inbuilt formats:

In MicroStation Update17 we have introduced a way to add custom Sr. No. 
SDK Sample:

In this blog, you will learn to introduce the custom Sr.No. provider implementation.    

This is available at: ..\examples\DgnEC\ ReportSrNoColumnExample

Implementation: 

Step 1: Implement Bentley::DgnPlatform::ISrNoProvider:

Bentley::DgnPlatform::ISrNoProvider is an abstract class, available under Bentley::DgnPlatform namespace in Bentley.DgnPlatform5.dll.
In the class, the constructor sets the unique value of the provider and priority value.
Implement _CalculateSrNo ().
_CalculateSrNo (): Add custom implementation using which the Sr.No values will be processed. e.g. 1), 2), 3) ….etc.  
A sample implementation is:

/*---------------------------------------------------------------------------------**//**
* @bsiclass                                                              Bentley Systems
* This is a custom SrNo class which implements ISrNoProvider.
+---------------+---------------+---------------+---------------+---------------+------*/
class CustomSrNo : public Bentley::DgnPlatform::ISrNoProvider
    {
    public:
        CustomSrNo(WCharCP formatName, int priority);
    protected :
        virtual bool _CalculateSrNo(int rowIndex, WStringR result) override;
    };

/*---------------------------------------------------------------------------------**//**
* Constructor of CustomSrNo
* @bsimethod                                                              Bentley Systems
+---------------+---------------+---------------+---------------+---------------+------*/
CustomSrNo::CustomSrNo(WCharCP formatName, int priority) : Bentley::DgnPlatform::ISrNoProvider(formatName, priority)
    {
    }

/*---------------------------------------------------------------------------------**//**
* This is a custom SrNo provider which generates Sr.No. as 1), 2), 3) etc.
* @bsimethod                                                              Bentley Systems
+---------------+---------------+---------------+---------------+---------------+------*/
bool CustomSrNo::_CalculateSrNo(int rowIndex, WStringR result)
    {
    if (rowIndex < 0)
        return false;

    WChar wStrSrNo[6] = { 0 }; 
    if (BentleyStatus::SUCCESS != BeStringUtilities::Itow(wStrSrNo, rowIndex, 6, 10))
        return false;
   
    result = wStrSrNo;
    result += L")";
    return true;
    }

Step 2: Register Provider:

/*---------------------------------------------------------------------------------**//**
* This function is called on key-in: ReportExample SRNOCOLUMN REGISTERCUSTOMSRNO
* @bsimethod                                                            Bentley Systems
+---------------+---------------+---------------+---------------+---------------+------*/
void RegisterCustomSrNo()
    {
    WString displayName = L"1), 2), 3)...";
    WString srNoProviderName = L"SrNoCustomFormat";
    s_customSrNo = new CustomSrNo(srNoProviderName.c_str(), DgnECManager::GetManager().GetNextPriorityValueForSrNo());
    s_customSrNo->SetDisplayLabel(displayName.c_str());
    if (nullptr != s_customSrNo)
        {
        DgnECManager::GetManager().RegisterSrNoProvider((ISrNoProvider*)s_customSrNo);
        mdlOutput_messageCenter(OutputMessagePriority::Info, L"Initialized custom Sr. No. Provider", NULL, OutputMessageAlert::None);
        }
    }

Step 3: See it running:
With this sample app you must execute the following key-ins:

User need to load the dll using Keyins dialog box.
mdl load ReportSrNoColumnExample

ReportExample SRNOCOLUMN REGISTERCUSTOMSRNO
ReportExample SRNOCOLUMN DEMORESULT

After executing the following keyin :  SRNOCOLUMN DEMORESULT we can see the .csv file is saved in MS_TMP directory. The results of the csv file are :

 

Name,Length,Sr.No.
Circle,10.00 in,1)
Circle,10.00 in,2)
Shape,10.00 in,3)
Shape,10.00 in,4)
Shape,10.00 in,5)
Line,10.00 in,6)
Line,10.00 in,7)
Line,10.00 in,8)
Line,10.00 in,9)

The last column of the .csv is Sr.No. column and numbers are appended with ")" sign.   

Note: SDK sample should be available in MicroStation Update17.