public override DataMatrix ExtractReportData(IProgressObserver progress) { if (progress != null) { progress.ProgressStart(string.Format("Retrieving Material records for {0}", Taxon.DisplayLabel), true); } var serviceMessage = new ServiceMessageDelegate((message) => { progress.ProgressMessage(message, 0); }); Service.ServiceMessage += serviceMessage; DataMatrix matrix = Service.GetMaterialForTaxon(Taxon.TaxaID.Value); Service.ServiceMessage -= serviceMessage; if (progress != null) { progress.ProgressEnd(string.Format("{0} rows retreived", matrix.Rows.Count)); } matrix.Columns.Add(new FormattedLatLongVirtualColumn(matrix)); matrix.Columns.Add(new FormattedDateVirtualColumn(matrix)); return(matrix); }
protected void ProgressEnd(string message) { if (ProgressObserver != null) { ProgressObserver.ProgressEnd(message); } }
public override DataMatrix ExtractReportData(IProgressObserver progress) { var service = new TaxaService(User); progress.ProgressStart(String.Format("Preparing Darwin Core records for {0} specimens...", _idSet.Count)); DataMatrix result = null; var idSet = new LinkedList<int>(_idSet); int chunkSize = 2000; var helper = new DarwinCoreReportHelper(); var chunk = new List<int>(); var count = 0; while (idSet.Count > 0) { chunk.Add(idSet.First.Value); idSet.RemoveFirst(); count++; if (chunk.Count >= chunkSize || idSet.Count == 0) { var percentComplete = ((double) count / (double) _idSet.Count) * 100; progress.ProgressMessage(String.Format("Preparing Darwin Core records {0} of {1}", count, _idSet.Count), percentComplete); var where = "tblMaterial.intMaterialID in (" + chunk.Join(",") + ")"; var dataChunk = helper.RunDwcQuery(service, where); if (result == null) { result = dataChunk; } else { result.AppendMatrix(dataChunk); } chunk = new List<int>(); } } progress.ProgressEnd(String.Format("{0} Darwin Core records retrieved.", count)); return result; }
protected override List <RefLink> SelectReferences(IProgressObserver progress) { var service = new SupportService(User); var taxaService = new TaxaService(User); if (progress != null) { progress.ProgressMessage("Retrieving Reference links..."); } var reflinks = service.GetReferenceLinks(TraitCategoryType.Taxon.ToString(), Taxon.TaxaID.Value); if (Options.IncludeChildReferences == true) { var children = taxaService.GetExpandFullTree(Taxon.TaxaID.Value); var elementCount = 0; int total = children.Count; if (progress != null) { progress.ProgressStart("Extracting references for children..."); } foreach (Taxon child in children) { if (progress != null) { double percent = (((double)elementCount) / ((double)total)) * 100.0; progress.ProgressMessage(string.Format("Processing {0}", child.TaxaFullName), percent); } elementCount++; var links = service.GetReferenceLinks(TraitCategoryType.Taxon.ToString(), child.TaxaID.Value); foreach (RefLink link in links) { reflinks.Add(link); } } if (progress != null) { progress.ProgressEnd(""); } } return(reflinks); }
public void ExportXML(List <int> taxonIds, XMLIOExportOptions options, IProgressObserver progress, Func <bool> isCancelledCallback) { try { if (progress != null) { progress.ProgressStart("Counting total taxa to export..."); } var exporter = new XMLIOExporter(User, taxonIds, options, progress, isCancelledCallback); exporter.Export(); } finally { if (progress != null) { progress.ProgressEnd("Export complete."); } } }
public bool OnProgress(string message, double percentComplete, ProgressEventType progressEventType) { if (_observer != null) { switch (progressEventType) { case ProgressEventType.Start: _observer.ProgressStart(message); break; case ProgressEventType.Update: _observer.ProgressMessage(message, percentComplete); break; case ProgressEventType.End: _observer.ProgressEnd(message); break; } } return(true); }
public override DataMatrix ExtractReportData(IProgressObserver progress) { var service = new TaxaService(User); progress.ProgressStart(String.Format("Preparing Darwin Core records for {0} specimens...", _idSet.Count)); DataMatrix result = null; var idSet = new LinkedList <int>(_idSet); int chunkSize = 2000; var helper = new DarwinCoreReportHelper(); var chunk = new List <int>(); var count = 0; while (idSet.Count > 0) { chunk.Add(idSet.First.Value); idSet.RemoveFirst(); count++; if (chunk.Count >= chunkSize || idSet.Count == 0) { var percentComplete = ((double)count / (double)_idSet.Count) * 100; progress.ProgressMessage(String.Format("Preparing Darwin Core records {0} of {1}", count, _idSet.Count), percentComplete); var where = "tblMaterial.intMaterialID in (" + chunk.Join(",") + ")"; var dataChunk = helper.RunDwcQuery(service, where); if (result == null) { result = dataChunk; } else { result.AppendMatrix(dataChunk); } chunk = new List <int>(); } } progress.ProgressEnd(String.Format("{0} Darwin Core records retrieved.", count)); return(result); }
public override DataMatrix ExtractReportData(IProgressObserver progress) { if (progress != null) { progress.ProgressStart(string.Format("Retrieving Material records for {0}", Taxon.DisplayLabel), true); } var serviceMessage = new ServiceMessageDelegate((message) => { progress.ProgressMessage(message, 0); }); Service.ServiceMessage += serviceMessage; DataMatrix matrix = Service.GetMaterialForTaxon(Taxon.TaxaID.Value); Service.ServiceMessage -= serviceMessage; if (progress != null) { progress.ProgressEnd(string.Format("{0} rows retreived", matrix.Rows.Count)); } matrix.Columns.Add(new FormattedLatLongVirtualColumn(matrix)); matrix.Columns.Add(new FormattedDateVirtualColumn(matrix)); return matrix; }
private DataMatrix AddMediaForTaxon(int taxonId, IProgressObserver progress) { var results = new DataMatrix(); results.Columns.Add(new MatrixColumn { Name = "MultimediaID", IsHidden = true }); results.Columns.Add(new MatrixColumn { Name = "TaxonID", IsHidden = true }); results.Columns.Add(new MatrixColumn { Name = "MultimediaLink", IsHidden = true }); results.Columns.Add(new MatrixColumn { Name = "Taxon name" }); results.Columns.Add(new MatrixColumn { Name = "Rank" }); results.Columns.Add(new MatrixColumn { Name = "Multimedia Name" }); results.Columns.Add(new MatrixColumn { Name = "Extension" }); results.Columns.Add(new MatrixColumn { Name = "Multimedia Type" }); results.Columns.Add(new MatrixColumn { Name = "Size" }); results.Columns.Add(new MatrixColumn { Name = "Attached To" }); results.Columns.Add(new MatrixColumn { Name = "MaterialID", IsHidden = true }); if (progress != null) { progress.ProgressMessage("Extracting multimedia details for item..."); } // First add the multimedia for this item var links = SupportService.GetMultimediaItems(TraitCategoryType.Taxon.ToString(), taxonId); var taxon = TaxaService.GetTaxon(taxonId); foreach (MultimediaLink link in links) { AddTaxonRow(results, taxon, link); } if (_includeMaterial) { AddMaterialRowsForTaxon(results, taxon); } if (_recurse) { // Now find all the children of this item if (progress != null) { progress.ProgressMessage("Retrieving child items..."); } var children = TaxaService.GetExpandFullTree(taxonId); var elementCount = 0; int total = children.Count; if (progress != null) { progress.ProgressStart("Extracting multimedia for children..."); } foreach (Taxon child in children) { if (progress != null) { double percent = (((double)elementCount) / ((double)total)) * 100.0; progress.ProgressMessage(string.Format("Processing {0}", child.TaxaFullName), percent); } elementCount++; links = SupportService.GetMultimediaItems(TraitCategoryType.Taxon.ToString(), child.TaxaID.Value); foreach (MultimediaLink link in links) { AddTaxonRow(results, child, link); } if (_includeMaterial) { AddMaterialRowsForTaxon(results, child); } } } if (progress != null) { progress.ProgressEnd(string.Format("{0} multimedia items found.", results.Rows.Count)); } return(results); }
public UpdateCheckResults CheckForUpdates(IProgressObserver progress) { // Get the running apps version to compare... // We need to use the parent window because its the main application assembly version we want, not this plugin. var v = PluginManager.Instance.ParentWindow.GetType().Assembly.GetName().Version; var results = new UpdateCheckResults { CurrentMajor = v.Major, CurrentMinor = v.Minor, CurrentBuild = v.Revision, UpdateExists = false, UpdateLink = "" }; if (progress != null) { progress.ProgressStart("Checking for updates..."); } Config.SetGlobal("BioLink.UpdateURL", "http://downloads.ala.org.au/feed/p/biolink"); var updateURL = Config.GetGlobal("BioLink.UpdateURL", "http://downloads.ala.org.au/feed/p/biolink"); try { if (progress != null) { progress.ProgressMessage("Contacting update site..."); } var reader = XmlReader.Create(updateURL); var feed = SyndicationFeed.Load(reader); if (progress != null) { progress.ProgressMessage("Checking update site data..."); } var pattern = new Regex(@"BioLinkInstaller-(\d+)[.](\d+)[.](\d+)[.]exe"); foreach (SyndicationItem item in feed.Items) { foreach (var link in item.Links) { var m = pattern.Match(link.Uri.AbsoluteUri); if (m.Success) { bool updateExists = false; var major = Int32.Parse(m.Groups[1].Value); var minor = Int32.Parse(m.Groups[2].Value); var build = Int32.Parse(m.Groups[3].Value); if (major > results.CurrentMajor) { updateExists = true; } else if (major == results.CurrentMajor) { if (minor > results.CurrentMinor) { updateExists = true; } else if (minor == results.CurrentMinor) { updateExists = build > results.CurrentBuild; } } if (updateExists) { results.UpdateMajor = major; results.UpdateMinor = minor; results.UpdateBuild = build; results.UpdateExists = true; results.UpdateLink = link.Uri.AbsoluteUri; return(results); } } } } } catch (Exception ex) { GlobalExceptionHandler.Handle(ex); } finally { if (progress != null) { progress.ProgressEnd("Update check complete."); } } return(results); }
public override DataMatrix ExtractReportData(IProgressObserver progress) { var matrix = new DataMatrix(); if (IsGroupedByTaxon) { matrix.Columns.Add(new MatrixColumn { Name = "TaxonName" }); matrix.Columns.Add(new MatrixColumn { Name = "BiotaID", IsHidden = true }); } matrix.Columns.Add(new MatrixColumn { Name = "Count" }); foreach (string colname in SelectedColumns) { matrix.Columns.Add(new MatrixColumn { Name = colname }); } // Open the feature layer data SelectedFeatureLayer.DataSource.Open(); var map = new Dictionary <string, FeatureCountPair>(); if (progress != null) { progress.ProgressMessage("Counting points...", 0); } int pointCount = 0; foreach (VectorLayer pointLayer in SelectedPointLayers) { var ds = pointLayer.DataSource; ds.Open(); pointCount += ds.GetFeatureCount(); } if (progress != null) { progress.ProgressStart(String.Format("Processing {0} points...", pointCount)); } int processed = 0; int notFoundCount = 0; var materialService = new MaterialService(User); var taxaService = new TaxaService(User); foreach (VectorLayer pointLayer in SelectedPointLayers) { var pointProvider = pointLayer.DataSource; pointProvider.Open(); for (uint i = 0; i < pointProvider.GetFeatureCount(); ++i) { var row = pointProvider.GetFeature(i); Taxon taxon = null; if (IsGroupedByTaxon) { int?materialId = (int?)row["MaterialID"]; if (materialId.HasValue) { var m = materialService.GetMaterial(materialId.Value); if (m.BiotaID > 0) { if (_taxonCache.ContainsKey(m.BiotaID)) { taxon = _taxonCache[m.BiotaID]; } else { taxon = taxaService.GetTaxon(m.BiotaID); _taxonCache[m.BiotaID] = taxon; } } } } SharpMap.Geometries.Point p = row.Geometry as Point; if (!ProcessPoint(SelectedFeatureLayer.DataSource, pointLayer, p, map, taxon)) { notFoundCount++; } processed++; if (progress != null) { double percent = ((double)processed) / ((double)pointCount) * 100; progress.ProgressMessage(String.Format("Processing {0} points...", pointCount), percent); } } } if (progress != null) { progress.ProgressMessage("Constructing result set...", 100); } int countIndex = matrix.IndexOf("Count"); int taxaIndex = matrix.IndexOf("TaxonName"); int biotaIDIndex = matrix.IndexOf("BiotaID"); foreach (FeatureCountPair pair in map.Values) { var matrixRow = matrix.AddRow(); foreach (DataColumn col in pair.First.Table.Columns) { if (SelectedColumns.Contains(col.ColumnName)) { var index = matrix.IndexOf(col.ColumnName); matrixRow[index] = pair.First[col]; } } matrixRow[countIndex] = pair.Second; if (IsGroupedByTaxon) { matrixRow[taxaIndex] = pair.Taxon == null ? "Unidentified" : pair.Taxon.TaxaFullName; matrixRow[biotaIDIndex] = pair.Taxon == null ? -1 : pair.Taxon.TaxaID.Value; } } if (IncludeUnmatchedPointRow && notFoundCount > 0) { var unmatched = matrix.AddRow(); unmatched[countIndex] = notFoundCount; } if (progress != null) { progress.ProgressEnd(String.Format("{0} points processed.", pointCount)); } return(matrix); }
private DataMatrix AddMediaForTaxon(int taxonId, IProgressObserver progress) { var results = new DataMatrix(); results.Columns.Add(new MatrixColumn { Name = "MultimediaID", IsHidden = true }); results.Columns.Add(new MatrixColumn { Name = "TaxonID", IsHidden = true }); results.Columns.Add(new MatrixColumn { Name = "MultimediaLink", IsHidden = true }); results.Columns.Add(new MatrixColumn { Name = "Taxon name" }); results.Columns.Add(new MatrixColumn { Name = "Rank" }); results.Columns.Add(new MatrixColumn { Name = "Multimedia Name" }); results.Columns.Add(new MatrixColumn { Name = "Extension" }); results.Columns.Add(new MatrixColumn { Name = "Multimedia Type" }); results.Columns.Add(new MatrixColumn { Name = "Size" }); results.Columns.Add(new MatrixColumn { Name = "Attached To" }); results.Columns.Add(new MatrixColumn { Name = "MaterialID", IsHidden= true }); if (progress != null) { progress.ProgressMessage("Extracting multimedia details for item..."); } // First add the multimedia for this item var links = SupportService.GetMultimediaItems(TraitCategoryType.Taxon.ToString(), taxonId); var taxon = TaxaService.GetTaxon(taxonId); foreach (MultimediaLink link in links) { AddTaxonRow(results, taxon, link); } if (_includeMaterial) { AddMaterialRowsForTaxon(results, taxon); } if (_recurse) { // Now find all the children of this item if (progress != null) { progress.ProgressMessage("Retrieving child items..."); } var children = TaxaService.GetExpandFullTree(taxonId); var elementCount = 0; int total = children.Count; if (progress != null) { progress.ProgressStart("Extracting multimedia for children..."); } foreach (Taxon child in children) { if (progress != null) { double percent = (((double)elementCount) / ((double)total)) * 100.0; progress.ProgressMessage(string.Format("Processing {0}", child.TaxaFullName), percent); } elementCount++; links = SupportService.GetMultimediaItems(TraitCategoryType.Taxon.ToString(), child.TaxaID.Value); foreach (MultimediaLink link in links) { AddTaxonRow(results, child, link); } if (_includeMaterial) { AddMaterialRowsForTaxon(results, child); } } } if (progress != null) { progress.ProgressEnd(string.Format("{0} multimedia items found.", results.Rows.Count )); } return results; }
public override DataMatrix ExtractReportData(IProgressObserver progress) { if (progress != null) { progress.ProgressMessage("Phase 1: Finding associate relationships..."); } int[] ids = new int[Taxa.Count]; int i = 0; foreach (TaxonViewModel vm in Taxa) { ids[i++] = vm.TaxaID.Value; } var matrix = Service.GetAssociatesForTaxa(RegionID, this.StripRTF, ids); var index = matrix.IndexOf("AssociateID"); if (index >= 0) { if (progress != null) { progress.ProgressMessage("Phase 2: Retrieving associates..."); } var idList = new List <int>(); foreach (MatrixRow row in matrix) { var associateId = (int)row[index]; if (!idList.Contains(associateId)) { idList.Add(associateId); } } if (progress != null) { progress.ProgressStart("Phase 3: Building view models..."); } var viewModels = new List <AssociateReportViewModel>(); if (idList.Count > 0) { var service = new SupportService(PluginManager.Instance.User); var associates = service.GetAssociatesById(idList); int count = 0; foreach (Associate m in associates) { count++; if (progress != null) { var percentComplete = ((double)count / (double)associates.Count) * 100.0; progress.ProgressMessage("Phase 3: Building view models...", percentComplete); } var vm = new AssociateReportViewModel(m); if (m.FromCatID == TraitCategoryTypeHelper.GetTraitCategoryTypeID(TraitCategoryType.Material)) { vm.FromViewModel = GetViewModel(LookupType.Material, m.FromIntraCatID); } else if (m.FromCatID == TraitCategoryTypeHelper.GetTraitCategoryTypeID(TraitCategoryType.Taxon)) { vm.FromViewModel = GetViewModel(LookupType.Taxon, m.FromIntraCatID); } else { vm.FromViewModel = new ViewModelPlaceholder(m.AssocDescription, "images/Description.png"); } if (m.ToCatID == TraitCategoryTypeHelper.GetTraitCategoryTypeID(TraitCategoryType.Material)) { vm.ToViewModel = GetViewModel(LookupType.Material, m.ToIntraCatID); } else if (m.ToCatID == TraitCategoryTypeHelper.GetTraitCategoryTypeID(TraitCategoryType.Taxon)) { vm.ToViewModel = GetViewModel(LookupType.Taxon, m.ToIntraCatID); } else { vm.ToViewModel = new ViewModelPlaceholder(m.AssocDescription, "images/Description.png"); } viewModels.Add(vm); } progress.ProgressEnd("Complete."); } matrix.Tag = viewModels; } return(matrix); }
protected override List<RefLink> SelectReferences(IProgressObserver progress) { var service = new SupportService(User); var taxaService = new TaxaService(User); if (progress != null) { progress.ProgressMessage("Retrieving Reference links..."); } var reflinks = service.GetReferenceLinks(TraitCategoryType.Taxon.ToString(), Taxon.TaxaID.Value); if (Options.IncludeChildReferences == true) { var children = taxaService.GetExpandFullTree(Taxon.TaxaID.Value); var elementCount = 0; int total = children.Count; if (progress != null) { progress.ProgressStart("Extracting references for children..."); } foreach (Taxon child in children) { if (progress != null) { double percent = (((double)elementCount) / ((double)total)) * 100.0; progress.ProgressMessage(string.Format("Processing {0}", child.TaxaFullName), percent); } elementCount++; var links = service.GetReferenceLinks(TraitCategoryType.Taxon.ToString(), child.TaxaID.Value); foreach (RefLink link in links) { reflinks.Add(link); } } if (progress != null) { progress.ProgressEnd(""); } } return reflinks; }
public UpdateCheckResults CheckForUpdates(IProgressObserver progress) { // Get the running apps version to compare... // We need to use the parent window because its the main application assembly version we want, not this plugin. var v = PluginManager.Instance.ParentWindow.GetType().Assembly.GetName().Version; var results = new UpdateCheckResults { CurrentMajor = v.Major, CurrentMinor = v.Minor, CurrentBuild = v.Revision, UpdateExists = false, UpdateLink = "" }; if (progress != null) { progress.ProgressStart("Checking for updates..."); } Config.SetGlobal("BioLink.UpdateURL", "http://downloads.ala.org.au/feed/p/biolink"); var updateURL = Config.GetGlobal("BioLink.UpdateURL", "http://downloads.ala.org.au/feed/p/biolink"); try { if (progress != null) { progress.ProgressMessage("Contacting update site..."); } var reader = XmlReader.Create(updateURL); var feed = SyndicationFeed.Load(reader); if (progress != null) { progress.ProgressMessage("Checking update site data..."); } var pattern = new Regex(@"BioLinkInstaller-(\d+)[.](\d+)[.](\d+)[.]exe"); foreach (SyndicationItem item in feed.Items) { foreach (var link in item.Links) { var m = pattern.Match(link.Uri.AbsoluteUri); if (m.Success) { bool updateExists = false; var major = Int32.Parse(m.Groups[1].Value); var minor = Int32.Parse(m.Groups[2].Value); var build = Int32.Parse(m.Groups[3].Value); if (major > results.CurrentMajor) { updateExists = true; } else if (major == results.CurrentMajor) { if (minor > results.CurrentMinor) { updateExists = true; } else if (minor == results.CurrentMinor) { updateExists = build > results.CurrentBuild; } } if (updateExists) { results.UpdateMajor = major; results.UpdateMinor = minor; results.UpdateBuild = build; results.UpdateExists = true; results.UpdateLink = link.Uri.AbsoluteUri; return results; } } } } } catch (Exception ex) { GlobalExceptionHandler.Handle(ex); } finally { if (progress != null) { progress.ProgressEnd("Update check complete."); } } return results; }