private void NotifyListenersOnEntitySaved(uint processedRowsCount) { if (_isNeedNotify || processedRowsCount % _onePercentValue > 0) { return; } var eventArgs = new ImportEntitySavingEventArgs { TotalRowsCount = _totalRowsCount, ProcessedRowsCount = processedRowsCount }; _importNotifier.Notify(this, eventArgs); }
/// <inheritdoc cref="IImportNotifier"/> public void Notify(object sender, ImportEntitySavingEventArgs eventArgs) { uint totalRowsCount = eventArgs.TotalRowsCount; uint processedRowsCount = eventArgs.ProcessedRowsCount; double onePercentValue = GetOnePercentValue(totalRowsCount); if (processedRowsCount % onePercentValue > 0) { return; } uint percent = processedRowsCount * 100 / totalRowsCount; PostMessage("processing", percent); }
/// <summary> /// Saves import entities. /// </summary> /// <param name="parameters">File import parameters.</param> protected virtual void SaveImportEntities(ImportParameters parameters) { OnBeforeImportEntitiesSave(new BeforeImportEntitiesSaveEventArgs { RootSchemaUId = parameters.RootSchemaUId, ImportTags = parameters.ImportTags }); var entities = parameters.Entities; ImportEntity importEntity; while ((importEntity = entities.FirstOrDefault()) != null) { try { InitEntityForSave(parameters, importEntity); var eventArgs = new ImportEntitySavingEventArgs { TotalRowsCount = parameters.TotalRowsCount, ProcessedRowsCount = parameters.ProcessedRowsCount }; OnImportEntitySaving(eventArgs); importEntity.Save(); OnImportEntitySaved(new ImportEntitySavedEventArgs { RootSchemaUId = parameters.RootSchemaUId, PrimaryEntity = importEntity.PrimaryEntity, ImportSessionId = parameters.ImportSessionId }); parameters.ImportedRowsCount++; } catch (OutOfMemoryException e) { throw; } catch (Exception e) { parameters.NotImportedRowsCount++; var eventArgs = new ImportEntitySaveErrorEventArgs { Exception = e, ImportEntity = importEntity, ImportSessionId = parameters.ImportSessionId }; OnImportEntitySaveError(eventArgs); } finally { parameters.ProcessedRowsCount++; entities.Remove(importEntity); } } }
/// <summary> /// Send message before save entity /// </summary> /// <param name="eventArgs"></param> private void OnImportEntitySaving(ImportEntitySavingEventArgs eventArgs) { ImportEntitySaving?.Invoke(this, eventArgs); }