public override bool isDatabaseOK() { //Get database name String DatabaseName = myBaseDao.GetDatabaseName(); String file_name = "Database\\" + DatabaseName + ".db"; SanitaLog.d(TAG, "isDatabaseOK"); //If have no database -> create datbase if (!File.Exists(file_name)) { SanitaLog.d(TAG, "Create database : " + file_name); CreateDatabase(DatabaseName); } System.Threading.Thread.Sleep(1000); //If have no database -> create datbase if (!File.Exists(file_name)) { SanitaLog.d(TAG, "false"); return(false); } else { SanitaLog.d(TAG, "true"); return(true); } }
void mWeb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { SanitaLog.d("Form_ThoCa_BaiTho", "mWeb_DocumentCompleted"); String data_group_tacgia = mWeb.DocumentText; if (!String.IsNullOrEmpty(data_group_tacgia)) { data_group_tacgia = System.Net.WebUtility.HtmlDecode(data_group_tacgia); if (!data_group_tacgia.ToLower().Contains("Nước:".ToLower()) && !data_group_tacgia.ToLower().Contains("poem - group - list".ToLower())) { return; } //Lấy danh sách tác phẩm { String pattern = "<a href=\"(?<Link1>[^\"]+)(/poem-)(?<Link2>[^\"]+)\">(?<Name>[^<]+)<"; MatchCollection list_match = new Regex(pattern, RegexOptions.Singleline | RegexOptions.IgnoreCase).Matches(data_group_tacgia); foreach (Match match in list_match) { String link = match.Groups["Link1"].Value + "/poem-" + match.Groups["Link2"].Value; String name = match.Groups["Name"].Value; name = name.Replace("?", ""); name = name.Replace("<", ""); name = name.Replace(">", ""); name = name.Replace("/", ""); name = name.Replace("\\", ""); name = name.Replace("#", ""); name = name.Replace(":", ""); SanitaLog.d("Form_ThoCa_BaiTho", "ten_tac_gia = " + ten_tac_gia); SanitaLog.d("Form_ThoCa_BaiTho", "ten_tac_pham = " + name); try { String path_file = "D:\\ThiVien.Net\\TacPham\\" + ten_tac_gia + "+++" + name + ".txt"; File.WriteAllText(path_file, "https://www.thivien.net/" + link); } catch (Exception ex) { SanitaLog.d("Form_ThoCa_BaiTho", ex.Message); IsNext = false; return; } } } IsNext = true; } }
void mWeb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { String data_group_tacgia = mWeb.DocumentText; if (!String.IsNullOrEmpty(data_group_tacgia)) { data_group_tacgia = System.Net.WebUtility.HtmlDecode(data_group_tacgia); if (!data_group_tacgia.ToLower().Contains("poem-content".ToLower())) { return; } //Lấy danh sách tác phẩm { IList <String> list_pattern = new List <String>(); list_pattern.Add("<h4><strong>" + ten_tac_pham + "</strong></h4>(?<NoiDung>.*?)</div>"); list_pattern.Add("<div class=\"poem-content\">(?<NoiDung>.*?)</div>"); bool IsOk = false; foreach (String pattern in list_pattern) { Match match = new Regex(pattern, RegexOptions.Singleline | RegexOptions.IgnoreCase).Match(data_group_tacgia); if (match != null && match.Success) { String name = match.Groups["NoiDung"].Value; try { String path_file = "D:\\ThiVien.Net\\TacPhamChiTiet\\" + ten_tac_gia_tac_pham + ".txt"; File.WriteAllText(path_file, name); IsOk = true; break; } catch (Exception ex) { SanitaLog.d("Form_ThoCa_BaiThoChiTiet", ex.Message); return; } } } if (!IsOk) { SanitaLog.d("Form_ThoCa_BaiThoChiTiet", "Parse failed : " + mWeb.Url); MessageBox.Show("Lỗi không xử lý được data, index = " + index_group); return; } } IsNext = true; } }
private void btnAdd_Click(object sender, EventArgs e) { IsNext = false; String group_tacgia = list_group_tacgia[index_group - 1]; String url_group_tacgia = File.ReadAllText(group_tacgia); String file_name_simple = new FileInfo(list_group_tacgia[index_group - 1]).Name; ten_tac_gia = file_name_simple.Replace(".txt", ""); SanitaLog.d("Form_ThoCa_BaiTho", "index_group = " + index_group); mWeb.Url = new Uri(url_group_tacgia); }
private void btnAdd_Click(object sender, EventArgs e) { IsNext = false; String group_tac_pham = list_danh_sach_tac_pham[index_group - 1]; String url_group_tacgia = File.ReadAllText(group_tac_pham); String file_name_simple = new FileInfo(group_tac_pham).Name; ten_tac_gia_tac_pham = file_name_simple.Replace(".txt", ""); IList <String> list_ten_tac_pham = ten_tac_gia_tac_pham.Split(new string[] { "+++" }, StringSplitOptions.None); ten_tac_pham = list_ten_tac_pham[1]; SanitaLog.d("Form_ThoCa_BaiThoChiTiet", "index_group = " + index_group); mWeb.Url = new Uri(url_group_tacgia); }
public T GetData <T>(String url) { try { var buf = mWebClient.DownloadData(url); if (buf != null) { string download = System.Text.Encoding.ASCII.GetString(buf); SanitaLog.d(TAG, download); return(JsonConvert.DeserializeObject <T>(download)); } else { SanitaLog.d(TAG, "buf=null"); } } catch (Exception ex) { SanitaLog.e(TAG, ex); } return(default(T)); }
static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); SanitaLog.SetLogName("Medibox"); SanitaLogEx.SetLogName("Medibox"); //Create temp if (!Directory.Exists(Path.Combine(Application.StartupPath, "Data"))) { Directory.CreateDirectory(Path.Combine(Application.StartupPath, "Data")); } if (!Directory.Exists(Path.Combine(Application.StartupPath, "Log"))) { Directory.CreateDirectory(Path.Combine(Application.StartupPath, "Log")); } //Get info object[] customAttributes = Assembly.GetExecutingAssembly().GetCustomAttributes(false); foreach (object attribute in customAttributes) { if (attribute.GetType() == typeof(AssemblyDescriptionAttribute)) { MyVar.mAppDescription = ((AssemblyDescriptionAttribute)attribute).Description; SanitaLog.d(TAG, "Description:" + MyVar.mAppDescription); } if (attribute.GetType() == typeof(AssemblyTitleAttribute)) { MyVar.mAppName = ((AssemblyTitleAttribute)attribute).Title; SanitaLog.d(TAG, "Name:" + MyVar.mAppName); } if (attribute.GetType() == typeof(AssemblyFileVersionAttribute)) { MyVar.mAppVersion = ((AssemblyFileVersionAttribute)attribute).Version; SanitaLog.d(TAG, "Version:" + MyVar.mAppVersion); } } //Init Toast ToastNotification.DefaultToastGlowColor = eToastGlowColor.Red; ToastNotification.DefaultToastPosition = eToastPosition.MiddleCenter; ToastNotification.ToastFont = new System.Drawing.Font("Tahoma", 10); //Load setting try { MyVar.mMediboxSetting = JsonConvert.DeserializeObject <MediboxSetting>(File.ReadAllText(MyVar.SettingsFileName)); if (MyVar.mMediboxSetting.DB_ENCRIPT) { MyVar.mMediboxSetting.DB_ENCRIPT = false; MyVar.mMediboxSetting.DB_SERVER = CryptorEngine.Decrypt(MyVar.mMediboxSetting.DB_SERVER, true); MyVar.mMediboxSetting.DB_USERID = CryptorEngine.Decrypt(MyVar.mMediboxSetting.DB_USERID, true); MyVar.mMediboxSetting.DB_PORT = CryptorEngine.Decrypt(MyVar.mMediboxSetting.DB_PORT, true); MyVar.mMediboxSetting.DB_USERPASSWORD = CryptorEngine.Decrypt(MyVar.mMediboxSetting.DB_USERPASSWORD, true); MyVar.mMediboxSetting.DB_NAME = CryptorEngine.Decrypt(MyVar.mMediboxSetting.DB_NAME, true); } } catch (Exception ex) { SanitaLog.e(TAG, ex); } //Start application { //Check database while (true) { String Localserver = MyVar.mMediboxSetting.DB_SERVER; String Localdatabase = MyVar.mMediboxSetting.DB_NAME; String Localuserid = MyVar.mMediboxSetting.DB_USERID; String Localpassword = MyVar.mMediboxSetting.DB_USERPASSWORD; SystemInfo.DatabaseType = Sanita.Utility.Database.Utility.DatabaseUtility.DATABASE_TYPE.POSTGRESQL; SoftUpdatePresenter.SetConnectionConfig(Localserver, Localuserid, Localpassword, Localdatabase, MyVar.DEFAULT_PORT); //Init database SoftUpdatePresenter.InitDatabase(); //Check database OK if (!SoftUpdatePresenter.IsDatabaseOK()) { using (FormConfigDatabase form = new FormConfigDatabase()) { if (form.ShowDialog() == DialogResult.OK) { continue; } else { SanitaMessageBox.Show("Lỗi kết nối cơ sở dữ liệu !", "Thông Báo"); return; } } } break; } //Start main form FormLogin mFormLogin = new FormLogin(); Application.Run(mFormLogin); } }
public static void DoUpdateDatabaseSQL() { SanitaLog.d(TAG, "DoUpdateDatabaseSQL--START"); try { IBaseDao baseDAO = MediboxDatabaseUtility.GetDatabaseDAO(); //Get connection using (IDbConnection connection = baseDAO.GetConnection()) { //Open connection connection.Open(); //Begin transtation using (IDbTransaction trans = connection.BeginTransaction()) { //Check sql SoftUpdate mSoftUpdate = SoftUpdateDB.mInstance.GetSoftUpdate_Simple(connection, trans); SanitaLog.d(TAG, "Database sql = " + mSoftUpdate.SoftUpdateSQL); SanitaLog.d(TAG, "Software sql = " + MediboxDatabaseUtility.GetDatabaseVersion()); if (MediboxDatabaseUtility.GetDatabaseVersion().GetDouble() > mSoftUpdate.SoftUpdateSQL.GetDouble()) { SanitaLog.d(TAG, "BEGIN UPDATE SQL"); int hosobenhan_partion = 0; if (mLocalDatabase.SynchDatabase(connection, trans, null, hosobenhan_partion, false)) { SanitaLog.d(TAG, "UPDATE SUCCESS !"); mSoftUpdate.SoftUpdateSQL = MediboxDatabaseUtility.GetDatabaseVersion(); if (mSoftUpdate.SoftUpdateID > 0) { if (SoftUpdateDB.mInstance.UpdateSoftUpdate_SQL(connection, trans, mSoftUpdate) < 0) { SanitaLog.d(TAG, "UPDATE SQL VERSION TO DATABASE NG !"); //Rollback trans.Rollback(); connection.Close(); return; } } else { if (SoftUpdateDB.mInstance.InsertSoftUpdate(connection, trans, mSoftUpdate) < 0) { SanitaLog.d(TAG, "INSERT SQL VERSION TO DATABASE NG !"); //Rollback trans.Rollback(); connection.Close(); return; } } } SanitaLog.d(TAG, "END UPDATE SQL"); } //----------------------------------------------------------------------------- //Commit transtation trans.Commit(); //Close connection connection.Close(); } } SanitaLog.d(TAG, "DoUpdateDatabaseSQL--END"); } catch (Exception ex) { SanitaLog.e(TAG, ex); } }