/// <summary>
        /// Writes the information about the selected files to the local download list.
        /// </summary>
        /// <param name="datasetFilesViewModel"></param>
        public void WriteToDownloadFile(List <DatasetFileViewModel> datasetFilesViewModel)
        {
            List <DatasetFile> datasetFiles = ConvertToModel(datasetFilesViewModel);
            var serializer = new JsonSerializer();

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

            using (var outputFile = new StreamWriter(applicationService.GetDownloadFilePath(), false))
                using (JsonWriter writer = new JsonTextWriter(outputFile))
                {
                    serializer.Serialize(writer, datasetFiles);
                    writer.Close();
                }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Create a default config file
 /// </summary>
 /// <returns></returns>
 public static ConfigFile GetDefaultConfigFile()
 {
     return(new ConfigFile()
     {
         Id = Guid.NewGuid(),
         Name = Default,
         FilePath = ApplicationService.GetDownloadFilePath(),
         DownloadDirectory = ApplicationService.GetDefaultDownloadDirectory(),
         LogDirectory = ApplicationService.GetDefaultLogDirectory(),
     });
 }
        /// <summary>
        /// Returns a list of dataset files to download.
        /// </summary>
        /// <returns></returns>
        public List <Download> GetSelectedFilesToDownload(ConfigFile configFile = null)
        {
            var downloadFilePath = _configFile != null ? _configFile.FilePath : ApplicationService.GetDownloadFilePath();

            try
            {
                using (var r = new StreamReader(downloadFilePath))
                {
                    var json = r.ReadToEnd();
                    var selecedForDownload = JsonConvert.DeserializeObject <List <Download> >(json);
                    r.Close();
                    selecedForDownload = RemoveDuplicatesIterative(selecedForDownload);
                    selecedForDownload = ConvertToNewVersionOfDownloadFile(selecedForDownload);
                    //selecedForDownload = GetAvailableProjections(selecedForDownload);
                    Log.Debug("Get selected files to download");
                    return(selecedForDownload);
                }
            }
            catch (Exception e)
            {
                Log.Error(e, "Could not get selected files to download");
                return(new List <Download>());
            }
        }