예제 #1
0
        public static bool ValidateSxGeo()
        {
            //проверяем наличие БД SxGeo
            SxPath = AddSlash(AddSlash(SettingsPath) + SxGeoDir) + SxGeoCity;
            IPGeoinfo tmpGeoInfo = new IPGeoinfo(SxPath);

            if (tmpGeoInfo.IsValidSxGeoFile()) //SxGeoSity найдена и валидная
            {
                SxGeoBase = SxGeoBaseType.SxGeoCity;
                return(true);
            }
            else
            {
                SxPath     = AddSlash(AddSlash(SettingsPath) + SxGeoDir) + SxGeoCountry;
                tmpGeoInfo = new IPGeoinfo(SxPath);
                if (tmpGeoInfo.IsValidSxGeoFile()) //SxGeoCountry найдена и валидная
                {
                    SxGeoBase = SxGeoBaseType.SxGeoCountry;
                    return(true);
                }
                else
                {
                    SxGeoBase = SxGeoBaseType.SxGeoNone;
                    SxPath    = string.Empty;
                    return(false);
                }
            }
        }
예제 #2
0
        private bool DumpToDataSet(DataSet ds, string TableName, string[] Data, char Divider)
        {
            IPGeoinfo GeoInfo = new IPGeoinfo(CommonFunctions.SxPath);

            if (!GeoInfo.Open())
            {
                ErrorMessage = GeoInfo.ErrorMessage;
                return(false);
            }
            ds.Tables[TableName].Rows.Clear();
            foreach (string rec in Data) //обходим массив входных строк
            {
                if (rec.Trim() != string.Empty)
                {
                    string[] val   = rec.Split(Divider); //разделяем строки на составляющие части
                    string   IP    = "";
                    string   Field = "";
                    try
                    {
                        IP    = val[0];
                        Field = val[1];
                    }
                    catch (Exception ex)
                    {
                        ErrorMessage = ex.Message;
                        GeoInfo.Close();
                        return(false);
                    }

                    // вытаскиваем из БД информацию об IP
                    Dictionary <string, object> IPInfo = GeoInfo.GetIPInfo(IP);

                    //раскладываем ее в DataSet
                    try
                    {
                        DataRow dr = ds.Tables[TableName].Rows.Add();
                        foreach (string Key in IPInfo.Keys)
                        {
                            dr[Key] = IPInfo[Key];
                        }
                        dr["Field"] = Field;
                    }
                    catch (Exception ex)
                    {
                        ErrorMessage = ex.Message;
                        GeoInfo.Close();
                        return(false);
                    }
                }
            }

            GeoInfo.Close();
            return(true);
        }
        private void btnUptateSxGeo_Click(object sender, EventArgs e)
        {
            DialogResult Ans = dlgOpenSxG.ShowDialog();

            if (Ans == DialogResult.Cancel)
            {
                return;
            }
            string ResultMess = "";
            string srcpath    = CommonFunctions.AddSlash(dlgOpenSxG.SelectedPath)
                                + CommonFunctions.SxGeoCountry;
            string dstpath = CommonFunctions.AddSlash(CommonFunctions.AddSlash(
                                                          CommonFunctions.SettingsPath) +
                                                      CommonFunctions.SxGeoDir) + CommonFunctions.SxGeoCountry;

            //ищем файл SxGeoCountry
            IPGeoinfo tmpGeoInfo = new IPGeoinfo(srcpath);

            if (tmpGeoInfo.IsValidSxGeoFile())
            {
                ResultMess = "Файл " + CommonFunctions.SxGeoCountry + " найден. \n"
                             + CommonFunctions.CopyFile(srcpath, dstpath) + "\n";
            }
            else
            {
                ResultMess = "Файл " + CommonFunctions.SxGeoCountry + ": "
                             + tmpGeoInfo.ErrorMessage + "\n";
            }

            //ищем файл SxGeoCity
            srcpath = CommonFunctions.AddSlash(dlgOpenSxG.SelectedPath)
                      + CommonFunctions.SxGeoCity;
            dstpath = CommonFunctions.AddSlash(CommonFunctions.AddSlash
                                                   (CommonFunctions.SettingsPath) +
                                               CommonFunctions.SxGeoDir) + CommonFunctions.SxGeoCity;

            tmpGeoInfo = new IPGeoinfo(srcpath);
            if (tmpGeoInfo.IsValidSxGeoFile())
            {
                ResultMess = ResultMess + "Файл " + CommonFunctions.SxGeoCity + " найден. \n"
                             + CommonFunctions.CopyFile(srcpath, dstpath);
            }
            else
            {
                ResultMess = ResultMess + "Файл " + CommonFunctions.SxGeoCity + ": "
                             + tmpGeoInfo.ErrorMessage;
            }

            CommonFunctions.ValidateSxGeo();

            MessageBox.Show(ResultMess, "Результат обновления",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
예제 #4
0
        private void CreateDataSet()
        {
            //вытаскиваем поля и строим таблицу DataSet
            IPGeoinfo tmpGeoInfo = new IPGeoinfo(CommonFunctions.SxPath);

            tmpGeoInfo.Open();
            Dictionary <string, Type> Fields = tmpGeoInfo.GetAllFields();

            Fields.Add("field", typeof(string));
            tmpGeoInfo.Close();

            dsIP.Tables.Add("Info");
            dsIP.Tables["Info"].Columns.Add("Parameter", typeof(string));
            dsIP.Tables["Info"].Columns.Add("Data", typeof(string));

            dsIP.Tables.Add("IP");
            foreach (string key in Fields.Keys)
            {
                dsIP.Tables["IP"].Columns.Add(key, Fields[key]);
            }
        }