This project is read-only.

Force plugin loading

Jan 14, 2011 at 4:20 PM

I have plugin that I am testing, however having to activate it every time I restart is getting aggrivating.  Is there any way for me to force a plugin to load when DS with an app manager launches?

 

Thanks

Aaron Parks

RTI International

Jan 14, 2011 at 4:45 PM

I think I added the capability right before I left for break, but I think I forgot to update the interface.  So even though your initialization arguments class has the AppManager on it as a parameter, it isn't visible unless you cast it to a MapPluginArgs instead of an IMapPluginArgs.  I will try to post a fix real quick.

 

Jan 14, 2011 at 4:53 PM

Currently, DS is not storing the information regarding what plugins are activitated.

Hydrodesktop does this currently on its own (see \hydrodesktop\trunk\Source\Libraries\DataAccess\HydroDesktop.Data\Configuration\ProjectFileManager.cs).

I don't have a clear cut workaround for this issue at this time, but will be working on pulling this code from HydroDesktop down into DS over the next week.

 

 

Jan 14, 2011 at 4:54 PM

Changeset 8308e9387e59 now includes an updated interface so you should have access to the AppManager.  You will be able to Activate and Deactivate plugin tokens from this.  Sorry about that Aaron.  I thought I had addressed this weeks ago, but I boned it by forgetting to update the interface =P.

Ted

 

Jan 14, 2011 at 5:03 PM

// To find your token and activate it directly
            foreach (PluginToken token in args.AppManager.PluginTokens)
            {
                // find your plugin by name
                if (token.UniqueName != "myPluginName") continue;

                // test if your plugin is active
                if (!args.AppManager.IsActive(token))
                {
                    // Activate your plugin
                    args.AppManager.ActivateToken(token);
                }
                else
                {
                    // Deactivate your plugin
                    args.AppManager.DeactivateToken(token);
                }
            }

Jan 14, 2011 at 9:59 PM

Got the new version, but it seems like I can only activate my plugin from inside my plugin, which is a bit of a chicken/egg thing.  To be clear I wanted to activate sometime after I finished adding my default background layers when the progam launched.

 

Thanks

Aaron Parks

RTI International

Jan 14, 2011 at 10:05 PM

Hmm.  Yes, I've been thinking we need something like an application settings that would remember which plugins were activated and leave them active once they have been activated at least once by the user, but we don't have that yet.  In the mean time, if you are writing your own application you can call the same code posted above from anywhere that knows what the AppManager is.  So in your main form where you should have a variable like appManager1, you can replacing args.AppManager with appManager1 and call it in the same block of code that adds your background layers.  You will want to modify the code to only activate or deactivate per your needs though.

Ted

 

Jan 14, 2011 at 10:16 PM

In that case I believe you can add the following code to your Windows Form, using the appropriate plugin name.

 

    protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
#if DEBUG
            const string STR_MyPluginName = "myPluginName";

            foreach (PluginToken token in appManager1.PluginTokens)
            {
                // find your plugin by name

                if (token.UniqueName != STR_MyPluginName) continue;

                // test if your plugin is active
                if (!appManager1.IsActive(token))
                {
                    // Activate your plugin
                    appManager1.ActivateToken(token);
                }

            }
#endif
        }

Jan 16, 2011 at 9:13 PM

appManager1.PluginTokens is null when the Load event of my main form throws.  The load event on the map never throws. 

Watching the console I can see the system skipping some DLLs:

A first chance exception of type 'System.BadImageFormatException' occurred in mscorlib.dll
Skipping non .Net library: Plugins\CONTOUR\Scripts\dist\wxmsw28uh_html_vc.dll

 

When looking at plugins, but that is 2 to 3 seconds after the map comes up.

 

 

Is there something else I can hook into?

 

Thanks

Aaron Parks

RTI International

Jan 17, 2011 at 3:49 PM

This function will do it if you run at the end of form load.  I just wait until the token list isn't null. 

        private void loadPlugin()
        {
            bool testvar = false;
           
           
            while (!testvar)
            {
                try
                {
                    if (appManager1.PluginTokens != null)
                    {
                        testvar = true;
                    }
                }
                catch (Exception e)
                {

                }
                Application.DoEvents();
            }
            // To find your token and activate it directly
            foreach (PluginToken token in appManager1.PluginTokens)
            {
                // find your plugin by name
                if (token.Name != "CAMELOT-.2") continue;

                // test if your plugin is active
                if (!appManager1.IsActive(token))
                {
                    // Activate your plugin
                    appManager1.ActivateToken(token);
                }
                else
                {
                    // Deactivate your plugin
                    appManager1.DeactivateToken(token);
                }
            }

        }

Thanks

Aaron Parks

RTI International

Jan 18, 2011 at 1:29 AM
Aaron,

This sounds like a broader problem that we need to sort out so that it doesn't show up for others down the road. I've asked Matthew to work with you on these kinds of things as high priority. Can you please email him directly about the details of how plugin working isn't working the way it should?

Thanks,

Dan

On Mon, Jan 17, 2011 at 8:49 AM, aparks <notifications@codeplex.com> wrote:

From: aparks

This function will do it if you run at the end of form load. I just wait until the token list isn't null.

private void loadPlugin()
{
bool testvar = false;


while (!testvar)
{
try
{
if (appManager1.PluginTokens != null)
{
testvar = true;
}
}
catch (Exception e)
{

}
Application.DoEvents();
}
// To find your token and activate it directly
foreach (PluginToken token in appManager1.PluginTokens)
{
// find your plugin by name
if (token.Name != "CAMELOT-.2") continue;

// test if your plugin is active
if (!appManager1.IsActive(token))
{
// Activate your plugin
appManager1.ActivateToken(token);
}
else
{
// Deactivate your plugin
appManager1.DeactivateToken(token);
}
}

}

Thanks

Aaron Parks

RTI International

Read the full discussion online.

To add a post to this discussion, reply to this email (DotSpatial@discussions.codeplex.com)

To start a new discussion for this project, email DotSpatial@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com




--
Daniel P. Ames, Ph.D. PE
Associate Professor, Geosciences
Idaho State University - Idaho Falls
amesdani@isu.edu
geology.isu.edu
www.mapwindow.org


Jan 18, 2011 at 3:12 PM

The broader question is really how we want to be able to interact with the plugins programmatically.  For instance in MW v4 the plugin states are stored in the map XML so you can turn them on/off by editing that file on the fly.  While that may not have been the best system it did get the job done when running MW4 from an outside program (the way D4EM did).

 

The above code isn't that awful as these things go, but it would be nice if there was an event we could hook into when the appManager finished loading the plugins directory.

 

Aaron Parks

RTI International

Jan 18, 2011 at 7:28 PM

I've added this event to AppManager as follows:

 

        protected virtual void OnLoad()
        {
            Update();

            OnLoaded(EventArgs.Empty);
        }

        public event EventHandler Loaded;

        #region OnLoaded

        /// <summary>
        /// Triggers the Loaded event.
        /// </summary>
        public virtual void OnLoaded(EventArgs ea)
        {
            if (Loaded != null)
                Loaded(this, ea);
        }

        #endregion

I'll synchronize my changes this evening. Is this what you wanted?

Jan 27, 2011 at 12:28 AM

I'm checking in code that lets you place your plugin in 

Application Extensions

It will be loaded and unavailable for deactivating. This might work well for your tests.