public void Setup()
 {
     originalAdapter      = LogManager.Adapter;
     loggerFactoryAdapter = new CaptureOutputLoggerFactoryAdapter();
     // LogManager.Adapter = loggerFactoryAdapter;
     exceptionHandlerAdvice = new ExceptionHandlerAdvice();
 }
 public void Setup()
 {
     originalAdapter = LogManager.Adapter;
     loggerFactoryAdapter = new CaptureOutputLoggerFactoryAdapter();
     LogManager.Adapter = loggerFactoryAdapter;
     exceptionHandlerAdvice = new ExceptionHandlerAdvice();
 }
 public LoggingFacility LogUsing <TCustomLoggerFactory>(TCustomLoggerFactory loggerFactory) where TCustomLoggerFactory : ILoggerFactory
 {
     loggerImplementation = LoggerImplementation.Custom;
     loggingFactoryType   = typeof(TCustomLoggerFactory);
     this.loggerFactory   = loggerFactory;
     return(this);
 }
Esempio n. 4
0
        /// <summary>
        /// Builds a <see cref="ILoggerFactoryAdapter"/> instance from the given <see cref="LogSetting"/>
        /// using <see cref="Activator"/>.
        /// </summary>
        /// <param name="setting"></param>
        /// <returns>the <see cref="ILoggerFactoryAdapter"/> instance. Is never <c>null</c></returns>
        private static ILoggerFactoryAdapter BuildLoggerFactoryAdapterFromLogSettings(LogSetting setting)
        {
            ArgUtils.AssertNotNull("setting", setting);
            // already ensured by LogSetting
            //            AssertArgIsAssignable<ILoggerFactoryAdapter>("setting.FactoryAdapterType", setting.FactoryAdapterType
            //                                , "Specified FactoryAdapter does not implement {0}.  Check implementation of class {1}"
            //                                , typeof(ILoggerFactoryAdapter).FullName
            //                                , setting.FactoryAdapterType.AssemblyQualifiedName);

            ILoggerFactoryAdapter adapter = null;

            ArgUtils.Guard(delegate
            {
                if (setting.Properties != null &&
                    setting.Properties.Count > 0)
                {
                    object[] args = { setting.Properties };

                    adapter = (ILoggerFactoryAdapter)Activator.CreateInstance(setting.FactoryAdapterType, args);
                }
                else
                {
                    adapter = (ILoggerFactoryAdapter)Activator.CreateInstance(setting.FactoryAdapterType);
                }
            }
                           , "Unable to create instance of type {0}. Possible explanation is lack of zero arg and single arg NameValueCollection constructors"
                           , setting.FactoryAdapterType.FullName
                           );

            // make sure
            ArgUtils.AssertNotNull("adapter", adapter, "Activator.CreateInstance() returned <null>");
            return(adapter);
        }
Esempio n. 5
0
        /// <summary>
        /// Builds the logger factory adapter.
        /// </summary>
        /// <returns>a factory adapter instance. Is never <c>null</c>.</returns>
        private static ILoggerFactoryAdapter BuildLoggerFactoryAdapter()
        {
#if UNITY3D
            ILoggerFactoryAdapter defaultFactory = new UnityDebugLoggerFactoryAdapter();
            return(defaultFactory);
#else
            object sectionResult = null;

            ArgUtils.Guard(delegate
            {
                sectionResult = ConfigurationReader.GetSection(COMMON_LOGGING_SECTION);
            }
                           , "Failed obtaining configuration for Common.Logging from configuration section 'common/logging'.");

            // configuration reader returned <null>
            if (sectionResult == null)
            {
                string message = (ConfigurationReader.GetType() == typeof(DefaultConfigurationReader))
                                     ? string.Format("no configuration section <{0}> found - suppressing logging output", COMMON_LOGGING_SECTION)
                                     : string.Format("Custom ConfigurationReader '{0}' returned <null> - suppressing logging output", ConfigurationReader.GetType().FullName);
#if PORTABLE
                Debug.WriteLine(message);
#else
                Trace.WriteLine(message);
#endif

                ILoggerFactoryAdapter defaultFactory = new NoOpLoggerFactoryAdapter();
                return(defaultFactory);
            }

            // ready to use ILoggerFactoryAdapter?
            if (sectionResult is ILoggerFactoryAdapter)
            {
#if PORTABLE
                Debug.WriteLine(string.Format("Using ILoggerFactoryAdapter returned from custom ConfigurationReader '{0}'", ConfigurationReader.GetType().FullName));
#else
                Trace.WriteLine(string.Format("Using ILoggerFactoryAdapter returned from custom ConfigurationReader '{0}'", ConfigurationReader.GetType().FullName));
#endif
                return((ILoggerFactoryAdapter)sectionResult);
            }

            // ensure what's left is a LogSetting instance
            ArgUtils.Guard(delegate
            {
                ArgUtils.AssertIsAssignable <LogSetting>("sectionResult", sectionResult.GetType());
            }
                           , "ConfigurationReader {0} returned unknown settings instance of type {1}"
                           , ConfigurationReader.GetType().FullName, sectionResult.GetType().FullName);

            ILoggerFactoryAdapter adapter = null;
            ArgUtils.Guard(delegate
            {
                adapter = BuildLoggerFactoryAdapterFromLogSettings((LogSetting)sectionResult);
            }
                           , "Failed creating LoggerFactoryAdapter from settings");

            return(adapter);
#endif
        }
Esempio n. 6
0
        /// <summary>
        /// Reset the <see cref="Common.Logging" /> infrastructure to its default settings. This means, that configuration settings
        /// will be re-read from section <c>&lt;common/logging&gt;</c> of your <c>app.config</c>.
        /// </summary>
        /// <remarks>
        /// This is mainly used for unit testing, you wouldn't normally use this in your applications.<br/>
        /// <b>Note:</b><see cref="ILog"/> instances already handed out from this LogManager are not(!) affected.
        /// Resetting LogManager only affects new instances being handed out.
        /// </remarks>
        public static void Reset()
        {
#if UNITY3D
            _adapter = BuildLoggerFactoryAdapter();
#else
            Reset(new DefaultConfigurationReader());
#endif
        }
 public TransmitPipe(ILoggerFactoryAdapter loggerFactoryAdapter, IConfiguration configuration, ICommandProcessor commandProcessor, IRegisterContainer registerContainer, GpioPin cePin)
 {
     _configuration = configuration;
     _commandProcessor = commandProcessor;
     _registerContainer = registerContainer;
     _logger = loggerFactoryAdapter.GetLogger(GetType());
     _cePin = cePin;
 }
Esempio n. 8
0
 public ArduinoDetails(IRadio radio, ILoggerFactoryAdapter loggerFactory, IConfiguration configuration, ICommandProcessor commandProcessor, IRegisterContainer registerContainer)
 {
     _radio             = radio;
     _logger            = loggerFactory.GetLogger(GetType());
     _configuration     = configuration;
     _commandProcessor  = commandProcessor;
     _registerContainer = registerContainer;
 }
Esempio n. 9
0
 /// <summary>
 /// 依据LoggerName获取<see cref="API.Logging.ILogger"/>
 /// </summary>
 /// <param name="loggerName">日志名称(例如:log4net的logger配置名称)</param>
 /// <returns><see cref="API.Logging.ILogger"/></returns>
 public static ILogger GetLogger(string loggerName)
 {
     if (_loggerFactoryAdapter == null)
     {
         _loggerFactoryAdapter = new NullLoggerFactoryAdapter();
     }
     return(_loggerFactoryAdapter.GetLogger(loggerName));
 }
 public TransmitPipe(ILoggerFactoryAdapter loggerFactoryAdapter, IConfiguration configuration, ICommandProcessor commandProcessor, IRegisterContainer registerContainer, GpioPin cePin)
 {
     _configuration     = configuration;
     _commandProcessor  = commandProcessor;
     _registerContainer = registerContainer;
     _logger            = loggerFactoryAdapter.GetLogger(GetType());
     _cePin             = cePin;
 }
 public ArduinoDetails(IRadio radio, ILoggerFactoryAdapter loggerFactory, IConfiguration configuration, ICommandProcessor commandProcessor, IRegisterContainer registerContainer)
 {
     _radio = radio;
     _logger = loggerFactory.GetLogger(GetType());
     _configuration = configuration;
     _commandProcessor = commandProcessor;
     _registerContainer = registerContainer;
 }
Esempio n. 12
0
        public static ILog GetCurrentClassLogger()
        {
            StackFrame            frame   = new StackFrame(1, false);
            ILoggerFactoryAdapter adapter = Adapter;
            MethodBase            method  = frame.GetMethod();
            Type declaringType            = method.DeclaringType;

            return(adapter.GetLogger(declaringType));
        }
Esempio n. 13
0
        public LoggerResolver(ILoggerFactoryAdapter loggerFactory)
        {
            if (loggerFactory == null)
            {
                throw new ArgumentNullException("loggerFactory");
            }

            this.loggerFactory = loggerFactory;
        }
Esempio n. 14
0
        public QuartzCronScheduler(Options options, IJobFactory jobFactory, ILoggerFactoryAdapter loggerFactory)
        {
            _options              = options;
            _scheduler            = StdSchedulerFactory.GetDefaultScheduler();
            _scheduler.JobFactory = jobFactory;

            LogManager.Adapter = loggerFactory;
            _logger            = LogManager.GetLogger("Quartz.Net");
        }
 protected PipeRegisterBase(ILoggerFactoryAdapter loggerFactoryAdapter, ICommandProcessor commandProcessor, byte address, byte length, byte[] defaultValue, byte pipeNumber, string name = "") :
     base(loggerFactoryAdapter, commandProcessor, length, address, defaultValue, name)
 {
     PipeNumber = pipeNumber;
     Name       = string.Format("{0}{1}{2}",
                                GetType().Name,
                                PipeNumber,
                                string.IsNullOrEmpty(name) ? "" : string.Format(" ({0})", name));
     Logger = loggerFactoryAdapter.GetLogger(Name);
 }
 protected override void Init()
 {
     if (loggerFactory == null)
     {
         loggerFactory = LogManager.Adapter;
     }
     Kernel.Register(Component.For <ILoggerFactoryAdapter>().NamedAutomatically("iloggerfactory").Instance(loggerFactory));
     Kernel.Register(Component.For <ILog>().NamedAutomatically("ilogger.default").Instance(loggerFactory.GetLogger("Default")));
     Kernel.Resolver.AddSubResolver(new LoggerResolver(loggerFactory));
 }
 protected PipeRegisterBase(ILoggerFactoryAdapter loggerFactoryAdapter, ICommandProcessor commandProcessor, byte address, byte length, byte[] defaultValue, byte pipeNumber, string name = "") :
     base(loggerFactoryAdapter, commandProcessor, length, address, defaultValue, name)
 {
     PipeNumber = pipeNumber;
     Name = string.Format("{0}{1}{2}",
                         GetType().Name,
                         PipeNumber,
                         string.IsNullOrEmpty(name) ? "" : string.Format(" ({0})", name));
     Logger = loggerFactoryAdapter.GetLogger(Name);
 }
 protected override void Init()
 {
     SetUpTypeConverter();
     if (loggerFactory == null)
     {
         loggerFactory = ReadConfigurationAndCreateLoggerFactory();
     }
     RegisterLoggerFactory(loggerFactory);
     RegisterDefaultILogger(loggerFactory);
     RegisterSubResolver(loggerFactory);
 }
 public ReceivePipe(ILoggerFactoryAdapter loggerFactoryAdapter, IConfiguration configuration, ICommandProcessor commandProcessor, IRegisterContainer registerContainer, IReceivePipeCollection parent, int pipeId)
 {
     if (PipeId > 5)
         throw new ArgumentOutOfRangeException(nameof(pipeId), "Invalid PipeId number for this Pipe");
     _logger = loggerFactoryAdapter.GetLogger(string.Format("{0}{1}", GetType().Name, pipeId));
     _configuration = configuration;
     _commandProcessor = commandProcessor;
     _registerContainer = registerContainer;
     _parent = parent;
     PipeId = pipeId;
 }
Esempio n. 20
0
 public ReceivePipeCollection(ILoggerFactoryAdapter loggerFactoryAdapter, IConfiguration configuration, ICommandProcessor commandProcessor, IRegisterContainer registerContainer)
 {
     _registerContainer = registerContainer;
     _commandProcessor  = commandProcessor;
     Add(0, new ReceivePipe(loggerFactoryAdapter, configuration, commandProcessor, registerContainer, this, 0));
     Add(1, new ReceivePipe(loggerFactoryAdapter, configuration, commandProcessor, registerContainer, this, 1));
     Add(2, new ReceivePipe(loggerFactoryAdapter, configuration, commandProcessor, registerContainer, this, 2));
     Add(3, new ReceivePipe(loggerFactoryAdapter, configuration, commandProcessor, registerContainer, this, 3));
     Add(4, new ReceivePipe(loggerFactoryAdapter, configuration, commandProcessor, registerContainer, this, 4));
     Add(5, new ReceivePipe(loggerFactoryAdapter, configuration, commandProcessor, registerContainer, this, 5));
 }
 public AddressPipeRegister(ILoggerFactoryAdapter loggerFactoryAdapter, ICommandProcessor commandProcessor, byte address, byte[] defaultValue, byte pipeNumber, string name = "") :
         base(loggerFactoryAdapter, commandProcessor, address, (byte)(pipeNumber <= 1 ? 5 : 1), defaultValue, pipeNumber, name)
 {
     bool transmitPipe = Address == RegisterAddresses.TX_ADDR;
     Name = string.Format("{0}{1}{2}{3}",
                          transmitPipe ? "Transmit" : "Receive",
                          GetType().Name,
                          transmitPipe ? "" : PipeNumber.ToString(),
                          string.IsNullOrEmpty(name) ? "" : string.Format(" ({0})", name));
     Logger = loggerFactoryAdapter.GetLogger(Name);
 }
 protected RegisterBase(ILoggerFactoryAdapter loggerFactoryAdapter, ICommandProcessor commandProcessor, int length, byte address, byte[] defaultValue, string name = "")
 {
     Logger           = loggerFactoryAdapter.GetLogger(GetType());
     _syncRoot        = new object();
     Buffer           = new byte[length];
     Name             = GetType().Name + (string.IsNullOrEmpty(name) ? "" : string.Format(" ({0})", name));
     CommandProcessor = commandProcessor;
     Length           = length;
     Address          = address;
     DefaultValue     = defaultValue;
     IsDirty          = false;
 }
        public AddressPipeRegister(ILoggerFactoryAdapter loggerFactoryAdapter, ICommandProcessor commandProcessor, byte address, byte[] defaultValue, byte pipeNumber, string name = "") :
            base(loggerFactoryAdapter, commandProcessor, address, (byte)(pipeNumber <= 1 ? 5 : 1), defaultValue, pipeNumber, name)
        {
            bool transmitPipe = Address == RegisterAddresses.TX_ADDR;

            Name = string.Format("{0}{1}{2}{3}",
                                 transmitPipe ? "Transmit" : "Receive",
                                 GetType().Name,
                                 transmitPipe ? "" : PipeNumber.ToString(),
                                 string.IsNullOrEmpty(name) ? "" : string.Format(" ({0})", name));
            Logger = loggerFactoryAdapter.GetLogger(Name);
        }
Esempio n. 24
0
        private static void TestLogging(ILoggerFactoryAdapter factory, string message)
        {
            // set our custom factory adapter
            LogManager.Adapter = factory;

            // obtain logger instance
            ILog log = LogManager.GetCurrentClassLogger();

            // log something
            log.Info(message);
            log.Debug(message);
        }
Esempio n. 25
0
 /// <summary>
 /// Reset the <see cref="Common.Logging" /> infrastructure to its default settings. This means, that configuration settings
 /// will be re-read from section <c>&lt;common/logging&gt;</c> of your <c>app.config</c>.
 /// </summary>
 /// <remarks>
 /// This is mainly used for unit testing, you wouldn't normally use this in your applications.<br/>
 /// <b>Note:</b><see cref="ILog"/> instances already handed out from this LogManager are not(!) affected.
 /// Resetting LogManager only affects new instances being handed out.
 /// </remarks>
 /// <param name="reader">
 /// the <see cref="IConfigurationReader"/> instance to obtain settings for
 /// re-initializing the LogManager.
 /// </param>
 public static void Reset(IConfigurationReader reader)
 {
     lock (_loadLock)
     {
         if (reader == null)
         {
             throw new ArgumentNullException("reader");
         }
         _configurationReader = reader;
         _adapter             = null;
     }
 }
 protected RegisterBase(ILoggerFactoryAdapter loggerFactoryAdapter, ICommandProcessor commandProcessor, int length, byte address, byte[] defaultValue, string name = "")
 {
     Logger = loggerFactoryAdapter.GetLogger(GetType());
     _syncRoot = new object();
     Buffer = new byte[length];
     Name = GetType().Name + (string.IsNullOrEmpty(name) ? "" : string.Format(" ({0})", name));
     CommandProcessor = commandProcessor;
     Length = length;
     Address = address;
     DefaultValue = defaultValue;
     IsDirty = false;
 }
Esempio n. 27
0
        private static void TestLogging(ILoggerFactoryAdapter factory, string message)
        {
            // set our custom factory adapter
            LogManager.Adapter = factory;

            // obtain logger instance
            ILog log = LogManager.GetCurrentClassLogger();

            // log something
            log.Info(message);
            log.Debug(message);
        }
        private static ILoggerFactoryAdapter BuildLoggerFactoryAdapter()
        {
            LogSetting section = null;

            try
            {
                section = (LogSetting)ConfigurationManager.GetSection(IBATIS_SECTION_LOGGING);
            }
            catch (Exception exception)
            {
                ILoggerFactoryAdapter adapter = BuildDefaultLoggerFactoryAdapter();
                adapter.GetLogger(typeof(LogManager)).Warn("Unable to read configuration. Using default logger.", exception);
                return(adapter);
            }
            if ((section != null) && !typeof(ILoggerFactoryAdapter).IsAssignableFrom(section.FactoryAdapterType))
            {
                ILoggerFactoryAdapter adapter2 = BuildDefaultLoggerFactoryAdapter();
                adapter2.GetLogger(typeof(LogManager)).Warn("Type " + section.FactoryAdapterType.FullName + " does not implement ILoggerFactoryAdapter. Using default logger");
                return(adapter2);
            }
            if (section != null)
            {
                if (section.Properties.Count > 0)
                {
                    try
                    {
                        object[] args = new object[] { section.Properties };
                        return((ILoggerFactoryAdapter)Activator.CreateInstance(section.FactoryAdapterType, args));
                    }
                    catch (Exception exception2)
                    {
                        ILoggerFactoryAdapter adapter4 = BuildDefaultLoggerFactoryAdapter();
                        adapter4.GetLogger(typeof(LogManager)).Warn("Unable to create instance of type " + section.FactoryAdapterType.FullName + ". Using default logger.", exception2);
                        return(adapter4);
                    }
                }
                try
                {
                    return((ILoggerFactoryAdapter)Activator.CreateInstance(section.FactoryAdapterType));
                }
                catch (Exception exception3)
                {
                    ILoggerFactoryAdapter adapter5 = BuildDefaultLoggerFactoryAdapter();
                    adapter5.GetLogger(typeof(LogManager)).Warn("Unable to create instance of type " + section.FactoryAdapterType.FullName + ". Using default logger.", exception3);
                    return(adapter5);
                }
            }
            ILoggerFactoryAdapter adapter6 = BuildDefaultLoggerFactoryAdapter();

            adapter6.GetLogger(typeof(LogManager)).Warn("Unable to read configuration IBatisNet/logging. Using default logger.");
            return(adapter6);
        }
Esempio n. 29
0
 public ReceivePipe(ILoggerFactoryAdapter loggerFactoryAdapter, IConfiguration configuration, ICommandProcessor commandProcessor, IRegisterContainer registerContainer, IReceivePipeCollection parent, int pipeId)
 {
     if (PipeId > 5)
     {
         throw new ArgumentOutOfRangeException(nameof(pipeId), "Invalid PipeId number for this Pipe");
     }
     _logger            = loggerFactoryAdapter.GetLogger(string.Format("{0}{1}", GetType().Name, pipeId));
     _configuration     = configuration;
     _commandProcessor  = commandProcessor;
     _registerContainer = registerContainer;
     _parent            = parent;
     PipeId             = pipeId;
 }
        public static void ClassInitialize(TestContext testContext)
        {
            GpioController gpioController = GpioController.GetDefault();
            _irqPin = gpioController.InitGpioPin(25, GpioPinDriveMode.InputPullUp);
            _cePin = gpioController.InitGpioPin(22, GpioPinDriveMode.Output);

            DeviceInformationCollection devicesInfo = DeviceInformation.FindAllAsync(SpiDevice.GetDeviceSelector("SPI0")).GetAwaiter().GetResult();
            _spiDevice = SpiDevice.FromIdAsync(devicesInfo[0].Id, new SpiConnectionSettings(0)).GetAwaiter().GetResult();
            _commandProcessor = new CommandProcessor(_spiDevice); // new MockCommandProcessor();
            _loggerFactoryAdapter = new NoOpLoggerFactoryAdapter();

            _radio = new Radio(_commandProcessor, _loggerFactoryAdapter, _cePin, _irqPin);
        }
Esempio n. 31
0
        /// <summary>
        /// Builds the logger factory adapter.
        /// </summary>
        /// <returns>a factory adapter instance. Is never <c>null</c>.</returns>
        private static ILoggerFactoryAdapter BuildLoggerFactoryAdapter()
        {
            // configuration reader returned <null>
            if (_type == null)
            {
                ILoggerFactoryAdapter defaultFactory = new NoOpLoggerFactoryAdapter();
                return(defaultFactory);
            }

            ILoggerFactoryAdapter adapter = adapter = (ILoggerFactoryAdapter)Activator.CreateInstance(_type);

            return(adapter);
        }
        public Configuration(ILoggerFactoryAdapter loggerFactoryAdapter, ICommandProcessor commandProcessor, IRegisterContainer registerContainer)
        {
            _logger = loggerFactoryAdapter.GetLogger(GetType());
            _commandProcessor = commandProcessor;
            _registerContainer = registerContainer;
            _payloadWidth = Constants.MaxPayloadWidth;

            // Attempt to set DataRate to 250Kbps to determine if this is a plus model
            DataRates oldDataRate = DataRate;
            DataRate = DataRates.DataRate250Kbps;
            _isPlusModel = DataRate == DataRates.DataRate250Kbps;
            DataRate = oldDataRate;

        }
Esempio n. 33
0
        public Configuration(ILoggerFactoryAdapter loggerFactoryAdapter, ICommandProcessor commandProcessor, IRegisterContainer registerContainer)
        {
            _logger            = loggerFactoryAdapter.GetLogger(GetType());
            _commandProcessor  = commandProcessor;
            _registerContainer = registerContainer;
            _payloadWidth      = Constants.MaxPayloadWidth;

            // Attempt to set DataRate to 250Kbps to determine if this is a plus model
            DataRates oldDataRate = DataRate;

            DataRate     = DataRates.DataRate250Kbps;
            _isPlusModel = DataRate == DataRates.DataRate250Kbps;
            DataRate     = oldDataRate;
        }
Esempio n. 34
0
        public static void ClassInitialize(TestContext testContext)
        {
            GpioController gpioController = GpioController.GetDefault();

            _irqPin = gpioController.InitGpioPin(25, GpioPinDriveMode.InputPullUp);
            _cePin  = gpioController.InitGpioPin(22, GpioPinDriveMode.Output);

            DeviceInformationCollection devicesInfo = DeviceInformation.FindAllAsync(SpiDevice.GetDeviceSelector("SPI0")).GetAwaiter().GetResult();

            _spiDevice            = SpiDevice.FromIdAsync(devicesInfo[0].Id, new SpiConnectionSettings(0)).GetAwaiter().GetResult();
            _commandProcessor     = new CommandProcessor(_spiDevice); // new MockCommandProcessor();
            _loggerFactoryAdapter = new NoOpLoggerFactoryAdapter();

            _radio = new Radio(_commandProcessor, _loggerFactoryAdapter, _cePin, _irqPin);
        }
        public Radio(ICommandProcessor commandProcessor, ILoggerFactoryAdapter loggerFactoryAdapter, GpioPin powerPin, GpioPin cePin, GpioPin irqPin = null)
        {
            _syncRoot      = new object();
            _operatingMode = OperatingModes.PowerOff;
            _powerPin      = powerPin;
            _powerPin.Write(GpioPinValue.Low);

            _cePin = cePin;
            _cePin.Write(GpioPinValue.Low);

            _loggerFactoryAdapter = loggerFactoryAdapter;
            _logger = _loggerFactoryAdapter.GetLogger(GetType());

            _commandProcessor = commandProcessor;
            _commandProcessor.LoggerFactory    = _loggerFactoryAdapter;
            _commandProcessor.GetOperatingMode = () => OperatingMode;

            RegisterContainer = new RegisterContainer(_loggerFactoryAdapter, _commandProcessor);
            OperatingMode     = OperatingModes.PowerDown;
            RegisterContainer.ResetRegistersToDefault();

            Configuration = new Configuration(_loggerFactoryAdapter, _commandProcessor, RegisterContainer);

            TransmitPipe = new TransmitPipe(_loggerFactoryAdapter, Configuration, _commandProcessor, RegisterContainer, _cePin);
            ReceivePipes = new ReceivePipeCollection(_loggerFactoryAdapter, Configuration, _commandProcessor, RegisterContainer);

            bool useIrq = irqPin != null;

            if (useIrq)
            {
                _irqPin = irqPin;
                _irqPin.Write(GpioPinValue.High);
                _irqPin.ValueChanged += irqPin_ValueChanged;
            }
            ConfigurationRegister configurationRegister = RegisterContainer.ConfigurationRegister;

            configurationRegister.MaximunTransmitRetriesMask = !useIrq;
            configurationRegister.ReceiveDataReadyMask       = !useIrq;
            configurationRegister.TransmitDataSentMask       = !useIrq;
            configurationRegister.Save();
            OperatingMode = OperatingModes.StandBy;
        }
        public Radio(ICommandProcessor commandProcessor, ILoggerFactoryAdapter loggerFactoryAdapter, GpioPin powerPin, GpioPin cePin, GpioPin irqPin = null)
        {
            _syncRoot = new object();
            _operatingMode = OperatingModes.PowerOff;
            _powerPin = powerPin;
            _powerPin.Write(GpioPinValue.Low);

            _cePin = cePin;
            _cePin.Write(GpioPinValue.Low);

            _loggerFactoryAdapter = loggerFactoryAdapter;
            _logger = _loggerFactoryAdapter.GetLogger(GetType());

            _commandProcessor = commandProcessor;
            _commandProcessor.LoggerFactory = _loggerFactoryAdapter;
            _commandProcessor.GetOperatingMode = () => OperatingMode;

            RegisterContainer = new RegisterContainer(_loggerFactoryAdapter, _commandProcessor);
            OperatingMode = OperatingModes.PowerDown;
            RegisterContainer.ResetRegistersToDefault();

            Configuration = new Configuration(_loggerFactoryAdapter, _commandProcessor, RegisterContainer);

            TransmitPipe = new TransmitPipe(_loggerFactoryAdapter, Configuration, _commandProcessor, RegisterContainer, _cePin);
            ReceivePipes = new ReceivePipeCollection(_loggerFactoryAdapter, Configuration, _commandProcessor, RegisterContainer);

            bool useIrq = irqPin != null;
            if (useIrq)
            {
                _irqPin = irqPin;
                _irqPin.Write(GpioPinValue.High);
                _irqPin.ValueChanged += irqPin_ValueChanged;
            }
            ConfigurationRegister configurationRegister = RegisterContainer.ConfigurationRegister;
            configurationRegister.MaximunTransmitRetriesMask = !useIrq;
            configurationRegister.ReceiveDataReadyMask = !useIrq;
            configurationRegister.TransmitDataSentMask = !useIrq;
            configurationRegister.Save();
            OperatingMode = OperatingModes.StandBy;

        }
Esempio n. 37
0
        private static void LoadLoggerFactoryAdapter()
        {
            var fileInfo = FileLoader.GetInfo("SmartSqlLog.xml");

            if (fileInfo.Exists)
            {
                using (var configFile = fileInfo.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    XmlSerializer xmlSerializer = new XmlSerializer(typeof(SmartSqlLog));
                    SmartSqlLog   smartSqlLog   = xmlSerializer.Deserialize(configFile) as SmartSqlLog;
                    AssemblyName  assemblyName  = new AssemblyName {
                        Name = smartSqlLog.LoggerFactoryAdapter.AssemblyName
                    };
                    Type loggerFactoryAdpterType = Assembly.Load(assemblyName)
                                                   .GetType(smartSqlLog.LoggerFactoryAdapter.TypeName);
                    _loggerFactoryAdapter = Activator.CreateInstance(loggerFactoryAdpterType) as ILoggerFactoryAdapter;
                }
            }
            else
            {
                _loggerFactoryAdapter = new NoneLoggerFactoryAdapter();
            }
        }
 public EnableAutoAcknowledgementRegister(ILoggerFactoryAdapter loggerFactoryAdapter, ICommandProcessor commandProcessor) :
     base(loggerFactoryAdapter, commandProcessor, 1, RegisterAddresses.EN_AA, RegisterDefaults.EN_AA, "EN_AA")
 { }
 public Network(ILoggerFactoryAdapter loggerFactoryAdapter)
 {
     _loggerFactoryAdapter = loggerFactoryAdapter;
     _logger = _loggerFactoryAdapter.GetLogger(GetType());
     NetworkAddressing = new NetworkAddressing(_loggerFactoryAdapter);
 }
        public RegisterContainer(ILoggerFactoryAdapter loggerFactoryAdapter, ICommandProcessor commandProcessor)
        {
            ConfigurationRegister = new ConfigurationRegister(loggerFactoryAdapter, commandProcessor);
            EnableAutoAcknowledgementRegister = new EnableAutoAcknowledgementRegister(loggerFactoryAdapter, commandProcessor);
            EnableReceiveAddressRegister = new EnableReceiveAddressRegister(loggerFactoryAdapter, commandProcessor);
            AddressWidthRegister = new SetupAddressWidthRegister(loggerFactoryAdapter, commandProcessor);
            SetupRetransmissionRegister = new SetupRetransmissionRegister(loggerFactoryAdapter, commandProcessor);
            RfChannelRegister = new RfChannelRegister(loggerFactoryAdapter, commandProcessor);
            RfSetupRegister = new RfSetupRegister(loggerFactoryAdapter, commandProcessor);
            StatusRegister = new StatusRegister(loggerFactoryAdapter, commandProcessor);
            ObserveTransmitRegister = new ObserveTransmitRegister(loggerFactoryAdapter, commandProcessor);
            ReceivedPowerDetectorRegister = new ReceivedPowerDetectorRegister(loggerFactoryAdapter, commandProcessor);
            TransmitAddressRegister = new AddressPipeRegister(loggerFactoryAdapter, commandProcessor, RegisterAddresses.TX_ADDR, RegisterDefaults.TX_ADDR, 0, "TX_ADDR");
            FifoStatusRegister = new FifoStatusRegister(loggerFactoryAdapter, commandProcessor);
            DynamicPayloadLengthRegister = new DynamicPayloadLengthRegister(loggerFactoryAdapter, commandProcessor);
            FeatureRegister = new FeatureRegister(loggerFactoryAdapter, commandProcessor);
            ReceiveAddressPipeRegisters = new RegisterCollection<AddressPipeRegister>
            {
                {0, new AddressPipeRegister(loggerFactoryAdapter, commandProcessor, RegisterAddresses.RX_ADDR_P0, RegisterDefaults.RX_ADDR_P0, 0, "RX_ADDR_P0")},
                {1, new AddressPipeRegister(loggerFactoryAdapter, commandProcessor, RegisterAddresses.RX_ADDR_P1, RegisterDefaults.RX_ADDR_P1, 1, "RX_ADDR_P1")},
                {2, new AddressPipeRegister(loggerFactoryAdapter, commandProcessor, RegisterAddresses.RX_ADDR_P2, RegisterDefaults.RX_ADDR_P2, 2, "RX_ADDR_P2")},
                {3, new AddressPipeRegister(loggerFactoryAdapter, commandProcessor, RegisterAddresses.RX_ADDR_P3, RegisterDefaults.RX_ADDR_P3, 3, "RX_ADDR_P3")},
                {4, new AddressPipeRegister(loggerFactoryAdapter, commandProcessor, RegisterAddresses.RX_ADDR_P4, RegisterDefaults.RX_ADDR_P4, 4, "RX_ADDR_P4")},
                {5, new AddressPipeRegister(loggerFactoryAdapter, commandProcessor, RegisterAddresses.RX_ADDR_P5, RegisterDefaults.RX_ADDR_P5, 5, "RX_ADDR_P5")},
            };
            ReceivePayloadWidthPipeRegisters = new RegisterCollection<ReceivePayloadWidthPipeRegister>
            {
                {0, new ReceivePayloadWidthPipeRegister(loggerFactoryAdapter, commandProcessor, RegisterAddresses.RX_PW_P0, RegisterDefaults.RX_PW_P0, 0, "RX_PW_P0")},
                {1, new ReceivePayloadWidthPipeRegister(loggerFactoryAdapter, commandProcessor, RegisterAddresses.RX_PW_P1, RegisterDefaults.RX_PW_P1, 1, "RX_PW_P1")},
                {2, new ReceivePayloadWidthPipeRegister(loggerFactoryAdapter, commandProcessor, RegisterAddresses.RX_PW_P2, RegisterDefaults.RX_PW_P2, 2, "RX_PW_P2")},
                {3, new ReceivePayloadWidthPipeRegister(loggerFactoryAdapter, commandProcessor, RegisterAddresses.RX_PW_P3, RegisterDefaults.RX_PW_P3, 3, "RX_PW_P3")},
                {4, new ReceivePayloadWidthPipeRegister(loggerFactoryAdapter, commandProcessor, RegisterAddresses.RX_PW_P4, RegisterDefaults.RX_PW_P4, 4, "RX_PW_P4")},
                {5, new ReceivePayloadWidthPipeRegister(loggerFactoryAdapter, commandProcessor, RegisterAddresses.RX_PW_P5, RegisterDefaults.RX_PW_P5, 5, "RX_PW_P5")}
            };
            AllRegisters = new RegisterCollection<IRegister>
            {
                {RegisterAddresses.CONFIG, ConfigurationRegister},
                {RegisterAddresses.EN_AA, EnableAutoAcknowledgementRegister},
                {RegisterAddresses.EN_RXADDR, EnableReceiveAddressRegister},
                {RegisterAddresses.SETUP_AW, AddressWidthRegister},
                {RegisterAddresses.SETUP_RETR, SetupRetransmissionRegister},
                {RegisterAddresses.RF_CH, RfChannelRegister},
                {RegisterAddresses.RF_SETUP, RfSetupRegister},
                {RegisterAddresses.STATUS, StatusRegister},
                {RegisterAddresses.OBSERVE_TX, ObserveTransmitRegister},
                {RegisterAddresses.RPD, ReceivedPowerDetectorRegister},
                {RegisterAddresses.RX_ADDR_P0, ReceiveAddressPipeRegisters[0]},
                {RegisterAddresses.RX_ADDR_P1, ReceiveAddressPipeRegisters[1]},
                {RegisterAddresses.RX_ADDR_P2, ReceiveAddressPipeRegisters[2]},
                {RegisterAddresses.RX_ADDR_P3, ReceiveAddressPipeRegisters[3]},
                {RegisterAddresses.RX_ADDR_P4, ReceiveAddressPipeRegisters[4]},
                {RegisterAddresses.RX_ADDR_P5, ReceiveAddressPipeRegisters[5]},
                {RegisterAddresses.TX_ADDR, TransmitAddressRegister},
                {RegisterAddresses.RX_PW_P0, ReceivePayloadWidthPipeRegisters[0]},
                {RegisterAddresses.RX_PW_P1, ReceivePayloadWidthPipeRegisters[1]},
                {RegisterAddresses.RX_PW_P2, ReceivePayloadWidthPipeRegisters[2]},
                {RegisterAddresses.RX_PW_P3, ReceivePayloadWidthPipeRegisters[3]},
                {RegisterAddresses.RX_PW_P4, ReceivePayloadWidthPipeRegisters[4]},
                {RegisterAddresses.RX_PW_P5, ReceivePayloadWidthPipeRegisters[5]},
                {RegisterAddresses.FIFO_STATUS, FifoStatusRegister},
                {RegisterAddresses.DYNPD, DynamicPayloadLengthRegister},
                {RegisterAddresses.FEATURE, FeatureRegister}
            };

            // Set the LoadStatusRegister Action of the ICommandProcessor to call 
            // StatusRegister.Load. This will ensure that the Status register is 
            // automatically updated after call ICommandProcessor.ExecuteCommand()
            commandProcessor.LoadStatusRegister = StatusRegister.Load;
        }
Esempio n. 41
0
 public void FixtureSetUp()
 {
     // set Adapter to report problems
     oldAdapter = LogManager.Adapter;
     LogManager.Adapter = new FailFastLoggerFactoryAdapter();
 }
 public ConfigurationRegister(ILoggerFactoryAdapter loggerFactoryAdapter, ICommandProcessor commandProcessor) :
     base(loggerFactoryAdapter, commandProcessor, 1, RegisterAddresses.CONFIG, RegisterDefaults.CONFIG, "CONFIG")
 { }
 public FeatureRegister(ILoggerFactoryAdapter loggerFactoryAdapter, ICommandProcessor commandProcessor) :
     base(loggerFactoryAdapter, commandProcessor, 1, RegisterAddresses.FEATURE, RegisterDefaults.FEATURE, "FEATURE")
 { }
 public SetupAddressWidthRegister(ILoggerFactoryAdapter loggerFactoryAdapter, ICommandProcessor commandProcessor) :
     base(loggerFactoryAdapter, commandProcessor, 1, RegisterAddresses.SETUP_AW, RegisterDefaults.SETUP_AW, "SETUP_AW")
 { }
 public ReceivePayloadWidthPipeRegister(ILoggerFactoryAdapter loggerFactoryAdapter, ICommandProcessor commandProcessor, byte address, byte[] defaultValue, byte pipeNumber, string name = "") :
     base(loggerFactoryAdapter, commandProcessor, address, 1, defaultValue, pipeNumber, name)
 { }
 public ReceivedPowerDetectorRegister(ILoggerFactoryAdapter loggerFactoryAdapter, ICommandProcessor commandProcessor) :
     base(loggerFactoryAdapter, commandProcessor, 1, RegisterAddresses.RPD, RegisterDefaults.RPD, "RPD")
 { }
 public StatusRegister(ILoggerFactoryAdapter loggerFactoryAdapter, ICommandProcessor commandProcessor) :
     base(loggerFactoryAdapter, commandProcessor, 1, RegisterAddresses.STATUS, RegisterDefaults.STATUS, "STATUS")
 { }
 public SetupRetransmissionRegister(ILoggerFactoryAdapter loggerFactoryAdapter, ICommandProcessor commandProcessor) :
     base(loggerFactoryAdapter, commandProcessor, 1, RegisterAddresses.SETUP_RETR, RegisterDefaults.SETUP_RETR, "SETUP_RETR")
 { }
 public ReceivePayloadWidthPipeRegister(ILoggerFactoryAdapter loggerFactoryAdapter, ICommandProcessor commandProcessor, byte address, byte[] defaultValue, byte pipeNumber, string name = "") :
     base(loggerFactoryAdapter, commandProcessor, address, 1, defaultValue, pipeNumber, name)
 {
 }
Esempio n. 50
0
        /// <summary>
        /// Builds the logger factory adapter.
        /// </summary>
        /// <returns></returns>
        private static ILoggerFactoryAdapter BuildLoggerFactoryAdapter()
        {
            LogSetting setting = null;

            try
            {
#if dotnet2
                setting = (LogSetting)ConfigurationManager.GetSection(IBATIS_SECTION_LOGGING);
#else
                setting = (LogSetting)ConfigurationSettings.GetConfig(IBATIS_SECTION_LOGGING);
#endif
            }
            catch (Exception ex)
            {
                ILoggerFactoryAdapter defaultFactory = BuildDefaultLoggerFactoryAdapter();
                ILog log = defaultFactory.GetLogger(typeof(LogManager));
                log.Warn("Unable to read configuration. Using default logger.", ex);
                return(defaultFactory);
            }

            if (setting != null && !typeof(ILoggerFactoryAdapter).IsAssignableFrom(setting.FactoryAdapterType))
            {
                ILoggerFactoryAdapter defaultFactory = BuildDefaultLoggerFactoryAdapter();
                ILog log = defaultFactory.GetLogger(typeof(LogManager));
                log.Warn("Type " + setting.FactoryAdapterType.FullName + " does not implement ILoggerFactoryAdapter. Using default logger");
                return(defaultFactory);
            }

            ILoggerFactoryAdapter instance = null;

            if (setting != null)
            {
                if (setting.Properties.Count > 0)
                {
                    try
                    {
                        object[] args = { setting.Properties };

                        instance = (ILoggerFactoryAdapter)Activator.CreateInstance(setting.FactoryAdapterType, args);
                    }
                    catch (Exception ex)
                    {
                        ILoggerFactoryAdapter defaultFactory = BuildDefaultLoggerFactoryAdapter();
                        ILog log = defaultFactory.GetLogger(typeof(LogManager));
                        log.Warn("Unable to create instance of type " + setting.FactoryAdapterType.FullName + ". Using default logger.", ex);
                        return(defaultFactory);
                    }
                }
                else
                {
                    try
                    {
                        instance = (ILoggerFactoryAdapter)Activator.CreateInstance(setting.FactoryAdapterType);
                    }
                    catch (Exception ex)
                    {
                        ILoggerFactoryAdapter defaultFactory = BuildDefaultLoggerFactoryAdapter();
                        ILog log = defaultFactory.GetLogger(typeof(LogManager));
                        log.Warn("Unable to create instance of type " + setting.FactoryAdapterType.FullName + ". Using default logger.", ex);
                        return(defaultFactory);
                    }
                }
            }
            else
            {
                ILoggerFactoryAdapter defaultFactory = BuildDefaultLoggerFactoryAdapter();
                ILog log = defaultFactory.GetLogger(typeof(LogManager));
                log.Warn("Unable to read configuration IBatisNet/logging. Using default logger.");
                return(defaultFactory);
            }

            return(instance);
        }
 public NetworkAddressing(ILoggerFactoryAdapter loggerFactoryAdapter)
 {
     _logger = loggerFactoryAdapter.GetLogger(GetType());
 }
Esempio n. 52
0
 public void FixtureSetUp()
 {
     // set Adapter to report problems
     oldAdapter         = LogManager.Adapter;
     LogManager.Adapter = new FailFastLoggerFactoryAdapter();
 }
 public RfSetupRegister(ILoggerFactoryAdapter loggerFactoryAdapter, ICommandProcessor commandProcessor) :
     base(loggerFactoryAdapter, commandProcessor, 1, RegisterAddresses.RF_SETUP, RegisterDefaults.RF_SETUP, "RF_SETUP")
 { }
 public EnableReceiveAddressRegister(ILoggerFactoryAdapter loggerFactoryAdapter, ICommandProcessor commandProcessor) :
     base( loggerFactoryAdapter, commandProcessor, 1, RegisterAddresses.EN_RXADDR, RegisterDefaults.EN_RXADDR, "EN_RXADDR")
 { }
 public ObserveTransmitRegister(ILoggerFactoryAdapter loggerFactoryAdapter, ICommandProcessor commandProcessor) :
     base(loggerFactoryAdapter, commandProcessor, 1, RegisterAddresses.OBSERVE_TX, RegisterDefaults.OBSERVE_TX, "OBSERVE_TX")
 { }
Esempio n. 56
0
 /// <summary>
 /// Initializes the <see cref="LogManager"/> class.
 /// </summary>
 static LogManager()
 {
     _adapter = null;
     _loadLock = new object();
 }
 public RfChannelRegister(ILoggerFactoryAdapter loggerFactoryAdapter, ICommandProcessor commandProcessor) :
     base(loggerFactoryAdapter, commandProcessor, 1, RegisterAddresses.RF_CH, RegisterDefaults.RF_CH, "RF_CH")
 { }
Esempio n. 58
0
 public static void InitializeLogFactory(ILoggerFactoryAdapter loggerFactoryAdapter)
 {
     _loggerFactoryAdapter = loggerFactoryAdapter;
 }
        public DynamicPayloadLengthRegister(ILoggerFactoryAdapter loggerFactoryAdapter, ICommandProcessor commandProcessor) :
            base(loggerFactoryAdapter, commandProcessor, 1, RegisterAddresses.DYNPD, RegisterDefaults.DYNPD, "DYNPD")

        { }