private void DownloadManager_Completed(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                return;
            }

            var dManager  = DownloadManager;
            var themeName = dManager.Information.StartArgs.DataTheme.Name;

            var         _themeManager = new ThemeManager();
            IFeatureSet featureSet;

            try
            {
                featureSet = _themeManager.GetFeatureSet(themeName);
            }
            catch (ArgumentException)
            {
                // No such theme in the database
                featureSet = null;
            }
            if (featureSet == null)
            {
                // in theory this condition always will be false
                if (dManager.Information.WithError != dManager.Information.TotalSeries)
                {
                    MessageBox.Show("Theme not found, but some series was saved!", "Error", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
                return;
            }

            featureSet.FillAttributes();

            var sourceLayer = (IFeatureLayer)dManager.Information.StartArgs.Tag;
            var lm          = SearchLayerModifier.Create(sourceLayer, (Map)App.Map, this);

            Debug.Assert(lm != null);

            lm.UpdateDataTable(featureSet, DownloadManager);
            lm.UpdateSymbolizing();
            lm.UpdateContextMenu();

            // Check for DataAggregation
            var aggPlugin = App.GetExtension <IDataAggregationPlugin>();

            if (aggPlugin != null)
            {
                aggPlugin.AttachLayerToPlugin(sourceLayer);
            }

            // Refresh list of the time series in the table and graph in the main form
            SeriesControl.RefreshSelection();
        }
        private void AttachLayerToPlugin(ILayer layer, bool isDeserializing = false)
        {
            if (SearchLayerModifier.IsSearchLayer(layer))
            {
                if (_searchLayerInformer == null)
                {
                    // Create popup-informer
                    var extractor = new HISCentralInfoExtractor(new Lazy <Dictionary <string, string> >(() => HisCentralServices.Services));
                    _searchLayerInformer = new SearchLayerInformer(extractor, (Map)App.Map);
                }

                var lm = SearchLayerModifier.Create(layer, (Map)App.Map, this);
                Debug.Assert(lm != null);

                if (!isDeserializing)
                {
                    lm.UpdateLabeling();
                    lm.UpdateSymbolizing();
                }
                lm.UpdateContextMenu();

                btnDownload1.Enabled = true;
                btnDownload2.Enabled = true;
            }

            var group = layer as IGroup;

            if (group != null)
            {
                group.LayerAdded   += Map_LayerAdded;
                group.LayerRemoved += Layers_LayerRemoved;

                foreach (var child in group.GetLayers())
                {
                    AttachLayerToPlugin(child, isDeserializing);
                }
            }
        }
        private void AttachLayerToPlugin(ILayer layer, bool isDeserializing = false)
        {
            if (SearchLayerModifier.IsSearchLayer(layer))
            {
                if (_searchLayerInformer == null)
                {
                    // Create popup-informer
                    var extractor = new HISCentralInfoExtractor(new Lazy <Dictionary <string, string> >(() => new HisCentralServices(App).Services));
                    _searchLayerInformer = new SearchLayerInformer(this, extractor, (Map)App.Map);
                }

                var lm = SearchLayerModifier.Create(layer, (Map)App.Map, this);
                Debug.Assert(lm != null);

                if (!isDeserializing)
                {
                    lm.UpdateLabeling();
                    lm.UpdateSymbolizing();
                }
                lm.UpdateContextMenu();

                if (_btnDownloadInSearch != null)
                {
                    _btnDownloadInSearch.Enabled = true;
                }
                if (_btnSearchOptions != null)
                {
                    _btnSearchOptions.Enabled = true;
                }
                //if (_btnSearchOptions != null)
                //{
                //    _btnSearchOptions.Enabled = true;
                //}
                if (_btnSearchResults != null)
                {
                    _btnSearchResults.Enabled = true;
                }
                if (_btnShowPopups != null)
                {
                    if (!_btnShowPopups.Enabled)
                    {
                        _btnShowPopups.Enabled = true;
                    }
                    if (!ShowPopups)
                    {
                        _btnShowPopups.Toggle();
                    }
                }


                //_btnDownload.Enabled = true;
                //_btnUpdate.Enabled = true;
                //_btnShowPopups.Enabled = true;
            }

            var group = layer as IGroup;

            if (group != null)
            {
                group.LayerAdded   += Map_LayerAdded;
                group.LayerRemoved += Layers_LayerRemoved;

                foreach (var child in group.GetLayers())
                {
                    AttachLayerToPlugin(child, isDeserializing);
                }
            }
        }