EBDN - Community - Question & Answers

  Friday, 21 July 2023
  1 Replies
  619 Visits
0
Votes
Undo
Hello everyone!

In "EB", I used "C #" to read 30000 data operations from the material worksheet function in the product catalog and exported them to CSV, which resulted in memory overflow. How can I solve this problem. Solve. Thank you.
Here is my code block:Please ignore the Chinese comments. Thank you。
This code mainly appears before exporting to CSV

foreach (WorksheetRow row in wSheet.Rows)
{
if (num % 50 == 0)
{
DateTime stTime = DateTime.Now;
log.Info($"清100缓冲前的时间:{stTime}");
log.Info($"达到100循环,清理缓冲");
myApplication.Utils.UnloadCache();

}
dlg.UpdateDialog(num, $"请稍等……\n正在处理……\n" + num + "/" + materials.Count());
var info = getCombination(row, wSheet, modelAttributeId);

materials.Add(info);
dlg.UpdateDialog(num);
num++;
}




Full Code

public void CatalogMaterialFromCatalog(Aucotec.EngineeringBase.Client.Runtime.Application myApplication, ObjectItem objectItem, string filePath)
{
ILog log = LogConfinuration(typeof(MyPlugIn));
int modelAttributeId = 0;
IList<AttributeId> ids = null;
//初始化加载型号属性ID
FilterExpression filter = myApplication.CreateFilter();
filter.Kind = ObjectKind.Attributes;
filter.Add("型号", BinaryOperator.Equal, "");
//型号
if (filter != null)
{
modelAttributeId = filter.FirstOrDefault().AttributeId;
ids = new List<AttributeId> {
AttributeId.Manufacturer,
AttributeId.CatalogNumber,
(AttributeId)modelAttributeId,
AttributeId.TId
};
}
else
{
ids = new List<AttributeId> {
AttributeId.Manufacturer,
AttributeId.CatalogNumber,
AttributeId.CatalogNumber,
AttributeId.TId
};
}

Aucotec.EngineeringBase.Client.Runtime.Worksheet wSheet = objectItem.OpenWorksheet(ObjectKind.Device, ids);

//wSheet.Export(WorksheetExportBehavior.CSV, "D:\\DataPortal\\materials-施耐德.csv");
//MessageBox.Show("Worksheet row count: " + wSheet.Rows.Count);
myApplication.Utils.UnloadCache();

List<MaterialInfo> materials = new List<MaterialInfo>();
using (WaitDialog dlg = myApplication.Dialogs.CreateWaitDialog())
{
int num = 1;
dlg.ShowDialogAsync(materials.Count, "数据处理", AnimationType.Search, "数据正在导出……");
foreach (WorksheetRow row in wSheet.Rows)
{
if (num % 50 == 0)
{
DateTime stTime = DateTime.Now;
log.Info($"清100缓冲前的时间:{stTime}");
log.Info($"达到100循环,清理缓冲");
myApplication.Utils.UnloadCache();

}
dlg.UpdateDialog(num, $"请稍等……\n正在处理……\n" + num + "/" + materials.Count());
var info = getCombination(row, wSheet, modelAttributeId);

materials.Add(info);
dlg.UpdateDialog(num);
num++;
}
#region eeeeTest
//for (int IRow = 0; IRow < wSheet.Rows.Count; IRow++)
//{
// for (int ICol = 0; ICol < wSheet.Columns.Count; ICol++)
// {

// var str1 = wSheet.Rows[IRow][ICol];

// }
// }
#endregion
dlg.CloseDialog();
}

//导出所有数据到CSV

ExportToCsv(materials, filePath, myApplication);



}