Question

How to execute custom logic on app start

Hi,

 

Curious if there is a way to execute custom logic (business process or some source code) when Creatio app starts?

 

Use case: I need to subscribe for a service bus queue to listen for a new messages everytime Creatio is starting.

Like 0

Like

2 comments
Best reply

You can create a class that inherits from AppEventListenerBase and override OnAppStart. Something like this (you can name the class whatever you want, it doesn't have to be called CustomAppEventListener):

namespace Terrasoft.Configuration
{
    using Common;
    using Core;
    using Web.Common;
 
    public class CustomAppEventListener : AppEventListenerBase
    {
        protected UserConnection UserConnection
        {
            get;
            private set;
        }
 
        protected UserConnection GetUserConnection(AppEventContext context)
        {
            var appConnection = context.Application["AppConnection"] as AppConnection;
            if (appConnection == null)
            {
                throw new ArgumentNullOrEmptyException("AppConnection");
            }
            return appConnection.SystemUserConnection;
        }
 
        public override void OnAppStart(AppEventContext context)
        {
            base.OnAppStart(context);
            UserConnection = GetUserConnection(context);
 
            // DO SOMETHING ON START UP HERE!
        }
    }
}

Ryan

You can create a class that inherits from AppEventListenerBase and override OnAppStart. Something like this (you can name the class whatever you want, it doesn't have to be called CustomAppEventListener):

namespace Terrasoft.Configuration
{
    using Common;
    using Core;
    using Web.Common;
 
    public class CustomAppEventListener : AppEventListenerBase
    {
        protected UserConnection UserConnection
        {
            get;
            private set;
        }
 
        protected UserConnection GetUserConnection(AppEventContext context)
        {
            var appConnection = context.Application["AppConnection"] as AppConnection;
            if (appConnection == null)
            {
                throw new ArgumentNullOrEmptyException("AppConnection");
            }
            return appConnection.SystemUserConnection;
        }
 
        public override void OnAppStart(AppEventContext context)
        {
            base.OnAppStart(context);
            UserConnection = GetUserConnection(context);
 
            // DO SOMETHING ON START UP HERE!
        }
    }
}

Ryan

thanks Ryan!

Show all comments