Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public IBrowsableDataObject SelectedRecord
_selectedRecord = value;
if (value != null)
{
DataExchange.FromRepositoryToShadowsAsync(value);
DataExchange.FromRepositoryToShadowsAsync(value).Wait();
DataExchange.ChangeTrackerSetChanges(value);
IsHashCorrect = DataExchange.IsHashCorrect(_selectedRecord, Asp.GetAuthenticationStateAsync().Result.User.Identity);
Changes = DataExchange.ChangeTrackerGetChanges().OrderBy(p => p.DateTime.Ticks).ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,22 +198,36 @@ await Task.Run(() =>
{
foreach (var fragment in DataFragments)
{
Pocos.AXOpen.Data.IAxoDataEntity poco = (Pocos.AXOpen.Data.IAxoDataEntity)fragment.RefUIData.CreatePoco();
poco.DataEntityId = identifier;
poco.Hash = HashHelper.CreateHash(poco);

fragment?.Repository.Create(identifier, poco);
CreateNewPocoInFragmentRepository(identifier, fragment);
}

DataFragments.First().Repository.Read(identifier);
});
}

private static void CreateNewPocoInFragmentRepository(string identifier, IAxoDataExchange fragment)
{
Pocos.AXOpen.Data.IAxoDataEntity poco = (Pocos.AXOpen.Data.IAxoDataEntity)fragment.RefUIData.CreatePoco();
poco.DataEntityId = identifier;
poco.Hash = HashHelper.CreateHash(poco);

fragment?.Repository.Create(identifier, poco);
}

public async Task FromRepositoryToShadowsAsync(IBrowsableDataObject entity)
{
foreach (var fragment in DataFragments)
{
await fragment.RefUIData.PlainToShadow(fragment.Repository.Read(entity.DataEntityId));
var exist = fragment.Repository.Exists(entity.DataEntityId);

if (exist)
{
await fragment.RefUIData.PlainToShadow(fragment.Repository.Read(entity.DataEntityId));
}
else
{
CreateNewPocoInFragmentRepository(entity.DataEntityId, fragment);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,33 @@ public async void CreateCopy_ShouldCreateInAllRepositoriesFromExisting()
Assert.Equal(4859ul, manip.CounterDelay);
}

[Fact]
public async void FromRepositoryToShadows_CreateMissingFragment()
{
var parent = NSubstitute.Substitute.For<ITwinObject>();
parent.GetConnector().Returns(AXSharp.Connector.ConnectorAdapterBuilder.Build().CreateDummy().GetConnector(null));
var sut = new ProcessData(parent, "a", "b");
var s = sut.CreateBuilder<ProcessData>();
var sharedRepo = new InMemoryRepository<Pocos.axosimple.SharedProductionData>();
var manipRepo = new InMemoryRepository<Pocos.examples.PneumaticManipulator.FragmentProcessData>();
s.Set.SetRepository(sharedRepo);
s.Manip.SetRepository(manipRepo);

sharedRepo.Create("hey remote create", new Pocos.axosimple.SharedProductionData()
{ ComesFrom = 185, GoesTo = 398 });
manipRepo.Create("hey remote create", new() { CounterDelay = 898577ul });
manipRepo.Delete("hey remote create");

sut.FromRepositoryToShadowsAsync(new SharedProductionData() { DataEntityId = "hey remote create" });

Assert.Equal("hey remote create", sut.Set.Set.DataEntityId.Shadow);
Assert.Equal(185, sut.Set.Set.ComesFrom.Shadow);
Assert.Equal(398, sut.Set.Set.GoesTo.Shadow);
Assert.Equal("", sut.Manip.Set.DataEntityId.Shadow);
Assert.Equal(0ul, sut.Manip.Set.CounterDelay.Shadow);

}

[Fact()]
public async void ExportTest()
{
Expand Down