From 069bd4a1e12918be06354b3022a325721998d6ce Mon Sep 17 00:00:00 2001 From: Serg Verevkin Date: Sat, 28 Sep 2024 15:52:41 +0700 Subject: [PATCH] 2024.09.28 --- 202409/ConsoleApp1/Program.cs | 156 +++++++++++++++++++++++++++++++- 202409/ConsoleApp1/XMLFile1.xml | 8 ++ 2 files changed, 160 insertions(+), 4 deletions(-) create mode 100644 202409/ConsoleApp1/XMLFile1.xml diff --git a/202409/ConsoleApp1/Program.cs b/202409/ConsoleApp1/Program.cs index f9a9ef1..5bbed40 100644 --- a/202409/ConsoleApp1/Program.cs +++ b/202409/ConsoleApp1/Program.cs @@ -1,5 +1,7 @@ using ConsoleApp1.Animals; using ConsoleApp1.Cards; +using System.Text; +using System.Xml; namespace ConsoleApp1 { @@ -8,12 +10,158 @@ namespace ConsoleApp1 static void Main(string[] args) { // h_PlayCards(); - Animal animal = new Animal(); - Animal.MilkConsumerAreaInfo info = animal.GetAreaInfo(); - h_Afd(); + //Animal animal = new Animal(); + //Animal.MilkConsumerAreaInfo info = animal.GetAreaInfo(); + //h_Afd();\ + // h_InfoIO(); + // File.Delete("123.csv"); + // string sFn = "123.csv"; + //h_WriteCsv(sFn); + //h_ReadCsv(sFn); + + string sXmlFn = "123.xml"; + h_WriteXml(sXmlFn); + h_ReadXml(sXmlFn); Console.ReadKey(); } + private static void h_WriteXml(string sXmlFn) + { + if (File.Exists(sXmlFn)) File.Delete(sXmlFn); + if (File.Exists(sXmlFn)) return; + Console.WriteLine(DateTime.Now); + using (Stream ms = File.Create(sXmlFn)) + { + using (XmlWriter sw = XmlWriter.Create(ms)) + { + sw.WriteStartDocument(); + sw.WriteStartElement("root"); + sw.WriteAttributeString("versionMy", "1.0"); + sw.WriteStartElement("items"); + for (int ii = 0; ii < 2999999; ii++) + { + sw.WriteStartElement("item"); + sw.WriteAttributeString("attr1", $"{ii}"); + sw.WriteString("content"); + sw.WriteEndElement(); + } + + sw.WriteEndElement(); + sw.WriteEndElement(); + sw.WriteEndDocument(); + } + } + + FileInfo fi = new FileInfo(sXmlFn); + Console.WriteLine($"{fi.Length / 1024 / 1024} Mb / {DateTime.Now}"); + + } + + + private static void h_ReadXml(string sXmlFn) + { + Console.WriteLine($"start {DateTime.Now}"); + XmlDocument? x = new XmlDocument(); + x.Load(sXmlFn); + // x.ChildNodes[0].ChildNodes[0].Attributes[0].Value... + Console.WriteLine($"end {DateTime.Now}"); + } + + private static void h_ReadCsv(string sFn) + { + using (Stream ms = File.OpenRead(sFn)) + { + using (StreamReader sr = new StreamReader(ms, System.Text.Encoding.UTF8)) + { + sr.ReadLine(); + int iCount = 0; + string sLine = String.Empty; + Console.WriteLine(sr.ReadLine()); + while (!sr.EndOfStream) + { + iCount++; + sLine = sr.ReadLine(); + } + Console.WriteLine($"{iCount} // {sLine}"); + } + } + } + + private static void h_WriteCsv(string sFn) + { + if (File.Exists(sFn)) return; + using (Stream ms = File.Create(sFn)) + { + using (StreamWriter sw = new StreamWriter(ms, System.Text.Encoding.UTF8)) + { + sw.WriteLine($"num;date"); + for (int ii = 0; ii < 99999999; ii++) + { + sw.WriteLine($"{ii};{DateTime.Now:mm.ss}"); + } + } + + } + FileInfo fi = new FileInfo(sFn); + Console.WriteLine(fi.Length); + + } + + private static void h_InfoIO() + { + var pp = typeof(Program).GetType().Assembly.Location; + string sDirectory = Path.GetDirectoryName(pp); + // Path.GetFileNameWithoutExtension() + // Path.ChangeExtension() + // DirectoryInfo di = new DirectoryInfo(sDirectory); + // di.EnumerateFiles(); + // Directory.EnumerateFiles() + + using (MemoryStream ms = new MemoryStream(new byte[40960])) + { + ms.Seek(0, SeekOrigin.Begin); + byte[] buffer = new byte[4096]; + ms.Read(buffer, 1, 4096); + int iB = ms.ReadByte(); + using (StreamWriter sw = new StreamWriter(ms, System.Text.Encoding.UTF8)) + { + sw.WriteLine("qwr"); + } + using (StreamReader sw = new StreamReader(ms, System.Text.Encoding.UTF8)) + { + string sLine = sw.ReadLine(); + } + + } + //Stream pFile = null; + //try + //{ + // pFile = File.Create("sa"); + // pFile.Seek(0, SeekOrigin.Begin); + // byte[] buffer = new byte[4096]; + // pFile.Read(buffer, 1, 4096); + // int iB = pFile.ReadByte(); + //} finally + //{ + // pFile?.Dispose(); + //} + using (FileStream fs = File.Create("sa")) + { + fs.Seek(0, SeekOrigin.Begin); + byte[] buffer = new byte[4096]; + fs.Read(buffer, 1, 4096); + int iB = fs.ReadByte(); + } + byte[] bt = File.ReadAllBytes("fn"); + string sText = File.ReadAllText("fn", Encoding.UTF8); + string[] arLines = File.ReadAllLines("fn", Encoding.UTF8); + } + + public static void h_XmlSax() + { + string sContent = @""; + } + private static void h_Afd() { int ii = 0; @@ -31,7 +179,7 @@ namespace ConsoleApp1 //h_CountOddAndEven(ll); } - private static bool h_CountOddAndEven(List ll, + private static bool h_CountOddAndEven(List ll, out int iEvenCount, out int iOddCount) { throw new NotImplementedException(); diff --git a/202409/ConsoleApp1/XMLFile1.xml b/202409/ConsoleApp1/XMLFile1.xml new file mode 100644 index 0000000..90369b5 --- /dev/null +++ b/202409/ConsoleApp1/XMLFile1.xml @@ -0,0 +1,8 @@ + + + + content + content + + + \ No newline at end of file