Project Settings for Multiple Addins

393
4
07-16-2019 05:45 AM
EvanMosher
New Contributor II

I have 2 addins that i would like to have settings items for. I have one working with Project Settings all set up, but when i try to add settings to my other addin, it seems that the override function to load project settings, OnReadSettingsAsync, only gets triggered in the one addin. Is there a way to share these settings across multiple addins?

Tags (2)
0 Kudos
4 Replies
GintautasKmieliauskas
Regular Contributor

Hi Evan,

I store settings in library dll as singleton class with properties, but use them from more than 10 add-ins. Library dll added to GAC. Project settings form is stored in one of add-ins. That add-in manages loading and saving project properties from Project to singleton class and back.  There is no cross-references between add-ins.

There is only one thing you need to do that project settings add-in will be loaded first. More info here:

https://www.esri.com/arcgis-blog/products/arcgis-pro/uncategorized/manage-arcgis-pro-add-in-loading/

In addition I use (<modules><insertModule .... autoLoad="true">...). 

DanH1
by
New Contributor II

Evan,

I'm going to need to do this before the end of the summer too so took a quick break and decided to create two boilerplate C# ArcGIS Pro SDK AddIn's.  In both instances, I overrode both the OnWriteSettingsAsync and the OnReadSettingsAsync as shown below.  The only other thing I did (took make sure the modules would load since I didn't write any other code) was I edited each config.daml to turn on the autoload="true" for the <insertModule> tag.  To get ArcGIS Pro to fire the OnWriteSettingsAsync, I just adjusted the zoom level of the map and responded "Yes" to whether I wanted to save settings and both AddIn's OnWriteSettingsAsync fired and save the "Name" string that I specified.  When I reloaded the same project file, both OnReadSettingsAsync were called one after the other. I confirmed this via break-point in each method.  I'm using ArcGIS Pro 2.4 and the corresponding SDK and Visual Studio 2019.  Hope that helps.

        protected override Task OnWriteSettingsAsync(ModuleSettingsWriter settings)
        {
            System.Diagnostics.Debug.WriteLine("OnWriteSettings TestWriteSettingsNumber2.....");
            settings.Add("Name", "TestWriteSettingsNumber2");
            return base.OnWriteSettingsAsync(settings);
        }
        protected override Task OnReadSettingsAsync(ModuleSettingsReader settings)
        {
            string l_progress = settings.Get("Name") as string;
            return base.OnReadSettingsAsync(settings);
        }
EvanMosher
New Contributor II

Hey Dan,

Thanks for the reply,

Are the modules in both addins both called Module1? Do you have these in seperate Visual Studio projects? and does each project have a ProjectSettingsViewModel? I have the AutoLoad=true for both but only triggering the one OnReadSettingsAsync.

-Evan

0 Kudos
DanH1
by
New Contributor II

1. They are boilerplate projects so both projects have Module1 (not renamed)

2. They in separate Visual Studio Projects but the same solution.

3. I did not use the ProjectSettingsViewModel.  Just to save settings to your project you don't need that IMHO (unless you really need the user to see a property page).  As you can see all I did was override the the OnRead... and OnWrite...methods.  In one of our AddIns we have quite a few state variables and user settings are that are persisted this way, again, without using ProjectSettingsViewModel.

Hope that helps.

0 Kudos