/// <summary> /// Starts import process. /// </summary> /// <param name="checker">Cancellation checker.</param> private void _Import(ICancellationChecker checker) { Debug.Assert(null != _profile); // inited Debug.Assert(null != _provider); // inited Debug.Assert(null != checker); // created // store records count _readCount = _GetNotEmptyRecordNumber(); Dictionary <string, int> references = PropertyHelpers.CreateImportMap(_profile.Settings.FieldsMap, _provider); // read source _provider.MoveFirst(); int index = 0; while (!_provider.IsEnd()) { // do import process checker.ThrowIfCancellationRequested(); if (!_provider.IsRecordEmpty) { _ImportObject(references, index); ++index; } _provider.MoveNext(); } }
/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// private List <FieldMap> _LoadFieldsMap(XmlNode nodeFieldsMap, ImportType type) { StringDictionary mapTitle2Name = PropertyHelpers.GetTitle2NameMap(type); List <FieldMap> fieldsMap = new List <FieldMap>(); foreach (XmlNode node in nodeFieldsMap.ChildNodes) { if (node.NodeType != XmlNodeType.Element) { continue; // skip comments and other non element nodes } if (node.Name.Equals(NODE_NAME_FIELDSMAP, StringComparison.OrdinalIgnoreCase)) { FieldMap fieldMap = new FieldMap(node.Attributes[ATTRIBUTE_NAME_DSTFIELD].Value, node.Attributes[ATTRIBUTE_NAME_SRCFIELD].Value); if (mapTitle2Name.ContainsValue(fieldMap.ObjectFieldName)) { fieldsMap.Add(fieldMap); } } } return(fieldsMap); }
/// <summary> /// Starts import process. /// </summary> /// <param name="parentPage">Page requirest importing.</param> /// <param name="profile">Import profile.</param> /// <param name="defaultDate">Default date for default initialize imported objects.</param> /// <param name="dataProvider">Data provider.</param> private void _StartImportProcess(AppPages.Page parentPage, ImportProfile profile, DateTime defaultDate, IDataProvider dataProvider) { Debug.Assert(null != parentPage); // created Debug.Assert(null != profile); // created Debug.Assert(null != dataProvider); // creatde // reset state _importer = null; _geocoder = null; // subscribe to events App currentApp = App.Current; currentApp.MainWindow.Closed += new EventHandler(_MainWindow_Closed); // create background worker Debug.Assert(null == _worker); // only once SuspendBackgroundWorker worker = _CreateBackgroundWorker(); // create internal objects var tracker = new ImportCancelTracker(worker); var cancelTracker = new CancellationTracker(tracker); _informer = new ProgressInformer(parentPage, profile.Type, tracker); _informer.SetStatus("ImportLabelImporting"); var infoTracker = new ProgressInfoTracker(worker, _informer.ParentPage, _informer.ObjectName, _informer.ObjectsName); _importer = new Importer(infoTracker); if (PropertyHelpers.IsGeocodeSupported(profile.Type)) { _geocoder = new Geocoder(infoTracker); } // set precondition string message = currentApp.GetString("ImportProcessStarted", _informer.ObjectName); currentApp.Messenger.AddInfo(message); // lock GUI currentApp.UIManager.Lock(true); // run worker var parameters = new ProcessParams(profile, defaultDate, dataProvider, cancelTracker, infoTracker); worker.RunWorkerAsync(parameters); _worker = worker; }
/// <summary> /// Checks is mandatory fields mapped. /// </summary> /// <param name="fieldMap">Map of object to source fields.</param> /// <param name="type">Imported objects type.</param> /// <param name="isAllNeed">All mandatory fields must mapped.</param> /// <returns>Return TRUE if mapped.</returns> private bool _IsMandatoryFieldsMapped(IList <FieldMap> fieldMap, Type type, bool isAllNeed) { Debug.Assert(null != fieldMap); StringCollection names = PropertyHelpers.GetDestinationPropertiesName(type); bool isFieldsMapped = false; for (int index = 0; index < names.Count; ++index) { string name = names[index]; bool isPresent = false; foreach (FieldMap map in fieldMap) { if (name == map.ObjectFieldName) { isPresent = !string.IsNullOrEmpty(map.SourceFieldName); break; // NOTE: result founded - stop process } } isFieldsMapped = isPresent; if (isAllNeed) { if (!isPresent) { break; // NOTE: result founded - stop process } } else if (isPresent) { break; // NOTE: result founded - stop process } } return(isFieldsMapped); }