/// <summary> /// Move content from old config file to default config file. /// </summary> public void ConvertDownloadToDefaultConfigFileIfExists() { var selecedForDownload = GetSelectedDatasetFilesFromDownloadFileAsDownloadModel(); if (selecedForDownload.Any()) { Log.Information("Convert from download.json to default.json"); selecedForDownload = RemoveDuplicatesIterative(selecedForDownload); selecedForDownload = ConvertToNewVersionOfDownloadFile(selecedForDownload); if (_configFile.IsDefault()) { WriteToConfigFile(selecedForDownload); File.Delete(ApplicationService.GetOldDownloadFilePath()); } } }
public Version GetLatest() { try { Version latestVersion = _releaseInfoReader.GetLatestVersion(); ApplicationService.SetTimeLastCheckForUpdate(DateTime.Now); return(latestVersion); } catch (Exception e) { Log.Error("Could not get latest version: " + e.Message); return(null); } }
/// <summary> /// Returns a list of projections. /// </summary> /// <returns></returns> public List <string> ReadFromDownloadUsagePurposes() { try { using (var r = new StreamReader(ApplicationService.GetPurposesFilePath())) { var json = r.ReadToEnd(); var upurposes = JsonConvert.DeserializeObject <List <string> >(json); Log.Debug("Read from download usage purpose file"); r.Close(); return(upurposes); } } catch (Exception e) { Log.Error(e, "Read from download usage purpose file"); return(new List <string>()); } }
/// <summary> /// /// Write list of download usage to file in case registry api won't respond /// </summary> /// <param name="userPurposes">list of purposes</param> public void WriteToUsagePurposeFile(List <string> userPurposes) { var serializer = new JsonSerializer(); serializer.Converters.Add(new JavaScriptDateTimeConverter()); serializer.NullValueHandling = NullValueHandling.Ignore; try { using (var outputFile = new StreamWriter(ApplicationService.GetPurposesFilePath(), false)) using (JsonWriter writer = new JsonTextWriter(outputFile)) { serializer.Serialize(writer, userPurposes); Log.Debug("Write to download usage purpose file"); writer.Close(); } } catch (Exception e) { Log.Error(e, "Write to download usage purpose file"); } }
/// <summary> /// Write list of projections to file in case epsg-registry won't respond /// </summary> /// <param name="projections"></param> public void WriteToProjectionFile(List <Projections> projections) { var serializer = new JsonSerializer(); serializer.Converters.Add(new JavaScriptDateTimeConverter()); serializer.NullValueHandling = NullValueHandling.Ignore; try { using (var outputFile = new StreamWriter(ApplicationService.GetProjectionFilePath(), false)) using (JsonWriter writer = new JsonTextWriter(outputFile)) { serializer.Serialize(writer, projections); Log.Debug("Write to projection file"); writer.Close(); } } catch (Exception e) { Log.Error(e, "Write to projection file"); } }
/// <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(); DownloadHistory downloadHistory = downloadHistories.FirstOrDefault(d => d.Id == url); return(downloadHistory); } } catch (FileNotFoundException e) { Log.Error("Could not find " + _configFile.Name + "- downloadHistory.json"); return(null); } }
/// <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>()); } }
/// <summary> /// Writes the information about the selected files to the local download list. /// </summary> public void WriteToDownloadLogFile(DownloadLog downloadLog) { var serializer = new JsonSerializer(); serializer.Converters.Add(new JavaScriptDateTimeConverter()); serializer.NullValueHandling = NullValueHandling.Ignore; try { using (var w = new StreamWriter(ApplicationService.GetDownloadLogFilePath(_configFile.LogDirectory))) { w.WriteLine("SELECTED DATASETS: " + downloadLog.TotalDatasetsToDownload); w.WriteLine("-------------------------------"); w.WriteLine(); w.WriteLine("FILES UPDATED: " + downloadLog.Updated.Count()); DownloadLog(downloadLog.Updated, w); w.WriteLine(); w.WriteLine("FILES NOT UPDATED: " + downloadLog.NotUpdated.Count()); DownloadLog(downloadLog.NotUpdated, w); w.WriteLine(); w.WriteLine("FAILED: " + downloadLog.Faild.Count()); DownloadLog(downloadLog.Faild, w); Log.Debug("Write to download log file"); } } catch (Exception e) { Log.Error(e, "Write to download log file"); } }
private static string GetEpsgName(DatasetFile selectedFile) { var projection = ApplicationService.GetProjections().FirstOrDefault(p => p.Epsg == selectedFile.Projection); return(projection != null ? projection.Name : selectedFile.Projection); }
public DateTime?GetTimeLastCheckForUpdate() { return(ApplicationService.GetTimeLastCheckForUpdate()); }