Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add objects api v2 #3513

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions All.sln
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConnectorCivil2025", "Conne
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConverterCivil2025", "Objects\Converters\ConverterAutocadCivil\ConverterCivil2025\ConverterCivil2025.csproj", "{F06E4C37-4076-4272-9CA6-FB505E02CD31}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SendReceive", "Core\Tests\SendReceive\SendReceive.csproj", "{F164E83B-C177-4BC7-9774-0AF7F239C4DC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug Mac|Any CPU = Debug Mac|Any CPU
Expand Down Expand Up @@ -2399,6 +2401,22 @@ Global
{F06E4C37-4076-4272-9CA6-FB505E02CD31}.Release|Any CPU.Build.0 = Release|Any CPU
{F06E4C37-4076-4272-9CA6-FB505E02CD31}.Release|x64.ActiveCfg = Release|Any CPU
{F06E4C37-4076-4272-9CA6-FB505E02CD31}.Release|x64.Build.0 = Release|Any CPU
{F164E83B-C177-4BC7-9774-0AF7F239C4DC}.Debug Mac|Any CPU.ActiveCfg = Debug|Any CPU
{F164E83B-C177-4BC7-9774-0AF7F239C4DC}.Debug Mac|Any CPU.Build.0 = Debug|Any CPU
{F164E83B-C177-4BC7-9774-0AF7F239C4DC}.Debug Mac|x64.ActiveCfg = Debug|Any CPU
{F164E83B-C177-4BC7-9774-0AF7F239C4DC}.Debug Mac|x64.Build.0 = Debug|Any CPU
{F164E83B-C177-4BC7-9774-0AF7F239C4DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F164E83B-C177-4BC7-9774-0AF7F239C4DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F164E83B-C177-4BC7-9774-0AF7F239C4DC}.Debug|x64.ActiveCfg = Debug|Any CPU
{F164E83B-C177-4BC7-9774-0AF7F239C4DC}.Debug|x64.Build.0 = Debug|Any CPU
{F164E83B-C177-4BC7-9774-0AF7F239C4DC}.Release Mac|Any CPU.ActiveCfg = Debug|Any CPU
{F164E83B-C177-4BC7-9774-0AF7F239C4DC}.Release Mac|Any CPU.Build.0 = Debug|Any CPU
{F164E83B-C177-4BC7-9774-0AF7F239C4DC}.Release Mac|x64.ActiveCfg = Debug|Any CPU
{F164E83B-C177-4BC7-9774-0AF7F239C4DC}.Release Mac|x64.Build.0 = Debug|Any CPU
{F164E83B-C177-4BC7-9774-0AF7F239C4DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F164E83B-C177-4BC7-9774-0AF7F239C4DC}.Release|Any CPU.Build.0 = Release|Any CPU
{F164E83B-C177-4BC7-9774-0AF7F239C4DC}.Release|x64.ActiveCfg = Release|Any CPU
{F164E83B-C177-4BC7-9774-0AF7F239C4DC}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -2575,6 +2593,7 @@ Global
{829688CD-CECE-4F6C-A5A0-032BB39CD9E0} = {BE521908-7944-46F3-98BF-B47D34509934}
{70DEAA13-6DC8-44A0-B287-9E806A8054F1} = {890F3257-FCC2-4ED8-9180-22B3641B494C}
{F06E4C37-4076-4272-9CA6-FB505E02CD31} = {BE521908-7944-46F3-98BF-B47D34509934}
{F164E83B-C177-4BC7-9774-0AF7F239C4DC} = {5009BB59-0F77-4202-8FD2-DECC07E93146}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1D43D91B-4F01-4A78-8250-CC6F9BD93A14}
Expand Down
11 changes: 8 additions & 3 deletions Core/Core/Transports/ServerUtils/ServerAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,11 @@ private async Task<Dictionary<string, bool>> HasObjectsImpl(string streamId, IRe
// Stopwatch sw = new Stopwatch(); sw.Start();

string objectsPostParameter = JsonConvert.SerializeObject(objectIds);
var payload = new Dictionary<string, string> { { "objects", objectsPostParameter } };
// var payload = new Dictionary<string, string> { { "objects", objectsPostParameter } };
var payload = new Dictionary<string, IReadOnlyList<string>> { { "objects", objectIds } };
string serializedPayload = JsonConvert.SerializeObject(payload);
var uri = new Uri($"/api/diff/{streamId}", UriKind.Relative);
// var uri = new Uri($"/api/diff/{streamId}", UriKind.Relative);
var uri = new Uri($"/api/v2/projects/{streamId}/objects/diff/", UriKind.Relative);

HttpResponseMessage response;
using StringContent stringContent = new(serializedPayload, Encoding.UTF8, "application/json");
Expand Down Expand Up @@ -399,8 +401,11 @@ private async Task UploadObjectsImpl(string streamId, List<List<(string, string)

CancellationToken.ThrowIfCancellationRequested();

// var uriString = $"/objects/{streamId}";
var uriString = $"/api/v2/projects/{streamId}/objects";

using HttpRequestMessage message =
new() { RequestUri = new Uri($"/objects/{streamId}", UriKind.Relative), Method = HttpMethod.Post };
new() { RequestUri = new Uri(uriString, UriKind.Relative), Method = HttpMethod.Post };

MultipartFormDataContent multipart = new();

Expand Down
64 changes: 64 additions & 0 deletions Core/Tests/SendReceive/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// See https://aka.ms/new-console-template for more information

using System.Diagnostics;
using Objects.BuiltElements;
using Speckle.Core.Api;
using Speckle.Core.Credentials;
using Speckle.Core.Transports;

var w = new Wall();

var receiveTransport = new ServerTransport(
new Account
{
token = "5689faeedd5bc670c2d6d9c793d1cfd5186fbdcdf8",
serverInfo = new ServerInfo { url = "https://testing.speckle.dev" }
},
"3fbcca650f"
);

var objectId = "eedf8fa00e9655d4b734afc7a665b4fc";

var obj = await Operations.Receive(objectId, receiveTransport).ConfigureAwait(false);

Console.WriteLine(obj.id);

var localServer = "https://testing.speckle.dev";
var localToken = "5689faeedd5bc670c2d6d9c793d1cfd5186fbdcdf8";

var localAccount = new Account
{
token = localToken,
serverInfo = new ServerInfo { url = localServer }
};
var client = new Client(localAccount);

var stopwatch = new Stopwatch();
stopwatch.Start();

for (int i = 0; i < 1; i++)
{
var projectId = await client
.StreamCreate(new StreamCreateInput { name = $"test @ {DateTime.Now}" })
.ConfigureAwait(false);

if (projectId is null)
{
throw new Exception("failed to create project");
}

var targetServer = "https://testing.speckle.dev";

localAccount.serverInfo.url = targetServer;

var localServerTransport = new ServerTransport(localAccount, projectId);
var objId = await Operations.Send(obj, new[] { localServerTransport }).ConfigureAwait(false);

// var rec = await Operations.Receive(objId, localServerTransport, localTransport: null).ConfigureAwait(false);
// Console.WriteLine(rec.id);
}

stopwatch.Stop();
Console.WriteLine($"took {stopwatch.ElapsedMilliseconds}");

client.Dispose();
15 changes: 15 additions & 0 deletions Core/Tests/SendReceive/SendReceive.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Core\Core.csproj" />
<ProjectReference Include="..\..\..\Objects\Objects\Objects.csproj" />
</ItemGroup>

</Project>
3 changes: 2 additions & 1 deletion SDK.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"Automate\\Speckle.Automate.Sdk\\Speckle.Automate.Sdk.csproj",
"Automate\\Tests\\Speckle.Automate.Sdk.Tests.Integration\\Speckle.Automate.Sdk.Tests.Integration.csproj",
"Core\\Core\\Core.csproj",
"Core\\Tests\\SendReceive\\SendReceive.csproj",
"Core\\Tests\\Speckle.Core.Tests.Integration\\Speckle.Core.Tests.Integration.csproj",
"Core\\Tests\\Speckle.Core.Tests.Performance\\Speckle.Core.Tests.Performance.csproj",
"Core\\Tests\\Speckle.Core.Tests.Unit\\Speckle.Core.Tests.Unit.csproj",
Expand All @@ -15,4 +16,4 @@
"Objects\\Tests\\Objects.Tests.Unit\\Objects.Tests.Unit.csproj"
]
}
}
}