コード例 #1
0
        public FileLockerRedialExecutor(IRedialer redialer, IInternetDetector validater) : base(redialer, validater)
        {
            if (!Directory.Exists(AtomicActionFolder))
            {
                Directory.CreateDirectory(AtomicActionFolder);
            }

            foreach (var file in Directory.GetFiles(AtomicActionFolder))
            {
                try
                {
                    File.Delete(file);
                }
                catch (Exception e)
                {
                    Logger.MyLog($"Delete atomic file failed: {e}", LogLevel.Error);
                }
            }
            try
            {
                File.Delete(RedialLockerFile);
            }
            catch (Exception e)
            {
                Logger.MyLog($"Delete redial lock file failed: {e}", LogLevel.Error);
            }
        }
コード例 #2
0
 public FileLockerRedialManager(INetworkValidater networkValidater, IRedialer redialer)
 {
     _lockerFilePath  = Path.Combine(SpiderEnviroment.GlobalDirectory, "redialer.lock");
     AtomicExecutor   = new FileLockerAtomicExecutor(this);
     NetworkValidater = networkValidater;
     Redialer         = redialer;
 }
コード例 #3
0
 public FileLockerRedialExecutor(IRedialer redialer, IInternetDetector validater) : base(redialer, validater)
 {
     if (!Directory.Exists(AtomicActionFolder))
     {
         Directory.CreateDirectory(AtomicActionFolder);
     }
 }
コード例 #4
0
        public FileLockerRedialExecutor(IRedialer redialer, IInternetDetector validater) : base(redialer, validater)
        {
            if (!Directory.Exists(AtomicActionFolder))
            {
                Directory.CreateDirectory(AtomicActionFolder);
            }

            foreach (var file in Directory.GetFiles(AtomicActionFolder))
            {
                try
                {
                    File.Delete(file);
                }
                catch
                {
                }
            }
            try
            {
                File.Delete(RedialLockerFile);
            }
            catch
            {
            }
        }
コード例 #5
0
        public RedisRedialManager(IDatabase db, INetworkValidater validater, IRedialer redialer, ILogService logger)
        {
            Logger = logger;

            Db               = db;
            AtomicExecutor   = new RedisAtomicExecutor(this);
            NetworkValidater = validater;
            Redialer         = redialer;
        }
コード例 #6
0
        public RedisRedialManager(string host, string password, INetworkValidater validater, IRedialer redialer, ILogService logger)
        {
            Logger = logger;
            if (!string.IsNullOrEmpty(host))
            {
                RedisHost = host;
            }
            else
            {
                throw new RedialException("Redis host should not be null.");
            }

            if (!string.IsNullOrEmpty(password))
            {
                Password = password;
            }
            else
            {
                Password = null;
            }

            var confiruation = new ConfigurationOptions()
            {
                ServiceName     = "DotnetSpider",
                Password        = password,
                ConnectTimeout  = 5000,
                KeepAlive       = 8,
                ConnectRetry    = 20,
                SyncTimeout     = 65530,
                ResponseTimeout = 65530
            };

#if NET_CORE
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                // Lewis: This is a Workaround for .NET CORE can't use EndPoint to create Socket.
                var address = Dns.GetHostAddressesAsync(host).Result.FirstOrDefault();
                if (address == null)
                {
                    throw new Exception("Can't resovle your host: " + host);
                }
                confiruation.EndPoints.Add(new IPEndPoint(address, 6379));
            }
            else
            {
                confiruation.EndPoints.Add(new DnsEndPoint(host, 6379));
            }
#else
            confiruation.EndPoints.Add(new DnsEndPoint(host, 6379));
#endif
            var redis = ConnectionMultiplexer.Connect(confiruation);

            Db               = redis.GetDatabase(3);
            AtomicExecutor   = new RedisAtomicExecutor(this);
            NetworkValidater = validater;
            Redialer         = redialer;
        }
コード例 #7
0
        public RedisRedialManager(IDatabase db, INetworkValidater validater, IRedialer redialer, ILogService logger)
        {
            Logger = logger;

            Db = db;
            AtomicExecutor = new RedisAtomicExecutor(this);
            NetworkValidater = validater;
            Redialer = redialer;
        }
コード例 #8
0
 /// <summary>
 /// 构造方法
 /// </summary>
 /// <param name="redialer">拨号器</param>
 /// <param name="validater">网络状态检测器</param>
 protected RedialExecutor(IRedialer redialer, IInternetDetector validater)
 {
     if (redialer == null || validater == null)
     {
         throw new ArgumentException("redialer, validater should not be null.");
     }
     Redialer         = redialer;
     InternetDetector = validater;
 }
コード例 #9
0
 protected RedialExecutor(IRedialer redialer, IInternetDetector validater)
 {
     if (redialer == null || validater == null)
     {
         throw new SpiderException("IWaitRedial should not be null.");
     }
     Redialer         = redialer;
     InternetDetector = validater;
 }
コード例 #10
0
ファイル: RedialExecutor.cs プロジェクト: wgms/DotnetSpider
 /// <summary>
 /// 构造方法
 /// </summary>
 /// <param name="redialer">拨号器</param>
 /// <param name="internetDetector">网络状态检测器</param>
 protected RedialExecutor(IRedialer redialer, IInternetDetector internetDetector)
 {
     if (redialer == null || internetDetector == null)
     {
         throw new ArgumentException("redialer, internetDetector should not be null");
     }
     Redialer         = redialer;
     InternetDetector = internetDetector;
 }
コード例 #11
0
 protected RedialExecutor(IRedialer redialer, IInternetDetector validater)
 {
     if (redialer == null || validater == null)
     {
         throw new SpiderException("IWaitRedial should not be null.");
     }
     Redialer         = redialer;
     InternetDetector = validater;
     Logger           = LogManager.GetCurrentClassLogger();
 }
コード例 #12
0
        public RedisRedialExecutor(string connectString, IRedialer redialer, IInternetDetector validater) : base(redialer, validater)
        {
            ConnectString = connectString;

            RedisConnection = Cache.Instance.Get(ConnectString);
            if (RedisConnection == null)
            {
                RedisConnection = new RedisConnection(ConnectString);
                Cache.Instance.Set(ConnectString, RedisConnection);
            }
        }
コード例 #13
0
        public FileLockerRedialExecutor(IRedialer redialer, IInternetDetector validater) : base(redialer, validater)
        {
            var fileInfo = new FileInfo(FileLocker.RedialLockerFile);

            if (fileInfo.Exists)
            {
                try
                {
                    fileInfo.Delete();
                }
                catch
                {
                }
            }
        }
コード例 #14
0
        protected LocalRedialExecutor(IRedialer redialer, IInternetDetector validater) : base(redialer, validater)
        {
            if (!Directory.Exists(AtomicActionFolder))
            {
                Directory.CreateDirectory(AtomicActionFolder);
            }

            foreach (var file in Directory.GetFiles(AtomicActionFolder))
            {
                try
                {
                    File.Delete(file);
                }
                catch
                {
                    // ignored
                }
            }
        }
コード例 #15
0
        public RedisRedialManager(string host, string password, INetworkValidater validater, IRedialer redialer, ILogService logger)
        {
            Logger = logger;
            if (!string.IsNullOrEmpty(host))
            {
                RedisHost = host;
            }
            else
            {
                throw new RedialException("Redis host should not be null.");
            }

            if (!string.IsNullOrEmpty(password))
            {
                Password = password;
            }
            else
            {
                Password = null;
            }

            var Redis = ConnectionMultiplexer.Connect(new ConfigurationOptions()
            {
                ServiceName = "DotnetSpider",
                Password = password,
                ConnectTimeout = 65530,
                KeepAlive = 8,
                ConnectRetry = 20,
                SyncTimeout = 65530,
                ResponseTimeout = 65530,
                EndPoints =
                { host, "6379" }
            });
            Db = Redis.GetDatabase(3);
            AtomicExecutor = new RedisAtomicExecutor(this);
            NetworkValidater = validater;
            Redialer = redialer;
        }
コード例 #16
0
 public FileLockerRedialExecutor(IRedialer redialer) : this(redialer, new DefaultInternetDetector())
 {
 }
コード例 #17
0
 /// <summary>
 /// 构造方法
 /// </summary>
 /// <param name="redialer">拨号器</param>
 protected RedialExecutor(IRedialer redialer) : this(redialer, new DefaultInternetDetector())
 {
 }
コード例 #18
0
 public RedisRedialExecutor(string host, string password, int port, IRedialer redialer, IInternetDetector validater) : base(redialer, validater)
 {
     Host     = host;
     Password = password;
     Port     = port;
 }
コード例 #19
0
 /// <summary>
 /// 构造方法
 /// </summary>
 /// <param name="redialer">拨号器</param>
 /// <param name="validater">网络状态检测器</param>
 public MutexRedialExecutor(IRedialer redialer, IInternetDetector validater) : base(redialer, validater)
 {
 }
コード例 #20
0
 /// <summary>
 /// 构造方法
 /// </summary>
 /// <param name="redialer">拨号器</param>
 public MutexRedialExecutor(IRedialer redialer) : this(redialer, new DefaultInternetDetector())
 {
 }
コード例 #21
0
 public FileLockerRedialExecutor(IRedialer redialer, IInternetDetector validater) : base(redialer, validater)
 {
 }
コード例 #22
0
 public override void SetRedialManager(INetworkValidater networkValidater, IRedialer redialer)
 {
     NetworkProxyManager.Current.Register(new RedialExecutor(new Redial.RedialManager.RedisRedialManager(Host, Password, networkValidater, redialer, null)));
 }
コード例 #23
0
 public override void SetRedialManager(INetworkValidater networkValidater, IRedialer redialer)
 {
     NetworkProxyManager.Current.Register(new RedialExecutor(new FileLockerRedialManager(networkValidater, redialer)));
 }
コード例 #24
0
 public abstract void SetRedialManager(INetworkValidater networkValidater, IRedialer redialer);
コード例 #25
0
 /// <summary>
 /// 构造方法
 /// </summary>
 /// <param name="redialer">拨号器</param>
 /// <param name="internetDetector">网络状态检测器</param>
 public MutexRedialExecutor(IRedialer redialer, IInternetDetector internetDetector) : base(redialer, internetDetector)
 {
 }