Beispiel #1
0
        public ProcessMonitor(DementorSettings appsettings, ILogger <Worker> logger)
        {
            this.appsettings = appsettings;
            this.logger      = logger;

            var retrievedRemoteBlacklist = true;

            try
            {
                logger.LogDebug("Retrieving blacklist...");
                using (var client = new WebClient())
                {
                    client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");

                    using (var data = client.OpenRead("https://raw.githubusercontent.com/doveryai/Dementor/master/blacklist.json"))
                    {
                        using (var reader = new StreamReader(data))
                        {
                            this.blackList = JsonConvert.DeserializeObject <BlackList>(reader.ReadToEnd());
                        }
                    }
                }
                logger.LogDebug("Blacklist retrieved.");
            }
            catch (Exception ex)
            {
                retrievedRemoteBlacklist = false;
            }

            //fall back to serialize from local file for now
            if (!retrievedRemoteBlacklist)
            {
                logger.LogDebug("Failed to retrieve blacklist. Using local list.");

                var path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), appsettings.BlacklistFile);

                using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read))
                {
                    using (var reader = new StreamReader(fs))
                    {
                        this.blackList = JsonConvert.DeserializeObject <BlackList>(reader.ReadToEnd());
                    }
                }
            }
        }
Beispiel #2
0
 public Worker(ILogger <Worker> logger, IOptions <DementorSettings> appsettings)
 {
     this.logger      = logger;
     this.appsettings = appsettings.Value;
 }