///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Creates and initializes a new instance of the <c>ProgressInfoTracker</c> class.
        /// </summary>
        /// <param name="worker">Background worker.</param>
        /// <param name="parentPage">Parent page for status panel.</param>
        /// <param name="objectName">Object name to progress message generation.</param>
        /// <param name="objectsName">Objects name to status message generation.</param>
        public ProgressInfoTracker(BackgroundWorker worker,
                                   AppPages.Page parentPage,
                                   string objectName,
                                   string objectsName)
        {
            Debug.Assert(!string.IsNullOrEmpty(objectsName)); // not empty
            Debug.Assert(!string.IsNullOrEmpty(objectName)); // not empty
            Debug.Assert(null != parentPage); // created
            Debug.Assert(null != worker); // created

            _parentPage = parentPage;
            _objectName = objectName;
            _objectsName = objectsName;
            _worker = worker;
        }
        private void _InitPageSettings(IDictionary<string, string> settingsMap, string categoryName,
                                       AppPages.Page page)
        {
            Debug.Assert(null != page);

            try
            {
                AppPages.ISupportSettings settings = page as AppPages.ISupportSettings;
                if (null != settings)
                {
                    string key = string.IsNullOrEmpty(categoryName) ? page.Name : string.Format(FULL_PAGE_NAME_FORMAT, categoryName, page.Name);
                    if (settingsMap.ContainsKey(key))
                        settings.LoadUserSettings(settingsMap[key]);
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }
        }
 /// <summary>
 /// Method builds widgets panel.
 /// </summary>
 private StackPanel _CreateWidgetsPanel(AppPages.Page page)
 {
     StackPanel widgetsPanel = new StackPanel();
     if (page.Widgets.Count != 0)
         widgetsPanel = _taskPanelContentBuilder.BuildTaskPanelContent(page);
     return widgetsPanel;
 }
        /// <summary>
        /// Toggle task panel widgets state.
        /// </summary>
        /// <param name="page">Page for selecting widgets.</param>
        /// <param name="ignoredWidgets">Collection of widgets that ignored this toggle.</param>
        /// <param name="isEnable">Enable state flag.</param>
        internal void ToggleWidgetsState(AppPages.Page page, ICollection<Type> ignoredWidgets, bool isEnable)
        {
            Debug.Assert(null != page);
            Debug.Assert(null != ignoredWidgets);

            StackPanel stackPanel = (StackPanel)_widgetsHash[page.GetType().FullName];
            _taskPanelContentBuilder.ToggleTaskPanelWidgetsState(stackPanel, ignoredWidgets, isEnable);
        }
        private void _SavePageSetting(string categoryName, AppPages.Page page, ref StringCollection names,
                                      ref StringBuilder settingsStorage)
        {
            // NOTE: store only unique named pages
            Debug.Assert(null != page);
            Debug.Assert(null != names);
            Debug.Assert(null != settingsStorage);

            AppPages.ISupportSettings settings = page as AppPages.ISupportSettings;
            if (null != settings)
            {
                string name = string.IsNullOrEmpty(categoryName) ? page.Name : string.Format(FULL_PAGE_NAME_FORMAT, categoryName, page.Name);
                if (!string.IsNullOrEmpty(name))
                {
                    string storeSettings = null;
                    try
                    {
                        storeSettings = settings.SaveUserSettings();
                    }
                    catch (Exception e)
                    {
                        Logger.Error(e);
                    }

                    if (!string.IsNullOrEmpty(storeSettings))
                    {
                        if (!names.Contains(name))
                        {
                            if (!string.IsNullOrEmpty(settingsStorage.ToString()))
                                settingsStorage.Append(SPLITTER_GROUPS);

                            settingsStorage.AppendFormat("{0}{1}{2}", name, SPLITTER_GROUP, storeSettings);
                            names.Add(name);
                        }
                    }
                }
            }
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Creates and initializes a new instance of the <c>ProgressTracker</c> class.
        /// </summary>
        /// <param name="parentPage">Parent page for status panel.</param>
        /// <param name="type">Import objects type.</param>
        /// <param name="canceler">Operation canceler interface (can be NULL).</param>
        public ProgressInformer(AppPages.Page parentPage, ImportType type, ICanceler canceler)
        {
            Debug.Assert(null != parentPage); // created

            // store context
            _parentPage = parentPage;
            _canceler = canceler;

            // initialize state
            _InitStrings(type);
            _InitStatusStack();
        }
        /// <summary>
        /// Adds or updates status for selected page.
        /// </summary>
        /// <param name="sourcePage">Source page to status updating.</param>
        /// <param name="statusContent">Status content (can be null).</param>
        private void _SetStatus(AppPages.Page sourcePage, object statusContent)
        {
            Debug.Assert(null != sourcePage);

            if (statusContent == null)
                // create empty status
                StatusContentControl.Content = _CreateStatusLabel(string.Empty);
            else
            {   // update status in source page
                if (_statusesHash.Contains(sourcePage))
                {
                    // only if real changed
                    if (!_statusesHash[sourcePage].Equals(statusContent))
                        _statusesHash[sourcePage] = statusContent;
                }
                else
                    // add status to page
                    _statusesHash.Add(sourcePage, statusContent);

                // force update status for current page
                if (App.Current.MainWindow.CurrentPage.Equals(sourcePage))
                    StatusContentControl.Content = statusContent;
            }
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Method sets status bar content.
        /// </summary>
        /// <param name="sourcePage">Status source page.</param>
        /// <param name="statusContent">Status content (must be simple string or control,
        /// or null for clearing).</param>
        public void SetStatus(AppPages.Page sourcePage, object statusContent)
        {
            Debug.Assert(null != sourcePage);

            if (statusContent is string)
                statusContent = _CreateStatusLabel(statusContent.ToString());

            _SetStatus(sourcePage, statusContent);
        }
        /// <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>
        /// 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);
                }
            }
        }
Example #11
0
 private void _SchedulePage_EditCommitted(object sender, AppPages.DataObjectEventArgs e)
 {
     _CheckEnabled();
 }