/// <summary> /// Download the latest NKHook from the github releases section /// </summary> public static void DownloadNKH() { Log.Output("Downloading latest NKHook5..."); string git_Text = WebHandler.ReadText_FromURL(gitURL); if (!Guard.IsStringValid(git_Text)) { Log.Output("Failed to read release info for NKHook5"); return; } BgThread.AddToQueue(new Thread(() => { var gitApi = GitApi.FromJson(git_Text); foreach (var a in gitApi) { foreach (var b in a.Assets) { string link = b.BrowserDownloadUrl.ToString(); if (!Guard.IsStringValid(link)) { continue; } WebHandler.DownloadFile(link, nkhDir); } } Log.Output("NKHook5 successfully downloaded!"); })); }
public IActionResult Graph(string repoUrl) { try { repoUrl = HttpUtility.UrlDecode(repoUrl); if (_cache.TryGetValue(repoUrl, out var graph)) { if (DateTime.Now - graph.Timestamp < TimeSpan.FromMinutes(10)) { return(Ok(graph)); } _cache.TryRemove(repoUrl, out var removed); } var rootPath = Environment.GetEnvironmentVariable("SGB_ROOT_PATH"); var repoName = Path.GetFileNameWithoutExtension(repoUrl); var repoPath = Path.GetFullPath(Path.Combine(rootPath, repoName)); Graph status = new Graph(repoUrl); var task = new Task(() => { try { if (!Directory.Exists(repoPath)) { GitApi.Clone(repoUrl, repoPath, (tp) => { var msg = $"Objects: {tp.ReceivedObjects} of {tp.TotalObjects}, Bytes: {tp.ReceivedBytes}"; _status.AddOrUpdate(repoUrl, msg, (s, n) => msg); }); } GitApi.Fetch(repoPath); var graph = GitApi.ParseProjectFiles(repoUrl, repoPath); _cache.TryAdd(repoUrl, graph); } catch (Exception ex) { _logger.LogError(ex, "Background task encountered a critical error"); } finally { _processing.TryRemove(repoUrl, out var removed); } }); if (_processing.TryAdd(repoUrl, task)) { task.Start(); } _status.TryGetValue(repoUrl, out var msg); status.message = msg; return(StatusCode(202, status)); } catch (Exception ex) { _logger.LogError(ex, "Failed to generate source graph"); return(StatusCode(500, "Something went wrong, you should talk to support about this")); } }