Skip to content

Commit 165e431

Browse files
committed
Replace OctopusRepositoryExtensions with methods that reuse RootResource
1 parent d2af450 commit 165e431

6 files changed

+79
-50
lines changed

source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ Octopus.Client
8989
Octopus.Client.IOctopusCommonAsyncRepository
9090
Octopus.Client.IOctopusSystemAsyncRepository
9191
{
92+
Octopus.Client.IOctopusSpaceAsyncRepository ForSpace(Octopus.Client.Model.SpaceResource)
93+
Octopus.Client.IOctopusSystemAsyncRepository ForSystem()
9294
}
9395
interface IOctopusClient
9496
IDisposable
@@ -168,6 +170,8 @@ Octopus.Client
168170
Octopus.Client.IOctopusCommonRepository
169171
Octopus.Client.IOctopusSystemRepository
170172
{
173+
Octopus.Client.IOctopusSpaceRepository ForSpace(Octopus.Client.Model.SpaceResource)
174+
Octopus.Client.IOctopusSystemRepository ForSystem()
171175
}
172176
interface IOctopusSpaceAsyncRepository
173177
Octopus.Client.IOctopusCommonAsyncRepository
@@ -440,6 +444,8 @@ Octopus.Client
440444
Octopus.Client.Repositories.Async.IVariableSetRepository VariableSets { get; }
441445
Octopus.Client.Repositories.Async.IWorkerPoolRepository WorkerPools { get; }
442446
Octopus.Client.Repositories.Async.IWorkerRepository Workers { get; }
447+
Octopus.Client.IOctopusSpaceAsyncRepository ForSpace(Octopus.Client.Model.SpaceResource)
448+
Octopus.Client.IOctopusSystemAsyncRepository ForSystem()
443449
Task<Boolean> HasLink(String)
444450
Task<Boolean> HasLinkParameter(String, String)
445451
Task<String> Link(String)
@@ -514,9 +520,9 @@ Octopus.Client
514520
Octopus.Client.IOctopusCommonRepository
515521
Octopus.Client.IOctopusSystemRepository
516522
{
523+
.ctor(Octopus.Client.IOctopusClient, Octopus.Client.RepositoryScope)
517524
.ctor(Octopus.Client.OctopusServerEndpoint)
518525
.ctor(Octopus.Client.OctopusServerEndpoint, Octopus.Client.RepositoryScope)
519-
.ctor(Octopus.Client.IOctopusClient, Octopus.Client.RepositoryScope)
520526
Octopus.Client.Repositories.IAccountRepository Accounts { get; }
521527
Octopus.Client.Repositories.IActionTemplateRepository ActionTemplates { get; }
522528
Octopus.Client.Repositories.IArchivedEventFileRepository ArchivedEventFiles { get; }
@@ -582,6 +588,8 @@ Octopus.Client
582588
Octopus.Client.Repositories.IVariableSetRepository VariableSets { get; }
583589
Octopus.Client.Repositories.IWorkerPoolRepository WorkerPools { get; }
584590
Octopus.Client.Repositories.IWorkerRepository Workers { get; }
591+
Octopus.Client.IOctopusSpaceRepository ForSpace(Octopus.Client.Model.SpaceResource)
592+
Octopus.Client.IOctopusSystemRepository ForSystem()
585593
Boolean HasLink(String)
586594
Boolean HasLinkParameter(String, String)
587595
String Link(String)
@@ -591,10 +599,6 @@ Octopus.Client
591599
abstract class OctopusRepositoryExtensions
592600
{
593601
static Octopus.Client.IOctopusAsyncRepository CreateRepository(Octopus.Client.IOctopusAsyncClient, Octopus.Client.RepositoryScope)
594-
static Octopus.Client.IOctopusSpaceAsyncRepository ForSpace(Octopus.Client.IOctopusAsyncRepository, Octopus.Client.Model.SpaceResource)
595-
static Octopus.Client.IOctopusSpaceRepository ForSpace(Octopus.Client.IOctopusRepository, Octopus.Client.Model.SpaceResource)
596-
static Octopus.Client.IOctopusSystemAsyncRepository ForSystem(Octopus.Client.IOctopusAsyncRepository)
597-
static Octopus.Client.IOctopusSystemRepository ForSystem(Octopus.Client.IOctopusRepository)
598602
}
599603
class OctopusRequest
600604
{

source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ Octopus.Client
8989
Octopus.Client.IOctopusCommonAsyncRepository
9090
Octopus.Client.IOctopusSystemAsyncRepository
9191
{
92+
Octopus.Client.IOctopusSpaceAsyncRepository ForSpace(Octopus.Client.Model.SpaceResource)
93+
Octopus.Client.IOctopusSystemAsyncRepository ForSystem()
9294
}
9395
interface IOctopusClient
9496
IDisposable
@@ -168,6 +170,8 @@ Octopus.Client
168170
Octopus.Client.IOctopusCommonRepository
169171
Octopus.Client.IOctopusSystemRepository
170172
{
173+
Octopus.Client.IOctopusSpaceRepository ForSpace(Octopus.Client.Model.SpaceResource)
174+
Octopus.Client.IOctopusSystemRepository ForSystem()
171175
}
172176
interface IOctopusSpaceAsyncRepository
173177
Octopus.Client.IOctopusCommonAsyncRepository
@@ -440,6 +444,8 @@ Octopus.Client
440444
Octopus.Client.Repositories.Async.IVariableSetRepository VariableSets { get; }
441445
Octopus.Client.Repositories.Async.IWorkerPoolRepository WorkerPools { get; }
442446
Octopus.Client.Repositories.Async.IWorkerRepository Workers { get; }
447+
Octopus.Client.IOctopusSpaceAsyncRepository ForSpace(Octopus.Client.Model.SpaceResource)
448+
Octopus.Client.IOctopusSystemAsyncRepository ForSystem()
443449
Task<Boolean> HasLink(String)
444450
Task<Boolean> HasLinkParameter(String, String)
445451
Task<String> Link(String)
@@ -512,9 +518,9 @@ Octopus.Client
512518
Octopus.Client.IOctopusCommonRepository
513519
Octopus.Client.IOctopusSystemRepository
514520
{
521+
.ctor(Octopus.Client.IOctopusClient, Octopus.Client.RepositoryScope)
515522
.ctor(Octopus.Client.OctopusServerEndpoint)
516523
.ctor(Octopus.Client.OctopusServerEndpoint, Octopus.Client.RepositoryScope)
517-
.ctor(Octopus.Client.IOctopusClient, Octopus.Client.RepositoryScope)
518524
Octopus.Client.Repositories.IAccountRepository Accounts { get; }
519525
Octopus.Client.Repositories.IActionTemplateRepository ActionTemplates { get; }
520526
Octopus.Client.Repositories.IArchivedEventFileRepository ArchivedEventFiles { get; }
@@ -580,6 +586,8 @@ Octopus.Client
580586
Octopus.Client.Repositories.IVariableSetRepository VariableSets { get; }
581587
Octopus.Client.Repositories.IWorkerPoolRepository WorkerPools { get; }
582588
Octopus.Client.Repositories.IWorkerRepository Workers { get; }
589+
Octopus.Client.IOctopusSpaceRepository ForSpace(Octopus.Client.Model.SpaceResource)
590+
Octopus.Client.IOctopusSystemRepository ForSystem()
583591
Boolean HasLink(String)
584592
Boolean HasLinkParameter(String, String)
585593
String Link(String)
@@ -589,10 +597,6 @@ Octopus.Client
589597
abstract class OctopusRepositoryExtensions
590598
{
591599
static Octopus.Client.IOctopusAsyncRepository CreateRepository(Octopus.Client.IOctopusAsyncClient, Octopus.Client.RepositoryScope)
592-
static Octopus.Client.IOctopusSpaceAsyncRepository ForSpace(Octopus.Client.IOctopusAsyncRepository, Octopus.Client.Model.SpaceResource)
593-
static Octopus.Client.IOctopusSpaceRepository ForSpace(Octopus.Client.IOctopusRepository, Octopus.Client.Model.SpaceResource)
594-
static Octopus.Client.IOctopusSystemAsyncRepository ForSystem(Octopus.Client.IOctopusAsyncRepository)
595-
static Octopus.Client.IOctopusSystemRepository ForSystem(Octopus.Client.IOctopusRepository)
596600
}
597601
class OctopusRequest
598602
{

source/Octopus.Server.Client/IOctopusAsyncRepository.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System.Threading.Tasks;
2-
using Octopus.Client.Repositories.Async;
1+
using Octopus.Client.Model;
32

43
namespace Octopus.Client
54
{
@@ -10,5 +9,7 @@ namespace Octopus.Client
109
/// </summary>
1110
public interface IOctopusAsyncRepository: IOctopusSpaceAsyncRepository, IOctopusSystemAsyncRepository
1211
{
12+
IOctopusSpaceAsyncRepository ForSpace(SpaceResource space);
13+
IOctopusSystemAsyncRepository ForSystem();
1314
}
1415
}

source/Octopus.Server.Client/IOctopusRepository.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using Octopus.Client.Model;
2+
13
namespace Octopus.Client
24
{
35
/// <summary>
@@ -7,5 +9,7 @@ namespace Octopus.Client
79
/// </summary>
810
public interface IOctopusRepository: IOctopusSpaceRepository, IOctopusSystemRepository
911
{
12+
IOctopusSpaceRepository ForSpace(SpaceResource space);
13+
IOctopusSystemRepository ForSystem();
1014
}
1115
}

source/Octopus.Server.Client/OctopusAsyncRepository.cs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,12 @@
1111

1212
namespace Octopus.Client
1313
{
14-
public static partial class OctopusRepositoryExtensions
14+
public static class OctopusRepositoryExtensions
1515
{
1616
public static IOctopusAsyncRepository CreateRepository(this IOctopusAsyncClient client, RepositoryScope scope = null)
1717
{
1818
return new OctopusAsyncRepository(client, scope);
1919
}
20-
21-
public static IOctopusSpaceAsyncRepository ForSpace(this IOctopusAsyncRepository repo, SpaceResource space)
22-
{
23-
return repo.Client.ForSpace(space);
24-
}
25-
26-
public static IOctopusSystemAsyncRepository ForSystem(this IOctopusAsyncRepository repo)
27-
{
28-
return repo.Client.ForSystem();
29-
}
3020
}
3121

3222
/// <summary>
@@ -50,7 +40,7 @@ public class OctopusAsyncRepository : IOctopusAsyncRepository
5040
private readonly Lazy<Task<SpaceRootResource>> loadSpaceRootResource;
5141
private static readonly string rootDocumentUri = "~/api";
5242

53-
public OctopusAsyncRepository(IOctopusAsyncClient client, RepositoryScope repositoryScope = null)
43+
private OctopusAsyncRepository(IOctopusAsyncClient client, RepositoryScope repositoryScope, RootResource rootResource)
5444
{
5545
#if FULL_FRAMEWORK
5646
LocationChecker.CheckAssemblyLocation();
@@ -120,11 +110,27 @@ public OctopusAsyncRepository(IOctopusAsyncClient client, RepositoryScope reposi
120110
UserPermissions = new UserPermissionsRepository(this);
121111
UserTeams = new UserTeamsRepository(this);
122112
UpgradeConfiguration = new UpgradeConfigurationRepository(this);
123-
loadRootResource = new AsyncLazy<RootResource>(LoadRootDocumentInner);
124-
loadSpaceRootResource = new Lazy<Task<SpaceRootResource>>(LoadSpaceRootDocumentInner, true);
125113
DeploymentFreezes = new DeploymentFreezeRepository(client);
114+
115+
loadRootResource = rootResource is not null
116+
? new AsyncLazy<RootResource>(_ => Task.FromResult(rootResource))
117+
: new AsyncLazy<RootResource>(LoadRootDocumentInner);
118+
119+
loadSpaceRootResource = new Lazy<Task<SpaceRootResource>>(LoadSpaceRootDocumentInner, true);
126120
}
127121

122+
protected OctopusAsyncRepository(OctopusAsyncRepository source, RepositoryScope repositoryScope)
123+
: this(
124+
source.Client,
125+
repositoryScope,
126+
source.loadRootResource.HasValue ? source.loadRootResource.Value(CancellationToken.None).Result : null)
127+
{
128+
}
129+
130+
public OctopusAsyncRepository(IOctopusAsyncClient client, RepositoryScope repositoryScope = null)
131+
: this(client, repositoryScope, null)
132+
{
133+
}
128134

129135
public IOctopusAsyncClient Client { get; }
130136
public RepositoryScope Scope { get; private set; }
@@ -233,6 +239,9 @@ public async Task<string> Link(string name)
233239
public Task<RootResource> LoadRootDocument(CancellationToken cancellationToken) => loadRootResource.Value(cancellationToken);
234240
public Task<SpaceRootResource> LoadSpaceRootDocument() => loadSpaceRootResource.Value;
235241

242+
public virtual IOctopusSpaceAsyncRepository ForSpace(SpaceResource space) => new OctopusAsyncRepository(this, RepositoryScope.ForSpace(space));
243+
public virtual IOctopusSystemAsyncRepository ForSystem() => new OctopusAsyncRepository(this, RepositoryScope.ForSystem());
244+
236245
private async Task<RootResource> LoadRootDocumentInner(CancellationToken cancellationToken)
237246
{
238247
var watch = Stopwatch.StartNew();

source/Octopus.Server.Client/OctopusRepository.cs

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,6 @@
99

1010
namespace Octopus.Client
1111
{
12-
public static partial class OctopusRepositoryExtensions
13-
{
14-
public static IOctopusSpaceRepository ForSpace(this IOctopusRepository repo, SpaceResource space)
15-
{
16-
return repo.Client.ForSpace(space);
17-
}
18-
19-
public static IOctopusSystemRepository ForSystem(this IOctopusRepository repo)
20-
{
21-
return repo.Client.ForSystem();
22-
}
23-
}
24-
2512
/// <summary>
2613
/// A simplified interface to commonly-used parts of the API.
2714
/// Functionality not exposed by this interface can be accessed
@@ -38,15 +25,7 @@ public class OctopusRepository : IOctopusRepository
3825
private readonly Lazy<RootResource> loadRootResource;
3926
private readonly Lazy<SpaceRootResource> loadSpaceRootResource;
4027

41-
public OctopusRepository(OctopusServerEndpoint endpoint) : this(new OctopusClient(endpoint))
42-
{
43-
}
44-
45-
public OctopusRepository(OctopusServerEndpoint endpoint, RepositoryScope repositoryScope) : this(new OctopusClient(endpoint), repositoryScope)
46-
{
47-
}
48-
49-
public OctopusRepository(IOctopusClient client, RepositoryScope repositoryScope = null)
28+
private OctopusRepository(IOctopusClient client, RepositoryScope repositoryScope, RootResource rootResource)
5029
{
5130
#if FULL_FRAMEWORK
5231
LocationChecker.CheckAssemblyLocation();
@@ -115,9 +94,34 @@ public OctopusRepository(IOctopusClient client, RepositoryScope repositoryScope
11594
UserTeams = new UserTeamsRepository(this);
11695
UserInvites = new UserInvitesRepository(this);
11796
UpgradeConfiguration = new UpgradeConfigurationRepository(this);
118-
loadRootResource = new Lazy<RootResource>(LoadRootDocumentInner, true);
119-
loadSpaceRootResource = new Lazy<SpaceRootResource>(LoadSpaceRootDocumentInner, true);
12097
DeploymentFreezes = new DeploymentFreezeRepository(client);
98+
99+
loadRootResource = rootResource is not null
100+
? new Lazy<RootResource>(() => rootResource)
101+
: new Lazy<RootResource>(LoadRootDocumentInner);
102+
103+
loadSpaceRootResource = new Lazy<SpaceRootResource>(LoadSpaceRootDocumentInner, true);
104+
}
105+
106+
protected OctopusRepository(OctopusRepository source, RepositoryScope repositoryScope)
107+
: this(
108+
source.Client,
109+
repositoryScope,
110+
source.loadRootResource.IsValueCreated ? source.loadRootResource.Value : null)
111+
{
112+
}
113+
114+
public OctopusRepository(IOctopusClient client, RepositoryScope repositoryScope = null)
115+
: this(client, repositoryScope, null)
116+
{
117+
}
118+
119+
public OctopusRepository(OctopusServerEndpoint endpoint) : this(new OctopusClient(endpoint))
120+
{
121+
}
122+
123+
public OctopusRepository(OctopusServerEndpoint endpoint, RepositoryScope repositoryScope) : this(new OctopusClient(endpoint), repositoryScope)
124+
{
121125
}
122126

123127
public IOctopusClient Client { get; }
@@ -215,6 +219,9 @@ public string Link(string name)
215219
public RootResource LoadRootDocument() => loadRootResource.Value;
216220
public SpaceRootResource LoadSpaceRootDocument() => loadSpaceRootResource.Value;
217221

222+
public virtual IOctopusSpaceRepository ForSpace(SpaceResource space) => new OctopusRepository(this, RepositoryScope.ForSpace(space));
223+
public virtual IOctopusSystemRepository ForSystem() => new OctopusRepository(this, RepositoryScope.ForSystem());
224+
218225
RootResource LoadRootDocumentInner()
219226
{
220227
var watch = Stopwatch.StartNew();

0 commit comments

Comments
 (0)