How to get information from configuration in AddIn

311
1
11-18-2020 05:10 PM
yuliu2
by
New Contributor

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

0 Kudos
1 Reply
Wolf
by Esri Regular Contributor
Esri Regular Contributor

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}");
}

 

 

 

0 Kudos