private void btnSave_Click(object sender, EventArgs e) { // // saveFileDialog // System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog(); saveFileDialog.DefaultExt = "Log"; saveFileDialog.Filter = "Log files|*.Log"; saveFileDialog.Title = "Save to file"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { String Format = "{0,20} {1}"; TStrings Log = new TStrings(); Log.Add(new String('-', 80)); Log.Add(""); Log.Add(String.Format(Format, "Who", System.Reflection.Assembly.GetExecutingAssembly().GetName().ToString())); Log.Add(String.Format(Format, "Version", LastChanceTrace.Version)); Log.Add(String.Format(Format, "Internal build", Assembly.GetExecutingAssembly().GetName().Version.ToString())); if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed) { System.Deployment.Application.ApplicationDeployment appDeploy; appDeploy = System.Deployment.Application.ApplicationDeployment.CurrentDeployment; Log.Add(String.Format(Format, "ClickOnce V", appDeploy.CurrentVersion)); } ; Log.Add(String.Format(Format, "BuildTimeStamp", LastChanceTrace.BuildTimeStamp)); Log.Add(String.Format(Format, "When", DateTime.Now.ToString())); Log.Add(String.Format(Format, "What", textBoxMessage.Text)); Log.Add(String.Format(Format, "Type", textBoxType.Text)); Log.Add(""); Log.Add(new String('-', 80)); Log.Add(""); Log.Add(textBoxStack.Text); Log.Add(""); Log.Add(new String('-', 80)); try { Log.Add(""); Log = GetConfig(Log); Log.Add(""); Log.Add(new String('-', 80)); } catch {}; Log.SaveToFile(saveFileDialog.FileName); } ; }
/// <summary> /// Flushes buffered INI file data to disk. /// </summary> public bool UpdateFile() { TStrings IniFile = new TStrings(); TStrings Section; for (int i = 0; i < FSections.Count; i++) { IniFile.Add("[" + FSections[i] + "]"); Section = (FSections.GetObject(i) as TStrings); for (int j = 0; j < Section.Count; j++) { IniFile.Add(Section[j]); } ; IniFile.Add(""); } ; IniFile.SaveToFile(FFileName, System.Text.Encoding.Unicode); return(true); }
public void _01_SaveToFile_Perftest_03() { FileName = System.IO.Path.GetTempFileName() + ".txt"; TStrings file = new TStrings(); for (int i = 0; i < 100000; i++) { file.Add(dummy); } ; var dt = DateTime.Now; file.SaveToFile(FileName); var dt1 = DateTime.Now - dt; System.IO.File.Delete(FileName); dt = DateTime.Now; string text = ""; for (int i = 0; i < file.Count; i++) { text = text + file.Get(i); } System.IO.File.WriteAllText(FileName, text); var dt2 = DateTime.Now - dt; Console.WriteLine($"{dt1.TotalMilliseconds} < {dt2.TotalMilliseconds}"); Assert.AreEqual(true, dt1 < dt2); }
public void TStrings_Save_Test_1() { FileName = System.IO.Path.GetTempFileName() + ".txt"; TStrings file = new TStrings(); file.Add(DateTime.Now.ToString()); file.Add("123"); file.SaveToFile(FileName); bool Exist = System.IO.File.Exists(FileName); Assert.AreEqual(true, Exist); }
public void _01_SaveToFile_Perftest_00() { FileName = System.IO.Path.GetTempFileName() + ".txt"; TStrings file = new TStrings(); for (int i = 0; i < 100000; i++) { file.Add(dummy); } ; var dt = DateTime.Now; file.SaveToFile(FileName); var dt1 = DateTime.Now - dt; System.IO.File.Delete(FileName); dt = DateTime.Now; using (var stream = new FileStream(FileName, FileMode.Create, FileAccess.Write, FileShare.Write)) { using (StreamWriter asw = new StreamWriter(stream, Encoding.Default)) { for (int i = 0; i < file.Count; i++) { asw.WriteLine(file.Get(i)); } }; }; var dt2 = DateTime.Now - dt; Console.WriteLine($"{dt1.TotalMilliseconds} < {dt2.TotalMilliseconds}"); Assert.AreEqual(true, dt1 < dt2); }