Ejemplo n.º 1
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Showes process results with details in message window.
        /// </summary>
        /// <param name="importer">Importer object.</param>
        /// <param name="geocoder">Geocoder object (can be NULL).</param>
        /// <param name="storage">Storage object</param>
        /// <param name="status">Status text.</param>
        public void Inform(Importer importer, Geocoder geocoder, Storage storage, string status)
        {
            Debug.Assert(!string.IsNullOrEmpty(status)); // not empty
            Debug.Assert(null != importer); // created
            Debug.Assert(null != storage); // created

            var details = new List<MessageDetail>();

            // add statistic
            string statistic = _CreateStatistic(importer, geocoder, storage);
            Debug.Assert(!string.IsNullOrEmpty(statistic));
            var statisticDetail = new MessageDetail(MessageType.Information, statistic);
            details.Add(statisticDetail);

            // add geocoder exception
            if ((null != geocoder) &&
                (null != geocoder.Exception))
            {
                details.Add(_GetServiceMessage(geocoder.Exception));
            }

            // add steps deatils
            details.AddRange(importer.Details);
            if (null != geocoder)
                details.AddRange(geocoder.Details);
            details.AddRange(storage.Details);

            // show status with details
            App.Current.Messenger.AddMessage(status, details);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets geocode objects statistic element text.
        /// </summary>
        /// <param name="geocoder">Reference to geocoder object.</param>
        /// <param name="importedCount">Count of imported objects.</param>
        /// <returns>Geocoded objects statistic element text.</returns>
        private string _GetGeocodeStatisticElementText(Geocoder geocoder, int importedCount)
        {
            Debug.Assert(null != geocoder); // inited

            int geocodedCount = geocoder.GeocodedCount;

            string text = _GetStatisticElement("ImportProcessStatusGeoded", geocodedCount);
            var sb = new StringBuilder(text);

            if (geocodedCount != importedCount)
            {   // append ungeocoded objects text
                sb.Append(_GetStatisticElement("ImportProcessStatusUngeoded",
                                               importedCount - geocodedCount));
            }

            return sb.ToString();
        }
Ejemplo n.º 3
0
        /// <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;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates statictic message.
        /// </summary>
        /// <param name="importer">Importer object.</param>
        /// <param name="geocoder">Geocoder object (can be NULL).</param>
        /// <param name="storage">Storage object</param>
        /// <returns>Process statictic description.</returns>
        private string _CreateStatistic(Importer importer, Geocoder geocoder, Storage storage)
        {
            Debug.Assert(null != importer); // created
            Debug.Assert(null != storage); // created

            // append totals text
            var sb = new StringBuilder(App.Current.FindString("ImportProcessStatisticTotals"));

            // append readed record from source text
            sb.Append(_GetStatisticText("ImportProcessStatisticRead", importer.RecordCount));

            // append imported objects text
            Debug.Assert(null != importer); // inited
            int importedCount = _GetImportedObjsCount(importer);
            sb.Append(_GetStatisticElement("ImportProcessStatisticImported", importedCount));

            if (0 < importedCount)
            {   // append imported objects text
                Debug.Assert(null != storage); // created

                // append import extended text
                string text = _GetImportStatisticExtElementText(importer);
                if (!string.IsNullOrEmpty(text))
                {
                    sb.Append(text);
                }

                // append valid objects text
                text = _GetStatisticElement("ImportProcessStatisticValid", storage.ValidCount);
                sb.Append(text);

                // append geocoding objects text
                if (null != geocoder)
                {   // append geocoded objects text
                    sb.Append(_GetGeocodeStatisticElementText(geocoder, importedCount));
                }

                // append added objects text
                int createdCount = storage.CreatedCount;
                sb.Append(_GetStatisticElement("ImportProcessStatisticAdded", createdCount));
                // append updated objects text
                int updatedCount = importedCount - createdCount;
                sb.Append(_GetStatisticElement("ImportProcessStatisticUpdated", updatedCount));
            }

            return sb.ToString();
        }
Ejemplo n.º 5
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Deletes created cursors.
        /// </summary>
        public void Dispose()
        {
            // unsubscribe to events
            if (null != App.Current.MainWindow)
                App.Current.MainWindow.Closed -= _MainWindow_Closed;

            if (null != _informer)
                _informer.Dispose();

            _informer = null;
            _importer = null;
            _geocoder = null;
            _worker = null;
        }