Exemplo n.º 1
0
        protected override void OnStart(OnStartServiceArgs args)
        {
            TraceLog.Initialize(Logger);
            EventLog.Initialize(Logger);

            ObjectConfigurator.Configurator.CustomItemTypes.Add(new TokenSelectionConfigurationItemType());
            ObjectConfigurator.Configurator.CustomItemTypes.Add(new XrmUriConfigurationItemType());
            ObjectConfigurator.Configurator.CustomItemTypes.Add(new UriConfigurationItemType());

            broker = new XRouter.Broker.BrokerService();
            processor = new XRouter.Processor.ProcessorService();
            gateway = new XRouter.Gateway.Gateway();

            string processorName = args.Settings[SectionKey_Processor].Parameters[SettingsKey_ComponentName];
            string gatewayName = args.Settings[SectionKey_Gateway].Parameters[SettingsKey_ComponentName];
            string connectionString = args.Settings[SectionKey_Broker].Parameters[SettingsKey_ConnectionString];

            broker.Start(
                connectionString,
                new[] { new GatewayProvider(gatewayName, gateway) },
                new[] { new ProcessorProvider(processorName, processor) }
            );

            processor.Start(processorName, broker);
            gateway.Start(gatewayName, broker);
        }
Exemplo n.º 2
0
        protected override void OnStart(OnStartServiceArgs args)
        {
            // event log
            this.Logger.Event.LogInfo(String.Format("ServiceName={0} IsDebugMode={1}",
                args.ServiceName, args.IsDebugMode));

            // get settings
            response = args.Settings["section"].Parameters["response"];

            // initialize and start the service thread
            thread = new Thread(new ThreadStart(this.ServiceLoop));
            thread.Start();
        }
Exemplo n.º 3
0
        protected override void OnStart(OnStartServiceArgs args)
        {
            XRouter.Common.TraceLog.Initialize(this.Logger);
            XRouter.Common.EventLog.Initialize(this.Logger);

            // managedService (required)
            string serviceName = args.Settings.Parameters["managedServiceName"].Trim();
            if (serviceName == null)
            {
                throw new ArgumentNullException("managedServiceName");
            }

            // E-MailSender (optional)
            EMailSender emailSender = null;
            if (args.Settings["email"] != null)
            {
                emailSender = CreateEmailSender(args);
            }
            else
            {
                this.Logger.Trace.LogWarning("E-mail notification sender has not been initialized.");
            }

            // Storages (required)
            StoragesInfo storagesInfo = CreateStoragesInfo(args);

            // Reporter (required)
            this.reporter = CreateReporter(serviceName, args, storagesInfo, emailSender);

            // ServiceWatcher (required)
            this.watcher = CreateServiceWatcher(serviceName, args, emailSender);

            // ConsoleServer (required)
            this.consoleServer = CreateConsoleServer(serviceName, args, this.watcher, storagesInfo);

            // start servers
            this.watcher.Start();
            this.consoleServer.Start();
            this.reporter.Start();
        }
Exemplo n.º 4
0
        protected override void OnStart(OnStartServiceArgs args)
        {
            // event log
            this.Logger.Event.LogInfo(String.Format("ServiceName={0} IsDebugMode={1}",
                args.ServiceName, args.IsDebugMode));

            // get settings
            int interval = 0;
            try
            {
                interval = Convert.ToInt32(args.Settings["timer"].Parameters["interval"]);
            }
            catch (Exception e)
            {
                this.Logger.Event.LogError(String.Format("Settings are invalid! {0}", e.Message));
                throw e;
            }

            // initialize and start timer
            this.timer = new Thread(new ParameterizedThreadStart(this.ServiceLoop));
            this.mreStopPending = new ManualResetEvent(false);
            this.timer.Start(interval);
        }
Exemplo n.º 5
0
        protected override void OnStart(OnStartServiceArgs args)
        {
            // event log
            this.Logger.Event.LogInfo(String.Format("ServiceName={0} IsDebugMode={1}",
                args.ServiceName, args.IsDebugMode));

            // get settings
            int messageCount = 0;
            int messageLength = 0;
            try
            {
                messageCount = Convert.ToInt32(args.Settings.Parameters["messageCount"]);
                messageLength = Convert.ToInt32(args.Settings.Parameters["messageLength"]);
            }
            catch (Exception e)
            {
                this.Logger.Event.LogError(String.Format("Settings are invalid! {0}", e.Message));
                throw e;
            }

            string message = GenerateMessage(messageLength);

            Stopwatch stopwatch = Stopwatch.StartNew();

            for (int i = 0; i < messageCount; i++)
            {
                this.Logger.Trace.LogInfo(message);
            }

            stopwatch.Stop();

            this.Logger.Event.LogInfo(String.Format(
                "Logged {0} trace log events with messages of {1} bytes in {2} ms, average {3} ms/record",
                messageCount, messageLength, stopwatch.ElapsedMilliseconds,
                stopwatch.ElapsedMilliseconds / (float)messageCount));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Starts the service.
        /// </summary>
        /// <remarks>
        /// OnStart() hook methods (from this and/or derived classes) are
        /// called upon starting the service.
        /// </remarks>
        /// <param name="serviceName">Service name. Must not be null.</param>
        /// <param name="isDebugMode">Indicates whether the service should run
        /// in debug mode (true) or as a true NT service (false).</param>
        /// <param name="logger">Instance of logger. Must not be null.</param>
        /// <param name="settings">Service settings. Must not be null.</param>
        internal void Start(
            string serviceName,
            bool isDebugMode,
            DaemonNT.Logging.Logger logger,
            DaemonNT.Configuration.Settings settings)
        {
            // prepare start args
            OnStartServiceArgs args = new OnStartServiceArgs()
            {
                ServiceName = serviceName,
                IsDebugMode = isDebugMode,
                Settings = settings
            };

            // start service
            this.Logger.Event.LogInfo(string.Format(
                "The '{0}' service is being started...", args.ServiceName));

            this.OnStart(args);

            this.Logger.Event.LogInfo(string.Format(
                "The '{0}' service has beed started successfully!",
                args.ServiceName));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Creates and initializes a console server.
        /// </summary>
        /// <param name="serviceName"></param>
        /// <param name="args"></param>
        /// <param name="watcher"></param>
        /// <param name="storagesInfo"></param>
        /// <returns></returns>
        private static ConsoleServer CreateConsoleServer(
            string serviceName,
            OnStartServiceArgs args,
            Watcher watcher,
            StoragesInfo storagesInfo)
        {
            if (args.Settings["console"] == null)
            {
                throw new ArgumentNullException("console");
            }

            // Web service URI (required)
            string uri = args.Settings["console"].Parameters["uri"].Trim();
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }

            // Metadata web service URI (required)
            string metadataUri = args.Settings["console"].Parameters["metadataUri"].Trim();
            if (uri == null)
            {
                throw new ArgumentNullException("metadataUri");
            }

            return new ConsoleServer(serviceName, args.IsDebugMode, uri, metadataUri, storagesInfo, watcher);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates and initializes a storage information provider.
        /// </summary>
        /// <param name="args">service arguments with settings</param>
        /// <returns>StoragesInfo instance</returns>
        private static StoragesInfo CreateStoragesInfo(OnStartServiceArgs args)
        {
            if (args.Settings["storages"] == null)
            {
                throw new ArgumentNullException("storages");
            }

            // Connection String
            string connectionString = args.Settings["storages"].Parameters["connectionString"].Trim();
            if (connectionString == null)
            {
                throw new ArgumentNullException("connectionString");
            }

            // Logs
            string logs = args.Settings["storages"].Parameters["logs"].Trim();

            return new StoragesInfo(connectionString, logs);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates and initializes a service watcher.
        /// </summary>
        /// <param name="serviceName"></param>
        /// <param name="args"></param>
        /// <param name="sender"></param>
        /// <returns></returns>
        private static Watcher CreateServiceWatcher(
            string serviceName,
            OnStartServiceArgs args,
            EMailSender sender)
        {
            if (args.Settings["watcher"] == null)
            {
                throw new ArgumentNullException("watcher");
            }

            // Auto-restart enabled (required)
            string autoRestartEnabledStr = args.Settings["watcher"].Parameters["autoStartEnabled"].Trim();
            if (autoRestartEnabledStr == null)
            {
                throw new ArgumentNullException("autoStartEnabled");
            }
            bool autoStartEnabled = Convert.ToBoolean(autoRestartEnabledStr);

            return new Watcher(serviceName, args.IsDebugMode, autoStartEnabled, sender);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Creates and initializes a reporter.
        /// </summary>
        /// <param name="serviceName"></param>
        /// <param name="args"></param>
        /// <param name="storagesInfo"></param>
        /// <param name="sender"></param>
        /// <returns></returns>
        private static Reporter CreateReporter(
            string serviceName,
            OnStartServiceArgs args,
            StoragesInfo storagesInfo,
            EMailSender sender)
        {
            if (args.Settings["reporter"] == null)
            {
                throw new ArgumentNullException("reporter");
            }

            // Time (required)
            string time = args.Settings["reporter"].Parameters["time"].Trim();
            if (time == null)
            {
                throw new ArgumentNullException("time");
            }
            TimeSpan timeSpan = TimeSpan.Parse(time);

            return new Reporter(serviceName, storagesInfo, sender, timeSpan);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Create and initialize an e-mail sender.
        /// </summary>
        /// <param name="args">service arguments with settings</param>
        /// <returns>EMailSender instance</returns>
        private static EMailSender CreateEmailSender(OnStartServiceArgs args)
        {
            // SMTP host
            string smtpHost = args.Settings["email"].Parameters["smtpHost"].Trim();
            if (smtpHost == null)
            {
                throw new ArgumentNullException("smtpHost");
            }

            // SMTP port (optional)
            string smtpPort = args.Settings["email"].Parameters["smtpPort"].Trim();
            int? port = null;
            if (smtpPort != null)
            {
                port = Convert.ToInt32(smtpPort);
            }

            // From
            string from = args.Settings["email"].Parameters["from"].Trim();
            if (from == null)
            {
                throw new ArgumentNullException("from");
            }
            System.Net.Mail.MailAddress fromAddress = new System.Net.Mail.MailAddress(from);

            // To
            string to = args.Settings["email"].Parameters["to"].Trim();
            if (to == null)
            {
                throw new ArgumentNullException("to");
            }
            System.Net.Mail.MailAddress toAddress = new System.Net.Mail.MailAddress(to);

            return new EMailSender(smtpHost, port, fromAddress, toAddress);
        }
Exemplo n.º 12
0
 /// <summary>
 /// A hook method which is called just when the Service has been
 /// started. It is intended to be implemented in a derived class.
 /// </summary>
 /// <remarks>
 /// <para>
 /// Typically, in this method a new thread with a service loop should
 /// be started. This method should not run indefinitely long, it is
 /// meant just for initialization.
 /// </para>
 /// <para>
 /// In derived classes it is not necessary to call base.OnStart().
 /// </para>
 /// </remarks>
 /// <param name="args">Arguments for starting the service.</param>
 protected virtual void OnStart(OnStartServiceArgs args)
 {
 }