Error when registering a trigger

Jul 26, 2011 at 1:59 AM

Perhaps I'm going about this incorrectly, but without any examples I didn't have much to go on. I'm trying to register some triggers that when an object is changed or deleted I throw a copy of the entity in another table that I use later on to synchronize via a web service.

When I call RegisterTrigger Sterling seems to intialize a new instance of itself and I get the error "The operation Activate() is not allowed. A Sterling engine is already active for this application. You must dispose the engine before activating a new one."

My trigger code is as follows:

public class ProjectTrigger : BaseSterlingTrigger<Project, Guid>
    {
        public ProjectTrigger()
        {

        }
        
        public override bool BeforeSave(Project instance)
        {
            return true;
        }

        public override void AfterSave(Project instance)
        {
		MojoServices.Instance.DataManager.RevisionManager.RevisionHistory.ObjectSaved(instance);
        }

        public override bool BeforeDelete(Guid key)
        {
            Project projectToDelete = MojoServices.Instance.DataManager.Database.Load<Project>(key);
            
            MojoServices.Instance.DataManager.RevisionManager.RevisionHistory.ObjectDeleted(projectToDelete);
            
            return true;
        }
    }

And here's the code how I register the trigger:

MojoServices.Instance.DataManager.Database.RegisterTrigger(new ProjectTrigger());

When I make the call the database is initialized and activated.

Coordinator
Jul 26, 2011 at 10:56 AM

Seems like maybe there is a conflict in your singleton code causing the issue. Why not keep a reference to the database in the trigger and pass the instance into the constructor, and see if that works better for you?

Jul 26, 2011 at 2:13 PM

Okay, I passs in the ISterlingDatabaseInstance to the constructor and try to register inside of that. Same issue. The second .RegisterTrigger is hit the .Active() method on the database is called. I can't even single step into it.

Do you have any projects with a trigger in them that I might be able to take a look at? What about a Test project I can try running? I couldn't find the method used at all in the solution in the repository.

Thanks for your help!

Coordinator
Jul 26, 2011 at 2:15 PM

Which version of Sterling are you using? Triggers are commented out in the test version for the phone due to errors in the test harness. They exist for the other versions however. You can also download the reference example included in the source download - the recipe database uses triggers.