|
|
|
|
using ConsoleApp1.Animals;
|
|
|
|
|
using ConsoleApp1.Cards;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
|
|
namespace ConsoleApp1
|
|
|
|
|
{
|
|
|
|
|
internal class Program
|
|
|
|
|
{
|
|
|
|
|
static void Main(string[] args)
|
|
|
|
|
{
|
|
|
|
|
h_DisposableDemo();
|
|
|
|
|
using (var object_ = h_DisposablelessDemo())
|
|
|
|
|
{
|
|
|
|
|
//...
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// h_PlayCards();
|
|
|
|
|
//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_DisposableDemo()
|
|
|
|
|
{
|
|
|
|
|
using (MealConsumer human = new MealConsumer(GetMealContainer1()))
|
|
|
|
|
{
|
|
|
|
|
//try
|
|
|
|
|
//{
|
|
|
|
|
human.ThreeHoursLater();
|
|
|
|
|
Thread.Sleep(3 * 60 * 60 * 1000 / 400000);
|
|
|
|
|
human.ThreeHoursLater();
|
|
|
|
|
Thread.Sleep(3 * 60 * 60 * 1000 / 400000);
|
|
|
|
|
human.ThreeHoursLater();
|
|
|
|
|
Thread.Sleep(3 * 60 * 60 * 1000 / 400000);
|
|
|
|
|
Console.WriteLine();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
//finally
|
|
|
|
|
//{
|
|
|
|
|
// human.Dispose();
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static MealConsumer h_DisposablelessDemo()
|
|
|
|
|
{
|
|
|
|
|
MealConsumer human = new MealConsumer(GetMealContainer1());
|
|
|
|
|
human.ThreeHoursLater();
|
|
|
|
|
Thread.Sleep(3 * 60 * 60 * 1000 / 400000);
|
|
|
|
|
human.ThreeHoursLater();
|
|
|
|
|
Thread.Sleep(3 * 60 * 60 * 1000 / 400000);
|
|
|
|
|
human.ThreeHoursLater();
|
|
|
|
|
Thread.Sleep(3 * 60 * 60 * 1000 / 400000);
|
|
|
|
|
Console.WriteLine();
|
|
|
|
|
return human;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static IMealContainer GetMealContainer1()
|
|
|
|
|
{
|
|
|
|
|
return new MealContainer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
Console.WriteLine(ii);
|
|
|
|
|
h_Afd1(ii);
|
|
|
|
|
Console.WriteLine(ii);
|
|
|
|
|
h_Afd2(ref ii);
|
|
|
|
|
Console.WriteLine(ii);
|
|
|
|
|
h_Afd3(out ii);
|
|
|
|
|
Console.WriteLine(ii);
|
|
|
|
|
|
|
|
|
|
List<int> ll = new List<int>();
|
|
|
|
|
h_Lfd(ll);
|
|
|
|
|
|
|
|
|
|
//h_CountOddAndEven(ll);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static bool h_CountOddAndEven(List<int> ll,
|
|
|
|
|
out int iEvenCount, out int iOddCount)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void h_Lfd(List<int> ll)
|
|
|
|
|
{
|
|
|
|
|
ll.Add(1);
|
|
|
|
|
ll.Add(2);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void h_Afd1(int ii)
|
|
|
|
|
{
|
|
|
|
|
ii++;
|
|
|
|
|
}
|
|
|
|
|
private static void h_Afd2(ref int ii)
|
|
|
|
|
{
|
|
|
|
|
ii++;
|
|
|
|
|
}
|
|
|
|
|
private static void h_Afd3(out int ii)
|
|
|
|
|
{
|
|
|
|
|
ii = 10;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void h_PlayCards()
|
|
|
|
|
{
|
|
|
|
|
CardSuit myCardType = CardSuit.Черви;
|
|
|
|
|
Console.WriteLine($"{myCardType}");
|
|
|
|
|
|
|
|
|
|
Card[] arCards = new Card[36];
|
|
|
|
|
CardSuit[] arColors = (CardSuit[])Enum.GetValues(typeof(CardSuit));
|
|
|
|
|
CardValue[] arValues = (CardValue[])Enum.GetValues(typeof(CardValue));
|
|
|
|
|
|
|
|
|
|
int ii = 0;
|
|
|
|
|
foreach (CardSuit color in arColors)
|
|
|
|
|
{
|
|
|
|
|
foreach (CardValue value in arValues)
|
|
|
|
|
{
|
|
|
|
|
Card _card = new Card(color, value);
|
|
|
|
|
arCards[ii] = _card;
|
|
|
|
|
ii++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var card in arCards)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"{card.Suit}:{card.Value}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|