- bool ret = true;
- ConnectionInfo connectionInfo = new ConnectionInfo("addons.inpost24.com", 22323, "inrouting", new PasswordAuthenticationMethod("inrouting", "OFIT6jJbSZRF18HzW"));
- SftpClient sftp = null;
- try
- {
- SendMessage(MessageType.Info, "Pobieranie danych z InPost", false);
- sftp = new SftpClient(connectionInfo);
- sftp.Connect();
- int lncnt = 0;
- using (MemoryStream ms = new MemoryStream())
- {
- SendMessage(MessageType.Info, "Wczytuję plik 'apm_micro_area.csv'", false);
- sftp.DownloadFile("/pl-regions/apm_micro_area/apm_micro_area.csv", ms);
- ms.Position = 0;
- using (StreamReader reader = new StreamReader(ms))
- {
- string header = reader.ReadLine();
- if (header == "box_machine_name;area_number;micro_area")
- {
- while (!reader.EndOfStream)
- {
- lncnt++;
- SendMessage(MessageType.Count, $"Plik: apm_micro_area.csv; Linia: {lncnt}", false);
- string[] line = reader.ReadLine().Split(';').Select(t => t.Trim('"', '\'')).ToArray();
- Data.Inpost.SetMicroArea(line[0], line[1], line[2]);
- }
- }
- else
- SendMessage(MessageType.Warning, "Nieznany nagłówek", false);
- }
- SendMessage(MessageType.Info, $"Wczytano {lncnt} linii", false);
- }
- lncnt = 0;
- using (MemoryStream ms = new MemoryStream())
- {
- SendMessage(MessageType.Info, "Wczytuję plik '4214456.csv'", false);
- sftp.DownloadFile("/pl-regions/4214456/4214456.csv", ms);
- ms.Position = 0;
- using (StreamReader reader = new StreamReader(ms))
- {
- string header = reader.ReadLine();
- if (header == "Postcode;Branch;BranchID;Area;SortingHubCode;LastModify")
- {
- while (!reader.EndOfStream)
- {
- lncnt++;
- SendMessage(MessageType.Count, $"Plik: 4214456.csv; Linia: {lncnt}", false);
- string[] line = reader.ReadLine().Split(';').Select(t => t.Trim('"', '\'')).ToArray();
- Data.Inpost.SetRoutingCode(line[0], line[1], line[3], line[4], line[5]);
- }
- }
- else
- SendMessage(MessageType.Warning, "Nieznany nagłówek", false);
- }
- SendMessage(MessageType.Info, $"Wczytano {lncnt} linii", false);
- }
- }
- catch (Exception ex)
- {
- ret = false;
- SendMessage(MessageType.Error, ex.Message, false);
- }
- finally
- {
- if (sftp != null)
- {
- if (sftp.IsConnected)
- sftp.Disconnect();
- sftp.Dispose();
- }
- }
- return ret;