private static void AnnualReport(NetworkStream stream, byte[] inputData, string clientIp) { var subsidiary = NetManager.ToString(inputData); var annualReport = new QuaterDataSerialize(); if (!Directory.Exists(Folder + "/" + subsidiary)) { var message = $"Данных для \"{subsidiary}\" не обнаружено."; NetManager.Send(stream, NetManager.ToBytes(message)); Console.WriteLine("{0}: {1}", clientIp, message); } else { var quaters = string.Empty; foreach (var item in new DirectoryInfo(Folder + "/" + subsidiary).GetFiles()) { quaters += ", " + Path.GetFileNameWithoutExtension(item.Name); var quater = new QuaterDataSerialize(); var vs = File.ReadAllBytes(Folder + "/" + subsidiary + "/" + item.Name); annualReport.AddData(quater.Deserialize(vs)); } quaters = quaters.Substring(1, quaters.Length - 1); var message = $"Отчет построен по данным за{quaters}."; NetManager.Send(stream, NetManager.ToBytes(message)); Console.WriteLine("{0}: {1}", clientIp, message); } NetManager.Send(stream, annualReport.Serialize()); }
private static void QuaterDataSave(NetworkStream stream, byte[] inputData, string clientIp) { try { QuaterDataSerialize quaterData = new QuaterDataSerialize(); quaterData = quaterData.Deserialize(inputData); if (!Directory.Exists(Folder + "/" + quaterData.Subsidiary)) { Directory.CreateDirectory(Folder + "/" + quaterData.Subsidiary); } File.WriteAllBytes(Folder + "/" + quaterData.Subsidiary + "/" + quaterData.Quater + ".dat", inputData); var message = $"Получены данные \"{quaterData.Subsidiary}\" за {quaterData.Quater} квартал."; NetManager.Send(stream, NetManager.ToBytes(message)); Console.WriteLine("{0}: {1}", clientIp, message); } catch (Exception ex) { ExceptManager.Write(ex); } }