public string GetServiceName(string org, string service) { string defaultLang = "nb-NO"; string filename = $"resource.{defaultLang}.json"; string serviceResourceDirectoryPath = _settings.GetResourcePath(org, service, AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext)) + filename; string serviceName = string.Empty; 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; } } return(serviceName); }
public string GetServiceName(string org, string app) { string defaultLang = "nb-NO"; string filename = $"resource.{defaultLang}.json"; string serviceResourceDirectoryPath = _settings.GetResourcePath(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); }
/// <summary> /// Creates a zip-file containing all files necessary for executing a service /// </summary> /// <param name="org">The organization code for the service owner</param> /// <param name="service">The service code for the current service</param> /// <param name="edition">The edition code for the current service</param> /// <returns>Was the package creation successful</returns> public bool CreateServicePackage(string org, string service, string edition) { ServiceMetadata serviceMetadata = _repository.GetServiceMetaData(org, service, edition); string packagesDir = _settings.GetServicePackagesPath(org, service, edition, AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext)); string tempDir = _settings.GetTemporaryPath(org, service, edition, AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext)); string tempDirName = Path.GetRandomFileName(); string tempDirPath = tempDir + tempDirName + "/"; CopyDirectoryContents(_settings.GetViewPath(org, service, edition, AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext)), tempDirPath + ServiceRepositorySettings.VIEW_FOLDER_NAME); CopyDirectoryContents(_settings.GetMetadataPath(org, service, edition, AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext)), tempDirPath + ServiceRepositorySettings.METADATA_FOLDER_NAME); CopyDirectoryContents(_settings.GetCodelistPath(org, service, edition, AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext)), tempDirPath + ServiceRepositorySettings.CODELISTS_FOLDER_NAME); CopyDirectoryContents(_settings.GetResourcePath(org, service, edition, AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext)), tempDirPath + ServiceRepositorySettings.RESOURCE_FOLDER_NAME); Directory.CreateDirectory(tempDirPath + "/Assemblies/"); Directory.CreateDirectory(packagesDir); string compileResult = string.Empty; string assemblyName = CreateServiceAssembly(org, service, edition, tempDirPath + "/Assemblies/").AssemblyName; ServicePackageDetails details = new ServicePackageDetails { AssemblyName = assemblyName, Organization = org, Service = service, Edition = edition, CreatedDateTime = DateTime.Now }; string detailsAsJson = JsonConvert.SerializeObject(details); string filePath = tempDirPath + "/ServicePackageDetails.json"; File.WriteAllText(filePath, detailsAsJson, Encoding.UTF8); ZipFile.CreateFromDirectory(tempDirPath, packagesDir + tempDirName + ".zip"); Directory.Delete(tempDirPath, true); return(true); }