question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support dynamic help address resolution

See original GitHub issue

For current moment developer have to put url to help topic into ExcelFunction attribute. So, it is unable to change URL dynamically, therefore it is unable to select different urls for production and staging environments.

What is expected: instead of http address. put link to static method, which will resolve help page dynamically.

E.g. signature can be:

public static Url ResolveHelpPage(ExcelFunctionAttribute targetMethod)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
govertcommented, Jan 18, 2018

Using the Registration helper is a bit simpler that the above example shows.

using System.Linq;
using ExcelDna.Integration;
using ExcelDna.Registration;

namespace RegistrationHelpUpdate
{
    public class AddIn : IExcelAddIn
    {
        public void AutoOpen()
        {
            RegisterFunctions();
        }

        public void AutoClose()
        {
        }

        public void RegisterFunctions()
        {
            ExcelRegistration.GetExcelFunctions()
                             .Select(funcReg => UpdateHelpTopic(funcReg))
                             .RegisterFunctions(); 
        }

        public ExcelFunctionRegistration UpdateHelpTopic(ExcelFunctionRegistration funcReg)
        {
            funcReg.FunctionAttribute.HelpTopic = "http://www.bing.com";
            return funcReg;
        }
    }

    public class Functions
    {
        [ExcelFunction(HelpTopic ="http://www.google.com")]
        public static object SayHelloFromRegistrationTest()
        {
            return "Hello!!!";
        }
    }
}
1reaction
augustoproietecommented, Jan 4, 2018

@imanushin This can be done with the Excel-DNA Registration Helper, a library that allows you to dynamically register your functions.

Install the package ExcelDna.Registration in your project, so you can have access to the custom registration classes.

image

In your .dna file, set the flag ExplicitRegistration to true to tell Excel-DNA that you’ll be doing the registrations of the functions yourself.

e.g.

<DnaLibrary Name="MyAddIn Add-In" RuntimeVersion="v4.0">
  <ExternalLibrary Path="MyAddIn.dll" ExplicitRegistration="true" (...) />
</DnaLibrary>

Declare your functions normally:

public static class MyFunctions
{
    [ExcelFunction]
    public static string Hello()
    {
        return "Hi";
    }

    [ExcelFunction]
    public static string Hello2()
    {
        return "Hi2";
    }
}

In your AutoOpen, register the functions, replacing the HelpTopic of each of the functions as you need.

e.g.

public class MyAddIn : IExcelAddIn
{
    public void AutoOpen()
    {
        RegisterFunctions();
    }

    public void AutoClose()
    {
    }

    private static void RegisterFunctions()
    {
        var registrationEntries =
            from assembly in ExcelIntegration.GetExportedAssemblies()
            from type in assembly.GetTypes()
            from methodInfo in type.GetMethods(BindingFlags.Public | BindingFlags.Static)
            where methodInfo.GetCustomAttribute<ExcelFunctionAttribute>() != null
            select new ExcelFunctionRegistration(methodInfo);

        var delList = new List<Delegate>();
        var attList = new List<object>();
        var argAttList = new List<List<object>>();

        foreach (var entry in registrationEntries)
        {
            try
            {
                var del = entry.FunctionLambda.Compile();
                var att = entry.FunctionAttribute;

                // ***************************************************************
                // Detect the environment where the add-in is running somehow
                // and dynamically set the HelpTopic.

                // For example, via an appSetting entry in the App.config file:

                var environment = ConfigurationManager.AppSettings["Environment"];
                att.HelpTopic = $"http://{environment}/help/{att.Name}";
                // ***************************************************************

                var argAtt = new List<object>(entry.ParameterRegistrations.Select(pr => pr.ArgumentAttribute));

                delList.Add(del);
                attList.Add(att);
                argAttList.Add(argAtt);
            }
            catch (Exception ex)
            {
                LogDisplay.WriteLine("Exception while registering method {0} - {1}", entry.FunctionAttribute.Name, ex.ToString());
            }
        }

        ExcelIntegration.RegisterDelegates(delList, attList, argAttList);
    }
}

Of course, the above is just to give an example… You can also allow the developer to set a HelpTopic template in the ExcelFunction attribute, and then replace parts of it…

e.g.

public static class MyFunctions
{
    [ExcelFunction(HelpTopic = "http://%environment%/help/%name%")]
    public static string Hello()
    {
        return "Hi";
    }
}
  // ...
                // ***************************************************************
                // Detect the environment where the add-in is running somehow
                // and dynamically set the HelpTopic.

                // For example, via an appSetting entry in the App.config file:

                var environment = ConfigurationManager.AppSettings["Environment"];
                att.HelpTopic = att.HelpTopic.Replace("%environment%", environment);
                att.HelpTopic = att.HelpTopic.Replace("%name%", att.Name);
                // ***************************************************************
  // ...
Read more comments on GitHub >

github_iconTop Results From Across the Web

What is Address Resolution Protocol (ARP)? Definition ...
Address Resolution Protocol (ARP) is a procedure for mapping a dynamic IP address to a permanent physical machine address in a local area...
Read more >
Dynamic Address Resolution
Dynamic Address Resolution. Direct mapping provides a simple and highly efficient means of resolving network layer addresses into data link layer addresses.
Read more >
Dynamic Address Resolution Protocol (ARP)
Dynamic ARP inspection (DAI) helps prevent malicious attacks on the switch by not relaying invalid ARP requests and responses to other ports in...
Read more >
Dynamic ARP Inspection - Cisco Meraki
DAI inspects Address Resolution Protocol (ARP) packets on the LAN and uses the information in the DHCP snooping table on the switch to...
Read more >
Address Resolution Protocol - Wikipedia
The Address Resolution Protocol (ARP) is a communication protocol used for discovering the link layer address, such as a MAC address, associated with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found