protected virtual void DownloadLeaflet(ILeaflet leaflet) { try { if (leaflet.Status == LeafletStatus.Ready) { string downloadedFileName = PrepareDownloadFileName(leaflet); _client.DownloadFile(new Uri(leaflet.FileDownloadUrl), downloadedFileName); leaflet.DownloadedFileName = downloadedFileName; } } catch (WebException e) { HttpWebResponse response = (HttpWebResponse)e.Response; leaflet.Status = LeafletStatus.StopProcessing; Console.WriteLine("Error downloading file"); } catch (Exception e) { leaflet.Status = LeafletStatus.StopProcessing; Console.WriteLine("Global Error"); } }
protected override string PrepareDownloadFileName(ILeaflet leaflet) { int week = (int)leaflet.Values["week"]; string weekPart = week.ToString().PadLeft(2, '0'); return($"{weekPart}_Kaufland_{DateTime.Now.ToString("yyyyMMddhhmmss")}.pdf"); }
protected virtual void DownloadLeaflets() { foreach (var leaflet in _leaflets) { _currentLeaflet = leaflet; DownloadLeaflet(_currentLeaflet); } }
protected abstract string PrepareDownloadFileName(ILeaflet leaflet);