Пример #1
0
        protected override void OnStart(string[] args)
        {
            this.log.Debug(string.Format(VolMixerHelper.BASE_METHOD_ENTERING_LOG, nameof(VolMixerService), nameof(OnStart)));

            string portname = ConfigurationManager.AppSettings["Portname"];

            if (string.IsNullOrEmpty(portname))
            {
                log.Error("Portname value in app config is null");
                return;
            }

            string deviceName = ConfigurationManager.AppSettings["DeviceName"];

            if (string.IsNullOrEmpty(deviceName))
            {
                log.Error("DeviceName value in app config is null");
            }

            int baudrate;

            if (int.TryParse(ConfigurationManager.AppSettings["Baudrate"], out baudrate) == false)
            {
                log.Error("unable to parse config key: 'Baudrate' to int");
                return;
            }

            int maxRetries;

            if (int.TryParse(ConfigurationManager.AppSettings["MaxRetries"], out maxRetries) == false)
            {
                log.Error("unable to parse config key: 'MaxRetries' to int");
                return;
            }

            IDictionary <string, string>       pinMapping = ReadPortMappingFromConfig();
            IDictionary <string, IList <int> > processMapping;

            if (VolMixerHelper.TryCreateProcessMapping(log, pinMapping, deviceName, out processMapping) == false)
            {
                log.Error("unable to initialize process mapping - terminating");
                return;
            }

            VolMixerConfig volMixerConfig = new VolMixerConfig(portname, baudrate, maxRetries, deviceName, pinMapping, processMapping);

            Components.VolMixer volMixer = new Components.VolMixer(log, volMixerConfig);
            workerThread = new Thread(volMixer.Run);

            this.log.Info(string.Format("starting service: {0}", nameof(VolMixerService)));
            workerThread.Start();

            this.log.Debug(string.Format(VolMixerHelper.BASE_METHOD_LEAVING_LOG, nameof(VolMixerService), nameof(OnStart)));
        }
Пример #2
0
        static void Main(string[] args)
        {
            ILog log = LogManager.GetLogger(nameof(Components.VolMixer));

            if (log == null)
            {
                throw new Exception("unable to initialize logger - terminating");
            }

            string portname = ConfigurationManager.AppSettings["Portname"];

            if (string.IsNullOrEmpty(portname))
            {
                log.Error("Portname value in app config is null - terminating");
                return;
            }

            string deviceName = ConfigurationManager.AppSettings["DeviceName"];

            if (string.IsNullOrEmpty(deviceName))
            {
                log.Error("DeviceName value in app config is null - terminating");
            }

            int baudrate;

            if (int.TryParse(ConfigurationManager.AppSettings["Baudrate"], out baudrate) == false)
            {
                log.Error("unable to parse config key: 'Baudrate' to int - terminating");
                return;
            }

            int maxRetries;

            if (int.TryParse(ConfigurationManager.AppSettings["MaxRetries"], out maxRetries) == false)
            {
                log.Error("unable to parse config key: 'MaxRetries' to int - terminating");
                return;
            }

            IDictionary <string, string>       pinMapping = ReadPortMappingFromConfig();
            IDictionary <string, IList <int> > processMapping;

            if (VolMixerHelper.TryCreateProcessMapping(log, pinMapping, deviceName, out processMapping) == false)
            {
                log.Error("unable to initialize process mapping - terminating");
                return;
            }

            VolMixerConfig volMixerConfig = new VolMixerConfig(portname, baudrate, maxRetries, deviceName, pinMapping, processMapping);

            Components.VolMixer volMixer = new Components.VolMixer(log, volMixerConfig);
            try
            {
                volMixer.Run();
            }
            catch (Exception e)
            {
                log.Error(string.Format("error while running {0}", nameof(Components.VolMixer)), e);
            }
        }