public void ProcessList(string ip, List <string> list, ref BlackVueDownloaderCopyStats blackVueDownloaderCopyStats) { var sw = new Stopwatch(); sw.Start(); // The list includes _NF and _NR files. // Loop through and download each, but also try and download .gps and .3gf files foreach (var s in list) { Console.WriteLine($"Processing File: {s}"); DownloadFile(ip, s, "video", ref blackVueDownloaderCopyStats); // Line below because the list may includes _NF and _NR. Only continue if it's an NF. // Otherwise it's trying to download files that are probably already downloaded if (!s.Contains("_NF.mp4")) { continue; } var gpsfile = s.Replace("_NF.mp4", "_N.gps"); DownloadFile(ip, gpsfile, "gps", ref blackVueDownloaderCopyStats); var gffile = s.Replace("_NF.mp4", "_N.3gf"); DownloadFile(ip, gffile, "3gf", ref blackVueDownloaderCopyStats); } sw.Stop(); blackVueDownloaderCopyStats.TotalTime = sw.Elapsed; Console.WriteLine( $"Copied {blackVueDownloaderCopyStats.Copied}, Ignored {blackVueDownloaderCopyStats.Ignored}, Errored {blackVueDownloaderCopyStats.Errored} TotalTime {blackVueDownloaderCopyStats.TotalTime}"); }
public void DownloadFile(string ip, string filename, string filetype, ref BlackVueDownloaderCopyStats blackVueDownloaderCopyStats) { if (_fileSystemHelper.Exists($"Record/{filename}")) { blackVueDownloaderCopyStats.Ignored++; } else { try { string url = $"http://{ip}/Record/{filename}"; var path = url.DownloadFileAsync("Record"); Console.WriteLine($"Downloading {filetype} file: {url}"); path.Wait(); blackVueDownloaderCopyStats.Copied++; } catch (FlurlHttpTimeoutException e) { Console.WriteLine($"FlurlHttpTimeoutException: {e.Message}"); blackVueDownloaderCopyStats.Errored++; } catch (FlurlHttpException e) { if (e.Call.Response != null) { Console.WriteLine($"Failed with response code: {e.Call.Response.StatusCode}"); } Console.Write($"Failed before getting a response: {e.Message}"); blackVueDownloaderCopyStats.Errored++; } catch (Exception e) { Console.WriteLine($"Exception: {e.Message}"); blackVueDownloaderCopyStats.Errored++; } } }
/// <summary> /// Instance Downloader with Moq friendly constructor /// </summary> /// <param name="fileSystemHelper"></param> public BlackVueDownloader(IFileSystemHelper fileSystemHelper) { _fileSystemHelper = fileSystemHelper; BlackVueDownloaderCopyStats = new BlackVueDownloaderCopyStats(); }
public void ProcessList(string ip, List <string> list) { var blackVueDownloaderCopyStats = new BlackVueDownloaderCopyStats(); ProcessList(ip, list, ref blackVueDownloaderCopyStats); }