I need to run one of my macro when a page is published. I there any way to do this in umbraco
There are some events you can hook into. In your case you might use the Document_AfterPublish() event.
static void Document_AfterPublish(Document sender,
umbraco.cms.businesslogic.PublishEventArgs e)
{
// your code
}
// hook into the event
Document.AfterPublish +=
new Document.PublishEventHandler(Document_AfterPublish);
Also look at this and this links which could be helpful.
Related
How to check in Vaadin 7 if scrollbar is visible or not for a certain component, for example for Panel
Any implementation of AbstractClientConnector can be extended with AbstractExtension: https://vaadin.com/api/com/vaadin/server/AbstractExtension.html
An extension is a possible way to extend the functionality of your component: https://vaadin.com/docs/-/part/framework/gwt/gwt-extension.html
Adding features to existing components by extending them by inheritance creates a problem when you want to combine such features. For example, one add-on could add spell-check to a TextField, while another could add client-side validation. Combining such add-on features would be difficult if not impossible. You might also want to add a feature to several or even to all components, but extending all of them by inheritance is not really an option. Vaadin includes a component plug-in mechanism for these purposes. Such plug-ins are simply called extensions.
In the client-side extension implementation you can write your custom GWT code like following (pseudo code):
#Override
protected void extend(ServerConnector target) {
// Get the extended widget
final Widget widget = ((ComponentConnector) target).getWidget();
// register RPCs
YourServerRpcImplementation serverRpc = getRpcProxy(YourServerRpcImplementation.class); // client to server
registerRpc(YourClientRpcImplementation.class, this); // server to client, unused in this example
// add listener and update server state
Window.addResizeHandler(new ResizeHandler() {
#Override
public void onResize(ResizeEvent event) {
boolean scrollbarVisible = widget.getElement().getScrollHeight() > widget.getElement().getClientHeight();
serverRpc.yourEventMethod(scrollbarVisible);
}
});
}
Passing events between server and client: https://vaadin.com/docs/-/part/framework/gwt/gwt-rpc.html
It seems like I just need to implement kind of a listener, if there is no something similar already.
Let's say I have a method which is executed each time build finishes (RunListener event); but that's not enough and I want to run the method each X minutes. I'm stuck!
So, I wonder if there is a way to do it (kind of a listener, event trigger, whatever).
Any info, thoughts are welcomed!
If you want to execute a task regularly in a Jenkins plugin, you can implement the PeriodicWork extension point.
A minimal example that would automatically register with Jenkins, and be executed every three minutes:
#Extension
public class MyPeriodicTask extends PeriodicWork {
#Override
public long getRecurrencePeriod() {
return TimeUnit.MINUTES.toMillis(3);
}
#Override
protected void doRun() throws Exception {
// Do something here, quickly.
// If it will take longer, use AsyncPeriodWork instead
}
}
What is the preferred way to remove a default pipeline contributor (OpenRasta 2.0.3)?
I haven't found a lot on that on the net, but one way seems to be writing a custom DependencyRegistrar, i.e. deriving from DefaultDependencyRegistrar and then e.g. overriding AddDefaultContributors(). Apart from that I doubt that it's the best way to remove just a single pipeline contributor, it seems to need additional per-host (ASP vs. InMemory) work, whereas I would consider messing with pipeline handlers to be a host-agnostic affair.
But even if I'd go this route, this guy here seems to have tried it without success: http://groups.google.com/group/openrasta/browse_thread/thread/d72b91e5994f402b
I tried similar things, but so far couldn't make my custom registrar replace the default.
So what's the simplest and best way to remove a default pipeline contributor, preferable in a host agnostic way? Is there a working example somewhere?
No, you just need to derive from the registrar and use the protected members that are available to imperatively remove the types you don't want auto-registered.
The registrar needs to be registered in your container before you provide it to OpenRasta, otherwise the type has been resolved already.
Answering myself with working code snippets as they might be helpful to others.
So it looks like removing default pipeline contributors cannot be done
in a host agnostic way (although I don't see why OpenRasta could not
be modified to allow for easy deletion of handlers in the future).
The 2 classes that need to be written are in fact independent of the
host(s) used:
public class MyDependencyRegistrar : DefaultDependencyRegistrar
{
protected override void AddDefaultContributors()
{
base.AddDefaultContributors();
PipelineContributorTypes.Remove(typeof(HandlerResolverContributor));
// If we remove the only contributor for the 'well-known'
// IHandlerSelection stage, like done above, we need to add
// another one implements IHandlerSelection, otherwise
// we'll run into errors (and what's the point of a pipeline
// without a handler selector anyway?). So let's do that here:
AddPipelineContributor<MyOwnHandlerResolverContributor>();
}
}
In order to make that Registrar available, we need to create an accessor
like the following, which then needs to be set in the various hosts:
public class MyDependencyResolverAccessor : IDependencyResolverAccessor
{
InternalDependencyResolver resolver;
public IDependencyResolver Resolver
{
get
{
if (resolver == null)
{
resolver = new InternalDependencyResolver();
resolver.AddDependency<IDependencyRegistrar, MyDependencyRegistrar>();
}
return resolver;
}
}
}
For Asp.Net, this seems to work for me:
public class Global : System.Web.HttpApplication
{
void Application_Start(object sender, EventArgs e)
{
OpenRastaModule.Host.DependencyResolverAccessor =
new MyDependencyResolverAccessor();
For InMemoryHost, which I use for integration testing and in-process access
of my handlers, I haven't found a way around copying the whole class
InMemoryHost and modifying it to my needs. In fact, we don't need
MyDependencyResolverAccessor in this case, as InMemoryHost implements
IDependencyResolverAccessor already. So here's how it could look like. Only the
last line was actually added to the existing code in InMemoryHost:
public class TwinMemoryHost : IHost, IDependencyResolverAccessor, IDisposable
{
readonly IConfigurationSource _configuration;
bool _isDisposed;
public TwinMemoryHost(IConfigurationSource configuration)
{
_configuration = configuration;
Resolver = new InternalDependencyResolver();
Resolver.AddDependency<IDependencyRegistrar, MyDependencyRegistrar>();
...
Just started doing some code porting from .Net CF to Blackberry JDE 4.6.1. But haven't found how to implement custom events.
I have a custom syncManager that raise events in .Net CF so I can update the UI (sort of the observer patron).
Any pointers or help where I can start?
I can recommend the j2me-observer project. It has a liberal license and will give you an implementation of the observer pattern which isn't included in J2ME. It can be used to allow UI changes to happen based on fired events.
you can send custom event using.
//you can use any int value for CUSTOM_EVENT
fieldChangeNotify(CUSTOM_EVENT);
and you can handle that event using
public void fieldChanged(Field field, int context) {
if(cotext == CUSTOM_EVENT){
Dialog.alert("custom event");
}
}
I can recommend the open source project javaEventing. It's available at http://code.google.com/p/javaeventing , and makes it easy to define, register for and trigger custom events, much like in C#.
An example:
Class MyEvent extends EventManager.EventObject {}
EventManager.registerEventListener(new EventManager.GenericEventListener(){
public void eventTriggered(Object sender, Event event) {
// <-- The event is triggered, do something.
}
}, new MyEvent());
EventManager.triggerEvent(this, new MyEvent()); // <-- Trigger the event
bob
I'm using the Entity Framework classes to make changes to my database like this:
testEntities.Products.AddObject(product);
I've got a ListBox bound to testEntities.Products and it shows them correctly, but when I add a new object and I save the changes (testEntities.SaveChanges()), the product appears into the database, but the ListBox isn't updated.
I really would like that those object collections from the EF would be "observable". Is there a simple way to achieve this?
Thanks a lot!
(I'm using VS.NET 2010)
Just a step away. Try not to use declarative DataSource, but a query instead.
In this case you have better flexibility and full control over the data binding process. Here is a small sample:
private void Form1_Load (object sender, EventArgs e) {
listBox1.DataSource = context.MASTER.Select(m => m.DATA);
}
private void button1_Click (object sender, EventArgs e) {
context.AddToMASTER(new MASTER
{
ID = 5,
DATA = "5"
});
context.SaveChanges();
listBox1.DataSource = context.MASTER.Select(m => m.DATA);
}
You can also put the code of the query into a separate RefreshList method, and simply call this method when you need to refresh the list in the code. That will be convenient also if you have a set of these list boxes and other databound controls.