public Server(int Port, string IP) { this.Host = IP; this.Port = Port; iPEndPoint = new IPEndPoint(IPAddress.Parse(Host), Port); logger = new LogProgram(ref database); worker = new Worker(ref database, ref logger); Console.WriteLine("Server run./ Host:port = " + Host + ":" + Port); logger.WriteLog("Server run. Host:port = " + Host + ":" + Port, LogLevel.Server); }
public void HandleXlsFile(ref FileStruct file) { DateTime created_At; ExcelWorksheet worksheet; string xlsxPath; string xlsPath = file.Path + file.Name; xlsPath = GetExcelFile(ref xlsPath); if (!File.Exists(xlsPath)) { loaderFile.DeleteFile(ref file); logger.WriteLog("Error in getting file. Delete file, file name=" + file.Name, LogLevel.Exceling); return; } created_At = DefineDatetimeZipfile(file.Path + file.Name); xlsxPath = ConvertXlsToXlsx(ref xlsPath); worksheet = GetFirstWorksheetExcel(ref xlsxPath); if (worksheet == null) { logger.WriteLog("Can not get First Worksheet Excel from file", LogLevel.Exceling); return; } SortOutProductCells(ref worksheet, ref created_At); Upload upload = new Upload(file.Name, created_At); database.upload.AddUpload(ref upload); logger.WriteLog("Handle xls file", LogLevel.Exceling); }
public void HandleDownloadXlsByEmail() { string answerFromHandle = ""; List <string> files = mail.ReceivedFileImap(loaderFile.Path_Zip_Save); foreach (string file in files) { string xls_name = file.Substring(file.LastIndexOf('/') + 1); if (database.upload.CheckUploadExist(ref xls_name)) { logger.WriteLog("Program did not handle this archive, because had finded the same file name in database", LogLevel.Exceling); return; } if (!excelModule.HandleXlsFile(file, ref answerFromHandle)) { logger.WriteLog("Error xls handle file" + "Answer of algoritm:\r\n" + answerFromHandle, LogLevel.Worker); } else { logger.WriteLog("Handle excelx file from imap protocol", LogLevel.Worker); } } }
private void ReceivedSocketData(ref Socket handleSocket) { try { byte[] buffer = new byte[1096]; int bytes = 0; string request = ""; int ContentLength = 0; for (; ;) { if (buffer.Length < bytes + 300) { Array.Resize(ref buffer, bytes + 2000); } else { bytes += handleSocket.Receive(buffer, bytes, 60, SocketFlags.None); } if (bytes > 500 && bytes < 1000 && buffer.Length == 1096) { request = Encoding.ASCII.GetString(buffer, 0, bytes); if (request.Contains("content-length:") || request.Contains("Content-Length:")) { ContentLength = GetRequestContentLenght(ref request); if (ContentLength > 0 && ContentLength < 210000000) { Array.Resize(ref buffer, ContentLength + bytes); } else if (ContentLength > 210000000) { handleSocket.Close(); } } } if (handleSocket.Available == 0 && bytes >= ContentLength) { break; } if (handleSocket.Available == 0 && bytes < ContentLength) { if ((handleSocket.Poll(10000, SelectMode.SelectRead) && (handleSocket.Available == 0)) || !handleSocket.Connected) { handleSocket.Close(); logger.WriteLog("Remote socket was disconnected.", LogLevel.Server); break; } } } if (handleSocket.Connected) { if (bytes < 210000000) { request = Encoding.ASCII.GetString(buffer, 0, bytes); IdentifyRequestMethod(ref request, ref handleSocket, ref buffer, ref bytes); } else { HttpIternalServerError(ref handleSocket); } } if (handleSocket.Connected) { handleSocket.Close(); } } catch (Exception e) { logger.WriteLog("Error in function ReceivedSocketData, message:" + e.Message, LogLevel.Error); } }