public ImportJobMappingStepViewModel(IRepositoryFactory<IImportRepository> repositoryFactory, IRepositoryFactory<ICatalogRepository> catalogRepositoryFactory, 
			ImportJob item, WizardViewModelBare parentVM,
			IImportJobEntityFactory importFactory,
			IViewModelsFactory<IPickAssetViewModel> assetVmFactory,
			IViewModelsFactory<IColumnMappingViewModel> mappingVmFactory,
			IImportService importService,
			ImportEntityType[] entityImporters,
			IAuthenticationContext authContext)
			: base(repositoryFactory, catalogRepositoryFactory, importFactory, item, parentVM, assetVmFactory, mappingVmFactory, importService, entityImporters, authContext)
		{
		}
		public CreateImportJobViewModel(
			IViewModelsFactory<IImportJobOverviewStepViewModel> overviewVmFactory,
			IViewModelsFactory<IImportJobMappingStepViewModel> mappingVmFactory,
			ImportJob item, 
			ImportEntityType[] entityImporters)
		{
			var itemParameter = new KeyValuePair<string, object>("item", item);
			var parentVM = new KeyValuePair<string, object>("parentVM", this);
			var _entityImporters = new KeyValuePair<string, object>("entityImporters", entityImporters);
			RegisterStep(overviewVmFactory.GetViewModelInstance(itemParameter, parentVM, _entityImporters));
			RegisterStep(mappingVmFactory.GetViewModelInstance(itemParameter, parentVM));
		}
Beispiel #3
0
		private void Import(ImportJob job, CsvReader reader, ImportResult result)
		{
			var skip = job.ImportStep;
			var count = job.ImportCount;
			var startIndex = job.StartIndex;

			var csvNames = GetCsvNamesAndIndexes(reader);
			if (csvNames.Count > 0)
			{
				var importer = _entityImporters.SingleOrDefault(i => i.Name == job.EntityImporter);

				if (importer != null)
				{
					var processed = 0;
					while (true)
					{
						try
						{
							var csvValues = reader.ReadRow();
							processed++;
							if (csvValues == null)
								break;

							if ((result.ProcessedRecordsCount < count || count <= 0) && processed >= startIndex && ((processed - startIndex) % skip == 0))
							{
								var systemValues = MapColumns(job.PropertiesMap.Where(prop => prop.IsSystemProperty), csvNames, csvValues,  result);
								var customValues = MapColumns(job.PropertiesMap.Where(prop => !prop.IsSystemProperty), csvNames, csvValues, result);
								if (systemValues != null && customValues != null)
								{
									var rep = IsTaxImport(importer.Name) ? _orderRepository : (IRepository)_catalogRepository;

									if (importer.Name == ImportEntityType.Localization.ToString() || importer.Name == ImportEntityType.Seo.ToString())
										rep = _appConfigRepositoryFactory.GetRepositoryInstance();

									var res = importer.Import(job.CatalogId, job.PropertySetId, systemValues, customValues, rep);
									result.CurrentProgress = reader.CurrentPosition;

									if (string.IsNullOrEmpty(res))
									{
										rep.UnitOfWork.Commit();
										result.ProcessedRecordsCount++;
									}
									else
									{
										result.ErrorsCount++;
										if (result.Errors == null)
											result.Errors = new List<string>();
										result.Errors.Add(string.Format("Row: {0}, Error: {1}", result.ProcessedRecordsCount + result.ErrorsCount, res));

										//check if errors amount reached the allowed errors limit if yes do not save made changes.
										if (result.ErrorsCount >= job.MaxErrorsCount)
										{
											break;
										}
									}
								}
								else
								{
									//check if errors amount reached the allowed errors limit if yes do not save made changes.
									if (result.ErrorsCount >= job.MaxErrorsCount)
									{
										break;
									}
								}
							}
						}
						catch (Exception e)
						{
							result.ErrorsCount++;
							if (result.Errors == null)
								result.Errors = new List<string>();
							result.Errors.Add(e.Message+Environment.NewLine+e);

							//check if errors amount reached the allowed errors limit if yes do not save made changes.
							if (result.ErrorsCount >= job.MaxErrorsCount)
							{
								break;
							}
						}
					}
				}
			}
			else
			{
				if (result.Errors == null)
					result.Errors = new List<string>();
				result.Errors.Add("File contains no rows");
			}

			if (result.ErrorsCount <= job.MaxErrorsCount)
			{
				try
				{
					_catalogRepository.UnitOfWork.Commit();
				}
				catch (Exception e)
				{
					if (result.Errors == null)
						result.Errors = new List<string>();
					result.Errors.Add(e.Message);
				}
			}

		}