Acumatica通过PXLongOperation恢复功能



我正在为Acumatica创建一个集成,该集成从另一个应用程序加载数据以同步库存项目。它使用API调用来获得一个列表(最多5000个项目(,然后我使用PXLongOperation来插入或更新这些项目。如果没有这个方法,我就无法运行它,因为大批量(也就是插入5000个库存项目(会超时并崩溃。

处理表单是一个自定义表/表单,它检索这些信息,然后解析JSON项目列表,并调用InventoryItemMaint图上的自定义函数。所有这些都很完美,但它永远不会返回到调用函数。我希望能够写下信息来记录它的成功或失败。我试过PXLongOperation.WaitCompletion,但似乎没有什么改变。我确信我没有正确地使用异步特性,但我想知道是否有合理的解决方案。

// This is the lsit of items from SI
List<TEKDTools.TEKdtoolModels.Product> theItems;
if (Guid.TryParse(Convert.ToString(theRow.DtoolsID), out theCatID))
{

// Get the list of items from dtools.
theItems = TEKDTools.TEKdtoolsCommon.ReadOneCatalog(theCatID);

// Start the long operation              
PXLongOperation.StartOperation(this, delegate () {
// Create the graph to make a new Stock Item
InventoryItemMaint itemMaint = PXGraph.CreateInstance<InventoryItemMaint>();

var itemMaintExt = itemMaint.GetExtension<InventoryItemMaintTEKExt>();

foreach (TEKDTools.TEKdtoolModels.Product theItem in theItems)
{
itemMaint.Clear();
itemMaintExt.CreateUpdateDToolsItem(theItem, true);
PXLongOperation.WaitCompletion(itemMaint.UID);
}
}    
);

}
stopWatch.Stop(); // Just using this to figure out how long things were taking.
// For fun I tried the Wait Completion here too
PXLongOperation.WaitCompletion(this.UID);
theRow = MasterView.Current;
// Tried some random static values to see if it was writing
theRow.RowsCreated = 10;
theRow.RowsUpdated = 11;

theRow.Data2 = "Elasped Milliseconds: " + stopWatch.ElapsedMilliseconds.ToString();
theRow.RunStart = startTime;
theRow.RunEnd = DateTime.Now;

// This never gets the record udpated.
Caches[typeof(TCDtoolsBatch)].Update(theRow);

一种可能的解决方案是使用PXLongOperation.SetCustomInfo方法。通常,这用于在长操作完成后更新UI线程。在这个";类";您可以订阅可用于更新行的事件。类的定义如下:

public class UpdateUICustomInfo : IPXCustomInfo
{
public void Complete(PXLongRunStatus status, PXGraph graph)
{
// Set Code Here
}
}

您正在使用的等待完成方法通常用于通过传递另一个长操作的键来等待该长操作完成。

最新更新