Exemplo n.º 1
0
Arquivo: Ip.cs Projeto: zhouweiaccp/X
        static Ip()
        {
            var dir = Runtime.IsWeb ? "..\\Data" : "Data";
            var ip  = dir.CombinePath("ip.gz").GetFullPath();

            if (File.Exists(ip))
            {
                DbFile = ip;
            }

            // 如果本地没有IP数据库,则从网络下载
            if (DbFile.IsNullOrWhiteSpace())
            {
                ThreadPoolX.QueueUserWorkItem(() =>
                {
                    var url = Setting.Current.PluginServer;
                    XTrace.WriteLine("没有找到IP数据库{0},准备联网获取 {1}", ip, url);

                    var client = new WebClientX
                    {
                        Log = XTrace.Log
                    };
                    var file = client.DownloadLink(url, "ip.gz", dir.GetFullPath());

                    if (File.Exists(file))
                    {
                        DbFile = file.GetFullPath();
                        zip    = null;
                        // 让它重新初始化
                        _inited = null;
                    }
                });
            }
        }
Exemplo n.º 2
0
        static Ip()
        {
            var dir = Runtime.IsWeb ? "..\\Data" : ".";
            var ip  = dir.CombinePath("ip.gz").GetFullPath();

            if (File.Exists(ip))
            {
                DbFile = ip;
            }

            // 如果本地没有IP数据库,则从网络下载
            if (DbFile.IsNullOrWhiteSpace())
            {
                Task.Factory.StartNew(() =>
                {
                    var url = Setting.Current.PluginServer;
                    XTrace.WriteLine("没有找到IP数据库{0},准备联网获取 {1}", ip, url);

                    var client = new WebClientX
                    {
                        Log = XTrace.Log
                    };
                    var file = client.DownloadLink(url, "ip.gz", dir.GetFullPath());

                    if (File.Exists(file))
                    {
                        DbFile = file.GetFullPath();
                        zip    = null;
                        // 让它重新初始化
                        _inited = null;
                    }
                }, TaskCreationOptions.LongRunning).LogException();
            }
        }
Exemplo n.º 3
0
        static void Test1()
        {
            //new AgentService().Main();

            var wc = new WebClientX
            {
                Log = XTrace.Log
            };
            var url = wc.DownloadLink("http://x.newlifex.com/", "Oracle.ManagedDataAccess.st", ".");

            XTrace.WriteLine(url);

            url = wc.DownloadLink("http://x.newlifex.com/", "MySql.Data.st", ".");
            XTrace.WriteLine(url);

            url = wc.DownloadLink("http://x.newlifex.com/", "MySql.Data64Fx40,MySql.Data", ".");
            XTrace.WriteLine(url);

            url = wc.DownloadLink("http://x.newlifex.com/", "System.Data.SqlClient.st", ".");
            XTrace.WriteLine(url);
        }
Exemplo n.º 4
0
        static Ip()
        {
            var dir = Runtime.IsWeb ? "..\\Data" : ".";
            var ip  = dir.CombinePath("ip.gz");

            if (File.Exists(ip))
            {
                DbFile = ip;
            }

            // 删除旧版本
            ip = "App_Data\\ip.gz".GetFullPath();
            if (File.Exists(ip))
            {
                File.Delete(ip);
                var di = "App_Data".AsDirectory();
                if (di.GetFiles().Length == 0)
                {
                    di.Delete(true);
                }
            }

            // 如果本地没有IP数据库,则从网络下载
            if (DbFile.IsNullOrWhiteSpace())
            {
                Task.Factory.StartNew(() =>
                {
                    var url = Setting.Current.PluginServer;
                    XTrace.WriteLine("没有找到IP数据库,准备联网获取 {0}", url);

                    var client = new WebClientX();
                    client.Log = XTrace.Log;
                    var file   = client.DownloadLink(url, "ip.gz", dir.GetFullPath());

                    if (File.Exists(file))
                    {
                        DbFile = file.GetFullPath();
                        zip    = null;
                        // 让它重新初始化
                        _inited = null;
                    }
                }, TaskCreationOptions.LongRunning).LogException();
            }
        }
Exemplo n.º 5
0
Arquivo: Ip.cs Projeto: zuojiashun/X
        static Ip()
        {
            var ns = new String[] { "qqwry.dat", "qqwry.gz", "ip.gz", "ip.gz.config", "ipdata.config" };

            foreach (var item in ns)
            {
                var fi = ".".AsDirectory().GetAllFiles(item, true).FirstOrDefault();
                if (fi != null)
                {
                    DbFile = fi.FullName;
                    break;
                }
            }

            // 如果本地没有IP数据库,则从网络下载
            if (DbFile.IsNullOrWhiteSpace())
            {
                Task.Factory.StartNew(() =>
                {
                    var url = Setting.Current.PluginServer;
                    XTrace.WriteLine("没有找到IP数据库,准备联网获取 {0}", url);

                    var client = new WebClientX();
                    client.Log = XTrace.Log;
                    var dir    = Runtime.IsWeb ? "App_Data" : "Data";
                    var file   = client.DownloadLink(url, "ip.gz", dir.GetFullPath());

                    if (File.Exists(file))
                    {
                        DbFile = file.GetFullPath();
                        zip    = null;
                        // 让它重新初始化
                        _inited = null;
                    }
                }, TaskCreationOptions.LongRunning).LogException();
            }
        }
Exemplo n.º 6
0
        static Ip()
        {
            var ns = new String[] { "qqwry.dat", "qqwry.gz", "ip.gz", "ip.gz.config", "ipdata.config" };

            foreach (var item in ns)
            {
                var fs = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, item, SearchOption.AllDirectories);
                if (fs != null && fs.Length > 0)
                {
                    DbFile = Path.GetFullPath(fs[0]);
                    break;
                }
            }

            // 如果本地没有IP数据库,则从网络下载
            if (DbFile.IsNullOrWhiteSpace())
            {
                Task.Factory.StartNew(() =>
                {
                    var url = Setting.Current.PluginServer;
                    XTrace.WriteLine("没有找到IP数据库,准备联网获取 {0}", url);

                    var client = new WebClientX();
                    client.Log = XTrace.Log;
                    var dir    = Runtime.IsWeb ? "App_Data" : "Data";
                    var file   = client.DownloadLink(url, "ip.gz", dir.GetFullPath());

                    if (File.Exists(file))
                    {
                        DbFile = file.GetFullPath();
                        zip    = null;
                        // 让它重新初始化
                        _inited = null;
                    }
                }, TaskCreationOptions.LongRunning).LogException();
            }
        }