Skip to content

Commit

Permalink
fix reading template as embedded resource instead as stream
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkoSekulic committed Oct 5, 2023
1 parent 8bee362 commit e86147d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ public ProcessModelingService(IAltinnGitRepositoryFactory altinnGitRepositoryFac
_altinnGitRepositoryFactory = altinnGitRepositoryFactory;
}

private string TemplatesLocation(Version version) => Path.Combine(Path.GetDirectoryName(typeof(ProcessModelingService).Assembly.Location)!, nameof(Services), nameof(Implementation), nameof(ProcessModeling), "Templates", $"v{version.Major}");

private string TemplatesFolderIdentifier(Version version) => string.Join(".", nameof(Services), nameof(Implementation), nameof(ProcessModeling), "Templates", $"v{version.Major}");

/// <inheritdoc/>
public IEnumerable<string> GetProcessDefinitionTemplates(Version version)
{
return EnumerateTemplates(version)
return EnumerateTemplateResources(version)
.Select(
templateName => templateName.Split(TemplatesFolderIdentifier(version)).Last().TrimStart('.'))!;
}
Expand Down Expand Up @@ -54,17 +52,17 @@ public Stream GetProcessDefinitionStream(AltinnRepoEditingContext altinnRepoEdit
return altinnAppGitRepository.GetProcessDefinitionFile();
}

private IEnumerable<string> EnumerateTemplates(Version version)
private IEnumerable<string> EnumerateTemplateResources(Version version)
{
return typeof(ProcessModelingService).Assembly.GetManifestResourceNames()
.Where(resourceName => resourceName.Contains(TemplatesFolderIdentifier(version)));
}

private Stream GetTemplateStream(Version version, string templateName)
{
var templates = EnumerateTemplates(version);
string templatePath = templates.Single(template => template.EndsWith(templateName));
return File.OpenRead(templatePath);
var templates = EnumerateTemplateResources(version);
string template = templates.Single(template => template.EndsWith(templateName));
return typeof(ProcessModelingService).Assembly.GetManifestResourceStream(template);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,20 @@ namespace Altinn.Studio.Designer.Services.Interfaces
{
public interface IProcessModelingService
{
/// <summary>
/// Gets defined process definition templates for a given version.
/// </summary>
/// <param name="version">Version of the app-lib</param>
/// <returns>An <see cref="IEnumerable{string}"/> containing supported templates for given version.</returns>
IEnumerable<string> GetProcessDefinitionTemplates(Version version);

/// <summary>
/// Saves the process definition file for a given app from a template.
/// </summary>
/// <param name="altinnRepoEditingContext">An <see cref="AltinnRepoEditingContext"/>.</param>
/// <param name="templateName">Name of the template.</param>
/// <param name="version">Version of the app-lib.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that observes if operation is cancelled.</param>
Task SaveProcessDefinitionFromTemplateAsync(AltinnRepoEditingContext altinnRepoEditingContext, string templateName, Version version, CancellationToken cancellationToken = default);

/// <summary>
Expand Down

0 comments on commit e86147d

Please sign in to comment.