/// <summary> /// Get full url to download NGrok on this platform /// </summary> /// <exception cref="NGrokUnsupportedException">Throws if platform not supported by NGrok</exception> /// <returns></returns> private string GetDownloadPath() { const string cdn = "https://bin.equinox.io"; const string cdnPath = "c/4VmDzA7iaHb/NGrok-stable"; return($"{cdn}/{cdnPath}-{RuntimeExtensions.GetOsArchitectureString()}.zip"); }
/// <summary> /// Download NGrok from equinox.io CDN /// </summary> /// <exception cref="NGrokUnsupportedException">Throws if platform not supported by NGrok</exception> /// <exception cref="HttpRequestException">Throws if failed to download from CDN</exception> /// <returns></returns> public async Task DownloadExecutableAsync(CancellationToken cancellationToken) { var downloadUrl = GetDownloadPath(); var fileName = $"{RuntimeExtensions.GetOsArchitectureString()}.zip"; var filePath = $"{Path.Combine(Directory.GetCurrentDirectory(), fileName)}"; if (File.Exists(filePath)) { return; } var downloadResponse = await _httpClient.GetAsync(downloadUrl, cancellationToken); downloadResponse.EnsureSuccessStatusCode(); // Download Zip var downloadStream = await downloadResponse.Content.ReadAsStreamAsync(); await using (var writer = File.Create(filePath)) { await downloadStream.CopyToAsync(writer, cancellationToken); } // Extract zip ZipFile.ExtractToDirectory(filePath, Directory.GetCurrentDirectory()); if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { GrantNGrokFileExecutablePermissions(); } }
void Operation(object data) { #if USEAFFINITY // The "extension" method SetThreadProcessorAffinity was missing the "this" notation, // so it's not really an extension hence this style of call. RuntimeExtensions.SetThreadProcessorAffinity(Thread.CurrentThread, 4); #endif try { var workload = data as WorkLoad; XDocument document; using (var stream = new MemoryStream(workload.data)) { document = XDocument.Load(stream); } var body = document.Root.Element("{http://www.w3.org/2006/10/ttaf1}body"); if (body != null && body.HasElements == false) { System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => OperationSucceeded(null)); } else { var parser = new TimedTextMarkerParser(); var markers = parser.ParseMarkerCollection(document, workload.timeOffset, workload.endTime); System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => OperationSucceeded(markers)); } } catch (Exception ex) { System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => OperationFailed(ex)); } }
public void ProcessRequest(HttpContext context) { if (lp == null) { lp = Helpers.Provider as IronSchemeLanguageProvider; se = lp.GetEngine(); RuntimeExtensions.Eval("(library-path (cons {0} (library-path)))", context.Server.MapPath("~/lib")); compiled.Clear(); } if (!File.Exists(context.Request.PhysicalPath)) { if (context.Request.AppRelativeCurrentExecutionFilePath == "~/process-routes.ss") { if (process_routes == null) { Callable eval = Builtins.SymbolValue(SymbolTable.StringToObject("eval-r6rs")) as Callable; StringReader r = new StringReader("(eval 'process-request (environment '(ironscheme web routing)))"); process_routes = eval.Call(Builtins.Read(r)) as Callable; } process_routes.Call(); } else { context.Response.StatusCode = 404; } return; } Compiled cc; lock (GLOBALLOCK) { if (!compiled.TryGetValue(context.Request.PhysicalPath, out cc) || cc.Time < File.GetLastWriteTime(context.Request.PhysicalPath) || cc.Closure == null) { Callable ccc = se.Evaluate(string.Format("(compile->closure \"{0}\")", context.Request.PhysicalPath.Replace('\\', '/'))) as Callable; cc = new Compiled(); cc.Time = DateTime.Now; cc.Closure = ccc; compiled[context.Request.PhysicalPath] = cc; } } cc.Closure.Call(); }
private async Task Register(string tag) { if (_lastRegister.AddSeconds(30) > DateTimeOffset.Now) { return; } _lastRegister = DateTimeOffset.Now; _lastIp = await TryGetIp(); var user = await _userService.GetUser(); await _api.Post <object>("botLauncher/register", new LauncherRegisterRequest { Tag = tag, Ip = _lastIp, Host = Dns.GetHostName(), MachineUsername = Environment.MachineName, Platform = RuntimeExtensions.RuntimeToString(), UserId = user.Id }); }
void ParseMarkers(object data) { #if USEAFFINITY // The "extension" method SetThreadProcessorAffinity was missing the "this" notation, // so it's not really an extension hence this style of call. RuntimeExtensions.SetThreadProcessorAffinity(Thread.CurrentThread, 4); #endif try { string result = data as string; XDocument markerXml = XDocument.Parse(result); IEnumerable <MediaMarker> markers = _markerParser.ParseMarkerCollection(markerXml, TimeSpan.Zero, TimeSpan.MaxValue) .Cast <MediaMarker>() .ToList(); System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => ParseSucceeded(markers)); } catch (Exception ex) { System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => LogParseError(ex)); } }