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();
        }
        /// <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);
        }