Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dui3/alpha' into dui3/ci/github-…
Browse files Browse the repository at this point in the history
…actions-test
  • Loading branch information
adamhathcock committed May 24, 2024
2 parents 68670f0 + 50370cf commit 27fec08
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 219 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Speckle.Autofac.DependencyInjection;
using Speckle.Connectors.DUI.Bindings;
using Speckle.Connectors.DUI.Bridge;
using Speckle.Connectors.ArcGis.Operations.Send;
using Speckle.Connectors.Utils.Cancellation;
using Speckle.Core.Logging;
using ICancelable = System.Reactive.Disposables.ICancelable;
Expand All @@ -17,6 +16,8 @@
using ArcGIS.Desktop.Editing.Events;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Core.Data;
using Speckle.Connectors.Utils.Operations;
using Speckle.Core.Models;

namespace Speckle.Connectors.ArcGIS.Bindings;

Expand All @@ -31,6 +32,8 @@ public sealed class ArcGISSendBinding : ISendBinding, ICancelable
private readonly List<ISendFilter> _sendFilters;
private readonly CancellationManager _cancellationManager;

private readonly Dictionary<string, ObjectReference> _convertedObjectReferences = new();

/// <summary>
/// Used internally to aggregate the changed objects' id.
/// </summary>
Expand Down Expand Up @@ -252,7 +255,7 @@ public List<CardSetting> GetSendSettings()
public async Task Send(string modelCardId)
{
//poc: dupe code between connectors
using IUnitOfWork<SendOperation> unitOfWork = _unitOfWorkFactory.Resolve<SendOperation>();
using IUnitOfWork<SendOperation<MapMember>> unitOfWork = _unitOfWorkFactory.Resolve<SendOperation<MapMember>>();
try
{
// 0 - Init cancellation token source -> Manager also cancel it if exist before
Expand All @@ -264,18 +267,48 @@ public async Task Send(string modelCardId)
throw new InvalidOperationException("No publish model card was found.");
}

string versionId = await unitOfWork.Service
.Execute(
modelCard.SendFilter.NotNull(),
modelCard.AccountId.NotNull(),
modelCard.ProjectId.NotNull(),
modelCard.ModelId.NotNull(),
(status, progress) => OnSendOperationProgress(modelCardId, status, progress),
cts.Token
)
var sendInfo = new SendInfo(
modelCard.AccountId.NotNull(),
modelCard.ProjectId.NotNull(),
modelCard.ModelId.NotNull(),
"ArcGIS",
_convertedObjectReferences,
modelCard.ChangedObjectIds
);

var sendResult = await QueuedTask
.Run(async () =>
{
List<MapMember> mapMembers = modelCard.SendFilter
.NotNull()
.GetObjectIds()
.Select(id => (MapMember)MapView.Active.Map.FindLayer(id) ?? MapView.Active.Map.FindStandaloneTable(id))
.Where(obj => obj != null)
.ToList();

var result = await unitOfWork.Service
.Execute(
mapMembers,
sendInfo,
(status, progress) => OnSendOperationProgress(modelCardId, status, progress),
cts.Token
)
.ConfigureAwait(false);

// Store the converted references in memory for future send operations, overwriting the existing values for the given application id.
foreach (var kvp in result.convertedReferences)
{
_convertedObjectReferences[kvp.Key + modelCard.ProjectId] = kvp.Value;
}

// It's important to reset the model card's list of changed obj ids so as to ensure we accurately keep track of changes between send operations.
modelCard.ChangedObjectIds = new();

return result;
})
.ConfigureAwait(false);

Commands.SetModelCreatedVersionId(modelCardId, versionId);
Commands.SetModelCreatedVersionId(modelCardId, sendResult.rootObjId);
}
catch (OperationCanceledException)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using ArcGIS.Desktop.Mapping;
using Speckle.Autofac.DependencyInjection;
using Speckle.Connectors.ArcGIS.Bindings;
using Speckle.Connectors.ArcGis.Operations.Send;
Expand All @@ -10,8 +11,10 @@
using Speckle.Autofac;
using Speckle.Connectors.ArcGIS.Filters;
using Speckle.Connectors.DUI;
using Speckle.Connectors.DUI.Bridge;
using Speckle.Connectors.DUI.Models;
using Speckle.Connectors.Utils;
using Speckle.Connectors.Utils.Operations;
using Speckle.Core.Models.GraphTraversal;

// POC: This is a temp reference to root object senders to tweak CI failing after having generic interfaces into common project.
Expand All @@ -28,6 +31,10 @@ public void Load(SpeckleContainerBuilder builder)
builder.AddDUI();
builder.AddDUIView();

// POC: Overwriting the SyncToMainThread to SyncToCurrentThread for ArcGIS only!
// On SendOperation, once we called QueuedTask, it expect to run everything on same thread.
builder.AddSingletonInstance<ISyncToThread, SyncToCurrentThread>();

builder.AddSingleton<DocumentModelStore, ArcGISDocumentStore>();

// Register bindings
Expand All @@ -45,8 +52,8 @@ public void Load(SpeckleContainerBuilder builder)
builder.AddSingleton(DefaultTraversal.CreateTraversalFunc());

// register send operation and dependencies
builder.AddScoped<SendOperation>();
builder.AddScoped<SendOperation<MapMember>>();
builder.AddScoped<RootObjectBuilder>();
builder.AddScoped<IRootObjectSender, RootObjectSender>();
builder.AddSingleton<IRootObjectBuilder<MapMember>, RootObjectBuilder>();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using ArcGIS.Desktop.Mapping;
using Speckle.Autofac.DependencyInjection;
using Speckle.Connectors.DUI.Models.Card.SendFilter;
using Speckle.Connectors.Utils.Builders;
using Speckle.Connectors.Utils.Operations;
using Speckle.Converters.Common;
using Speckle.Core.Logging;
using Speckle.Core.Models;

namespace Speckle.Connectors.ArcGis.Operations.Send;

/// <summary>
/// Stateless builder object to turn an ISendFilter into a <see cref="Base"/> object
/// </summary>
public class RootObjectBuilder
public class RootObjectBuilder : IRootObjectBuilder<MapMember>
{
private readonly IUnitOfWorkFactory _unitOfWorkFactory;

Expand All @@ -20,65 +20,51 @@ public RootObjectBuilder(IUnitOfWorkFactory unitOfWorkFactory)
}

public Base Build(
ISendFilter sendFilter,
IReadOnlyList<MapMember> objects,
SendInfo sendInfo,
Action<string, double?>? onOperationProgressed = null,
CancellationToken ct = default
)
{
if (MapView.Active == null)
if (!objects.Any())
{
throw new SpeckleException("No Map currently active");
// POC: not sure if we would want to throw in here?
throw new InvalidOperationException("No objects were found. Please update your send filter!");
}

List<string> selectedObjects = sendFilter.GetObjectIds().Where(obj => obj != null).ToList();

if (selectedObjects.Count == 0)
{
throw new InvalidOperationException("No layers were found. Please update your send filter!");
}

Base commitObject = ConvertObjects(selectedObjects, onOperationProgressed, ct);
return commitObject;
}

//poc: semi dupe
private Collection ConvertObjects(
IReadOnlyList<string> uriList,
Action<string, double?>? onOperationProgressed = null,
CancellationToken cancellationToken = default
)
{
// POC: does this feel like the right place? I am wondering if this should be called from within send/rcv?
// begin the unit of work
using var uow = _unitOfWorkFactory.Resolve<IRootToSpeckleConverter>();
var converter = uow.Service;

// var rootObjectCollection = new Collection { name = RhinoDoc.ActiveDoc.Name ?? "Unnamed document" };
int count = 0;

Collection rootObjectCollection = new(); //TODO: Collections

foreach (string uri in uriList)
foreach (MapMember mapMember in objects)
{
cancellationToken.ThrowIfCancellationRequested();
ct.ThrowIfCancellationRequested();
var collectionHost = rootObjectCollection;
var applicationId = uri;

Base converted = new();

MapMember mapMember = MapView.Active.Map.FindLayer(uri);
if (mapMember is null)
{
mapMember = MapView.Active.Map.FindStandaloneTable(uri);
}
if (mapMember is null)
{
continue;
}
var applicationId = mapMember.URI;

try
{
converted = converter.Convert(mapMember);
Base converted;
if (
!sendInfo.ChangedObjectIds.Contains(applicationId)
&& sendInfo.ConvertedObjects.TryGetValue(applicationId + sendInfo.ProjectId, out ObjectReference? value)
)
{
converted = value;
}
else
{
converted = converter.Convert(mapMember);
converted.applicationId = applicationId;
}

// add to host
collectionHost.elements.Add(converted);
}
// POC: Exception handling on conversion logic must be revisited after several connectors have working conversions
catch (SpeckleConversionException e)
Expand All @@ -94,10 +80,7 @@ private Collection ConvertObjects(
continue;
}

converted.applicationId = applicationId;
// add to host
collectionHost.elements.Add(converted);
onOperationProgressed?.Invoke("Converting", (double)++count / uriList.Count);
onOperationProgressed?.Invoke("Converting", (double)++count / objects.Count);
}

return rootObjectCollection;
Expand Down

This file was deleted.

Loading

0 comments on commit 27fec08

Please sign in to comment.