Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Xml.Serialization;
- using System.Runtime.Serialization.Json;
- using System.Threading.Tasks;
- using MessageLib;
- using System.Runtime.InteropServices;
- using System.IO;
- namespace ConsoleApp1
- {
- public class Program
- {
- // Экземпляр класса Random для генерации случайных чисел
- private static Random random = new Random();
- private const string Pattern = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
- private static string GetRandomContent(int length)
- {
- string result = "";
- for (var i = 0; i < length; i++)
- result += Pattern[random.Next(0, Pattern.Length)];
- return result;
- }
- static void Main(string[] args)
- {
- // Цикл повтора решения
- do
- {
- Console.Clear(); // Очистка консоли
- Console.Write("Введите число n(n >= 10 && n <= 1000): ");
- uint n;
- while (!uint.TryParse(Console.ReadLine(), out n) || n < 10 || n > 1000)
- {
- Console.WriteLine("Неверные входные данные!");
- Console.Write("Введите число n(n >= 10 && n <= 1000): ");
- }
- MessageBox messageBox = new MessageBox();
- uint count = 0;
- while (count != n)
- try
- {
- Message tempMsg = new Message(GetRandomContent(random.Next(5, 100 + 1)), DateTime.Now);
- messageBox.ReceiveMail(tempMsg);
- count++;
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- n /= 2;
- count = 0;
- while (count != n)
- {
- Dmessage tempMsg = new Dmessage(GetRandomContent(random.Next(5, 36 + 1)), DateTime.Now, random.Next(1, 1000 + 1));
- messageBox.ReceiveMail(tempMsg);
- count++;
- }
- foreach (var message in messageBox)
- Console.WriteLine(message.ToString());
- DataContractJsonSerializer jsonFormatter = new DataContractJsonSerializer(typeof(MessageBox));
- using (FileStream fs = new FileStream("messageBox.json", FileMode.Create))
- {
- jsonFormatter.WriteObject(fs, messageBox);
- }
- Console.WriteLine("Для завершения работы нажмите Esc...\nДля продолжения любую иную клавишу...");
- }
- while (Console.ReadKey(true).Key != ConsoleKey.Escape);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment