コード例 #1
0
        public static void Register()
        {
            // Get configuration data
            string configFile = Path.Combine(Environment.CurrentDirectory, "NerdBotPriceUpdater.ini");

            if (!File.Exists(configFile))
            {
                throw new Exception("Configuration file 'NerdBotPriceUpdater.ini' does not exist.");
            }

            string dbConnectionString = null;
            string mtgDbName          = null;
            string priceDbName        = null;

            LoadConfiguration(configFile, out dbConnectionString, out mtgDbName, out priceDbName);

            // Register the instance of ILoggingService
            TinyIoCContainer.Current.Register <ILoggingService>((c, p) => new NLogLoggingService());

            // Register the instance of IHttpClient
            TinyIoCContainer.Current.Register <IHttpClient, SimpleHttpClient>();

            // Register the instance of IQueryStatisticsStore
            var queryStatStore = new QueryStatisticsStore(
                dbConnectionString,
                mtgDbName,
                TinyIoCContainer.Current.Resolve <ILoggingService>()
                );

            TinyIoCContainer.Current.Register <IQueryStatisticsStore>(queryStatStore);

            // Register the instance of IMtgStore
            var mtgStore = new MtgStore(
                dbConnectionString,
                mtgDbName,
                TinyIoCContainer.Current.Resolve <IQueryStatisticsStore>(),
                TinyIoCContainer.Current.Resolve <ILoggingService>(),
                TinyIoCContainer.Current.Resolve <SearchUtility>());

            TinyIoCContainer.Current.Register <IMtgStore>(mtgStore);

            // Register the instance of ICardPriceStore
            var priceStore = new EchoMtgPriceStore(
                dbConnectionString,
                priceDbName,
                TinyIoCContainer.Current.Resolve <ILoggingService>(),
                TinyIoCContainer.Current.Resolve <SearchUtility>());

            TinyIoCContainer.Current.Register <ICardPriceStore>(priceStore);

            // Register the instance of IPriceUpdater
            var priceUpdater = new EchoMtgPriceUpdater(
                TinyIoCContainer.Current.Resolve <IMtgStore>(),
                TinyIoCContainer.Current.Resolve <ICardPriceStore>(),
                TinyIoCContainer.Current.Resolve <IHttpClient>(),
                TinyIoCContainer.Current.Resolve <ILoggingService>(),
                TinyIoCContainer.Current.Resolve <SearchUtility>());

            TinyIoCContainer.Current.Register <IPriceUpdater>(priceUpdater);
        }
コード例 #2
0
        protected override void ConfigureApplicationContainer(TinyIoCContainer container)
        {
            base.ConfigureApplicationContainer(container);

            // Get configuration data
            string configFile = Path.Combine(Environment.CurrentDirectory, "NerdBot.ini");

            if (!File.Exists(configFile))
            {
                throw new Exception("Configuration file 'NerdBot.ini' does not exist.");
            }

            string dbConnectionString;
            string dbName;
            string priceDbName;
            string msgrBotId;
            string msgrBotName;
            string msgrEndPointUrl;

            string[] msgrIgnoreNames;
            string   botRouteToken;
            string   urlUser;
            string   urlKey;
            string   reporterBotId;
            string   reporterBotName;
            string   hostUrl;
            string   adminUser;
            string   adminPassword;
            string   imgUrl      = null;
            string   imgHiResUrl = null;

            this.LoadConfiguration(
                configFile,
                out dbConnectionString,
                out dbName,
                out priceDbName,
                out msgrBotId,
                out msgrBotName,
                out msgrEndPointUrl,
                out msgrIgnoreNames,
                out botRouteToken,
                out urlUser,
                out urlKey,
                out reporterBotId,
                out reporterBotName,
                out hostUrl,
                out adminUser,
                out adminPassword,
                out imgUrl,
                out imgHiResUrl
                );

            // Register the instance of ILoggingService
            container.Register <ILoggingService>((c, p) => new NLogLoggingService());

            // Register the instance of IUrlShortener
            var bitlyUrl = new BitlyUrlShortener(
                urlUser,
                urlKey);

            container.Register <IUrlShortener>(bitlyUrl);

            // Register the instance of IMtgStore
            var mtgStore = new MtgStore(
                dbConnectionString,
                dbName,
                container.Resolve <ILoggingService>(),
                container.Resolve <SearchUtility>());

            container.Register <IMtgStore>(mtgStore);

            // Register the instance of IQueryStatisticsStore
            var queryStatStore = new QueryStatisticsStore(
                dbConnectionString,
                dbName,
                container.Resolve <ILoggingService>()
                );

            container.Register <IQueryStatisticsStore>(queryStatStore);

            // Register the instance of IHttpClient
            container.Register <IHttpClient, SimpleHttpClient>();

            // Register the instance of ICommandParser
            container.Register <ICommandParser, CommandParser>();

            // Register the main instance of IMessenger
            var groupMeMessenger = new GroupMeMessenger(
                msgrBotId,
                msgrBotName,
                msgrIgnoreNames,
                msgrEndPointUrl,
                container.Resolve <IHttpClient>(),
                container.Resolve <ILoggingService>());

            container.Register <IMessenger>(groupMeMessenger);

            // Register IReporter
            var reporterMessenger = new GroupMeMessenger(
                reporterBotId,
                reporterBotName,
                msgrIgnoreNames,
                msgrEndPointUrl,
                container.Resolve <IHttpClient>(),
                container.Resolve <ILoggingService>());

            var groupmeReporter = new GroupMeReporter(reporterMessenger);

            container.Register <IReporter>(groupmeReporter);

            // Register the instance of ICardPriceStore
            var priceStore = new EchoMtgPriceStore(
                dbConnectionString,
                priceDbName,
                container.Resolve <ILoggingService>(),
                container.Resolve <SearchUtility>());

            container.Register <ICardPriceStore>(priceStore);

            // Register BotConfig
            string secretToken = botRouteToken;
            var    botConfig   = new BotConfig()
            {
                SecretToken   = secretToken,
                HostUrl       = hostUrl,
                AdminUser     = adminUser,
                AdminPassword = adminPassword
            };

            container.Register(botConfig);

            // Register the instance of IPluginManager
            //string pluginDirectory = Environment.CurrentDirectory;
            string pluginDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),
                                                  "plugins");

            var pluginManager = new PluginManager(
                msgrBotName,
                pluginDirectory,
                container.Resolve <ILoggingService>(),
                container.Resolve <IMtgStore>(),
                container.Resolve <ICommandParser>(),
                container.Resolve <IReporter>(),
                container);

            container.Register <IPluginManager>(pluginManager);

            container.Register <IUserMapper, UserMapper>();

            // Register the instance of MtgJsonMapper
            var mtgJsonMapper = new MtgJsonMapper(
                container.Resolve <SearchUtility>());

            mtgJsonMapper.ImageUrl      = imgUrl;
            mtgJsonMapper.ImageHiResUrl = imgHiResUrl;

            container.Register <IMtgDataMapper <MtgJsonCard, MtgJsonSet> >(mtgJsonMapper);

            container.Register <IImporter, MtgImporter>();
        }