public StalkConfiguration(
     IAppConfiguration configuration,
     ILogger logger,
     IStalkFactory stalkFactory,
     IFileService fileService)
     : base(configuration.StalkConfigFile,
            "stalks",
            logger,
            stalkFactory.NewFromXmlElement,
            stalkFactory.ToXmlElement,
            fileService)
 {
 }
예제 #2
0
        public Launch(
            ILogger logger,
            IIrcClient freenodeClient,
            IIrcClient wikimediaClient,
            IAppConfiguration appConfig,
            ITemplateConfiguration templateConfiguration,
            IBotUserConfiguration userConfiguration,
            IChannelConfiguration channelConfiguration,
            IStalkFactory stalkFactory,
            IFileService fileService)
        {
            this.logger               = logger;
            this.freenodeClient       = freenodeClient;
            this.wikimediaClient      = wikimediaClient;
            this.appConfig            = appConfig;
            this.channelConfiguration = channelConfiguration;

            if (!this.channelConfiguration.Items.Any())
            {
                this.logger.InfoFormat("Migrating to channel configuration file...");

                var defaultChannel = new IrcChannel(this.appConfig.FreenodeChannel);
                this.channelConfiguration.Add(defaultChannel);

                if (appConfig.StalkConfigFile != null)
                {
                    var stalkConfig = new StalkConfiguration(
                        appConfig,
                        logger.CreateChildLogger("LegacyStalkConfig"),
                        stalkFactory,
                        fileService
                        );
                    stalkConfig.Initialize();

                    foreach (var stalk in stalkConfig.Items)
                    {
                        stalk.Channel = this.appConfig.FreenodeChannel;
                        defaultChannel.Stalks.Add(stalk.Identifier, stalk);
                        stalkConfig.Remove(stalk.Identifier);
                    }

                    stalkConfig.Save();
                }

                this.channelConfiguration.Save();
            }

            this.logger.InfoFormat(
                "Tracking {0} stalks, {1} templates, {2} users, and {3} channels.",
                this.channelConfiguration.Items.Aggregate(0, (i, channel) => i + channel.Stalks.Count),
                templateConfiguration.Items.Count,
                userConfiguration.Items.Count,
                channelConfiguration.Items.Count
                );

            if (appConfig.MetricsPort != 0)
            {
                this.logger.DebugFormat("Setting up metrics server on port {0}", appConfig.MetricsPort);
                this.metricsServer = new MetricServer(appConfig.MetricsPort);
                this.metricsServer.Start();

                VersionInfo.WithLabels(
                    FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion,
                    FileVersionInfo.GetVersionInfo(Assembly.GetAssembly(typeof(IrcClient)).Location)
                    .FileVersion,
                    FileVersionInfo.GetVersionInfo(Assembly.GetAssembly(typeof(CommandBase)).Location)
                    .FileVersion,
                    FileVersionInfo.GetVersionInfo(Assembly.GetAssembly(typeof(MediaWikiApi)).Location)
                    .FileVersion,
                    FileVersionInfo.GetVersionInfo(Assembly.GetAssembly(typeof(ConduitClient)).Location)
                    .FileVersion,
                    Environment.Version.ToString(),
                    Environment.OSVersion.ToString(),
                    ((TargetFrameworkAttribute)Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(TargetFrameworkAttribute), false).FirstOrDefault())?.FrameworkDisplayName ?? "Unknown"
                    )
                .Set(1);

                this.logger.DebugFormat("Metrics server configured.");
            }
            else
            {
                this.logger.Warn("Prometheus metrics server disabled.");
            }

            this.freenodeClient.DisconnectedEvent  += this.OnDisconnect;
            this.wikimediaClient.DisconnectedEvent += this.OnDisconnect;
        }
예제 #3
0
 public ChannelFactory(ILogger logger, IIrcClient freenodeClient, IStalkFactory stalkFactory) : base(logger)
 {
     this.freenodeClient = freenodeClient;
     this.stalkFactory   = stalkFactory;
 }