Dotnet plugin: An interesting problem I'd like advice on.

Interested in developing new plug-ins? Got one to share? Post here!
bokkie
Posts: 767
Joined: Sun Feb 08, 2009 6:30 am

Dotnet plugin: An interesting problem I'd like advice on.

Postby bokkie » Wed Nov 07, 2012 6:13 am

I drag my plugin onto the MSIcode window.

The first call the bridge makes is to DesignTimeEdit. The arguments are the window handle, state, newState and displayDialog. Ignore the handle. The state and newState arguments are both null strings and displayDialog is true. When returning on the first call if the value I want to return is "Fred Was Here" I'd set the return value of DesignTimeEdit to 13 which is the length of the string. Control then passes back to the bridge, etc. Notice that on the first call you can only give back the length of the string and not the string itself.

The bridge then makes a second call to DesignTimeEdit. Again, ignore the handle. The state and newState arguments are still null strings but this time, the displayDialog is false. The next thing you do is give back the string "Fred Was Here". In our example, I'd set newState = "Fred Was Here". That works.

But notice that between the calls the string "Fred Was Here" is no longer available in the second. I guess this is because the calls are not in the same process as each other. I got round this by creating a text file in the plugin's installation folder and I write "Fred Was Here" to it. On the second call I then read the text and give that back to the newState argument.

My question really is if there is some way of preserving the string I need to return on the second call without writing it to a file or burying it in the registry. Serialising the string doesn't help because you still need to write an external file. I'm looking for some way to hold it in memory. I've Googled all the variations I can think of but there's nothing really useful.

It's interesting to note that the default IA Dotnet plugin template uses a constant string value so it doesn't have the same problem. I won't have a problem when building or installing a setup as the plugin uses totally different methods; only the IDE interaction is the issue.

Any ideas?
Peter. Smartly dressed, he still resembles an unmade bed.
InstallAware MVP

christ23
Posts: 82
Joined: Mon Jan 16, 2012 4:51 am

Re: Dotnet plugin: An interesting problem I'd like advice on

Postby christ23 » Thu Nov 08, 2012 10:05 am

Bokkie,

no - you do not have to go the way with the .txt file.
The thing you mentioned (the static string) is close to the solution.

This is how i am doing it:

Code: Select all

 [ComVisible(true), GuidAttribute("9C7B484A-EFE1-45B2-ADE6-042601741914")]
    public class Ide
    {
        // define the variables you want to store
        // this variable is stored in the CompileTimeBuild(...), State variable
        string TestString = "";
         ....
         ....
public int DesignTimeEdit(uint window, string state, ref string newState, bool displayDialog)
        {
            System.Diagnostics.Debugger.Launch();
            if (displayDialog)
            {
               //  ... (do your logic here. I am opening a dialog an put my information
               //       into a serializable class (because i want to store more than ONE string).)
                String xml = SerializeToXmlString(myTestclass1);
                TestString = xml.Replace("\r\n", "$NEWLINE$");  //remember to replace the \rn with $NEWLINE$ !!
                return TestString.Length;  //first return the length
           }
           else
           {
             newState = TestString;
             return 0;
           }
       }


bokkie
Posts: 767
Joined: Sun Feb 08, 2009 6:30 am

Re: Dotnet plugin: An interesting problem I'd like advice on

Postby bokkie » Thu Nov 08, 2012 4:11 pm

I'm losing it all somewhere.

When I drag the plugin onto MSIcode a new instance of the Ide class is created. Calls to DesignTimeEdit work okay.

Eventually, DesignTimeText gets called and that also creates a new instance of the Ide class meaning I don't have the state from the first available to the second. If I write the state from the first to the registry I can pick it up in the second and all is well.

In the morning, I'll take a new plugin and see what's happening in that one. I've obviously messed something up.

Edit: My bad! I bury my head in shame. I compared my source to a backup of a few days ago. The all important statement to save the state between calls was in the code but I never got to the point where I could test it. I placed it in a chunk of code among some trace statements and I deleted them as I didn't want them anymore, hence the null value between calls. Doh! :oops: Once I put it back in and removed the registry access it all worked just fine and dandy. I never knew about System.Diagnostics.Debugger.Launch. Boy, does that make things so much easier to debug. Until now, I'd been populating my code with message boxes. I can now move on to the next phase. :)
Peter. Smartly dressed, he still resembles an unmade bed.
InstallAware MVP

christ23
Posts: 82
Joined: Mon Jan 16, 2012 4:51 am

Re: Dotnet plugin: An interesting problem I'd like advice on

Postby christ23 » Fri Nov 09, 2012 1:52 am

Bokkie,

fine that you got it up and running.

One question i have is, what do you mean with "The all important statement to save the state between calls was in the code but I never got to the point where I could test it" ?

Edit : "System.Diagnostics.Debugger.Launch(); is a nice thing, he? ;)

bokkie
Posts: 767
Joined: Sun Feb 08, 2009 6:30 am

Re: Dotnet plugin: An interesting problem I'd like advice on

Postby bokkie » Fri Nov 09, 2012 2:24 am

One question i have is, what do you mean with "The all important statement to save the state between calls was in the code but I never got to the point where I could test it" ?


I have a static string that I use to store the text that IA requires. Like you know, DesignTimeEdit returns the length on the first call, and the actual text on the second. I use the static string to hold the text between the two calls. I was storing the text correctly but at the time I was not in a position to test it to see if it had what I was expecting. It's assignment was in a block of debugging code which I deleted. I never noticed that I deleted the assignment as well so it was always null. That's why I thought there was a state problem between the calls so I stored it in the registry. That did not feel right but I was convinced I did everything right.

As they say; if you don't learn from history you make the same mistakes as you did in the past. :)
Peter. Smartly dressed, he still resembles an unmade bed.
InstallAware MVP

FrancescoT
Site Admin
Posts: 5361
Joined: Sun Aug 22, 2010 4:28 am

Re: Dotnet plugin: An interesting problem I'd like advice on

Postby FrancescoT » Fri Nov 09, 2012 11:49 am

Dear Bokkie,

I am not quite shure if I understood correctly your question.

Your target is to share data between different calls in IA script of the same plugin?

Let me know.

Regards
Francesco Toscano
InstallAware Software

White Papers (HowTos) - http://www.installaware.com/publication ... papers.htm
Publications - http://www.installaware.com/publications-review.htm
InstallAware Help -F1 anywhere in the InstallAware IDE

bokkie
Posts: 767
Joined: Sun Feb 08, 2009 6:30 am

Re: Dotnet plugin: An interesting problem I'd like advice on

Postby bokkie » Fri Nov 09, 2012 12:55 pm

Francesco,

All is okay. I was losing the text between the calls. It was my problem and it's working okay now. I don't need to share data between the plugins. Instead I was losing data in the same plugin. I've fixed it now and my plugin feeds data back to IA and it receives what IA sends to the plugin when you edit it in the MSIcode. In other words, it behaves like a plugin should! :)
Peter. Smartly dressed, he still resembles an unmade bed.
InstallAware MVP

FrancescoT
Site Admin
Posts: 5361
Joined: Sun Aug 22, 2010 4:28 am

Re: Dotnet plugin: An interesting problem I'd like advice on

Postby FrancescoT » Fri Nov 09, 2012 12:59 pm

Happy that you solved :D :D :D !
Francesco Toscano
InstallAware Software

White Papers (HowTos) - http://www.installaware.com/publication ... papers.htm
Publications - http://www.installaware.com/publications-review.htm
InstallAware Help -F1 anywhere in the InstallAware IDE


Return to “Plug-In Development”

Who is online

Users browsing this forum: No registered users and 2 guests