private void StartExport()
        {
            _isCancelled = false;

            // save the file off in prefs for later...
            Config.SetUser(User, "XMLIOExport.LastExportFile", txtFilename.Text);

            if (string.IsNullOrEmpty(txtFilename.Text))
            {
                ErrorMessage.Show("You must select a destination file before you can continue");
                return;
            }

            btnStart.IsEnabled  = false;
            btnCancel.IsEnabled = true;

            var options = new XMLIOExportOptions {
                Filename = this.Filename, ExportChildTaxa = this.ExportChildTaxa, ExportMaterial = this.ExportMaterial, ExportTraits = this.ExportNotes, ExportMultimedia = this.ExportMultimedia, ExportNotes = this.ExportNotes, IncludeFullClassification = this.IncludeFullClassification, KeepLogFile = this.KeepLogFile
            };

            var service = new XMLIOService(User);

            JobExecutor.QueueJob(() => {
                service.ExportXML(TaxonIDs, options, this, IsCancelled);
                this.InvokeIfRequired(() => {
                    btnStart.IsEnabled  = true;
                    btnCancel.IsEnabled = false;
                });
            });
        }
Exemplo n.º 2
0
        private void AddPluginContributions(IBioLinkPlugin plugin)
        {
            Logger.Debug("Looking for workspace contributions from {0}", plugin.Name);
            List <IWorkspaceContribution> contributions = plugin.GetContributions();

            try {
                foreach (IWorkspaceContribution contrib in contributions)
                {
                    if (contrib is MenuWorkspaceContribution)
                    {
                        AddMenu(contrib as MenuWorkspaceContribution);
                    }
                    else if (contrib is IExplorerWorkspaceContribution)
                    {
                        IExplorerWorkspaceContribution explorer = contrib as IExplorerWorkspaceContribution;
                        DockableContent newContent = new DockableContent();
                        newContent.Title   = explorer.Title;
                        newContent.Content = explorer.Content;
                        newContent.Name    = plugin.Name + "_" + explorer.Name;

                        this.explorersPane.Items.Add(newContent);

                        JobExecutor.QueueJob(() => {
                            explorer.InitializeContent();
                        });
                    }
                }
            } finally {
            }
        }
        private void DoConvert()
        {
            JobExecutor.QueueJob(() => {
                try {
                    this.InvokeIfRequired(() => {
                        btnCancel.IsEnabled  = false;
                        btnConvert.IsEnabled = false;
                    });

                    this.InvokeIfRequired(() => {
                        totalProgressBar.Maximum = _jobList.Count;
                        totalProgressBar.Value   = 0;
                    });

                    foreach (GazetteerConversionTarget job in _jobList)
                    {
                        job.IsCurrent = true;
                        ConvertFile(job);
                        this.InvokeIfRequired(() => {
                            totalProgressBar.Value++;
                        });
                        job.IsComplete = true;
                        job.IsCurrent  = false;
                    }
                } finally {
                    this.InvokeIfRequired(() => {
                        btnCancel.IsEnabled  = true;
                        btnConvert.IsEnabled = true;
                    });
                }
            });
        }
Exemplo n.º 4
0
        private void LoadModelAsync()
        {
            JobExecutor.QueueJob(() => {
                var service = new LoanService(User);
                var list    = service.ListLoansForContact(ContactID);
                _model      = new ObservableCollection <LoanViewModel>(list.Select((model) => {
                    return(new LoanViewModel(model));
                }));

                this.InvokeIfRequired(() => {
                    lvw.ItemsSource = _model;
                });
            });
        }
Exemplo n.º 5
0
        private void CheckForUpdates()
        {
            var checker = new UpdateChecker();

            var progress = new UpdateCheckWindow();

            progress.Owner = MainWindow.Instance;
            progress.Show();

            JobExecutor.QueueJob(() => {
                var results = checker.CheckForUpdates(progress);
                progress.InvokeIfRequired(() => progress.ShowUpdateResults(results));
            });
        }
Exemplo n.º 6
0
        private void DisplayMultimedia(MultimediaLinkViewModel selected)
        {
            if (selected != null)
            {
                JobExecutor.QueueJob(() => {
                    BitmapSource image = null;
                    try {
                        string filename       = _tempFileManager.GetContentFileName(selected.MultimediaID, selected.Extension);
                        selected.TempFilename = filename;
                        image = GraphicsUtils.LoadImageFromFile(filename);
                        if (image != null)
                        {
                            imgPreview.InvokeIfRequired(() => {
                                imgPreview.Stretch          = Stretch.Uniform;
                                imgPreview.StretchDirection = StretchDirection.DownOnly;
                                imgPreview.Source           = image;
                                gridInfo.DataContext        = image;
                                FileInfo f = new FileInfo(filename);

                                if (f.Length != selected.SizeInBytes)
                                {
                                    selected.SuspendChangeMonitoring = true;
                                    selected.SizeInBytes             = (int)f.Length;
                                    selected.SuspendChangeMonitoring = false;
                                }

                                lblImageInfo.Content = string.Format("{0}x{1}  {2} DPI  {3}", image.PixelWidth, image.PixelHeight, image.DpiX, ByteLengthConverter.FormatBytes(f.Length));
                                lblFilename.Content  = string.Format("Filename: {0}", filename);
                            });
                        }
                    } finally {
                        if (image == null)
                        {
                            imgPreview.InvokeIfRequired(() => {
                                imgPreview.Source    = null;
                                lblImageInfo.Content = "No image";
                                lblFilename.Content  = "";
                            });
                        }
                    }
                });
            }
            else
            {
                imgPreview.Source    = null;
                lblFilename.Content  = "";
                lblImageInfo.Content = "";
            }
        }
        public override void OnPageEnter(WizardDirection fromdirection)
        {
            var progress = new ProgressWindow(this.FindParentWindow(), "Extracting column information from data source...", true);

            _fields = _fieldSource();
            lvwFields.ItemsSource = _fields;

            CollectionView           myView           = (CollectionView)CollectionViewSource.GetDefaultView(lvwFields.ItemsSource);
            PropertyGroupDescription groupDescription = new PropertyGroupDescription("Category");

            myView.GroupDescriptions.Add(groupDescription);
            var model = new List <ImportFieldMapping>();

            JobExecutor.QueueJob(() => {
                List <String> columns = null;
                columns = ImportContext.Importer.GetColumnNames();

                var existingMappings = ImportContext.FieldMappings;
                if (existingMappings != null && existingMappings.Count() > 0)
                {
                    foreach (ImportFieldMapping mapping in existingMappings)
                    {
                        model.Add(mapping);
                    }
                }
                else
                {
                    foreach (string columnName in columns)
                    {
                        var mapping = new ImportFieldMapping {
                            SourceColumn = columnName
                        };
                        model.Add(mapping);
                    }
                }

                _model = new ObservableCollection <ImportFieldMappingViewModel>(model.Select((m) => {
                    return(new ImportFieldMappingViewModel(m));
                }));

                lvwMappings.InvokeIfRequired(() => {
                    lvwMappings.ItemsSource = _model;
                });

                progress.InvokeIfRequired(() => {
                    progress.Dispose();
                });
            });
        }
        void lstTraitTypes_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (IsPopulated)
            {
                var info = lstTypeData.SelectedItem as TypeDataViewModel;
                if (info != null)
                {
                    lvwValues.ItemsSource = null;

                    JobExecutor.QueueJob(() => {
                        lock (lvwValues) {
                            try {
                                this.InvokeIfRequired(() => {
                                    lvwValues.Cursor = Cursors.Wait;
                                });

                                List <TypeDataOwnerInfo> list = null;
                                if (_type == "trait")
                                {
                                    list = new List <TypeDataOwnerInfo>(Service.GetTraitOwnerInfo(info.ID));
                                }
                                else if (_type == "note")
                                {
                                    list = new List <TypeDataOwnerInfo>(Service.GetNoteOwnerInfo(info.ID));
                                }
                                else
                                {
                                    throw new NotImplementedException();
                                }

                                if (list != null)
                                {
                                    this.InvokeIfRequired(() => {
                                        lvwValues.ItemsSource = new ObservableCollection <TypeDataOwnerInfo>(list);
                                    });
                                }
                            } finally {
                                this.InvokeIfRequired(() => {
                                    lvwValues.Cursor = Cursors.Arrow;
                                });
                            }
                        }
                    });
                }
            }
        }
        private void StartSpeciesRichness()
        {
            btnStartRichness.IsEnabled = false;
            btnStopRichness.IsEnabled  = true;

            var pointsModel = new ObservableCollection <SpeciesRichnessPointSetViewModel>(pointSets.PointSets.Select((m) => {
                var vm    = new SpeciesRichnessPointSetViewModel(m);
                vm.Status = "Pending";
                return(vm);
            }));

            lvwRichness.ItemsSource = pointsModel;

            var cutOff = _richnessOptions.CutOff;

            var processor = new SpeciesRichnessProcessor(_richnessOptions.SelectedModel, pointsModel, _layerFilenames.Select(m => m.Name), cutOff, _richnessOptions.chkRetainFiles.IsChecked == true);

            processor.ProgressObserver        = new SpeciesRichnessProgressAdapter(this);
            processor.PointSetModelStarted   += new Action <MapPointSet>(processor_PointSetModelStarted);
            processor.PointSetModelCompleted += new Action <MapPointSet>(processor_PointSetModelCompleted);
            processor.PointSetModelProgress  += new Action <MapPointSet, string, double?>(processor_PointSetModelProgress);

            JobExecutor.QueueJob(() => {
                try {
                    var result = processor.RunSpeciesRichness();
                    if (result != null)
                    {
                        this.InvokeIfRequired(() => {
                            this.progressRichness.Value    = 0;
                            this.lblRichnessStatus.Content = "Showing map";
                            var imageFilename = SystemUtils.ChangeExtension(_richnessOptions.txtFilename.Text, "bmp");
                            ShowGridLayerInMap(result, pointsModel.Count, 0, _richnessOptions, imageFilename);
                            result.SaveToGRDFile(_richnessOptions.txtFilename.Text);
                        });
                    }
                } finally {
                    this.InvokeIfRequired(() => {
                        btnStartRichness.IsEnabled     = true;
                        btnStopRichness.IsEnabled      = false;
                        this.lblRichnessStatus.Content = "";
                    });
                }
            });
        }
Exemplo n.º 10
0
        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            StatusMessage("Please wait while a list of available servers is being built...");

            this.Cursor = Cursors.Wait;

            JobExecutor.QueueJob(() => {
                try {
                    var list = DiscoverServers(true);
                    tvw.InvokeIfRequired(() => {
                        _model          = new ObservableCollection <HierarchicalViewModelBase>(list);
                        tvw.ItemsSource = _model;
                    });
                } finally {
                    this.InvokeIfRequired(() => {
                        this.Cursor = Cursors.Arrow;
                        StatusMessage(string.Format("{0} servers found.", _model.Count));
                    });
                }
            });
        }
        private void StartImport()
        {
            string filename = txtFilename.Text;

            if (string.IsNullOrWhiteSpace(filename))
            {
                ErrorMessage.Show("You must supply the name of an XML file to import from");
                return;
            }

            if (!File.Exists(filename))
            {
                ErrorMessage.Show("The specified file does not exist!");
                return;
            }



            JobExecutor.QueueJob(() => {
                this.InvokeIfRequired(() => {
                    btnStart.IsEnabled  = false;
                    btnCancel.IsEnabled = false;
                    btnStop.IsEnabled   = true;
                });

                try {
                    var importer = new XMLIOImporter(PluginManager.Instance.User, filename, this);
                    importer.Import();
                } finally {
                    this.InvokeIfRequired(() => {
                        btnStart.IsEnabled  = true;
                        btnCancel.IsEnabled = true;
                        btnStop.IsEnabled   = false;
                    });
                }
            });
        }
        private void DoSearch()
        {
            if (Service == null)
            {
                return;
            }

            string division = null;

            if (chkRestrictPlaceType.IsChecked.ValueOrFalse() && !string.IsNullOrEmpty(cmbPlaceType.Text))
            {
                division = cmbPlaceType.SelectedItem as string;
            }

            btnCancel.IsEnabled = true;
            btnSearch.IsEnabled = false;

            Cancelled = false;
            var delta      = 0.2; // degrees to go out each time...
            var latitude   = ctlPosition.Latitude;
            var longitude  = ctlPosition.Longitude;
            var info       = Service.GetGazetteerInfo();
            int maxResults = Int32.Parse(txtMaxResults.Text);

            maxResults = Math.Min(maxResults, info.RecordCount);
            JobExecutor.QueueJob(() => {
                double range = 0;
                int count    = 0;
                try {
                    double x1, y1, x2, y2;

                    while (count < maxResults && range < 50 && !Cancelled)
                    {
                        StatusMessage("Searching for places near {0} (+/- {1} degrees). {2} places found.", GeoUtils.FormatCoordinates(latitude, longitude), range, count);
                        range += delta;
                        y1     = latitude - range;
                        y2     = latitude + range;
                        x1     = longitude - range;
                        x2     = longitude + range;
                        count  = Service.CountPlacesInBoundedBox(x1, y1, x2, y2, division);
                    }


                    this.InvokeIfRequired(() => {
                        this.Cursor = Cursors.Wait;
                    });

                    StatusMessage("Retrieving places near {0} (+/- {1} degrees). {2} places found.", GeoUtils.FormatCoordinates(latitude, longitude), range, count);

                    y1 = latitude - range;
                    y2 = latitude + range;
                    x1 = longitude - range;
                    x2 = longitude + range;

                    var list  = Service.GetPlacesInBoundedBox(x1, y1, x2, y2, division);
                    var model = new List <PlaceNameViewModel>(list.Select((m) => {
                        var vm           = new PlaceNameViewModel(m);
                        vm.Distance      = GeoUtils.GreatCircleArcLength(m.Latitude, m.Longitude, latitude, longitude, DistanceUnits);
                        string direction = "";
                        var numPoints    = (vm.Distance < 10 ? 16 : 32);
                        direction        = GeoUtils.GreatCircleArcDirection(m.Latitude, m.Longitude, latitude, longitude, numPoints);
                        vm.Offset        = String.Format("{0:0.0} {1} {2}", vm.Distance, "KM", direction);
                        return(vm);
                    }));

                    model.Sort(new Comparison <PlaceNameViewModel>((o1, o2) => {
                        return((int)(o1.Distance - o2.Distance));
                    }));

                    if (model.Count > maxResults)
                    {
                        model.RemoveRange(maxResults, model.Count - maxResults);
                    }

                    lstResults.InvokeIfRequired(() => {
                        lstResults.ItemsSource = model;
                        CollectionView myView  = (CollectionView)CollectionViewSource.GetDefaultView(lstResults.ItemsSource);
                        myView.SortDescriptions.Add(new SortDescription("Distance", ListSortDirection.Ascending));
                    });

                    if (!Cancelled)
                    {
                        StatusMessage("{0} places retrieved.", model.Count);
                    }
                    else
                    {
                        StatusMessage("{0} places retrieved (Cancelled).", model.Count);
                    }
                } finally {
                    this.InvokeIfRequired(() => {
                        btnCancel.IsEnabled = false;
                        btnSearch.IsEnabled = true;
                        this.Cursor         = Cursors.Arrow;
                    });
                }
            });
        }
        private void StartSingleModel()
        {
            var points = pointSets.PointSets;

            if (points == null || points.Count() == 0)
            {
                ErrorMessage.Show("There are no training points to model from!");
                return;
            }

            int totalPoints = 0;

            points.ForEach((set) => {
                totalPoints += set.Count();
            });

            if (totalPoints == 0)
            {
                ErrorMessage.Show("There are no training points to model from!");
                return;
            }

            if (_layerFilenames.Count == 0)
            {
                ErrorMessage.Show("There are no environmental grid layers specified!");
                return;
            }

            _currentModel = _singleModelOptions.cmbModelType.SelectedItem as DistributionModel;
            if (_currentModel != null)
            {
                _currentModel.ProgressObserver = this;

                btnStart.IsEnabled = false;
                btnStop.IsEnabled  = true;

                JobExecutor.QueueJob(() => {
                    try {
                        var layers = _layerFilenames.Select((mm) => {
                            ProgressMessage(string.Format("Loading grid layer {0}", mm.Name));
                            return(new GridLayer(mm.Name));
                        }).ToList();

                        ProgressMessage("Running model...");

                        var result = _currentModel.RunModel(layers, points);

                        if (_currentModel.IsCancelled)
                        {
                            MessageBox.Show("Model cancelled", "Model cancelled", MessageBoxButton.OK, MessageBoxImage.Warning);
                            return;
                        }

                        this.InvokeIfRequired(() => {
                            ProgressMessage("Saving file...");
                            result.SaveToGRDFile(_singleModelOptions.txtFilename.Text);

                            if (_singleModelOptions.chkGenerateImage.IsChecked == true)
                            {
                                ProgressMessage("Preparing map...");
                                string imageFilename = SystemUtils.ChangeExtension(_singleModelOptions.txtFilename.Text, "bmp");
                                TempFileManager.Attach(imageFilename);
                                double cutoff = _singleModelOptions.CutOff;
                                int intervals = _singleModelOptions.Intervals;
                                ShowGridLayerInMap(result, intervals, cutoff, _singleModelOptions, imageFilename);
                            }
                        });
                        ProgressMessage("Model complete.");
                    } catch (Exception ex) {
                        MessageBox.Show(ex.ToString());
                    } finally {
                        this.InvokeIfRequired(() => {
                            btnStart.IsEnabled = true;
                            btnStop.IsEnabled  = false;
                        });
                        _currentModel = null;
                    }
                });
            }
        }
Exemplo n.º 14
0
        public ContextMenu BuildExplorerMenu()
        {
            ContextMenuBuilder builder = new ContextMenuBuilder(FormatterFunc);


            if (Explorer.IsUnlocked)
            {
                if (!Taxon.IsRootNode)
                {
                    builder.New("TaxonExplorer.menu.Delete", Taxon.DisplayLabel).Handler(() => { Explorer.DeleteTaxon(Taxon); });
                    builder.New("TaxonExplorer.menu.DeleteCurrentLevel", Taxon.DisplayLabel).Handler(() => { Explorer.DeleteLevel(Taxon); });
                    builder.New("TaxonExplorer.menu.Rename", Taxon.DisplayLabel).Handler(() => { Explorer.RenameTaxon(Taxon); });
                    builder.Separator();
                    builder.New("TaxonExplorer.menu.ChangeRank", Taxon.DisplayLabel).Handler(() => { Explorer.ChangeRank(Taxon); });
                    if (Taxon.AvailableName == true)
                    {
                        builder.New("TaxonExplorer.menu.ChangeToLiterature", Taxon.DisplayLabel).Handler(() => { Explorer.ChangeAvailable(Taxon); });
                    }
                    else if (Taxon.LiteratureName == true)
                    {
                        builder.New("TaxonExplorer.menu.ChangeToAvailable", Taxon.DisplayLabel).Handler(() => { Explorer.ChangeAvailable(Taxon); });
                    }
                }

                MenuItem addMenu = BuildAddMenuItems();
                if (addMenu != null && addMenu.Items.Count > 0)
                {
                    builder.Separator();
                    builder.AddMenuItem(addMenu);
                }
            }
            else
            {
                builder.New("TaxonExplorer.menu.Unlock").Handler(() => { Explorer.btnLock.IsChecked = true; });
            }

            builder.Separator();

            builder.New("TaxonExplorer.menu.ExpandAll").Handler(() => {
                JobExecutor.QueueJob(() => {
                    Explorer.tvwAllTaxa.InvokeIfRequired(() => {
                        try {
                            using (new OverrideCursor(Cursors.Wait)) {
                                Explorer.ExpandChildren(Taxon);
                            }
                        } catch (Exception ex) {
                            GlobalExceptionHandler.Handle(ex);
                        }
                    });
                });
            });

            MenuItem sortMenu = BuildSortMenuItems();

            if (sortMenu != null && sortMenu.HasItems)
            {
                builder.Separator();
                builder.AddMenuItem(sortMenu);
            }

            builder.Separator();
            builder.AddMenuItem(CreateFavoriteMenuItems());

            if (!Explorer.IsUnlocked)
            {
                builder.Separator();
                builder.New("TaxonExplorer.menu.Refresh").Handler(() => Explorer.Refresh()).End();
            }

            if (!Taxon.IsRootNode)
            {
                MenuItem reports = CreateReportMenuItems();
                if (reports != null && reports.HasItems)
                {
                    builder.Separator();
                    builder.New("Distribution _Map").Handler(() => { Explorer.DistributionMap(Taxon); }).End();
                    builder.AddMenuItem(reports);
                }

                builder.Separator();
                builder.New("Export (XML)").Handler(() => { Explorer.XMLIOExport(Taxon.TaxaID.Value); }).End();

                builder.Separator();
                var pinnable = Explorer.Owner.CreatePinnableTaxon(Taxon.TaxaID.Value);
                builder.New("_Pin to pin board").Handler(() => { PluginManager.Instance.PinObject(pinnable); }).End();
                builder.Separator();
                builder.New("_Permissions...").Handler(() => Explorer.EditBiotaPermissions(Taxon)).End();
                builder.Separator();
                builder.New("_Edit Name...").Handler(() => { Explorer.EditTaxonName(Taxon); });
                builder.New("_Edit Details...").Handler(() => { Explorer.EditTaxonDetails(Taxon.TaxaID); }).End();
            }

            return(builder.ContextMenu);
        }
Exemplo n.º 15
0
 private void StartImportAsync()
 {
     JobExecutor.QueueJob(() => {
         StartImport();
     });
 }