Here is the thing:
I have a ProConfiguration program to design startPage and control the AddIns. In ProConfiguration,I set a LogIn page.How can I get the UserName from ProConfiguration in my AddIn program? I need set different functions based on UserName.
The Code in Configuration is simple so I don not copy to this problem.
Thank you
Jerry
You can create a class library with your common code, in this case mainly this interface:
public interface IFromConfiguration
{
string UserName { get; set; }
}
Include a reference to this library in both the configuration and the add-in. In the configuration you need to implement the interface in your Module class (which in my case is called ConfigurationModule):
internal class ConfigurationModule : Module, IFromConfiguration
{
/// ... existing Module code ....
internal string UserName { get; set; }
string IFromConfiguration.UserName { get => UserName; set { UserName = value; } }
/// ... existing Module code ....
}
In your add-in you can now access the configuration as follows - this is from a button OnClick method:
try
{
// get the configuration module:
var configModule = FrameworkApplication.FindModule("ProConfigurationTest_Module");
if (configModule is ProConfigurationTest.IFromConfiguration configInterface)
{
MessageBox.Show($@"Username from configuration: {configInterface.UserName}");
}
}
catch (Exception ex)
{
MessageBox.Show($@"Error: {ex}");
}