void timer1_Tick(object sender, EventArgs e) { try { if (checkgenerateUpload.Checked) { GenAndUpload(); return; } if (CheckTimeupran() && !_isupdate1folder) { //random upload if (listBox1.Items.Count <= 0) { return; } if (listBox1.Items.Count == 1) { _isupdate1folder = true; } FTPHelper ftphelper = new FTPHelper(CTLConfig._user, CTLConfig._pass, CTLConfig._pathftp); Random ran = new Random(); int x = ran.Next(listBox1.Items.Count); DirectoryInfo d = new DirectoryInfo(listBox1.Items[x].ToString()); foreach (FileInfo f in d.GetFiles("*.txt")) { string str = ftphelper.UploadFile(f.FullName); CTLError.WriteError("Update " + d.Name, str); } } else if (CheckTimeupDefault() && !_isupload) { FTPHelper ftphelper = new FTPHelper(CTLConfig._user, CTLConfig._pass, CTLConfig._pathftp); //upload default _isupload = true; DirectoryInfo d = new DirectoryInfo(CTLConfig._pathdefault); foreach (FileInfo f in d.GetFiles("*.txt")) { string str = ftphelper.UploadFile(f.FullName); CTLError.WriteError("Update " + d.Name, str); } } } catch (Exception ex) { CTLError.WriteError("Loi Timer Tick ", ex.Message); return; } }
private void bttestupload_Click(object sender, EventArgs e) { try { OpenFileDialog openfile = new OpenFileDialog(); if (openfile.ShowDialog() == DialogResult.OK) { FTPHelper ftphelper = new FTPHelper(CTLConfig._user, CTLConfig._pass, CTLConfig._pathftp); string res = ftphelper.UploadFile(openfile.FileName); if (res != string.Empty) { MessageBox.Show("Upload Thanh cong!!", "Upload Config", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception ex) { CTLError.WriteError("loi test upload ", ex.Message); return; } }
public void GenAndUpload() { try { //DirectoryInfo dsource = new DirectoryInfo(CTLConfig._pathfilelocal); //code cu GenFrom file txt //foreach(FileInfo f in dsource.GetFiles("*.txt")) //{ // //set ID APP // SetValueFile(f.FullName); // //set ads // SetTrueFalseAD(f.FullName); // FTPHelper ftphelper = new FTPHelper(CTLConfig._user, CTLConfig._pass, CTLConfig._pathftp); // ftphelper.UploadFile(f.FullName); //} //end //code moi genfromfile xml FileInfo filegenxml = new FileInfo(Path.Combine(Application.StartupPath, "ConfigADS.xml")); if (filegenxml.Exists) { XmlDocument doc = new XmlDocument(); doc.Load(Application.StartupPath + @"\ConfigADS.xml"); XmlNode nodeList = doc.SelectSingleNode("/GenADS"); if (nodeList != null) { foreach (XmlNode node in nodeList.ChildNodes) { string[] OnAds = node.Attributes["OnAds"].Value.Split(','); string[] RanAds = node.Attributes["RanAds"].Value.Split(','); FileInfo fileUpload = new FileInfo(Path.Combine(CTLConfig._pathfilelocal, node.Name + ".txt")); if (!fileUpload.Exists) { continue; } entyconfigfile enty = new entyconfigfile(fileUpload.FullName); enty.loadValuFromFile(); enty.SetFalseALLAd(); foreach (string str in OnAds) { enty.SetvalueKey(str, "true"); } Random ran = new Random(); foreach (string str in RanAds) { enty.SetvalueKey(str, ran.Next(0, 3) > 0 ? "true" : "false"); } FTPHelper ftphelper = new FTPHelper(CTLConfig._user, CTLConfig._pass, CTLConfig._pathftp); ftphelper.UploadFile(fileUpload.FullName); } } } else { CTLError.WriteError("KO ton tai file ConfigADS.xml ", "Loi gen ads"); } } catch (Exception ex) { CTLError.WriteError("loi GenAndUpload ", ex.Message); MessageBox.Show("Loi " + ex.Message); } }