From 1b10dd369ac428aae9d4cd3b8b2e2986f2e5df67 Mon Sep 17 00:00:00 2001 From: "blazej.kuhajda" Date: Tue, 15 Apr 2025 07:11:18 +0200 Subject: [PATCH 1/5] Create draft PR for #668 From 6e79fc827deace5e7e5df4a7450964594e845a06 Mon Sep 17 00:00:00 2001 From: "blazej.kuhajda" Date: Tue, 15 Apr 2025 09:18:12 +0200 Subject: [PATCH 2/5] sent to plc - fixed, added logs --- .../AxoDataExchange/DataExchangeView.razor | 50 ++-- .../DistributedDataSelectorView.razor.cs | 2 +- .../DistributedDataSelectorViewModel.cs | 53 +++- .../Distributed/DistributedDataView.razor | 4 +- .../Distributed/DistributedDataView.razor.cs | 20 +- .../Distributed/DistributedDataViewModel.cs | 237 +++++++++++++++--- 6 files changed, 285 insertions(+), 81 deletions(-) diff --git a/src/data/src/AXOpen.Data.Blazor/AxoDataExchange/DataExchangeView.razor b/src/data/src/AXOpen.Data.Blazor/AxoDataExchange/DataExchangeView.razor index 3af4cd3b2..65b406abe 100644 --- a/src/data/src/AXOpen.Data.Blazor/AxoDataExchange/DataExchangeView.razor +++ b/src/data/src/AXOpen.Data.Blazor/AxoDataExchange/DataExchangeView.razor @@ -304,7 +304,7 @@ else @@ -316,7 +316,7 @@ else @@ -616,18 +616,24 @@ else
// - + //
diff --git a/src/data/src/AXOpen.Data.Blazor/AxoDataExchange/DataExchangeView.razor b/src/data/src/AXOpen.Data.Blazor/AxoDataExchange/DataExchangeView.razor index 65b406abe..10ff22ec2 100644 --- a/src/data/src/AXOpen.Data.Blazor/AxoDataExchange/DataExchangeView.razor +++ b/src/data/src/AXOpen.Data.Blazor/AxoDataExchange/DataExchangeView.razor @@ -298,7 +298,7 @@ else
- +@* @if (EnableUpdateFromPlc) { @@ -309,7 +309,7 @@ else - } + } *@ @if (EnableSendToPlc) { @@ -552,7 +552,7 @@ else @Localizer["Load from ALL PLCs"] } - else if (ButtonOperationName.Equals("UpdateFromPlc")) + @* else if (ButtonOperationName.Equals("UpdateFromPlc")) { - } + } *@ } @@ -589,13 +589,13 @@ else @Localizer["Load from PLC into THIS repository"] } - else if (ButtonOperationName.Equals("UpdateFromPlc")) + @* else if (ButtonOperationName.Equals("UpdateFromPlc")) { - } + } *@ diff --git a/src/data/src/AXOpen.Data.Blazor/AxoDataExchange/DataExchangeView.razor.cs b/src/data/src/AXOpen.Data.Blazor/AxoDataExchange/DataExchangeView.razor.cs index a7e5667f8..f3c22df71 100644 --- a/src/data/src/AXOpen.Data.Blazor/AxoDataExchange/DataExchangeView.razor.cs +++ b/src/data/src/AXOpen.Data.Blazor/AxoDataExchange/DataExchangeView.razor.cs @@ -57,7 +57,7 @@ public partial class DataExchangeView : ComponentBase, IDisposable [Parameter] public bool EnableExport { get; set; } = false; [Parameter] public bool EnableSorting { get; set; } = false; - [Parameter] public bool EnableUpdateFromPlc { get; set; } = false; + //[Parameter] public bool EnableUpdateFromPlc { get; set; } = false; [Parameter] public RenderFragment ChildContent { get; set; } diff --git a/src/data/src/AXOpen.Data.Blazor/AxoDataExchange/DataExchangeViewModel.cs b/src/data/src/AXOpen.Data.Blazor/AxoDataExchange/DataExchangeViewModel.cs index 9cf981572..4f2de13ff 100644 --- a/src/data/src/AXOpen.Data.Blazor/AxoDataExchange/DataExchangeViewModel.cs +++ b/src/data/src/AXOpen.Data.Blazor/AxoDataExchange/DataExchangeViewModel.cs @@ -450,42 +450,42 @@ public async Task LoadFromPlc() } } - public async Task UpdateFromPlc() - { - try - { - var identifier = SelectedRecord.DataEntityId; - - var refdata = DataExchange.CloneDataObject(); - - var DataEntityId = (refdata as IAxoDataEntity).DataEntityId; - - List batchRedElements = new(); - - batchRedElements.Add(DataEntityId); - - await refdata.GetConnector().ReadBatchAsync(batchRedElements); - - if (DataEntityId.Cyclic != identifier) - { - AlertDialogService?.AddAlertDialog(eAlertType.Warning, "Update error", $"Online record has different ID that requested to update: {DataEntityId.Cyclic}/{identifier}!", 14); - return; - } - - await DataExchange.RemoteUpdate(identifier); - AlertDialogService?.AddAlertDialog(eAlertType.Success, "Update from PLC!", "Item was successfully updated from PLC!", 10); - AxoApplication.Current.Logger.Information($"Updated from Plc {identifier} into {DataExchange.PresentableInstanceName} by user action.", AuthenticationProvider.GetAuthenticationStateAsync().Result.User.Identity); - } - catch (Exception e) - { - AlertDialogService?.AddAlertDialog(eAlertType.Danger, "Failed to update a record from the controller", e.Message, 10); - } - finally - { - await FillObservableRecordsAsync(); - CreateItemId = null; - } - } + //public async Task UpdateFromPlc() + //{ + // try + // { + // var identifier = SelectedRecord.DataEntityId; + + // var refdata = DataExchange.CloneDataObject(); + + // var DataEntityId = (refdata as IAxoDataEntity).DataEntityId; + + // List batchRedElements = new(); + + // batchRedElements.Add(DataEntityId); + + // await refdata.GetConnector().ReadBatchAsync(batchRedElements); + + // if (DataEntityId.Cyclic != identifier) + // { + // AlertDialogService?.AddAlertDialog(eAlertType.Warning, "Update error", $"Online record has different ID that requested to update: {DataEntityId.Cyclic}/{identifier}!", 14); + // return; + // } + + // await DataExchange.RemoteUpdate(identifier); + // AlertDialogService?.AddAlertDialog(eAlertType.Success, "Update from PLC!", "Item was successfully updated from PLC!", 10); + // AxoApplication.Current.Logger.Information($"Updated from Plc {identifier} into {DataExchange.PresentableInstanceName} by user action.", AuthenticationProvider.GetAuthenticationStateAsync().Result.User.Identity); + // } + // catch (Exception e) + // { + // AlertDialogService?.AddAlertDialog(eAlertType.Danger, "Failed to update a record from the controller", e.Message, 10); + // } + // finally + // { + // await FillObservableRecordsAsync(); + // CreateItemId = null; + // } + //} public Task ExportDataAsync(string path) diff --git a/src/data/src/AXOpen.Data.Blazor/AxoDataExchange/IDataExchangeGlobalActions.cs b/src/data/src/AXOpen.Data.Blazor/AxoDataExchange/IDataExchangeGlobalActions.cs index 72bd52b60..329bce351 100644 --- a/src/data/src/AXOpen.Data.Blazor/AxoDataExchange/IDataExchangeGlobalActions.cs +++ b/src/data/src/AXOpen.Data.Blazor/AxoDataExchange/IDataExchangeGlobalActions.cs @@ -7,7 +7,7 @@ public interface IDataExchangeGlobalActions public Task Copy(string identifier, string newIdentifier); public Task Create(string identifier); public Task CreateNewFromPlc(string identifier); - public Task UpdateFromPlc(string identifier); + //public Task UpdateFromPlc(string identifier); public Task SendToPlc(string identifier); } diff --git a/src/data/src/AXOpen.Data.Blazor/Distributed/DistributedDataView.razor b/src/data/src/AXOpen.Data.Blazor/Distributed/DistributedDataView.razor index f6002fb80..f80029933 100644 --- a/src/data/src/AXOpen.Data.Blazor/Distributed/DistributedDataView.razor +++ b/src/data/src/AXOpen.Data.Blazor/Distributed/DistributedDataView.razor @@ -151,7 +151,6 @@ else EnableCreateNewFromPlc="@this.EnableCreateNewFromPlc" EnableSendToPlc="@this.EnableSendToPlc" - EnableUpdateFromPlc="@this.EnableUpdateFromPlc" EnableFiltering="@this.EnableFiltering" EnableSorting="@this.EnableSorting" diff --git a/src/data/src/AXOpen.Data.Blazor/Distributed/DistributedDataView.razor.cs b/src/data/src/AXOpen.Data.Blazor/Distributed/DistributedDataView.razor.cs index 1d70cd7de..7ebed04a0 100644 --- a/src/data/src/AXOpen.Data.Blazor/Distributed/DistributedDataView.razor.cs +++ b/src/data/src/AXOpen.Data.Blazor/Distributed/DistributedDataView.razor.cs @@ -27,7 +27,7 @@ public partial class DistributedDataView [Parameter] public bool EnableDelete { get; set; } = false; [Parameter] public bool EnableSendToPlc { get; set; } = false; [Parameter] public bool EnableCreateNewFromPlc { get; set; } = false; - [Parameter] public bool EnableUpdateFromPlc { get; set; } = false; + //[Parameter] public bool EnableUpdateFromPlc { get; set; } = false; [Parameter] public bool EnableFiltering { get; set; } = false; [Parameter] public bool EnableExport { get; set; } = false; diff --git a/src/data/src/AXOpen.Data.Blazor/Distributed/DistributedDataViewModel.cs b/src/data/src/AXOpen.Data.Blazor/Distributed/DistributedDataViewModel.cs index fa5d419af..08a663b05 100644 --- a/src/data/src/AXOpen.Data.Blazor/Distributed/DistributedDataViewModel.cs +++ b/src/data/src/AXOpen.Data.Blazor/Distributed/DistributedDataViewModel.cs @@ -286,107 +286,107 @@ public async Task CreateNewFromPlc(string identifier) } - public async Task UpdateFromPlc(string identifier) - { - if (string.IsNullOrEmpty(identifier)) - { - AlertService?.AddAlertDialog(eAlertType.Warning, "Update data error", "Please enter valid identifier!", 20); - return; - } - - List updated = new List(); - List created = new List(); - List notSameIdInPlc = new List(); - - foreach (var exchange in DisplayedDataFragments.DistinctBy(p => p.ManagerDataTypeName)) - { - //TODO optimalize -> clone only EntityId - var refdata = exchange.CloneDataObject(); - - var DataEntityId = (refdata as IAxoDataEntity).DataEntityId; - - List batchRedElements = new(); - - batchRedElements.Add(DataEntityId); - - await refdata.GetConnector().ReadBatchAsync(batchRedElements); - - if (DataEntityId.Cyclic != identifier) - { - notSameIdInPlc.Add(exchange.ManagerDataTypeName); - continue; - } - - if (exchange.Repository.Exists(identifier)) - { - await exchange.RemoteUpdate(identifier); - updated.Add(exchange.ManagerDataTypeName); - } - else - { - await exchange.RemoteCreate(identifier); - created.Add(exchange.ManagerDataTypeName); - } - } - - if (updated.Count > 0) - { - string updatedInRepositories = string.Join(", ", updated); - - // Alert - AlertService?.AddAlertDialog( - eAlertType.Info, - "Update record", - $"Record \"{identifier}\" was updated in repositories: {updatedInRepositories}.", - 7 - ); - - // Log - AxoApplication.Current.Logger.Information( - $"Updated record \"{identifier}\" in repositories: {updatedInRepositories} by user action.", - Authentication.GetAuthenticationStateAsync().Result.User.Identity - ); - } - - if (created.Count > 0) - { - string createdInRepositories = string.Join(", ", created); - - // Alert - AlertService?.AddAlertDialog( - eAlertType.Info, - "Create record", - $"Record \"{identifier}\" was created in repositories: {createdInRepositories}.", - 7 - ); - - // Log - AxoApplication.Current.Logger.Information( - $"Created record \"{identifier}\" in repositories: {createdInRepositories} by user action.", - Authentication.GetAuthenticationStateAsync().Result.User.Identity - ); - } - - if (notSameIdInPlc.Count > 0) - { - string notEqualEntityIds = string.Join(", ", notSameIdInPlc); - - // Alert - AlertService?.AddAlertDialog( - eAlertType.Warning, - "Update error", - $"Online records have a different ID than requested for update: {notEqualEntityIds}.", - 14 - ); - - // Log - AxoApplication.Current.Logger.Warning( - $"Updating record \"{identifier}\" by user action failed – mismatched IDs in: {notEqualEntityIds}.", - Authentication.GetAuthenticationStateAsync().Result.User.Identity - ); - } - - } + //public async Task UpdateFromPlc(string identifier) + //{ + // if (string.IsNullOrEmpty(identifier)) + // { + // AlertService?.AddAlertDialog(eAlertType.Warning, "Update data error", "Please enter valid identifier!", 20); + // return; + // } + + // List updated = new List(); + // List created = new List(); + // List notSameIdInPlc = new List(); + + // foreach (var exchange in DisplayedDataFragments.DistinctBy(p => p.ManagerDataTypeName)) + // { + // //TODO optimalize -> clone only EntityId + // var refdata = exchange.CloneDataObject(); + + // var DataEntityId = (refdata as IAxoDataEntity).DataEntityId; + + // List batchRedElements = new(); + + // batchRedElements.Add(DataEntityId); + + // await refdata.GetConnector().ReadBatchAsync(batchRedElements); + + // if (DataEntityId.Cyclic != identifier) + // { + // notSameIdInPlc.Add(exchange.ManagerDataTypeName); + // continue; + // } + + // if (exchange.Repository.Exists(identifier)) + // { + // await exchange.RemoteUpdate(identifier); + // updated.Add(exchange.ManagerDataTypeName); + // } + // else + // { + // await exchange.RemoteCreate(identifier); + // created.Add(exchange.ManagerDataTypeName); + // } + // } + + // if (updated.Count > 0) + // { + // string updatedInRepositories = string.Join(", ", updated); + + // // Alert + // AlertService?.AddAlertDialog( + // eAlertType.Info, + // "Update record", + // $"Record \"{identifier}\" was updated in repositories: {updatedInRepositories}.", + // 7 + // ); + + // // Log + // AxoApplication.Current.Logger.Information( + // $"Updated record \"{identifier}\" in repositories: {updatedInRepositories} by user action.", + // Authentication.GetAuthenticationStateAsync().Result.User.Identity + // ); + // } + + // if (created.Count > 0) + // { + // string createdInRepositories = string.Join(", ", created); + + // // Alert + // AlertService?.AddAlertDialog( + // eAlertType.Info, + // "Create record", + // $"Record \"{identifier}\" was created in repositories: {createdInRepositories}.", + // 7 + // ); + + // // Log + // AxoApplication.Current.Logger.Information( + // $"Created record \"{identifier}\" in repositories: {createdInRepositories} by user action.", + // Authentication.GetAuthenticationStateAsync().Result.User.Identity + // ); + // } + + // if (notSameIdInPlc.Count > 0) + // { + // string notEqualEntityIds = string.Join(", ", notSameIdInPlc); + + // // Alert + // AlertService?.AddAlertDialog( + // eAlertType.Warning, + // "Update error", + // $"Online records have a different ID than requested for update: {notEqualEntityIds}.", + // 14 + // ); + + // // Log + // AxoApplication.Current.Logger.Warning( + // $"Updating record \"{identifier}\" by user action failed – mismatched IDs in: {notEqualEntityIds}.", + // Authentication.GetAuthenticationStateAsync().Result.User.Identity + // ); + // } + + //} public async Task SendToPlc(string identifier) { From 12377b8590fde6f40147a0abed39fdee0be80f8e Mon Sep 17 00:00:00 2001 From: "blazej.kuhajda" Date: Wed, 16 Apr 2025 06:30:27 +0200 Subject: [PATCH 5/5] add injected ids as a parameter --- .../DistributedDataSelectorView.razor.cs | 9 +- .../Distributed/DistributedDataView.razor | 9 +- .../Distributed/DistributedDataView.razor.cs | 12 ++- .../Distributed/DistributedDataViewModel.cs | 91 ++++++++++--------- .../DistributedDataExchangeExtension.cs | 35 +++++++ 5 files changed, 100 insertions(+), 56 deletions(-) create mode 100644 src/data/src/AXOpen.Data/Distributed/DistributedDataExchangeExtension.cs diff --git a/src/data/src/AXOpen.Data.Blazor/Distributed/DistributedDataSelectorView.razor.cs b/src/data/src/AXOpen.Data.Blazor/Distributed/DistributedDataSelectorView.razor.cs index 19b9f965f..31643bb63 100644 --- a/src/data/src/AXOpen.Data.Blazor/Distributed/DistributedDataSelectorView.razor.cs +++ b/src/data/src/AXOpen.Data.Blazor/Distributed/DistributedDataSelectorView.razor.cs @@ -16,14 +16,11 @@ public partial class DistributedDataSelectorView [Parameter, EditorRequired] public string GroupName { get; set; } - [Parameter] - public string ConfigSuffix { get; set; } = ""; + [Parameter] public string ConfigSuffix { get; set; } = ""; - [Parameter] - public PredicateContainer? InjectedPredicateContainer { set; get; } + [Parameter] public PredicateContainer? InjectedPredicateContainer { set; get; } - [Parameter] - public Action? OnDataSend { get; set; } + [Parameter] public Action? OnDataSend { get; set; } [Inject] diff --git a/src/data/src/AXOpen.Data.Blazor/Distributed/DistributedDataView.razor b/src/data/src/AXOpen.Data.Blazor/Distributed/DistributedDataView.razor index f80029933..06d2e642d 100644 --- a/src/data/src/AXOpen.Data.Blazor/Distributed/DistributedDataView.razor +++ b/src/data/src/AXOpen.Data.Blazor/Distributed/DistributedDataView.razor @@ -59,13 +59,13 @@ @if (DistributedVM.InjectedEntities != null && DistributedVM.InjectedEntities.Count > 0) { -