private ImportProfile _LoadProfile(XmlNode nodeSettings) { ImportProfile profile = new ImportProfile(); profile.Name = nodeSettings.Attributes[ATTRIBUTE_NAME_NAME].Value; bool isSupportedType = true; try { profile.Type = (ImportType)Enum.Parse(typeof(ImportType), nodeSettings.Attributes[ATTRIBUTE_NAME_TYPE].Value); } catch { isSupportedType = false; } if (!isSupportedType) { return(null); } bool isDefault = bool.Parse(nodeSettings.Attributes[ATTRIBUTE_NAME_DEFAULT].Value); // NOTE: ignored in this version - it is left to backward compatibility profile.IsOnTime = false; if (null != nodeSettings.Attributes[ATTRIBUTE_NAME_ONTIME]) { profile.IsOnTime = bool.Parse(nodeSettings.Attributes[ATTRIBUTE_NAME_ONTIME].Value); } else if (isDefault) { profile.IsOnTime = true; } profile.IsDefault = false; // else Do nothing foreach (XmlNode node in nodeSettings.ChildNodes) { if (node.NodeType != XmlNodeType.Element) { continue; // skip comments and other non element nodes } if (node.Name.Equals(NODE_NAME_DESCRIPTION, StringComparison.OrdinalIgnoreCase)) { if (null != node.FirstChild) { profile.Description = node.FirstChild.Value; } } else if (node.Name.Equals(NODE_NAME_SETTINGS, StringComparison.OrdinalIgnoreCase)) { profile.Settings = _LoadSettings(node, profile.Type); } } return(profile); }
/// <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; }
/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// public object Clone() { ImportProfile obj = new ImportProfile(); obj._name = this._name; obj._type = this._type; obj._isDefault = this._isDefault; obj._isOnTime = this._isOnTime; obj._description = this._description; obj._settings = this._settings.Clone() as ImportSettings; return(obj); }
/// <summary> /// Creates a new instance of the <c>ProcessParams</c> class. /// </summary> /// <param name="profile">Import profile to importing.</param> /// <param name="defaultDate">Default date for default initialize imported objects.</param> /// <param name="dataProvider">Data provider.</param> /// <param name="cancelChecker">Cancellation checker.</param> /// <param name="informer">Progress informer.</param> public ProcessParams(ImportProfile profile, DateTime defaultDate, IDataProvider dataProvider, ICancellationChecker cancelChecker, IProgressInformer informer) { Debug.Assert(null != profile); // created Debug.Assert(null != dataProvider); // creatde Debug.Assert(null != cancelChecker); // created Debug.Assert(null != informer); // created Profile = profile; DefaultDate = defaultDate; DataProvider = dataProvider; CancelChecker = cancelChecker; Informer = informer; }
/// <summary> /// Import procedure. /// </summary> /// <param name="parameters">Process parameters.</param> private void _Import(ProcessParams parameters) { Debug.Assert(null != _informer); // inited Debug.Assert(null != parameters); // created ImportProfile profile = parameters.Profile; ICancellationChecker cancelChecker = parameters.CancelChecker; // do import operation from source var projectData = new ProjectDataContext(App.Current.Project); _importer.Import(profile, parameters.DataProvider, parameters.DefaultDate, projectData, cancelChecker); cancelChecker.ThrowIfCancellationRequested(); IList <AppData.DataObject> importedObjects = _importer.ImportedObjects; // do geocode imported objects if ((null != _geocoder) && (0 < importedObjects.Count)) { Geocoder.GeocodeType type = _GetGeocodeType(profile.Settings); _geocoder.Geocode(importedObjects, type, cancelChecker); } _AddObjectsToFeatureServiceIfNeeded(importedObjects); cancelChecker.ThrowIfCancellationRequested(); // commit additions of related objects _informer.ParentPage.Dispatcher.BeginInvoke(new Action(() => { projectData.Commit(); projectData.Dispose(); }), System.Windows.Threading.DispatcherPriority.Send); cancelChecker.ThrowIfCancellationRequested(); }
/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Initializes data source provider. /// </summary> /// <param name="profile">Profile to importing.</param> /// <returns>Created data provider interface or NULL.</returns> /// <remarks>If problem detected add message to messenger.</remarks> private IDataProvider _InitDataSourceProvider(ImportProfile profile) { Debug.Assert(null != profile); // created // check source bool isFileExist = true; string source = profile.Settings.Source; if (DataSourceOpener.IsConnectionString(source)) { DataSourceOpener.ConnectionString = source; } else { DataSourceOpener.FilePath = source; isFileExist = System.IO.File.Exists(source); } // get provider App currentApp = App.Current; IDataProvider dataProvider = null; if (isFileExist) { // try open datasource string messageFailure = null; dataProvider = DataSourceOpener.Open(profile.Settings.TableName, out messageFailure); // show connection problem message if (!string.IsNullOrEmpty(messageFailure)) { currentApp.Messenger.AddError(messageFailure); } } else { // file not found string messageFailure = currentApp.GetString("DataSourceNotFoundFormat", profile.Settings.Source); currentApp.Messenger.AddWarning(messageFailure); // show error } return(dataProvider); }
/// <summary> /// Add new or update presented import profile in application collection. /// </summary> /// <param name="profile">Profile object.</param> /// <param name="previouslyName">Previously profile name (for edited profile).</param> public void AddOrUpdateProfile(ImportProfile profile, string previouslyName) { List <ImportProfile> profiles = _file.Profiles; bool isEditProcess = (null != previouslyName); string nameForSeek = isEditProcess ? previouslyName : profile.Name; // remove older profile with equals name ImportProfile profileToRemove = null; for (int i = 0; i < profiles.Count; ++i) { if (profiles[i].Name.Equals(nameForSeek, StringComparison.OrdinalIgnoreCase)) { profileToRemove = profiles[i]; break; // NOTE: founded } } if (null != profileToRemove) { profiles.Remove(profileToRemove); } // update default state if (profile.IsDefault) { ResetDefaultProfileForType(profile.Type); } else { // select first profile to type as default if (isEditProcess && !_DoesDefaultProfileSetForType(profile.Type)) { profile.IsDefault = true; } } // add created profile _file.Profiles.Add(profile); StoreState(); }
/// <summary> /// Loads <c>ImportProfile</c> from file. /// </summary> /// <param name="nodeProfiles">Profiles node.</param> /// <exception cref="T:System.NotSupportedException.NotSupportedException"> /// XML file is invalid.</exception> private void _LoadContent(XmlElement nodeProfiles) { List <ImportProfile> profiles = Profiles; foreach (XmlNode node in nodeProfiles.ChildNodes) { if (node.NodeType != XmlNodeType.Element) { continue; // skip comments and other non element nodes } if (node.Name.Equals(NODE_NAME_IMPORTS_PROFILE, StringComparison.OrdinalIgnoreCase)) { ImportProfile profile = _LoadProfile(node); if (null != profile) { profiles.Add(profile); } } // else Do nothing } }
/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Starts asynchronous import process. /// </summary> /// <param name="parentPage">Page requirest importing.</param> /// <param name="profile">Import profile to importing.</param> /// <param name="defaultDate">Default date for default initialize imported objects.</param> public void ImportAsync(AppPages.Page parentPage, ImportProfile profile, DateTime defaultDate) { Debug.Assert(null != parentPage); // created Debug.Assert(null != profile); // created IDataProvider dataProvider = _InitDataSourceProvider(profile); if (null != dataProvider) { // provider must present if (0 == dataProvider.RecordsCount) { // empty file detected App currentApp = App.Current; string message = currentApp.FindString("ImportStatusFileIsEmpty"); currentApp.Messenger.AddWarning(message); } else { // provider in valid state - start process _StartImportProcess(parentPage, profile, defaultDate, dataProvider); } } }
/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Importes objects from source. /// </summary> /// <param name="profile">Import source settings.</param> /// <param name="provider">Data provider.</param> /// <param name="defaultDate">Default date for default initialize imported objects.</param> /// <param name="projectData">Project data.</param> /// <param name="checker">Cancellation checker.</param> public void Import(ImportProfile profile, IDataProvider provider, DateTime defaultDate, IProjectDataContext projectData, ICancellationChecker checker) { Debug.Assert(null != profile); // created Debug.Assert(null != provider); // created Debug.Assert(null != projectData); // created Debug.Assert(null != checker); // created // reset internal state first _Reset(); // store contects _profile = profile; _provider = provider; _defaultDate = defaultDate; _projectData = projectData; // start process _Import(checker); }
/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Add new or update presented import profile in application collection. /// </summary> /// <param name="profile">Profile object.</param> public void AddOrUpdateProfile(ImportProfile profile) { AddOrUpdateProfile(profile, null); }
/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// public object Clone() { ImportProfile obj = new ImportProfile(); obj._name = this._name; obj._type = this._type; obj._isDefault = this._isDefault; obj._isOnTime = this._isOnTime; obj._description = this._description; obj._settings = this._settings.Clone() as ImportSettings; return obj; }
private ImportProfile _LoadProfile(XmlNode nodeSettings) { ImportProfile profile = new ImportProfile(); profile.Name = nodeSettings.Attributes[ATTRIBUTE_NAME_NAME].Value; bool isSupportedType = true; try { profile.Type = (ImportType)Enum.Parse(typeof(ImportType), nodeSettings.Attributes[ATTRIBUTE_NAME_TYPE].Value); } catch { isSupportedType = false; } if (!isSupportedType) return null; bool isDefault = bool.Parse(nodeSettings.Attributes[ATTRIBUTE_NAME_DEFAULT].Value); // NOTE: ignored in this version - it is left to backward compatibility profile.IsOnTime = false; if (null != nodeSettings.Attributes[ATTRIBUTE_NAME_ONTIME]) profile.IsOnTime = bool.Parse(nodeSettings.Attributes[ATTRIBUTE_NAME_ONTIME].Value); else if (isDefault) profile.IsOnTime = true; profile.IsDefault = false; // else Do nothing foreach (XmlNode node in nodeSettings.ChildNodes) { if (node.NodeType != XmlNodeType.Element) continue; // skip comments and other non element nodes if (node.Name.Equals(NODE_NAME_DESCRIPTION, StringComparison.OrdinalIgnoreCase)) { if (null != node.FirstChild) profile.Description = node.FirstChild.Value; } else if (node.Name.Equals(NODE_NAME_SETTINGS, StringComparison.OrdinalIgnoreCase)) profile.Settings = _LoadSettings(node, profile.Type); } return profile; }
/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Initializes data source provider. /// </summary> /// <param name="profile">Profile to importing.</param> /// <returns>Created data provider interface or NULL.</returns> /// <remarks>If problem detected add message to messenger.</remarks> private IDataProvider _InitDataSourceProvider(ImportProfile profile) { Debug.Assert(null != profile); // created // check source bool isFileExist = true; string source = profile.Settings.Source; if (DataSourceOpener.IsConnectionString(source)) { DataSourceOpener.ConnectionString = source; } else { DataSourceOpener.FilePath = source; isFileExist = System.IO.File.Exists(source); } // get provider App currentApp = App.Current; IDataProvider dataProvider = null; if (isFileExist) { // try open datasource string messageFailure = null; dataProvider = DataSourceOpener.Open(profile.Settings.TableName, out messageFailure); // show connection problem message if (!string.IsNullOrEmpty(messageFailure)) currentApp.Messenger.AddError(messageFailure); } else { // file not found string messageFailure = currentApp.GetString("DataSourceNotFoundFormat", profile.Settings.Source); currentApp.Messenger.AddWarning(messageFailure); // show error } return dataProvider; }
private void _ParentPage_Loaded(object sender, RoutedEventArgs e) { IsEnabled = _isEnabled; // update tooltip // do import if (null != _onFlyProfile) { // store profile for using _Application.ImportProfilesKeeper.AddOrUpdateProfile(_onFlyProfile); _DoImport(_onFlyProfile); _onFlyProfile = null; _doesNewProfile = false; } }
/// <summary> /// Removes profile from application collection. /// </summary> /// <param name="profile">Profile object to removing.</param> public void Remove(ImportProfile profile) { _file.Profiles.Remove(profile); }
/// <summary> /// Add new or update presented import profile in application collection. /// </summary> /// <param name="profile">Profile object.</param> /// <param name="previouslyName">Previously profile name (for edited profile).</param> public void AddOrUpdateProfile(ImportProfile profile, string previouslyName) { List<ImportProfile> profiles = _file.Profiles; bool isEditProcess = (null != previouslyName); string nameForSeek = isEditProcess ? previouslyName : profile.Name; // remove older profile with equals name ImportProfile profileToRemove = null; for (int i = 0; i < profiles.Count; ++i) { if (profiles[i].Name.Equals(nameForSeek, StringComparison.OrdinalIgnoreCase)) { profileToRemove = profiles[i]; break; // NOTE: founded } } if (null != profileToRemove) profiles.Remove(profileToRemove); // update default state if (profile.IsDefault) ResetDefaultProfileForType(profile.Type); else { // select first profile to type as default if (isEditProcess && !_DoesDefaultProfileSetForType(profile.Type)) profile.IsDefault = true; } // add created profile _file.Profiles.Add(profile); StoreState(); }
private void _onFlyCreatingProfilePage_EditOK(object sender, EventArgs e) { Debug.Assert(null != _onFlyCreatingProfilePage); // store created profile _onFlyProfile = (sender as FleetSetupWizardImportObjectsPage).Profile; _GoBackToParentPage(); }
/// <summary> /// Do import process. /// </summary> /// <param name="profile">Profile to importing.</param> private void _DoImport(ImportProfile profile) { var manager = new ImportManager(); // Subscribe to order completed. If parent page is OptimizeAndEditPage - // call Ungeocoded orders page. manager.ImportCompleted += new ImportCompletedEventHandler(_ImportCompleted); manager.ImportAsync(ParentPage, profile, App.Current.CurrentDate); }