I have an Umbraco (v4.7) site installed on localhost.
I need to do an action (let's say log to console or file) every time a umbraco node is published.
So I need to interact with an external application (like Console or Windows Service) from an Umbraco site...
I don't need to manipulate umbraco site with a console application, but rather respond to umbraco events with a console(or windos servie) application action.
I have
public class ContentEvents : umbraco.BusinessLogic.ApplicationBase
{
void PlumbEvents()
{
// ...
Document.AfterPublish += new Document.PublishEventHandler(
Document_AfterPublish);
// ...
}
void Document_AfterPublish(Document sender, PublishEventArgs e)
{
// HERE I NEEDD TO CALL BY EG
// "MyExternalApplication" + "sender" as parameter
// where "MyExternalApplication" could be
// a ConsoleApplication or a WindowsService
}
// ...
}
is it possible to call something external from that code?
What you're trying to do is not really possible. What you would do instead is create your separate application with some kind of listener that you can trigger from the umbraco application.
Events are raised inside umbraco whenever an action occur and you can create custom code that triggers on those events (like in your example). If you are doing something pretty simple (as logging published nodes to a log file) I would suggest you just do it directly inside your umbraco web process on that specific event instead of overcomplicating things.
However if you really need to do something more advanced that can not be done from within your umbraco process, I would suggest coding an app that listens for events and then connecting to that app/triggering events by hitting a webservice inside that app (or something similar to this), using the umbraco event handlers.
You may be able to do some interprocess calls to actually achieve what you initially asked for but I'd say it's more trouble than it is worth. The web service/http listener solution would also allow you to separate out the application from the web server running the umbraco instance, in case you need to run this on two separate machines.
Another way of doing it could be to queue events in a message queue outside umbraco and then watch this message queue from your own application. I'm not sure how advanced your solution should be however and this might be a bit out of scope!