//code cu gen random ad all in config file public void SetTrueFalseAD(string pathFile) { try { foreach (string s in CTLConfig._GenAd) { entyconfigfile enty = new entyconfigfile(pathFile); enty.loadValuFromFile(); enty.SetvalueKey(s, "false"); } //setamazon entyconfigfile entyama = new entyconfigfile(pathFile); entyama.loadValuFromFile(); entyama.SetvalueKey("ad3", "true"); Random ran = new Random(); int CountTrue = ran.Next(1, CTLConfig._GenAd.Count); for (int i = 0; i < CountTrue; i++) { Random ran1 = new Random(); int index = ran1.Next(0, CTLConfig._GenAd.Count); entyconfigfile enty = new entyconfigfile(pathFile); enty.loadValuFromFile(); enty.SetvalueKey(CTLConfig._GenAd[index], "true"); } } catch (Exception ex) { CTLError.WriteError("loi SetTrueFalseAD " + pathFile, ex.Message); MessageBox.Show("Loi " + pathFile + ex.Message); } }
public void SetValueFile(string pathFile) { try { FileInfo FileSource = new FileInfo(pathFile); foreach (string s in CTLConfig._Gentypead) { FileInfo f = new FileInfo(Path.Combine(CTLConfig._pathfilelocal, s.Trim() + FileSource.Name.Split('.')[0])); if (f.Exists) { StreamReader read = new StreamReader(f.FullName); List <string> temp = new List <string>(); while (!read.EndOfStream) { string str = read.ReadLine(); if (str != string.Empty) { temp.Add(str); } } Random ran = new Random(); int index = ran.Next(0, temp.Count); entyconfigfile enty = new entyconfigfile(pathFile); enty.loadValuFromFile(); enty.SetvalueKey(s, temp[index]); } } } catch (Exception ex) { CTLError.WriteError("loi SetValueFile " + pathFile, ex.Message); MessageBox.Show("Loi " + pathFile + ex.Message); } }
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); } }
public void SetValue() { try { if (txtpathfileSetkey.Text == string.Empty) { MessageBox.Show("vui long chon Path File"); return; } DirectoryInfo dparent = new DirectoryInfo(txtpathfileSetkey.Text); if (checkSetparentKey.Checked) { foreach (FileInfo f in dparent.GetFiles(txtfilename.Text)) { if (f.Exists) { entyconfigfile enty = new entyconfigfile(f.FullName); enty.loadValuFromFile(); enty.SetvalueKey(txtKeySet.Text, txtValukey.Text); } } } int CountKey = 0; List <string> listkey = new List <string>(); if (checksetfromfile.Checked) { StreamReader read = new StreamReader(txtfromfile.Text); while (!read.EndOfStream) { string readline = read.ReadLine(); if (readline.Trim() != string.Empty) { listkey.Add(readline); } } } foreach (DirectoryInfo dsource in dparent.GetDirectories()) { foreach (FileInfo f in dsource.GetFiles(txtfilename.Text)) { if (f.Exists) { string valuekey = txtValukey.Text; if (checksetfromfile.Checked) { if (listkey.Count > CountKey) { valuekey = listkey[CountKey++]; } else { valuekey = listkey[CountKey - 1]; } } entyconfigfile enty = new entyconfigfile(f.FullName); enty.loadValuFromFile(); enty.SetvalueKey(txtKeySet.Text, valuekey); } } } labthongbao.Text = "Set Value Thanh Cong"; } catch (Exception ex) { CTLError.WriteError("loi SetValue tab3 ", ex.Message); labthongbao.Text = "Loi " + ex.Message; return; } }