/// <summary>
        /// Returns a list of downloded datasets.
        /// </summary>
        /// <returns></returns>
        public DownloadHistory GetFileDownloaHistory(string url)
        {
            var downloadHistoryFilePath = ApplicationService.GetDownloadHistoryFilePath(_configFile.Name);

            try
            {
                using (var r = new StreamReader(downloadHistoryFilePath))
                {
                    var json = r.ReadToEnd();
                    var downloadHistories = JsonConvert.DeserializeObject <List <DownloadHistory> >(json);
                    Log.Debug("Read from download history file, " + _configFile.Name + "- downloadHistory.json");
                    r.Close();
                    if (downloadHistories != null)
                    {
                        DownloadHistory downloadHistory = downloadHistories.FirstOrDefault(d => d.Id == url);
                        return(downloadHistory);
                    }
                    return(null);
                }
            }
            catch (FileNotFoundException e)
            {
                Log.Error("Could not find " + _configFile.Name + "- downloadHistory.json");
                return(null);
            }
        }
        /// <summary>
        /// Writes the information about the selected files to the local download list.
        /// </summary>
        /// <param name="datasetFilesViewModel"></param>
        public void WriteToDownloadHistoryFile(List <Download> downloads)
        {
            var downloadHistory = new List <DownloadHistory>();

            foreach (var dataset in downloads)
            {
                foreach (var datasetFile in dataset.Files)
                {
                    downloadHistory.Add(new DownloadHistory(datasetFile.Url, datasetFile.FilePath, datasetFile.DownloadedDate, datasetFile.LastUpdated));
                }
            }

            var serializer = new JsonSerializer();

            serializer.Converters.Add(new JavaScriptDateTimeConverter());
            serializer.NullValueHandling = NullValueHandling.Ignore;

            try
            {
                using (var outputFile = new StreamWriter(ApplicationService.GetDownloadHistoryFilePath(_configFile.Name), false))
                    using (JsonWriter writer = new JsonTextWriter(outputFile))
                    {
                        serializer.Serialize(writer, downloadHistory);
                        Log.Debug("Write to download history file " + _configFile.Name + "-downloadHistory.json");
                        writer.Close();
                    }
            }
            catch (Exception e)
            {
                Log.Error(e, "Write to download history file " + _configFile.Name + "-downloadHistory.json");
            }
        }
        /// <summary>
        /// Writes the information about the selected files to the local download list.
        /// </summary>
        /// <param name="datasetFilesViewModel"></param>
        public void WriteToDownloadHistoryFile(List <DatasetFile> datasetFilesToDownload)
        {
            var downloadHistory = new List <DownloadHistory>();

            foreach (var datasetFile in datasetFilesToDownload)
            {
                downloadHistory.Add(new DownloadHistory(datasetFile.Url, datasetFile.FilePath));
            }

            var serializer = new JsonSerializer();

            serializer.Converters.Add(new JavaScriptDateTimeConverter());
            serializer.NullValueHandling = NullValueHandling.Ignore;

            using (var outputFile = new StreamWriter(applicationService.GetDownloadHistoryFilePath(), false))
                using (JsonWriter writer = new JsonTextWriter(outputFile))
                {
                    serializer.Serialize(writer, downloadHistory);
                    writer.Close();
                }
        }