Refresh listView after ManagedOperation execution

StatusIDPriorityType
Closed33961MajorQuestion
ProfileReply
gabossoloClient

Hi !

Could you please to help me on how to refresh listView after executed a ManagedOperation ?

Thank you!

Replies

UserDescriptionPosted On
MariyaVoytovichAgent

Hello gabossolo!

Can I get more information?

Regards,
Mariya
On behalf of Xafari Client Services Team

gabossoloClient

Hi Mariya,

For example if I excuted a ManagedOperation from a SimpleAction Excute method.
At the end of the operation, my ListVew is not refleshing.

Code:

private void ManifestActionOnExecute(object sender, SimpleActionExecuteEventArgs e)
{
var objectsToProcess = new ArrayList(e.SelectedObjects);
var operation = new ManifestExecutionOperation(objectsToProcess);
var managedOperation = new ManagedOperation(Application)
{
Name = "TEST",
ProcessCode = operation.Execute,
ZoneType = ManagedOperationZoneTypes.Local,
TotalStep = objectsToProcess.Count,
TraceLevel = TraceLevel.Verbose
};
managedOperation.Start();
SyncManagedOperationHelper.CreateHelper(managedOperation).InitShowViewParametersProgress(e.ShowViewParameters, true);
View.ObjectSpace.Refresh();
}

MariyaVoytovichAgent

Hello gabossolo!

Sorry for the delay with the answer.

To refresh the list view after executing ManagedOperation, you need to subscribe to the Finalized event of the Managed Operation.
In the event handler, use View.Refresh () to update the ListView.

Regards,
Mariya
On behalf of Xafari Client Services Team

gabossoloClient

Hi Mariya -- I tried but nothing happened. My listView has not been updated.

Here is my code:

--- Controller

private void ExecuteManifestActionOnExecute(object sender, SimpleActionExecuteEventArgs e)
{
var selectedObjects = new ArrayList(e.SelectedObjects);
var operation = new ManifestExecutionOperation(selectedObjects);

var managedOperation = new ManagedOperation(Application)
{
Name = CargoAirModuleLocalizer.Active.GetLocalizedString(
CargoAirModuleItemsStringId.ManifestExecutionOperation),
ProcessCode = operation.Execute,
ZoneType = ManagedOperationZoneTypes.Local,
TotalStep = selectedObjects.Count,
TraceLevel = TraceLevel.Verbose
};
managedOperation.Start();
managedOperation.Finalized += ManagedOperationOnFinalized;
SyncManagedOperationHelper.CreateHelper(managedOperation)
.InitShowViewParametersProgress(e.ShowViewParameters, true);
}

private void ManagedOperationOnFinalized(object sender, EventArgs e)
{
View?.Refresh();
}

--- ManagedOp

public class ManifestExecutionOperation
{
private readonly ArrayList _selectedObjects;

public ManifestExecutionOperation(ArrayList selectedObjects)
{
Guard.ArgumentNotNull(selectedObjects, nameof(selectedObjects));
_selectedObjects = selectedObjects;
}

public void Execute(IManagedOperation operation)
{
if (_selectedObjects.Count == 0) return;
operation.TotalStep = _selectedObjects.Count;
using (var objectSpace = ObjectSpaceFactory.Instance.CreateObjectSpace())
{
foreach (var obj in _selectedObjects)
{
var manifest = (Manifest)objectSpace.GetObject(obj);
operation.NextStep($"Exécution du manifest {manifest.ManifestNumber}");
manifest.ReceiptDate = DateTime.Now;
manifest.NumberOfPiecesReceived = manifest.NumberOfPiecesManifested;
manifest.WeightReceived = manifest.WeightManifested;
manifest.IsLockedObject = true;
operation.CurrentStep++;
}
objectSpace.CommitChanges();
}
}
}

MariyaVoytovichAgent

I looked at your code.

By default, Managed Operations are performed in the background thread.
So, there may be problems with Xpo objects. I do not recommend using a third-party ObjectSpace in a Managed Operation. Therefore, you can change your code like this:

--- Controller
private void ExecuteManifestActionOnExecute(object sender, SimpleActionExecuteEventArgs e)
{
var selectedObjects = new ArrayList(e.SelectedObjects);
var operation = new ManifestExecutionOperation(selectedObjects);var managedOperation = new ManagedOperation(Application)
{
Name = CargoAirModuleLocalizer.Active.GetLocalizedString(
CargoAirModuleItemsStringId.ManifestExecutionOperation),
ProcessCode = operation.Execute,
ZoneType = ManagedOperationZoneTypes.Local,
TotalStep = selectedObjects.Count,
TraceLevel = TraceLevel.Verbose
};
managedOperation.Start();
managedOperation.Finalized += ManagedOperationOnFinalized;
SyncManagedOperationHelper.CreateHelper(managedOperation)
.InitShowViewParametersProgress(e.ShowViewParameters, true);
}private void ManagedOperationOnFinalized(object sender, EventArgs e)
{
this.View.ObjectSpace.CommitChanges();
this.View.Refresh();
}
}--- ManagedOp
public class ManifestExecutionOperation
{
private readonly ArrayList _selectedObjects; 

public ManifestExecutionOperation(ArrayList selectedObjects)
{
Guard.ArgumentNotNull(selectedObjects, nameof(selectedObjects));
_selectedObjects = selectedObjects;
}

public void Execute(IManagedOperation operation)
{
var random = new Random(1000);
if (_selectedObjects.Count == 0) return;
operation.TotalStep = _selectedObjects.Count;

foreach (Manifest manifest in _selectedObjects)
{
operation.NextStep($"Exécution du manifest {manifest.ManifestNumber}");
manifest.ReceiptDate = DateTime.Now;
manifest.NumberOfPiecesReceived = manifest.NumberOfPiecesManifested;
manifest.WeightReceived = manifest.WeightManifested;
manifest.IsLockedObject = true;
operation.CurrentStep++;
}
}
}

The same operations can be performed in the main thread.
For this:

private void ExecuteManifestActionOnExecute(object sender, SimpleActionExecuteEventArgs e)
{
var selectedObjects = new ArrayList(e.SelectedObjects);
var operation = new ManifestExecutionOperation(selectedObjects);var managedOperation = new ManagedOperation(Application, Guid.NewGuid(), false)
{
Name = CargoAirModuleLocalizer.Active.GetLocalizedString(
CargoAirModuleItemsStringId.ManifestExecutionOperation),
ProcessCode = operation.Execute,
ZoneType = ManagedOperationZoneTypes.Local,
TotalStep = selectedObjects.Count,
TraceLevel = TraceLevel.Verbose, 

};
managedOperation.Finalized += ManagedOperationOnFinalized;
managedOperation.Start();

SyncManagedOperationHelper.CreateHelper(managedOperation)
.InitShowViewParametersProgress(e.ShowViewParameters, true);
}
private void ManagedOperationOnFinalized(object sender, EventArgs e)
{
var controller = this.Frame.GetController<RefreshController>();
controller.RefreshAction.DoExecute();
}

To change operation then it is not necessary.

Regards,
Mariya
On behalf of Xafari Client Services Team

gabossoloClient

Still not working....

MariyaVoytovichAgent

Can you send me a small demo project, reproducing the problem.

Regards,
Mariya
On behalf of Xafari Client Services Team

gabossoloClient

Hi Mariya -- Please find attached a demo project.

Thanks for your support.

Regards,

gabossoloClient

Hi Mariya -- Please find attached a demo project.

Thanks for your support.

Regards,

Attached files:
MariyaVoytovichAgent

Hello gabossolo!

Sorry for the delay with the answer.

I check your project and made changes to it.
The attached files contain a modified project and a video that demonstrates the operation of the controller.

Regards,
Mariya
On behalf of Xafari Client Services Team

gabossoloClient

Working fine now!!!

Thank you very much.

× This ticket is closed.

Write US