示例#1
0
        protected override void OnStart(string[] args)
        {
            try
            {
                _log.Info($"Starting RadiusServerService build version {FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion}");
                _log.Info("Reading configuration");

                var loggerFactory = new LoggerFactory();
                loggerFactory.AddNLog();
                var dictionary = new RadiusDictionary(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) + "\\content\\radius.dictionary", loggerFactory.CreateLogger <RadiusDictionary>());


                var radiusPacketParser = new RadiusPacketParser(loggerFactory.CreateLogger <RadiusPacketParser>(), dictionary);
                var packetHandler      = new TestPacketHandler();
                var repository         = new PacketHandlerRepository();

                repository.AddPacketHandler(IPAddress.Parse("127.0.0.1"), packetHandler, "secret");

                _authenticationServer = new RadiusServer(
                    new Net.UdpClientFactory(),
                    new IPEndPoint(IPAddress.Any, 1812),
                    radiusPacketParser,
                    RadiusServerType.Authentication,
                    repository,
                    loggerFactory.CreateLogger <RadiusServer>());


                _log.Info("Configuration read");

                _authenticationServer.Start();
            }
            catch (Exception ex)
            {
                _log.Fatal(ex, "Failed to start service");
                throw;
            }
        }