From 1fbe6f2fd7e41d723101422a661d4e0a7a506680 Mon Sep 17 00:00:00 2001 From: Alan Rynne Date: Mon, 29 Aug 2022 16:52:07 +0200 Subject: [PATCH] feat(gh): Added ability for the receiver to fetch public streams without an account. --- ...perations.VariableInputReceiveComponent.cs | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/ConnectorGrasshopper/ConnectorGrasshopper/Ops/Operations.VariableInputReceiveComponent.cs b/ConnectorGrasshopper/ConnectorGrasshopper/Ops/Operations.VariableInputReceiveComponent.cs index 432128bdc0..4b10692a16 100644 --- a/ConnectorGrasshopper/ConnectorGrasshopper/Ops/Operations.VariableInputReceiveComponent.cs +++ b/ConnectorGrasshopper/ConnectorGrasshopper/Ops/Operations.VariableInputReceiveComponent.cs @@ -24,6 +24,7 @@ using Speckle.Core.Credentials; using Speckle.Core.Logging; using Speckle.Core.Models; +using Speckle.Core.Models.Extensions; using Speckle.Core.Transports; using Utilities = ConnectorGrasshopper.Extras.Utilities; @@ -424,8 +425,20 @@ private async Task ResetApiClient(StreamWrapper wrapper) try { ApiClient?.Dispose(); - var acc = await wrapper.GetAccount(); - ApiClient = new Client(acc); + Account account = null; + try + { + account = wrapper?.GetAccount().Result; + } + catch (Exception e) + { + AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, e.ToFormattedString()); + account = new Account + { + id = wrapper?.StreamId, serverInfo = new ServerInfo() { url = wrapper?.ServerUrl }, token = "", refreshToken = "" + }; + } + ApiClient = new Client(account); ApiClient.SubscribeCommitCreated(StreamWrapper.StreamId); ApiClient.OnCommitCreated += ApiClient_OnCommitCreated; } @@ -543,22 +556,10 @@ public override void DoWork(Action ReportProgress, Action Done) } }); }; + + Speckle.Core.Logging.Analytics.TrackEvent(receiveComponent.ApiClient.Account, Speckle.Core.Logging.Analytics.Events.Receive, new Dictionary() { { "auto", receiveComponent.AutoReceive } }); - Client client; - try - { - client = new Client(InputWrapper?.GetAccount().Result); - } - catch (Exception e) - { - RuntimeMessages.Add((GH_RuntimeMessageLevel.Warning, e.InnerException?.Message ?? e.Message)); - Done(); - return; - } - - Speckle.Core.Logging.Analytics.TrackEvent(client.Account, Speckle.Core.Logging.Analytics.Events.Receive, new Dictionary() { { "auto", receiveComponent.AutoReceive } }); - - var remoteTransport = new ServerTransport(InputWrapper?.GetAccount().Result, InputWrapper?.StreamId); + var remoteTransport = new ServerTransport(receiveComponent.ApiClient.Account, InputWrapper?.StreamId); remoteTransport.TransportName = "R"; // Means it's a copy paste of an empty non-init component; set the record and exit fast unless ReceiveOnOpen is true. @@ -575,7 +576,7 @@ public override void DoWork(Action ReportProgress, Action Done) var t = Task.Run(async () => { ((VariableInputReceiveComponent)Parent).PrevReceivedData = null; - var myCommit = await GetCommit(InputWrapper, client, (level, message) => + var myCommit = await GetCommit(InputWrapper, receiveComponent.ApiClient, (level, message) => { RuntimeMessages.Add((level, message)); @@ -607,7 +608,7 @@ public override void DoWork(Action ReportProgress, Action Done) try { - await client.CommitReceived(new CommitReceivedInput + await receiveComponent.ApiClient.CommitReceived(new CommitReceivedInput { streamId = InputWrapper.StreamId, commitId = myCommit.id,