protected SourceWatcherBase(IHostingEnvironment env, IConfiguration configuration, IInvokerCacheService invokerCache, IGistCacheService gistCache, string eventSource)
 {
     _env          = env;
     _config       = configuration;
     _invokerCache = invokerCache;
     _gistCache    = gistCache;
     _eventSource  = eventSource;
 }
        public SourceWatcherService(IHostingEnvironment env, IConfiguration configuration, IInvokerCacheService invokerCacheService, IGistCacheService gistCacheService, ISearchService searchService)
        {
            SourceWatcherType watcherType;

            if (env.IsProduction())
            {
                string watcherTypeRegistryValue = Registry.GetValue(RegistryConstants.SourceWatcherRegistryPath, RegistryConstants.WatcherTypeKey, 0).ToString();
                if (!Enum.TryParse <SourceWatcherType>(watcherTypeRegistryValue, out watcherType))
                {
                    throw new NotSupportedException($"Source Watcher Type : {watcherTypeRegistryValue} not supported.");
                }
            }
            else
            {
                watcherType = Enum.Parse <SourceWatcherType>(configuration[$"SourceWatcher:{RegistryConstants.WatcherTypeKey}"]);
            }

            switch (watcherType)
            {
            case SourceWatcherType.LocalFileSystem:
                _watcher = new LocalFileSystemWatcher(env, configuration, invokerCacheService, gistCacheService);
                break;

            case SourceWatcherType.Github:
                IGithubClient githubClient = new GithubClient(env, configuration);
                _watcher = new GitHubWatcher(env, configuration, invokerCacheService, gistCacheService, githubClient, searchService);
                break;

            default:
                throw new NotSupportedException("Source Watcher Type not supported");
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GithubGistWorker"/> class.
 /// </summary>
 /// <param name="gistCache">Gist cache service.</param>
 public GithubGistWorker(IGistCacheService gistCache)
 {
     GistCache = gistCache;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="GitHubWatcher" /> class.
        /// </summary>
        /// <param name="env">Hosting environment.</param>
        /// <param name="configuration">The configuration.</param>
        /// <param name="invokerCache">Invoker cache.</param>
        /// <param name="gistCache">Gist cache.</param>
        /// <param name="githubClient">Github client.</param>
        public GitHubWatcher(IHostingEnvironment env, IConfiguration configuration, IInvokerCacheService invokerCache, IGistCacheService gistCache, IGithubClient githubClient, ISearchService searchService)
            : base(env, configuration, invokerCache, gistCache, "GithubWatcher")
        {
            _githubClient  = githubClient;
            _searchService = searchService;

            LoadConfigurations();

            #region Initialize Github Worker

            // TODO: Register the github worker with destination path.
            var gistWorker     = new GithubGistWorker(gistCache);
            var detectorWorker = new GithubDetectorWorker(invokerCache);

            GithubWorkers = new Dictionary <string, IGithubWorker>
            {
                { gistWorker.Name, gistWorker },
                { detectorWorker.Name, detectorWorker }
            };

            #endregion Initialize Github Worker

            Start();
        }
 public LocalFileSystemWatcher(IHostingEnvironment env, IConfiguration configuration, IInvokerCacheService invokerCache, IGistCacheService gistCache)
     : base(env, configuration, invokerCache, gistCache, "LocalFileSystemWatcher")
 {
     LoadConfigurations();
     Start();
     _invokerDictionary = new Dictionary <EntityType, ICache <string, EntityInvoker> >
     {
         { EntityType.Detector, invokerCache },
         { EntityType.Signal, invokerCache },
         { EntityType.Gist, gistCache }
     };
 }