protected override void OnStart(string[] args)
        {
            var fn = Method.fn();
            Trace.WriteLine("{0}.{1}", this.GetType().FullName, fn);

            var configuration = new ScheduledJobsWorkerConfiguration(new ScheduledJobsWorkerConfigurationLoader(), args);
            scheduledJobsWorker = new ScheduledJobsWorker(configuration);

            base.OnStart(args);
        }
        public ScheduledJobsWorker(ScheduledJobsWorkerConfiguration configuration)
        {
            Contract.Requires(configuration.IsValid());

            this.configuration = configuration;

            Trace.WriteLine(Method.fn());

            var result = false;

            try
            {
                Trace.WriteLine("Uri: '{0}'", configuration.Uri.AbsoluteUri, "");

                // connect to Appclusive server
                var baseUri = new Uri(string.Format("{0}api", configuration.Uri.AbsoluteUri));
                endpoints = new AppclusiveEndpoints(baseUri, configuration.Credential);

                // initialise each plugin
                foreach (var plugin in configuration.Plugins)
                {
                    try
                    {
                        Trace.WriteLine("Initialising plugin '{0}' [{1}, {2}] ...", plugin.Metadata.Type, plugin.Metadata.Role, plugin.Metadata.Priority);

                        var pluginParameters = new DictionaryParameters
                        {
                            {typeof(AppclusiveEndpoints).ToString(), endpoints}
                        };
                        plugin.Value.Initialise(pluginParameters, configuration.Logger, true);

                        Trace.WriteLine
                        (
                            "Initialising plugin '{0}' [{1}, {2}] COMPLETED. IsInitialised {3}. IsActive {4}."
                            , 
                            plugin.Metadata.Type, plugin.Metadata.Role, plugin.Metadata.Priority
                            ,
                            plugin.Value.IsInitialised, plugin.Value.IsActive
                        );
                    }
                    catch (Exception ex)
                    {
                        var message = string.Format("Initialising plugin '{0}' [{1}, {2}] FAILED.", plugin.Metadata.Type, plugin.Metadata.Role, plugin.Metadata.Priority);
                        Trace.WriteException(message, ex);
                    }
                }

                // get all defined scheduled jobs for all tenants (based on credentials)
                result = GetScheduledJobs();

                // create the timer to process all scheduled jobs periodically
                stateTimer = new ScheduledJobsWorkerTimerFactory().CreateTimer(new TimerCallback(RunJobs), null, 1000, 1000 * 60);
            }
            catch (Exception ex)
            {
                Trace.WriteException(ex.Message, ex);
                throw;
            }

            this.isInitialised = result;
            this.IsActive = result;
        
            return;
        }