public void SaveTimestampFile(string folderPath, LocalUpdateFile updateFile) { string updateJson = JsonSerializer.Serialize <LocalUpdateFile>(updateFile); string filePath = Path.Combine(folderPath, "SnippetSync.json"); File.WriteAllText(filePath, updateJson); }
// SyncSnippets public async Task SyncSnippetFolder(string folderPath, string RepoUrl) { if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } DateTime localFileTimestamp = GetTimestampFromLocalFile(folderPath); Repository repo = new Repository(RepoUrl); DateTime repoTimestamp = await repo.LastUpdated(); if (repoTimestamp > localFileTimestamp) { ClearFolder(folderPath); List <GithubFile> repoFiles = await repo.GetFilesListFromRepo(); foreach (GithubFile file in repoFiles) { await DownloadFile(file, folderPath); } LocalUpdateFile updateFile = new LocalUpdateFile { LastUpdated = DateTime.Now }; SaveTimestampFile(folderPath, updateFile); } }
public DateTime GetTimestampFromLocalFile(string folderPath) { string filePath = Path.Combine(folderPath, "SnippetSync.json"); if (!File.Exists(filePath)) { return(DateTime.MinValue); } string updateJson = File.ReadAllText(filePath); LocalUpdateFile updateFile = JsonSerializer.Deserialize <LocalUpdateFile>(updateJson); return(updateFile.LastUpdated); }