-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathAltinnGitRepositoryFactory.cs
76 lines (69 loc) · 3.81 KB
/
AltinnGitRepositoryFactory.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System.IO;
using Altinn.Studio.Designer.Configuration;
using Altinn.Studio.Designer.Helpers.Extensions;
using Altinn.Studio.Designer.Infrastructure.GitRepository;
using Altinn.Studio.Designer.Services.Interfaces;
namespace Altinn.Studio.Designer.Factories
{
/// <summary>
/// Factory class for creating <see cref="AltinnGitRepository"/> objects.
/// </summary>
public class AltinnGitRepositoryFactory : IAltinnGitRepositoryFactory
{
private readonly string _repositoriesRootDirectory;
/// <summary>
/// Initializes a new instance of the <see cref="AltinnGitRepositoryFactory"/> class.
/// </summary>
/// <param name="serviceRepositorySettings">Settings controlling where to find the repositories (using the value <see cref="ServiceRepositorySettings.RepositoryLocation"/>.</param>
public AltinnGitRepositoryFactory(ServiceRepositorySettings serviceRepositorySettings) : this(serviceRepositorySettings.RepositoryLocation)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="AltinnGitRepositoryFactory"/> class.
/// </summary>
/// <param name="repositoriesRootDirectory">Full path to the root directory wher the repositories recides on-disk.</param>
public AltinnGitRepositoryFactory(string repositoriesRootDirectory)
{
_repositoriesRootDirectory = Path.GetFullPath(repositoriesRootDirectory); // We do this to normalize the path according to the OS and avoid slashes in all directions.
}
/// <summary>
/// Creates an instance of <see cref="AltinnGitRepository"/>
/// </summary>
/// <returns><see cref="AltinnGitRepository"/></returns>
public AltinnGitRepository GetAltinnGitRepository(string org, string repository, string developer)
{
var repositoryDirectory = GetRepositoryPath(org, repository, developer);
return new AltinnGitRepository(org, repository, developer, _repositoriesRootDirectory, repositoryDirectory);
}
/// <summary>
/// Creates an instance of <see cref="AltinnAppGitRepository"/>
/// </summary>
/// <returns><see cref="AltinnAppGitRepository"/></returns>
public AltinnAppGitRepository GetAltinnAppGitRepository(string org, string repository, string developer)
{
var repositoryDirectory = GetRepositoryPath(org, repository, developer);
return new AltinnAppGitRepository(org, repository, developer, _repositoriesRootDirectory, repositoryDirectory);
}
/// <summary>
/// Gets the full path to a repository.
/// </summary>
/// <param name="org">Organization owning the repository identified by it's short name.</param>
/// <param name="repository">Repository name to search for schema files.</param>
/// <param name="developer">Developer that is working on the repository.</param>
/// <returns>Returns the full, OS normalized, path to the root directory of the repository.</returns>
public string GetRepositoryPath(string org, string repository, string developer)
{
string[] paths = { _repositoriesRootDirectory, developer.AsFileName(), org.AsFileName(), repository.AsFileName() };
return Path.Combine(paths);
}
/// <summary>
/// Creates an instance of <see cref="AltinnOrgGitRepository"/>
/// </summary>
/// <returns><see cref="AltinnOrgGitRepository"/></returns>
public AltinnOrgGitRepository GetAltinnOrgGitRepository(string org, string repository, string developer)
{
var repositoryDirectory = GetRepositoryPath(org, repository, developer);
return new AltinnOrgGitRepository(org, repository, developer, _repositoriesRootDirectory, repositoryDirectory);
}
}
}