Smrf.NodeXL.ExcelTemplate.VertexWorksheetReader.ReadCustomMenuItems C# (CSharp) Method

ReadCustomMenuItems() protected method

protected ReadCustomMenuItems ( ExcelTableReader oRow, String>.ICollection aoCustomMenuItemPairNames, IVertex oVertex ) : void
oRow Smrf.AppLib.ExcelTableReader
aoCustomMenuItemPairNames String>.ICollection
oVertex IVertex
return void
    ReadCustomMenuItems
    (
        ExcelTableReader.ExcelTableRow oRow,
        ICollection< KeyValuePair<String, String> > aoCustomMenuItemPairNames,
        IVertex oVertex
    )
    {
        Debug.Assert(oRow != null);
        Debug.Assert(aoCustomMenuItemPairNames != null);
        Debug.Assert(oVertex != null);
        AssertValid();

        // List of string pairs, one pair for each custom menu item to add to
        // the vertex's context menu in the graph.  The key is the custom menu
        // item text and the value is the custom menu item action.

        List<KeyValuePair<String, String>> oCustomMenuItemInformation =
            new List<KeyValuePair<String, String>>();

        foreach (KeyValuePair<String, String> oPairNames in
            aoCustomMenuItemPairNames)
        {
            String sCustomMenuItemText, sCustomMenuItemAction;

            // Both the menu item text and menu item action must be specified. 
            // Skip the pair if either is missing.

            if (
                !oRow.TryGetNonEmptyStringFromCell(oPairNames.Key,
                    out sCustomMenuItemText)
                ||
                !oRow.TryGetNonEmptyStringFromCell(oPairNames.Value,
                    out sCustomMenuItemAction)
                )
            {
                continue;
            }

            Int32 iCustomMenuItemTextLength = sCustomMenuItemText.Length;

            if (iCustomMenuItemTextLength > MaximumCustomMenuItemTextLength)
            {
                Range oInvalidCell = oRow.GetRangeForCell(oPairNames.Key);

                OnWorkbookFormatError( String.Format(

                    "The cell {0} contains custom menu item text that is {1}"
                    + " characters long.  Custom menu item text can't be"
                    + " longer than {2} characters."
                    ,
                    ExcelUtil.GetRangeAddress(oInvalidCell),
                    iCustomMenuItemTextLength,
                    MaximumCustomMenuItemTextLength
                    ),

                    oInvalidCell
                    );
            }

            oCustomMenuItemInformation.Add( new KeyValuePair<String, String>(
                sCustomMenuItemText, sCustomMenuItemAction) );
        }

        if (oCustomMenuItemInformation.Count > 0)
        {
            oVertex.SetValue( ReservedMetadataKeys.CustomContextMenuItems,
                oCustomMenuItemInformation.ToArray() );
        }
    }