System.Addin , Call Host From Addin

B

bivoauc

I am currently working with the System.Addin system. I have created my plugin
and everything is working but I am having a problem with one thing I wish to
do. It is easy to have the host send items to the Addin Assembly, but how can
I send messages from the Plugin Assembly.

I tried adding a Register Method to my Interface and Implementing in on the
Plugin side.

void RegisterMessenger(IMessenger messenger);

-- IMessenger

public interface IMessenger
{
void WriteMessage(string message);
}

[Serializable]
public class SimpleMessenger : IMessenger
{
public void WriteMessage(string msg)
{
Console.Writeline(msg);
}
}

Then on the host after activating my Token I would then register my
messenger with the plugin

== host ==
SimpleMessenger sm = new SimpeMessenger();
MyAddin myaddin = token.Activate<MyAddin>(AddInSecurityLevel.FullTrust);
myaddin.RegisterMessenger(sm);


== Addin ==

[AddIn("MyAddin", Version="1.0")]
public class MyAddin : MyContract
{
public void RegisterMessenger(IMessenger msg)
{
msg.WriteMessage("Plugins RegisterMessenger called");
}
}

That is not all of the code but the Idea on how I tried send messages back
to the host which did not work. Is there an easy way built in to the
System.Addin framework to do this? If not then how should I go about this. I
know there is Remoting , which I am not familiar with. I also looked at
sending messages through the XDMessaging library, but this will eventually
be a web app. Any help on this would be appreciated.
 
J

Jialiang Ge [MSFT]

Hello,

From your post, my understanding on this issue is: you wonder how to send
messages, or manipulate host (If I understand it correctly), from the addin
side in the communication pipeline between Host and Add-in. If I'm off
base, please feel free to let me know.

According to the MSDN blog .NET Application Extensibility Part1, 2
http://msdn.microsoft.com/msdnmag/issues/07/02/CLRInsideOut/default.aspx?loc
=en
http://msdn.microsoft.com/msdnmag/issues/07/03/CLRInsideOut/default.aspx
there are three categories of the communication:
1. The add-in provides a service to the host application. That is to say
Host call Add-in's method
2. The host offers its behavior to the add-in and lets the add-in define
how it automates the host. In this scenario, the host is really providing a
service to the add-in. Most Microsoft? Office add-ins fall under this
category: upon initialization of the add-in, the Office application will
pass its root object to the add-in, allowing it to automate the host.
3. add-ins that use the host mainly for screen real-estate rather than any
host-specific functionality

Based on my understanding of your question, I think the 2nd category fits
your request. That is to say, the add-in is able to automate the host
application, like setting data, invoking a host side event, calling a host
side method, etc. Take the Office automation as an example, Office add-ins
are able to manipulate Office documents because Office host passes its
object (Application object) to add-in, and add-in is able to operate the
host using the Application object. Therefore, in order to accomplish your
request, we need to pass the host object to the add-in with a interface
defined in Contract/Adapters/Views. When the add-in get the host object, it
can directly call host's method/event/property to set values, and so on.

Please let me know if I understand you question correctly, or if you have
any other concerns.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
For MSDN subscribers whose posts are left unanswered, please check this
document: http://blogs.msdn.com/msdnts/pages/postingAlias.aspx

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express/Windows Mail, please make sure
you clear the check box "Tools/Options/Read: Get 300 headers at a time" to
see your reply promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jialiang Ge [MSFT]

Hi,

Would you mind letting me know the result of the suggestions? If you need
further assistance, feel free to let me know. I will be more than happy to
be of assistance.

Have a great day!

Sincerely,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top