Skip to content

Commit

Permalink
Use server url as fallback to find matching account
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzhankoral committed Jul 2, 2024
1 parent a368121 commit ea081f0
Show file tree
Hide file tree
Showing 17 changed files with 98 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public async Task Receive(string modelCardId)
var receiveOperationResults = await unitOfWork.Service
.Execute(
modelCard.AccountId.NotNull(), // POC: I hear -you are saying why we're passing them separately. Not sure pass the DUI3-> Connectors.DUI project dependency to the SDK-> Connector.Utils
new Uri(modelCard.ServerUrl.NotNull()),
modelCard.ProjectId.NotNull(),
modelCard.ProjectName.NotNull(),
modelCard.ModelName.NotNull(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@
"Microsoft.Extensions.Logging.Abstractions": "[7.0.0, )",
"Speckle.Autofac": "[2.0.999-local, )",
"Speckle.Connectors.Utils": "[2.0.999-local, )",
"Speckle.Core": "[3.0.1-alpha.14, )",
"Speckle.Core": "[3.0.1-alpha.15, )",
"System.Threading.Tasks.Dataflow": "[6.0.0, )"
}
},
Expand All @@ -399,7 +399,7 @@
"dependencies": {
"Serilog.Extensions.Logging": "[7.0.0, )",
"Speckle.Autofac": "[2.0.999-local, )",
"Speckle.Core": "[3.0.1-alpha.14, )"
"Speckle.Core": "[3.0.1-alpha.15, )"
}
},
"speckle.converters.arcgis3": {
Expand Down Expand Up @@ -456,8 +456,8 @@
"Speckle.Core": {
"type": "CentralTransitive",
"requested": "[3.0.1-alpha.14, )",
"resolved": "3.0.1-alpha.14",
"contentHash": "RzQPVIGFFkKvG56YLr8ACtiwdWJE6IJ9vCQ4qHa0PIsUEpfzAIAi59jnzqtByOFC0FiFrFPow9bkfzylaZorAA==",
"resolved": "3.0.1-alpha.15",
"contentHash": "khv7uLeMMZ5JKJi3NZtz2nti7YPFGQiqllIDqVuNAl8hbqJ52t6OWyOJ87n0sthvGtAO2SpaLik3f+Fh5G/7ww==",
"dependencies": {
"GraphQL.Client": "6.0.0",
"Microsoft.CSharp": "4.7.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@
"Microsoft.Extensions.Logging.Abstractions": "[7.0.0, )",
"Speckle.Autofac": "[2.0.999-local, )",
"Speckle.Connectors.Utils": "[2.0.999-local, )",
"Speckle.Core": "[3.0.1-alpha.14, )",
"Speckle.Core": "[3.0.1-alpha.15, )",
"System.Threading.Tasks.Dataflow": "[6.0.0, )"
}
},
Expand All @@ -452,7 +452,7 @@
"dependencies": {
"Serilog.Extensions.Logging": "[7.0.0, )",
"Speckle.Autofac": "[2.0.999-local, )",
"Speckle.Core": "[3.0.1-alpha.14, )"
"Speckle.Core": "[3.0.1-alpha.15, )"
}
},
"speckle.converters.autocad2023": {
Expand Down Expand Up @@ -512,8 +512,8 @@
"Speckle.Core": {
"type": "CentralTransitive",
"requested": "[3.0.1-alpha.14, )",
"resolved": "3.0.1-alpha.14",
"contentHash": "RzQPVIGFFkKvG56YLr8ACtiwdWJE6IJ9vCQ4qHa0PIsUEpfzAIAi59jnzqtByOFC0FiFrFPow9bkfzylaZorAA==",
"resolved": "3.0.1-alpha.15",
"contentHash": "khv7uLeMMZ5JKJi3NZtz2nti7YPFGQiqllIDqVuNAl8hbqJ52t6OWyOJ87n0sthvGtAO2SpaLik3f+Fh5G/7ww==",
"dependencies": {
"GraphQL.Client": "6.0.0",
"Microsoft.CSharp": "4.7.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public async Task Receive(string modelCardId)
var operationResults = await unitOfWork.Service
.Execute(
modelCard.AccountId.NotNull(), // POC: I hear -you are saying why we're passing them separately. Not sure pass the DUI3-> Connectors.DUI project dependency to the SDK-> Connector.Utils
new Uri(modelCard.ServerUrl.NotNull()),
modelCard.ProjectId.NotNull(),
modelCard.ProjectName.NotNull(),
modelCard.ModelName.NotNull(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@
"Microsoft.Extensions.Logging.Abstractions": "[7.0.0, )",
"Speckle.Autofac": "[2.0.999-local, )",
"Speckle.Connectors.Utils": "[2.0.999-local, )",
"Speckle.Core": "[3.0.1-alpha.14, )",
"Speckle.Core": "[3.0.1-alpha.15, )",
"System.Threading.Tasks.Dataflow": "[6.0.0, )"
}
},
Expand All @@ -455,7 +455,7 @@
"dependencies": {
"Serilog.Extensions.Logging": "[7.0.0, )",
"Speckle.Autofac": "[2.0.999-local, )",
"Speckle.Core": "[3.0.1-alpha.14, )"
"Speckle.Core": "[3.0.1-alpha.15, )"
}
},
"speckle.converters.autocad2024": {
Expand Down Expand Up @@ -521,8 +521,8 @@
"Speckle.Core": {
"type": "CentralTransitive",
"requested": "[3.0.1-alpha.14, )",
"resolved": "3.0.1-alpha.14",
"contentHash": "RzQPVIGFFkKvG56YLr8ACtiwdWJE6IJ9vCQ4qHa0PIsUEpfzAIAi59jnzqtByOFC0FiFrFPow9bkfzylaZorAA==",
"resolved": "3.0.1-alpha.15",
"contentHash": "khv7uLeMMZ5JKJi3NZtz2nti7YPFGQiqllIDqVuNAl8hbqJ52t6OWyOJ87n0sthvGtAO2SpaLik3f+Fh5G/7ww==",
"dependencies": {
"GraphQL.Client": "6.0.0",
"Microsoft.CSharp": "4.7.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@
"Microsoft.Extensions.Logging.Abstractions": "[7.0.0, )",
"Speckle.Autofac": "[2.0.999-local, )",
"Speckle.Connectors.Utils": "[2.0.999-local, )",
"Speckle.Core": "[3.0.1-alpha.14, )",
"Speckle.Core": "[3.0.1-alpha.15, )",
"System.Threading.Tasks.Dataflow": "[6.0.0, )"
}
},
Expand All @@ -463,7 +463,7 @@
"dependencies": {
"Serilog.Extensions.Logging": "[7.0.0, )",
"Speckle.Autofac": "[2.0.999-local, )",
"Speckle.Core": "[3.0.1-alpha.14, )"
"Speckle.Core": "[3.0.1-alpha.15, )"
}
},
"speckle.converters.common": {
Expand Down Expand Up @@ -518,8 +518,8 @@
"Speckle.Core": {
"type": "CentralTransitive",
"requested": "[3.0.1-alpha.14, )",
"resolved": "3.0.1-alpha.14",
"contentHash": "RzQPVIGFFkKvG56YLr8ACtiwdWJE6IJ9vCQ4qHa0PIsUEpfzAIAi59jnzqtByOFC0FiFrFPow9bkfzylaZorAA==",
"resolved": "3.0.1-alpha.15",
"contentHash": "khv7uLeMMZ5JKJi3NZtz2nti7YPFGQiqllIDqVuNAl8hbqJ52t6OWyOJ87n0sthvGtAO2SpaLik3f+Fh5G/7ww==",
"dependencies": {
"GraphQL.Client": "6.0.0",
"Microsoft.CSharp": "4.7.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public async Task Receive(string modelCardId)
HostObjectBuilderResult conversionResults = await unitOfWork.Service
.Execute(
modelCard.AccountId.NotNull(), // POC: I hear -you are saying why we're passing them separately. Not sure pass the DUI3-> Connectors.DUI project dependency to the SDK-> Connector.Utils
new Uri(modelCard.ServerUrl.NotNull()),
modelCard.ProjectId.NotNull(),
modelCard.ProjectName.NotNull(),
modelCard.ModelName.NotNull(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@
"Microsoft.Extensions.Logging.Abstractions": "[7.0.0, )",
"Speckle.Autofac": "[2.0.999-local, )",
"Speckle.Connectors.Utils": "[2.0.999-local, )",
"Speckle.Core": "[3.0.1-alpha.14, )",
"Speckle.Core": "[3.0.1-alpha.15, )",
"System.Threading.Tasks.Dataflow": "[6.0.0, )"
}
},
Expand All @@ -460,7 +460,7 @@
"dependencies": {
"Serilog.Extensions.Logging": "[7.0.0, )",
"Speckle.Autofac": "[2.0.999-local, )",
"Speckle.Core": "[3.0.1-alpha.14, )"
"Speckle.Core": "[3.0.1-alpha.15, )"
}
},
"speckle.converters.common": {
Expand Down Expand Up @@ -512,8 +512,8 @@
"Speckle.Core": {
"type": "CentralTransitive",
"requested": "[3.0.1-alpha.14, )",
"resolved": "3.0.1-alpha.14",
"contentHash": "RzQPVIGFFkKvG56YLr8ACtiwdWJE6IJ9vCQ4qHa0PIsUEpfzAIAi59jnzqtByOFC0FiFrFPow9bkfzylaZorAA==",
"resolved": "3.0.1-alpha.15",
"contentHash": "khv7uLeMMZ5JKJi3NZtz2nti7YPFGQiqllIDqVuNAl8hbqJ52t6OWyOJ87n0sthvGtAO2SpaLik3f+Fh5G/7ww==",
"dependencies": {
"GraphQL.Client": "6.0.0",
"Microsoft.CSharp": "4.7.0",
Expand Down
16 changes: 8 additions & 8 deletions DUI3-DX/DUI3/Speckle.Connectors.DUI.WebView/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@
"Microsoft.Extensions.Logging.Abstractions": "[7.0.0, )",
"Speckle.Autofac": "[2.0.999-local, )",
"Speckle.Connectors.Utils": "[2.0.999-local, )",
"Speckle.Core": "[3.0.1-alpha.14, )",
"Speckle.Core": "[3.0.1-alpha.15, )",
"System.Threading.Tasks.Dataflow": "[6.0.0, )"
}
},
Expand All @@ -435,7 +435,7 @@
"dependencies": {
"Serilog.Extensions.Logging": "[7.0.0, )",
"Speckle.Autofac": "[2.0.999-local, )",
"Speckle.Core": "[3.0.1-alpha.14, )"
"Speckle.Core": "[3.0.1-alpha.15, )"
}
},
"Microsoft.Extensions.Logging.Abstractions": {
Expand All @@ -461,8 +461,8 @@
"Speckle.Core": {
"type": "CentralTransitive",
"requested": "[3.0.1-alpha.14, )",
"resolved": "3.0.1-alpha.14",
"contentHash": "RzQPVIGFFkKvG56YLr8ACtiwdWJE6IJ9vCQ4qHa0PIsUEpfzAIAi59jnzqtByOFC0FiFrFPow9bkfzylaZorAA==",
"resolved": "3.0.1-alpha.15",
"contentHash": "khv7uLeMMZ5JKJi3NZtz2nti7YPFGQiqllIDqVuNAl8hbqJ52t6OWyOJ87n0sthvGtAO2SpaLik3f+Fh5G/7ww==",
"dependencies": {
"GraphQL.Client": "6.0.0",
"Microsoft.CSharp": "4.7.0",
Expand Down Expand Up @@ -865,7 +865,7 @@
"Microsoft.Extensions.Logging.Abstractions": "[7.0.0, )",
"Speckle.Autofac": "[2.0.999-local, )",
"Speckle.Connectors.Utils": "[2.0.999-local, )",
"Speckle.Core": "[3.0.1-alpha.14, )",
"Speckle.Core": "[3.0.1-alpha.15, )",
"System.Threading.Tasks.Dataflow": "[6.0.0, )"
}
},
Expand All @@ -874,7 +874,7 @@
"dependencies": {
"Serilog.Extensions.Logging": "[7.0.0, )",
"Speckle.Autofac": "[2.0.999-local, )",
"Speckle.Core": "[3.0.1-alpha.14, )"
"Speckle.Core": "[3.0.1-alpha.15, )"
}
},
"Microsoft.Extensions.Logging.Abstractions": {
Expand All @@ -896,8 +896,8 @@
"Speckle.Core": {
"type": "CentralTransitive",
"requested": "[3.0.1-alpha.14, )",
"resolved": "3.0.1-alpha.14",
"contentHash": "RzQPVIGFFkKvG56YLr8ACtiwdWJE6IJ9vCQ4qHa0PIsUEpfzAIAi59jnzqtByOFC0FiFrFPow9bkfzylaZorAA==",
"resolved": "3.0.1-alpha.15",
"contentHash": "khv7uLeMMZ5JKJi3NZtz2nti7YPFGQiqllIDqVuNAl8hbqJ52t6OWyOJ87n0sthvGtAO2SpaLik3f+Fh5G/7ww==",
"dependencies": {
"GraphQL.Client": "6.0.0",
"Microsoft.CSharp": "4.7.0",
Expand Down
6 changes: 5 additions & 1 deletion DUI3-DX/DUI3/Speckle.Connectors.DUI/Models/Card/ModelCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ public class ModelCard : DiscriminatedObject
/// Project id. FKA stream id.
/// </summary>
public string? ProjectId { get; set; }

/// <summary>
/// Account id that model card created with it initially.
/// </summary>
public string? AccountId { get; set; }

/// <summary>
/// Information to store for later check any matching server.
/// Server that model card created on it initially.
/// </summary>
public string? ServerUrl { get; set; }

Expand Down
8 changes: 4 additions & 4 deletions DUI3-DX/DUI3/Speckle.Connectors.DUI/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
},
"Speckle.Core": {
"type": "Direct",
"requested": "[3.0.1-alpha.14, )",
"resolved": "3.0.1-alpha.14",
"contentHash": "RzQPVIGFFkKvG56YLr8ACtiwdWJE6IJ9vCQ4qHa0PIsUEpfzAIAi59jnzqtByOFC0FiFrFPow9bkfzylaZorAA==",
"requested": "[3.0.1-alpha.15, )",
"resolved": "3.0.1-alpha.15",
"contentHash": "khv7uLeMMZ5JKJi3NZtz2nti7YPFGQiqllIDqVuNAl8hbqJ52t6OWyOJ87n0sthvGtAO2SpaLik3f+Fh5G/7ww==",
"dependencies": {
"GraphQL.Client": "6.0.0",
"Microsoft.CSharp": "4.7.0",
Expand Down Expand Up @@ -538,7 +538,7 @@
"dependencies": {
"Serilog.Extensions.Logging": "[7.0.0, )",
"Speckle.Autofac": "[2.0.999-local, )",
"Speckle.Core": "[3.0.1-alpha.14, )"
"Speckle.Core": "[3.0.1-alpha.15, )"
}
},
"Serilog.Extensions.Logging": {
Expand Down
20 changes: 10 additions & 10 deletions DUI3-DX/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageVersion Include="Serilog.Extensions.Logging" Version="7.0.0" />
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0"/>
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageVersion Include="Moq" Version="4.20.70" />
<PackageVersion Include="NUnit" Version="4.1.0" />
<PackageVersion Include="NUnit.Analyzers" Version="4.2.0"/>
<PackageVersion Include="NUnit.Analyzers" Version="4.2.0" />
<PackageVersion Include="System.Threading.Tasks.Dataflow" Version="6.0.0" />
<PackageVersion Include="Microsoft.Web.WebView2" Version="1.0.1823.32"/>
<PackageVersion Include="Microsoft.Web.WebView2" Version="1.0.1823.32" />
<PackageVersion Include="Esri.ArcGISPro.Extensions30" Version="3.2.0.49743" />
<PackageVersion Include="Speckle.Civil3D.API" Version="2024.0.0" />
<PackageVersion Include="CefSharp.Wpf" Version="92.0.260"/>
<PackageVersion Include="Revit.Async" Version="2.0.1" />
<PackageVersion Include="Speckle.Core" Version="3.0.1-alpha.14" />
<PackageVersion Include="CefSharp.Wpf" Version="92.0.260" />
<PackageVersion Include="Revit.Async" Version="2.0.1" />
<PackageVersion Include="Speckle.Core" Version="3.0.1-alpha.15" />
<PackageVersion Include="Speckle.Objects" Version="3.0.1-alpha.14" />
<PackageVersion Include="Speckle.AutoCAD.API" Version="2023.0.0" />
<PackageVersion Include="Speckle.Revit.API" Version="2023.0.0" />
<PackageVersion Include="RhinoCommon" Version="7.13.21348.13001" />
<PackageVersion Include="RhinoWindows" Version="7.13.21348.13001" />
<PackageVersion Include="System.Resources.Extensions" Version="7.0.0"/>
<PackageVersion Include="RhinoCommon" Version="7.13.21348.13001" />
<PackageVersion Include="RhinoWindows" Version="7.13.21348.13001" />
<PackageVersion Include="System.Resources.Extensions" Version="7.0.0" />
<GlobalPackageReference Include="PolySharp" Version="1.14.1" />
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<GlobalPackageReference Include="Speckle.InterfaceGenerator" Version="0.9.5" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public static void AddConnectorUtils(this SpeckleContainerBuilder builder)
// send operation and dependencies
builder.AddSingleton<CancellationManager>();
builder.AddScoped<ReceiveOperation>();
builder.AddScoped<AccountService>();

//TODO: Logger will likely be removed from Core, we'll plan to figure out the config later...
var serilogLogger = SpeckleLog.Logger;
Expand Down
27 changes: 27 additions & 0 deletions DUI3-DX/Sdk/Speckle.Connectors.Utils/Operations/AccountService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Speckle.Core.Credentials;

namespace Speckle.Connectors.Utils.Operations;

public class AccountService
{
/// <summary>
/// Account to retrieve with its id, if not exist try to retrieve from matching serverUrl.
/// </summary>
/// <param name="accountId">Id of the account.</param>
/// <param name="serverUrl">Server url to search matching account.</param>
/// <returns></returns>
/// <exception cref="SpeckleAccountManagerException"> Throws if server url doesn't match with any account.</exception>
public Account GetAccountWithServerUrlFallback(string accountId, Uri serverUrl)
{
try
{
return AccountManager.GetAccount(accountId);
}
catch (SpeckleAccountManagerException)
{
var accounts = AccountManager.GetAccounts(serverUrl);
return accounts.First()
?? throw new SpeckleAccountManagerException($"No any account found that matches with server {serverUrl}");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,22 @@ public sealed class ReceiveOperation
{
private readonly IHostObjectBuilder _hostObjectBuilder;
private readonly ISyncToThread _syncToThread;
private readonly AccountService _accountService;

public ReceiveOperation(IHostObjectBuilder hostObjectBuilder, ISyncToThread syncToThread)
public ReceiveOperation(
IHostObjectBuilder hostObjectBuilder,
ISyncToThread syncToThread,
AccountService accountService
)
{
_hostObjectBuilder = hostObjectBuilder;
_syncToThread = syncToThread;
_accountService = accountService;
}

public async Task<HostObjectBuilderResult> Execute(
string accountId, // POC: all these string arguments exists in ModelCard but not sure to pass this dependency here, TBD!
Uri serverUrl,
string projectId,
string projectName,
string modelName,
Expand All @@ -28,7 +35,7 @@ public async Task<HostObjectBuilderResult> Execute(
)
{
// 2 - Check account exist
Account account = AccountManager.GetAccount(accountId);
Account account = _accountService.GetAccountWithServerUrlFallback(accountId, serverUrl);

// 3 - Get commit object from server
using Client apiClient = new(account);
Expand Down
Loading

0 comments on commit ea081f0

Please sign in to comment.