示例#1
0
        private void InitEnvorimentAndVerify()
        {
            if (Entities == null || Entities.Count == 0)
            {
                this.Log("Count of entity is 0.", LogLevel.Error);
                throw new SpiderException("Count of entity is 0.");
            }

            if (EntityPipelines == null || EntityPipelines.Count == 0)
            {
                this.Log("Need at least one entity pipeline.", LogLevel.Error);
                throw new SpiderException("Need at least one entity pipeline.");
            }

            if (RedialExecutor != null)
            {
                RedialExecutor.Init();
                NetworkCenter.Current.Executor = RedialExecutor;
            }
        }
示例#2
0
        private void InitEnvorimentAndVerify()
        {
            if (Entities == null || Entities.Count == 0)
            {
                this.Log("Count of entity is 0.", LogLevel.Error);
                throw new SpiderException("Count of entity is 0.");
            }

            if (EntityPipelines == null || EntityPipelines.Count == 0)
            {
                this.Log("Need at least one entity pipeline.", LogLevel.Error);
                throw new SpiderException("Need at least one entity pipeline.");
            }

            if (RedialExecutor != null)
            {
                RedialExecutor.Init();
                NetworkCenter.Current.Executor = RedialExecutor;
            }

            if (string.IsNullOrEmpty(RedisHost))
            {
                RedisHost     = Configuration.GetValue("redisHost");
                RedisPassword = Configuration.GetValue("redisPassword");
                int port;
                RedisPort = int.TryParse(Configuration.GetValue("redisPort"), out port) ? port : 6379;
            }

            if (!string.IsNullOrEmpty(RedisHost))
            {
                var confiruation = new ConfigurationOptions()
                {
                    ServiceName     = "DotnetSpider",
                    Password        = RedisPassword,
                    ConnectTimeout  = 65530,
                    KeepAlive       = 8,
                    ConnectRetry    = 3,
                    ResponseTimeout = 3000
                };
#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(RedisHost).Result.FirstOrDefault();
                    if (address == null)
                    {
                        this.Log($"Can't resovle host: {RedisHost}", LogLevel.Error);
                        throw new SpiderException($"Can't resovle host: {RedisHost}");
                    }
                    confiruation.EndPoints.Add(new IPEndPoint(address, RedisPort));
                }
                else
                {
                    confiruation.EndPoints.Add(new DnsEndPoint(RedisHost, RedisPort));
                }
#else
                confiruation.EndPoints.Add(new DnsEndPoint(RedisHost, RedisPort));
#endif
                Redis = ConnectionMultiplexer.Connect(confiruation);
                Db    = Redis.GetDatabase(1);
            }
        }