From 7a6fa0a5e461495beabeda283b294c6611f30d48 Mon Sep 17 00:00:00 2001 From: Eugene Kazakov Date: Tue, 17 Oct 2023 10:12:23 +0300 Subject: [PATCH] =?UTF-8?q?2=20=D0=BB=D0=B0=D0=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tasks/kazakov-ev/lab_2/docker-compose.yml | 13 +++++++++++ tasks/kazakov-ev/lab_2/var/data/test1.txt | 3 +++ tasks/kazakov-ev/lab_2/var/data/test2.txt | 5 +++++ tasks/kazakov-ev/lab_2/var/data/test3.txt | 10 +++++++++ tasks/kazakov-ev/lab_2/worker-1/Program.cs | 24 +++++++++++++++++++-- tasks/kazakov-ev/lab_2/worker-2/Program.cs | 25 ++++++++++++++++++++-- 6 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 tasks/kazakov-ev/lab_2/docker-compose.yml create mode 100644 tasks/kazakov-ev/lab_2/var/data/test1.txt create mode 100644 tasks/kazakov-ev/lab_2/var/data/test2.txt create mode 100644 tasks/kazakov-ev/lab_2/var/data/test3.txt diff --git a/tasks/kazakov-ev/lab_2/docker-compose.yml b/tasks/kazakov-ev/lab_2/docker-compose.yml new file mode 100644 index 0000000..fe26cfe --- /dev/null +++ b/tasks/kazakov-ev/lab_2/docker-compose.yml @@ -0,0 +1,13 @@ +version: "3.1" +services: + worker-1: + build: ./worker-1 + volumes: + - ./data:/var/data + - ./result:/var/result + worker-2: + build: ./worker-2 + volumes: + - ./result:/var/result + depends_on: + - worker-1 \ No newline at end of file diff --git a/tasks/kazakov-ev/lab_2/var/data/test1.txt b/tasks/kazakov-ev/lab_2/var/data/test1.txt new file mode 100644 index 0000000..5f5fbe7 --- /dev/null +++ b/tasks/kazakov-ev/lab_2/var/data/test1.txt @@ -0,0 +1,3 @@ +1 +2 +3 \ No newline at end of file diff --git a/tasks/kazakov-ev/lab_2/var/data/test2.txt b/tasks/kazakov-ev/lab_2/var/data/test2.txt new file mode 100644 index 0000000..627e109 --- /dev/null +++ b/tasks/kazakov-ev/lab_2/var/data/test2.txt @@ -0,0 +1,5 @@ +1 +1 +1 +1 +1 diff --git a/tasks/kazakov-ev/lab_2/var/data/test3.txt b/tasks/kazakov-ev/lab_2/var/data/test3.txt new file mode 100644 index 0000000..ec47769 --- /dev/null +++ b/tasks/kazakov-ev/lab_2/var/data/test3.txt @@ -0,0 +1,10 @@ +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 \ No newline at end of file diff --git a/tasks/kazakov-ev/lab_2/worker-1/Program.cs b/tasks/kazakov-ev/lab_2/worker-1/Program.cs index 3751555..6c038fd 100644 --- a/tasks/kazakov-ev/lab_2/worker-1/Program.cs +++ b/tasks/kazakov-ev/lab_2/worker-1/Program.cs @@ -1,2 +1,22 @@ -// See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World!"); +using System.Text; + +string[] files = Directory.GetFiles("/var/data"); +string maxFilePath = ""; +long maxL = 0; +foreach(var filePath in files){ + FileInfo fileInfo = new FileInfo(filePath); + if(fileInfo.Length > maxL){ + maxL = fileInfo.Length; + maxFilePath = filePath; + } +} +using (FileStream fstream = File.OpenRead(maxFilePath)){ + byte[] buffer = new byte[fstream.Length]; + await fstream.ReadAsync(buffer, 0, buffer.Length); + string text = Encoding.Default.GetString(buffer); + using(FileStream fstream1 = new FileStream("/var/result/data.txt", FileMode.OpenOrCreate)){ + fstream1.SetLength(0); + byte[] buffer1 = Encoding.Default.GetBytes(text); + await fstream1.WriteAsync(buffer1, 0, buffer1.Length); + } +} diff --git a/tasks/kazakov-ev/lab_2/worker-2/Program.cs b/tasks/kazakov-ev/lab_2/worker-2/Program.cs index 3751555..59211c8 100644 --- a/tasks/kazakov-ev/lab_2/worker-2/Program.cs +++ b/tasks/kazakov-ev/lab_2/worker-2/Program.cs @@ -1,2 +1,23 @@ -// See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World!"); +using System.Text; + +int[] numbers = File.ReadAllLines("../../../../var/data/data.txt").Select(x=> int.Parse(x)).ToArray(); +int maxNumber = 0; +int maxNumberCount = 0; +foreach(var number in numbers){ + if(number < maxNumber){ + continue; + } + if(number == maxNumber){ + maxNumberCount++; + continue; + } + if(number > maxNumber){ + maxNumber = number; + maxNumberCount = 1; + } +} +using(FileStream fstream = new FileStream("../../../../var/result/result.txt", FileMode.OpenOrCreate)){ + byte[] buffer = Encoding.Default.GetBytes(maxNumberCount.ToString()); + await fstream.WriteAsync(buffer, 0, buffer.Length); +} +Console.WriteLine(maxNumberCount);