Skip to content

Commit

Permalink
Refactor to Oryx v3 (#236)
Browse files Browse the repository at this point in the history
* Refactor to Oryx v3
  • Loading branch information
dbrattli authored Feb 26, 2021
1 parent db40af4 commit 986b45c
Show file tree
Hide file tree
Showing 41 changed files with 638 additions and 534 deletions.
3 changes: 2 additions & 1 deletion CogniteSdk.Types/Common/ResponseError.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2020 Cognite AS
// SPDX-License-Identifier: Apache-2.0

using System;
using System.Collections.Generic;

using CogniteSdk.Types.Common;
Expand Down Expand Up @@ -56,7 +57,7 @@ public class ApiResponseError
/// <summary>
/// Convert error to exception.
/// </summary>
public ResponseException ToException()
public Exception ToException()
{
var exn = new ResponseException(this.Error.Message) {
Code = this.Error.Code,
Expand Down
27 changes: 13 additions & 14 deletions CogniteSdk/src/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using CogniteSdk.Resources;

using static Oryx.Cognite.ContextModule;
using HttpContext = Oryx.Context<Microsoft.FSharp.Core.Unit>;

namespace CogniteSdk
{
Expand Down Expand Up @@ -101,7 +100,7 @@ public class Client
/// </summary>
/// <param name="authHandler">The authentication handler.</param>
/// <param name="ctx">Context to use for this session.</param>
private Client(Func<CancellationToken, Task<string>> authHandler, HttpContext ctx)
private Client(Func<CancellationToken, Task<string>> authHandler, Context ctx)
{
// Setup resources.
Assets = new AssetsResource(authHandler, ctx);
Expand Down Expand Up @@ -129,7 +128,7 @@ private Client(Func<CancellationToken, Task<string>> authHandler, HttpContext ct
[SuppressMessage("Design", "CA1034:Nested types should not be visible", Justification = "Builder pattern.")]
public sealed class Builder
{
private HttpContext _context = create();
private Context? _context = create();
private Func<CancellationToken, Task<string>> _authHandler;

/// <summary>
Expand All @@ -138,7 +137,7 @@ public sealed class Builder
/// <param name="httpClient">Optional HttpClient to use for HTTP requests.</param>
public Builder(HttpClient httpClient = null)
{
_context = httpClient == null ? _context : Context.withHttpClient(httpClient, _context);
_context = httpClient == null ? _context : ContextModule.withHttpClient(httpClient, _context.Value);
}

/// <summary>
Expand All @@ -159,7 +158,7 @@ public Builder AddHeader(string name, string value)
throw new ArgumentNullException(nameof(value));
}

_context = Context.withHeader(name, value, _context);
_context = ContextModule.withHeader(name, value, _context.Value);
return this;
}

Expand Down Expand Up @@ -206,7 +205,7 @@ public Builder SetProject(string project)
throw new ArgumentNullException(nameof(project));
}

_context = withProject(project, _context);
_context = withProject(project, _context.Value);
return this;
}

Expand All @@ -222,7 +221,7 @@ public Builder SetAppId(string appId)
throw new ArgumentNullException(nameof(appId));
}

_context = withAppId(appId, _context);
_context = withAppId(appId, _context.Value);
return this;
}

Expand All @@ -238,7 +237,7 @@ public Builder SetHttpClient(HttpClient client)
throw new ArgumentNullException(nameof(client));
}

_context = Context.withHttpClient(client, _context);
_context = ContextModule.withHttpClient(client, _context.Value);
return this;
}

Expand All @@ -254,7 +253,7 @@ public Builder SetBaseUrl(Uri baseUrl)
throw new ArgumentNullException(nameof(baseUrl));
}

_context = withBaseUrl(baseUrl, _context);
_context = withBaseUrl(baseUrl, _context.Value);
return this;
}

Expand All @@ -270,7 +269,7 @@ public Builder SetLogger(ILogger logger)
throw new ArgumentNullException(nameof(logger));
}

_context = Context.withLogger(logger, _context);
_context = ContextModule.withLogger(logger, _context.Value);
return this;
}

Expand All @@ -281,7 +280,7 @@ public Builder SetLogger(ILogger logger)
/// <returns>Updated builder.</returns>
public Builder SetLogLevel(LogLevel logLevel)
{
_context = Context.withLogLevel(logLevel, _context);
_context = ContextModule.withLogLevel(logLevel, _context.Value);
return this;
}

Expand All @@ -297,7 +296,7 @@ public Builder SetLogFormat(string format)
throw new ArgumentNullException(nameof(format));
}

_context = Context.withLogFormat(format, _context);
_context = ContextModule.withLogFormat(format, _context.Value);
return this;
}

Expand All @@ -313,7 +312,7 @@ public Builder SetMetrics(IMetrics metrics)
throw new ArgumentNullException(nameof(metrics));
}

_context = Context.withMetrics(metrics, _context);
_context = ContextModule.withMetrics(metrics, _context.Value);
return this;
}

Expand All @@ -324,7 +323,7 @@ public Builder SetMetrics(IMetrics metrics)
public Client Build()
{
// Check for optional fields etc here
HttpContext ctx = _context;
Context ctx = _context.Value;
Func<CancellationToken, Task<string>> authHandler = _authHandler;

// Builder is invalid after this
Expand Down
10 changes: 5 additions & 5 deletions CogniteSdk/src/Resources/3DAssetMappings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
using System.Threading;
using System.Threading.Tasks;

using Oryx;
using Oryx.Cognite;
using static Oryx.Cognite.HandlerModule;
using HttpContext = Oryx.Context<Microsoft.FSharp.Core.Unit>;

namespace CogniteSdk.Resources
{
Expand All @@ -23,7 +23,7 @@ public class ThreeDAssetMappingsResource : Resource
/// </summary>
/// <param name="authHandler">Authentication handler.</param>
/// <param name="ctx">Context to use for the request.</param>
internal ThreeDAssetMappingsResource(Func<CancellationToken, Task<string>> authHandler, HttpContext ctx) : base(authHandler, ctx)
internal ThreeDAssetMappingsResource(Func<CancellationToken, Task<string>> authHandler, Context ctx) : base(authHandler, ctx)
{
}

Expand All @@ -42,7 +42,7 @@ public async Task<ItemsWithCursor<ThreeDAssetMapping>> ListAsync(long modelId, l
throw new ArgumentNullException(nameof(query));
}

var req = ThreeDAssetMappings.list<ItemsWithCursor<ThreeDAssetMapping>>(modelId, revisionId, query);
var req = ThreeDAssetMappings.list(modelId, revisionId, query);
return await RunAsync(req, token).ConfigureAwait(false);
}

Expand All @@ -61,7 +61,7 @@ public async Task<IEnumerable<ThreeDAssetMapping>> CreateAsync(long modelId, lon
throw new ArgumentNullException(nameof(ThreeDAssetMapping));
}

var req = ThreeDAssetMappings.create<IEnumerable<ThreeDAssetMapping>>(modelId, revisionId, ThreeDAssetMapping);
var req = ThreeDAssetMappings.create(modelId, revisionId, ThreeDAssetMapping);
return await RunAsync(req, token).ConfigureAwait(false);
}

Expand All @@ -81,7 +81,7 @@ public async Task<EmptyResponse> DeleteAsync(long modelId, long revisionId, IEnu
throw new ArgumentNullException(nameof(ids));
}

var req = ThreeDAssetMappings.delete<EmptyResponse>(modelId, revisionId, ids);
var req = ThreeDAssetMappings.delete(modelId, revisionId, ids);
return await RunAsync(req, token).ConfigureAwait(false);
}

Expand Down
14 changes: 7 additions & 7 deletions CogniteSdk/src/Resources/3DModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
using System.Threading;
using System.Threading.Tasks;

using Oryx;
using Oryx.Cognite;
using static Oryx.Cognite.HandlerModule;
using HttpContext = Oryx.Context<Microsoft.FSharp.Core.Unit>;

namespace CogniteSdk.Resources
{
Expand All @@ -23,7 +23,7 @@ public class ThreeDModelsResource : Resource
/// </summary>
/// <param name="authHandler">Authentication handler.</param>
/// <param name="ctx">Context to use for the request.</param>
internal ThreeDModelsResource(Func<CancellationToken, Task<string>> authHandler, HttpContext ctx) : base(authHandler, ctx)
internal ThreeDModelsResource(Func<CancellationToken, Task<string>> authHandler, Context ctx) : base(authHandler, ctx)
{
}

Expand All @@ -40,7 +40,7 @@ public async Task<ItemsWithCursor<ThreeDModel>> ListAsync(ThreeDModelQuery query
throw new ArgumentNullException(nameof(query));
}

var req = ThreeDModels.list<ItemsWithCursor<ThreeDModel>>(query);
var req = ThreeDModels.list(query);
return await RunAsync(req, token).ConfigureAwait(false);
}

Expand All @@ -57,7 +57,7 @@ public async Task<IEnumerable<ThreeDModel>> CreateAsync(IEnumerable<ThreeDModelC
throw new ArgumentNullException(nameof(ThreeDModel));
}

var req = ThreeDModels.create<IEnumerable<ThreeDModel>>(ThreeDModel);
var req = ThreeDModels.create(ThreeDModel);
return await RunAsync(req, token).ConfigureAwait(false);
}

Expand All @@ -75,7 +75,7 @@ public async Task<EmptyResponse> DeleteAsync(IEnumerable<Identity> ids, Cancella
throw new ArgumentNullException(nameof(ids));
}

var req = ThreeDModels.delete<EmptyResponse>(ids);
var req = ThreeDModels.delete(ids);
return await RunAsync(req, token).ConfigureAwait(false);
}

Expand Down Expand Up @@ -106,7 +106,7 @@ public async Task<EmptyResponse> DeleteAsync(IEnumerable<long> internalIds, Canc
/// <param name="token">Optional cancellation token.</param>
public async Task<ThreeDModel> RetrieveAsync(long modelId, CancellationToken token = default)
{
var req = ThreeDModels.retrieve<ThreeDModel>(modelId);
var req = ThreeDModels.retrieve(modelId);
return await RunAsync(req, token).ConfigureAwait(false);
}

Expand All @@ -126,7 +126,7 @@ public async Task<ThreeDModel> RetrieveAsync(long modelId, CancellationToken tok
throw new ArgumentNullException(nameof(query));
}

var req = ThreeDModels.update<IEnumerable<ThreeDModel>>(query);
var req = ThreeDModels.update(query);
return await RunAsync(req, token).ConfigureAwait(false);
}
}
Expand Down
20 changes: 10 additions & 10 deletions CogniteSdk/src/Resources/3DRevisions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
using System.Threading;
using System.Threading.Tasks;

using Oryx;
using Oryx.Cognite;
using static Oryx.Cognite.HandlerModule;
using HttpContext = Oryx.Context<Microsoft.FSharp.Core.Unit>;

namespace CogniteSdk.Resources
{
Expand All @@ -23,7 +23,7 @@ public class ThreeDRevisionsResource : Resource
/// </summary>
/// <param name="authHandler">Authentication handler.</param>
/// <param name="ctx">Context to use for the request.</param>
internal ThreeDRevisionsResource(Func<CancellationToken, Task<string>> authHandler, HttpContext ctx) : base(authHandler, ctx)
internal ThreeDRevisionsResource(Func<CancellationToken, Task<string>> authHandler, Context ctx) : base(authHandler, ctx)
{
}

Expand All @@ -41,7 +41,7 @@ public async Task<ItemsWithCursor<ThreeDRevision>> ListAsync(long modelId, Three
throw new ArgumentNullException(nameof(query));
}

var req = ThreeDRevisions.list<ItemsWithCursor<ThreeDRevision>>(modelId, query);
var req = ThreeDRevisions.list(modelId, query);
return await RunAsync(req, token).ConfigureAwait(false);
}

Expand All @@ -55,7 +55,7 @@ public async Task<ItemsWithCursor<ThreeDRevision>> ListAsync(long modelId, Three
/// <returns>List of ThreeDRevision matching given filters and optional cursor</returns>
public async Task<ItemsWithCursor<ThreeDRevisionLog>> ListLogsAsync(long modelId, long revisionId, ThreeDRevisionLogQuery query, CancellationToken token = default)
{
var req = ThreeDRevisions.listLogs<ItemsWithCursor<ThreeDRevisionLog>>(modelId, revisionId, query);
var req = ThreeDRevisions.listLogs(modelId, revisionId, query);
return await RunAsync(req, token).ConfigureAwait(false);
}

Expand All @@ -74,7 +74,7 @@ public async Task<ItemsWithCursor<ThreeDNode>> ListNodesAsync(long modelId, long
throw new ArgumentNullException(nameof(query));
}

var req = ThreeDNodes.list<ItemsWithCursor<ThreeDNode>>(modelId, revisionId, query);
var req = ThreeDNodes.list(modelId, revisionId, query);
return await RunAsync(req, token).ConfigureAwait(false);
}

Expand All @@ -92,7 +92,7 @@ public async Task<IEnumerable<ThreeDRevision>> CreateAsync(long modelId, IEnumer
throw new ArgumentNullException(nameof(ThreeDRevision));
}

var req = ThreeDRevisions.create<IEnumerable<ThreeDRevision>>(modelId, ThreeDRevision);
var req = ThreeDRevisions.create(modelId, ThreeDRevision);
return await RunAsync(req, token).ConfigureAwait(false);
}

Expand All @@ -112,7 +112,7 @@ public async Task<EmptyResponse> DeleteAsync(long modelId, IEnumerable<Identity>
}


var req = ThreeDRevisions.delete<EmptyResponse>(modelId, ids);
var req = ThreeDRevisions.delete(modelId, ids);
return await RunAsync(req, token).ConfigureAwait(false);
}

Expand Down Expand Up @@ -145,7 +145,7 @@ public async Task<EmptyResponse> DeleteAsync(long modelId, IEnumerable<long> int
/// <param name="token">Optional cancellation token.</param>
public async Task<ThreeDRevision> RetrieveAsync(long modelId, long revisionId, CancellationToken token = default)
{
var req = ThreeDRevisions.retrieve<ThreeDRevision>(modelId, revisionId);
var req = ThreeDRevisions.retrieve(modelId, revisionId);
return await RunAsync(req, token).ConfigureAwait(false);
}

Expand All @@ -166,7 +166,7 @@ public async Task<ThreeDRevision> RetrieveAsync(long modelId, long revisionId, C
throw new ArgumentNullException(nameof(query));
}

var req = ThreeDRevisions.update<IEnumerable<ThreeDRevision>>(modelId, query);
var req = ThreeDRevisions.update(modelId, query);
return await RunAsync(req, token).ConfigureAwait(false);
}

Expand All @@ -181,7 +181,7 @@ public async Task<ThreeDRevision> RetrieveAsync(long modelId, long revisionId, C
/// <returns>List of updated ThreeDRevision.</returns>
public async Task<EmptyResponse> UpdateThumbnailAsync (long modelId, long revisionId, long fileId, CancellationToken token = default )
{
var req = ThreeDRevisions.updateThumbnail<EmptyResponse>(modelId, revisionId, fileId);
var req = ThreeDRevisions.updateThumbnail(modelId, revisionId, fileId);
return await RunAsync(req, token).ConfigureAwait(false);
}
}
Expand Down
Loading

0 comments on commit 986b45c

Please sign in to comment.