public IActionResult GetServiceName(string org, string app) { string defaultLang = "nb"; string filename = $"resource.{defaultLang}.json"; string serviceResourceDirectoryPath = _settings.GetLanguageResourcePath(org, app, AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext)) + filename; try { if (System.IO.File.Exists(serviceResourceDirectoryPath)) { string textResource = System.IO.File.ReadAllText(serviceResourceDirectoryPath, Encoding.UTF8); ResourceCollection textResourceObject = JsonConvert.DeserializeObject <ResourceCollection>(textResource); return(Content(textResourceObject?.Resources?.FirstOrDefault(r => r.Id == "appName" || r.Id == "ServiceName")?.Value ?? string.Empty)); } return(Problem($"Working directory does not exist for {org}/{app}")); } catch (JsonException ex) { return(Problem(title: $"Failed to parse App/config/texts/{filename} as JSON", instance: $"App/config/texts/{filename}", detail: $"Failed to parse App/config/texts/{filename} as JSON\n" + ex.Message)); } }
public string GetServiceName(string org, string app) { string defaultLang = "nb"; string filename = $"resource.{defaultLang}.json"; string serviceResourceDirectoryPath = _settings.GetLanguageResourcePath(org, app, AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext)) + filename; string serviceName = string.Empty; var watch = System.Diagnostics.Stopwatch.StartNew(); if (System.IO.File.Exists(serviceResourceDirectoryPath)) { string textResource = System.IO.File.ReadAllText(serviceResourceDirectoryPath, Encoding.UTF8); ResourceCollection textResourceObject = JsonConvert.DeserializeObject <ResourceCollection>(textResource); if (textResourceObject != null) { serviceName = textResourceObject.Resources.FirstOrDefault(r => r.Id == "ServiceName") != null?textResourceObject.Resources.FirstOrDefault(r => r.Id == "ServiceName").Value : string.Empty; } } watch.Stop(); _logger.Log(LogLevel.Information, "Getservicename - {0} ", watch.ElapsedMilliseconds); return(serviceName); }