private void fetchTaxonLists() { TaxonLists.Clear(); string sql = String.Format("SELECT * FROM {0};", taxonListsExpression); var connRep = ConnectionsAccess.RepositoryDefinitions.CreateConnection(); var cmd = connRep.CreateCommand(); cmd.CommandText = sql; try { connRep.Open(); var rdr = cmd.ExecuteReader(); while (rdr.Read()) { TaxonList tl = new TaxonList(); tl.DataSource = rdr["Datasource"].ToString(); tl.DisplayText = rdr["DisplayText"].ToString(); tl.IsSelected = false; tl.TaxonomicGroup = rdr["TaxonomicGroup"].ToString(); TaxonLists.Add(tl); } } catch (Exception e) { //TODO Error } finally { connRep.Close(); connRep.Dispose(); } }
public TaxonListVM(TaxonList model) { _model = model; _model.ObservableForProperty(x => x.IsSelected) .Subscribe(_ => this.RaisePropertyChanged(x => x.IsSelected)); }
public void RemoveSelectionTaxon() { FactorList factors; IFactor factor1, factor2; Int32 speciesFactCount; ITaxon taxon1, taxon2; TaxonList taxa; factor1 = CoreData.FactorManager.GetFactor(GetUserContext(), FactorId.SwedishHistory); factor2 = CoreData.FactorManager.GetFactor(GetUserContext(), FactorId.SwedishOccurrence); taxon1 = CoreData.TaxonManager.GetTaxon(GetUserContext(), TaxonId.DrumGrasshopper); taxon2 = CoreData.TaxonManager.GetTaxon(GetUserContext(), TaxonId.Wolverine); factors = new FactorList(); factors.Add(factor1); factors.Add(factor2); taxa = new TaxonList(); taxa.Add(taxon1); taxa.Add(taxon2); GetDataSet(true).AddSelection(GetUserContext(), factors); GetDataSet().AddSelectionTaxa(GetUserContext(), taxa); speciesFactCount = GetDataSet().SpeciesFacts.Count; Assert.IsFalse(GetDataSet().Taxa.IsEmpty()); Assert.IsFalse(GetDataSet().SpeciesFacts.IsEmpty()); GetDataSet().RemoveSelectionTaxon(GetUserContext(), taxon1); Assert.IsFalse(GetDataSet().Taxa.IsEmpty()); Assert.IsFalse(GetDataSet().SpeciesFacts.IsEmpty()); Assert.IsTrue(speciesFactCount > GetDataSet().SpeciesFacts.Count); taxon1 = null; GetDataSet().RemoveSelectionTaxon(GetUserContext(), taxon1); }
public void AddSelectionHost() { FactorList factors; IFactor factor1, factor2; Int32 speciesFactCount; ITaxon host, taxon1, taxon2; TaxonList taxa; factor1 = CoreData.FactorManager.GetFactor(GetUserContext(), 1137); // Svampdelar (inkl lavar). factor2 = CoreData.FactorManager.GetFactor(GetUserContext(), 1138); // Mycel. taxon1 = CoreData.TaxonManager.GetTaxon(GetUserContext(), 100090); // Nötkråka. taxon2 = CoreData.TaxonManager.GetTaxon(GetUserContext(), 100381); //tvåfläckig barkskinnbagge factors = new FactorList(); factors.Add(factor1); factors.Add(factor2); taxa = new TaxonList(); taxa.Add(taxon1); taxa.Add(taxon2); GetDataSet(true).AddSelection(GetUserContext(), factors); GetDataSet().AddSelectionTaxa(GetUserContext(), taxa); speciesFactCount = GetDataSet().SpeciesFacts.Count; host = CoreData.TaxonManager.GetTaxon(GetUserContext(), 230260); // skägglav. GetDataSet().AddSelectionHost(GetUserContext(), host); Assert.IsTrue(speciesFactCount > GetDataSet().SpeciesFacts.Count); host = null; GetDataSet().AddSelectionHost(GetUserContext(), host); }
public void RemoveSelectionSpeciesFactDataSetSelection() { FactorList factors; IFactor factor1, factor2; Int32 speciesFactCount; ISpeciesFactDataSetSelection selection; ITaxon taxon1, taxon2; TaxonList taxa; factor1 = CoreData.FactorManager.GetFactor(GetUserContext(), FactorId.RedlistCategory); factor2 = CoreData.FactorManager.GetFactor(GetUserContext(), FactorId.Redlist_OrganismLabel1); taxon1 = CoreData.TaxonManager.GetTaxon(GetUserContext(), TaxonId.DrumGrasshopper); taxon2 = CoreData.TaxonManager.GetTaxon(GetUserContext(), TaxonId.Wolverine); factors = new FactorList(); factors.Add(factor1); factors.Add(factor2); taxa = new TaxonList(); taxa.Add(taxon1); taxa.Add(taxon2); selection = new SpeciesFactDataSetSelection(); selection.Factors = factors; selection.Taxa = taxa; GetDataSet(true).AddSelection(GetUserContext(), selection); Assert.IsFalse(GetDataSet().Factors.IsEmpty()); Assert.IsFalse(GetDataSet().Taxa.IsEmpty()); Assert.IsFalse(GetDataSet().SpeciesFacts.IsEmpty()); speciesFactCount = GetDataSet().SpeciesFacts.Count; selection = new SpeciesFactDataSetSelection(); selection.Factors.Add(factor1); selection.Taxa.Add(taxon1); GetDataSet().RemoveSelection(GetUserContext(), selection); Assert.IsTrue(speciesFactCount > GetDataSet().SpeciesFacts.Count); }
/// <summary> /// Get parent taxa for specified taxon. /// The information is extracted from a taxon tree. /// </summary> /// <param name="taxonTree">A taxon tree.</param> /// <param name="taxon">The taxon.</param> /// <param name="parentTaxa">Parent taxa output.</param> private static void GetParentTaxa( ITaxonTreeNode taxonTree, ITaxon taxon, TaxonList parentTaxa) { if (taxonTree.Taxon.Id == taxon.Id) { // This is the taxon that we are looking for. if (taxonTree.Parents.IsNotEmpty()) { foreach (ITaxonTreeNode parentTaxonTree in taxonTree.Parents) { // Add parent. parentTaxa.Add(parentTaxonTree.Taxon); } } } else { if (taxonTree.Children.IsNotEmpty()) { foreach (ITaxonTreeNode childTaxonTree in taxonTree.Children) { GetParentTaxa(childTaxonTree, taxon, parentTaxa); if (parentTaxa.IsNotEmpty()) { // We have already found the parents. break; } } } } }
public List <TaxonViewModel> GetAllTaxaBySearchCriteriaViewModel() { TaxonList taxonList = CoreData.TaxonManager.GetTaxa(UserContext, TaxaSetting.TaxonIds.ToList()); List <TaxonViewModel> taxaList = taxonList.GetGenericList().ToTaxonViewModelList(); return(taxaList); }
public void AddSelectionIndividualCategory() { FactorList factors; IFactor factor1, factor2; IIndividualCategory individualCategory; Int32 speciesFactCount; ITaxon taxon1, taxon2; TaxonList taxa; factor1 = CoreData.FactorManager.GetFactor(GetUserContext(), FactorId.SwedishHistory); factor2 = CoreData.FactorManager.GetFactor(GetUserContext(), FactorId.SwedishOccurrence); taxon1 = CoreData.TaxonManager.GetTaxon(GetUserContext(), TaxonId.DrumGrasshopper); taxon2 = CoreData.TaxonManager.GetTaxon(GetUserContext(), TaxonId.Wolverine); factors = new FactorList(); factors.Add(factor1); factors.Add(factor2); taxa = new TaxonList(); taxa.Add(taxon1); taxa.Add(taxon2); GetDataSet(true).AddSelection(GetUserContext(), factors); GetDataSet().AddSelectionTaxa(GetUserContext(), taxa); speciesFactCount = GetDataSet().SpeciesFacts.Count; individualCategory = CoreData.FactorManager.GetDefaultIndividualCategory(GetUserContext()); GetDataSet().AddSelection(GetUserContext(), individualCategory); Assert.IsFalse(GetDataSet().Factors.IsEmpty()); Assert.IsFalse(GetDataSet().SpeciesFacts.IsEmpty()); Assert.AreEqual(speciesFactCount, GetDataSet().SpeciesFacts.Count); GetDataSet().AddSelection(GetUserContext(), CoreData.FactorManager.GetIndividualCategories(GetUserContext())[3]); Assert.IsTrue(speciesFactCount < GetDataSet().SpeciesFacts.Count); individualCategory = null; GetDataSet().AddSelection(GetUserContext(), individualCategory); }
/// <summary> /// Lump taxa /// </summary> /// <param name="userContext"></param> /// <param name="replacingTaxon"></param> /// <param name="taxonRevision"></param> /// <param name="ctrLumpTaxonIdList"></param> public void LumpTaxa(IUserContext userContext, int?replacingTaxonId, ITaxonRevision taxonRevision, List <int?> ctrLumpTaxonIdList) { ITaxon replacingTaxon = null; if (replacingTaxonId.IsNotNull()) { replacingTaxon = CoreData.TaxonManager.GetTaxon(userContext, (int)replacingTaxonId); } TaxonList taxaToLump = new TaxonList(); foreach (var taxonId in ctrLumpTaxonIdList) { if (taxonId.IsNotNull()) { taxaToLump.Add(CoreData.TaxonManager.GetTaxon(userContext, (int)taxonId)); } } using (ITransaction transaction = userContext.StartTransaction()) { CoreData.TaxonManager.LumpTaxon(userContext, taxaToLump, replacingTaxon, taxonRevision); // Update reference for taxon, set revision reference as Source reference and remove old reference. ReferenceRelationList referencesToAdd = ReferenceHelper.GetDefaultReferences(userContext, replacingTaxon, taxonRevision, null); ReferenceRelationList referencesToRemove = ReferenceHelper.RemoveTaxonSourceReferences(userContext, taxonRevision, replacingTaxon); CoreData.ReferenceManager.CreateDeleteReferenceRelations(userContext, referencesToAdd, referencesToRemove); transaction.Commit(); } }
/// <summary> /// Calculates species observation count grid for each taxon in <paramref name="taxonIds"/>. /// </summary> /// <param name="taxonIds">The taxon ids.</param> /// <param name="gridCoordinateSystem">The grid coordinate system.</param> /// <returns>Species observation count for each taxon grouped by grid cells.</returns> public TaxonSpecificGridSpeciesObservationCountResult CalculateMultipleSpeciesObservationGrid( List <int> taxonIds, GridCoordinateSystem?gridCoordinateSystem) { Dictionary <IGridCellBase, Dictionary <int, IGridCellSpeciesObservationCount> > totalResult; IList <IGridCellSpeciesObservationCount> taxonResult; List <int> taxonIdList = new List <int>(taxonIds); if (taxonIdList.IsEmpty()) { taxonIdList.Add(0); } totalResult = new Dictionary <IGridCellBase, Dictionary <int, IGridCellSpeciesObservationCount> >(new GridCellBaseCenterPointComparer()); foreach (int taxonId in taxonIdList) { taxonResult = CalculateSpeciesObservationGrid(taxonId, gridCoordinateSystem); AddTaxonResult(taxonId, taxonResult, totalResult); } TaxonList taxonList = CoreData.TaxonManager.GetTaxa(UserContext, taxonIdList); List <TaxonViewModel> taxaList = taxonList.GetGenericList().ToTaxonViewModelList(); TaxonSpecificGridSpeciesObservationCountResult result = new TaxonSpecificGridSpeciesObservationCountResult() { Taxa = taxaList, GridCells = totalResult }; return(result); }
public void RemoveSelectionPeriods() { FactorList factors; IFactor factor1, factor2; Int32 speciesFactCount; ITaxon taxon1, taxon2; PeriodList periods; TaxonList taxa; factor1 = CoreData.FactorManager.GetFactor(GetUserContext(), FactorId.RedlistCategory); factor2 = CoreData.FactorManager.GetFactor(GetUserContext(), FactorId.Redlist_OrganismLabel1); taxon1 = CoreData.TaxonManager.GetTaxon(GetUserContext(), TaxonId.DrumGrasshopper); taxon2 = CoreData.TaxonManager.GetTaxon(GetUserContext(), TaxonId.Wolverine); factors = new FactorList(); factors.Add(factor1); factors.Add(factor2); taxa = new TaxonList(); taxa.Add(taxon1); taxa.Add(taxon2); GetDataSet(true).AddSelection(GetUserContext(), factors); GetDataSet().AddSelectionTaxa(GetUserContext(), taxa); GetDataSet().AddSelection(GetUserContext(), CoreData.FactorManager.GetPeriods(GetUserContext())); speciesFactCount = GetDataSet().SpeciesFacts.Count; periods = new PeriodList(); periods.Add(GetDataSet().Periods[0]); periods.Add(GetDataSet().Periods[1]); GetDataSet().RemoveSelection(GetUserContext(), periods); Assert.IsFalse(GetDataSet().Factors.IsEmpty()); Assert.IsFalse(GetDataSet().SpeciesFacts.IsEmpty()); Assert.IsTrue(speciesFactCount > GetDataSet().SpeciesFacts.Count); periods = null; GetDataSet().RemoveSelection(GetUserContext(), periods); }
/// <summary> /// /// </summary> /// <param name="userContext"></param> /// <param name="taxonIdList"></param> /// <returns></returns> public IList <TaxonParentViewModelHelper> GetTaxonList(IUserContext userContext, List <int?> taxonIdList) { IList <TaxonParentViewModelHelper> list = new List <TaxonParentViewModelHelper>(); IUserContext loggedInUser = userContext; if (taxonIdList.IsNotNull() && !taxonIdList.Contains(null)) { var idList = taxonIdList.Cast <int>().ToList(); TaxonList taxa = CoreData.TaxonManager.GetTaxa(loggedInUser, idList); if (taxa.IsNotNull() && taxa.Count > 0) { foreach (ITaxon taxon in taxa) { var taxonModel = new TaxonParentViewModelHelper(); taxonModel.Category = taxon.Category.Name; taxonModel.SortOrder = taxon.Category.SortOrder; taxonModel.CommonName = taxon.CommonName.IsNotEmpty() ? taxon.CommonName : string.Empty; taxonModel.ScientificName = taxon.ScientificName.IsNotEmpty() ? taxon.ScientificName : string.Empty; taxonModel.TaxonId = taxon.Id.ToString(); list.Add(taxonModel); } } } return(list); }
public void Constructor() { TaxonList taxa; taxa = new TaxonList(); Assert.IsNotNull(taxa); }
/// <summary> /// Cache taxon list information about all valid taxa. /// </summary> private void LoadTaxonListInformation() { // Get taxa. ITaxonSearchCriteria searchCriteria = new TaxonSearchCriteria(); searchCriteria.IsValidTaxon = true; TaxonList taxa = CoreData.TaxonManager.GetTaxa(mContext, searchCriteria); // Init new taxon information items. foreach (ITaxon taxon in taxa) { var taxonListInformation = new TaxonListInformation { CommonName = taxon.CommonName, Id = taxon.Id, CategoryId = taxon.Category.Id, ParentCategoryId = taxon.Category.ParentId, ScientificName = taxon.ScientificName }; mTaxonInformationCache.TaxonInformation[taxon.Id] = taxonListInformation; } // Add species fact information. //GetLandscapeTypeSpeciesFactsToCache(); //GetOrganismGroupSpeciesFactsToCache(); GetRedListCategorySpeciesFactsToCache(); //GetRedListCriteriaSpeciesFactsToCache(); //GetRedListTaxonCategorySpeciesFactsToCache(); //GetSwedishOccurrenceSpeciesFactsToCache(); //GetRedListOldCategorySpeciesFactsToCache(); }
public void Activate() { _Result = new List <TaxonTreeNode>(); TaxonUtils.OriginalRoot.ParseNode(CheckLeaf); TaxonList list = new TaxonList { HasFile = true, FileName = Path.Combine(TaxonUtils.GetLogPath(), "ListOfNonSpeciesLeaves.lot") }; list.FromTaxonTreeNodeList(_Result); list.Save(false, TaxonList.FileFilterIndexEnum.ListOfTaxons); string message = string.Format("{0} taxons with no children and that are not species or sub species", _Result.Count); string logFile = Path.Combine(TaxonUtils.GetLogPath(), "ListOfNonSpeciesLeaves.log"); using (StreamWriter log = new StreamWriter(logFile)) { log.WriteLine(message); log.WriteLine(); foreach (TaxonTreeNode node in _Result) { log.WriteLine(node.GetHierarchicalName()); } } message += string.Format("\ntaxons found are saved as filter list in {0}", list.FileName); message += string.Format("\nfor more details, look at {0}", logFile); Loggers.WriteInformation(LogTags.Data, message); }
public void selectTaxonList(TaxonList list) { if (list == null || !TaxonList.ValidTableIDs.Contains(list.TableID)) { Debugger.Break(); return; } if (list.IsSelected) return; withSelections(ctx => { var tables = from s in ctx.TaxonLists where s.TaxonomicGroup == list.TaxonomicGroup select s; var oldSelection = tables.FirstOrDefault(s => s.IsSelected); if (oldSelection != null) { oldSelection.IsSelected = false; } list.IsSelected = false; ctx.TaxonLists.Attach(list); list.IsSelected = true; ctx.SubmitChanges(); } ); }
/// <summary> /// Gets the underlying taxa. /// </summary> /// <param name="parentTaxon">The parent taxon.</param> /// <returns>List of taxa that have red list category factor.</returns> public TaxonList GetUnderlyingTaxa(ITaxon parentTaxon) { TaxonList taxonList = parentTaxon.GetChildTaxonTree(mUserContext, true).GetChildTaxa(); taxonList.Insert(0, parentTaxon); return(taxonList); }
/// <summary> /// Gets the taxa. /// </summary> /// <param name="userContext">The user context.</param> /// <returns></returns> public List <ITaxon> GetTaxa(IUserContext userContext) { List <int> taxonIds = GetTaxonIdsFromString(); TaxonList taxonList = CoreData.TaxonManager.GetTaxa(userContext, taxonIds); List <ITaxon> taxa = taxonList.Cast <ITaxon>().ToList(); return(taxa); }
/// <summary> /// Creates a TaxonMove view model /// </summary> /// <param name="taxon"></param> /// <param name="isOkToMove"></param> /// <returns></returns> public TaxonMoveViewModel CreateTaxonMoveViewModel(ITaxon taxon, ITaxonRevision taxonRevision, bool isOkToMove = true) { var model = new TaxonMoveViewModel(); model.TaxonId = taxon.Id; model.OldParentTaxonId = taxon.Id; model.HasChildren = true; model.IsOkToMove = isOkToMove; // Child taxa model.ChildTaxa = new List <RelatedTaxonViewModel>(); if (taxon.GetNearestChildTaxonRelations(_user).IsNotEmpty()) { foreach (ITaxonRelation taxonRelation in taxon.GetNearestChildTaxonRelations(_user)) { model.ChildTaxa.Add(new RelatedTaxonViewModel(taxonRelation.ChildTaxon, taxonRelation.ChildTaxon.Category, null, taxonRelation.IsMainRelation)); } } if (model.ChildTaxa.Count == 0) { // TODO cant throw exception //throw new Exception("Taxon has no children"); model.HasChildren = false; } // Available parents TaxonCategoryList categories2 = new TaxonCategoryList(); model.AvailableParents = new List <RelatedTaxonViewModel>(); if (model.ChildTaxa.Count != 0) { ITaxon revisionTaxon = CoreData.TaxonManager.GetTaxon(_user, model.ChildTaxa[0].TaxonId); TaxonList list = revisionTaxon.GetTaxaPossibleParents(_user, taxonRevision); foreach (var tx in list) { categories2.Merge(tx.Category); } categories2.Sort(new TaxonCategoryComparer()); foreach (ITaxon possibleParentTaxon in list) { model.AvailableParents.Add(new RelatedTaxonViewModel(possibleParentTaxon, possibleParentTaxon.Category, null)); } } // Taxon categories model.TaxonCategories = new List <TaxonCategoryViewModel>(); // var categories = GetTaxonCategories(taxon); // Get all categories within this revision TaxonCategoryList categories = GetTaxonCategories(taxonRevision.RootTaxon); foreach (ITaxonCategory taxonCategory in categories2) { model.TaxonCategories.Add(new TaxonCategoryViewModel(taxonCategory.Id, taxonCategory.Name)); } return(model); }
public List <TaxonViewModel> GetSettingsSummaryModel() { IUserContext userContext = CoreData.UserManager.GetCurrentUser(); ObservableCollection <int> taxonIds = SessionHandler.MySettings.Filter.Taxa.TaxonIds; TaxonList taxa = CoreData.TaxonManager.GetTaxa(userContext, taxonIds.ToList()); List <TaxonViewModel> taxonList = taxa.GetGenericList().ToTaxonViewModelList(); return(taxonList); }
private TaxonList GetTaxa(Boolean refresh) { if (_taxon.IsNull() || refresh) { _taxon = new TaxonList(); _taxon.Add(TaxonTest.GetTaxon(GetUserContext())); } return(_taxon); }
///// <summary> ///// Get current search result taxa From Session. ///// </summary> ///// <returns>List of taxon information or null.</returns> //public List<TaxonListInformation> GetSelectedTaxaListModelFromSession() //{ // if (SessionHandler.CurrentSelectedTaxa.IsNotNull()) // { // return SessionHandler.CurrentSelectedTaxa; // } // return null; //} ///// <summary> ///// Get current selected taxa From Session. ///// </summary> ///// <returns>List of taxon information or null.</returns> //public List<TaxonListInformation> GetViewModelSelectedTaxaListModelFromSession() //{ // if (SessionHandler.CurrentViewModelSelectedTaxa.IsNotNull()) // { // return SessionHandler.CurrentViewModelSelectedTaxa; // } // return null; //} ///// <summary> ///// Gets the namesearch string ///// </summary> ///// <returns></returns> //public string GetCurrentFilterSearchStringFromSession() //{ // return SessionHandler.FilterSearchString; //} ///// <summary> ///// Sets the filtersearch string ///// </summary> ///// <param name="filterSearchString"></param> //public void SetCurrentFilterSearchStringInSession(string filterSearchString) //{ // SessionHandler.FilterSearchString = filterSearchString; //} ///// <summary> ///// Sets the viewmodel from the latest namesearch ///// </summary> ///// <param name="model"></param> //public void SetNameSearchViewModelInSession(List<TaxonSearchResultItemViewModel> model) //{ // SessionHandler.TaxonSearchViewModel = model; //} //public List<TaxonSearchResultItemViewModel> GetNameSearchViewModelFromSession() //{ // return SessionHandler.TaxonSearchViewModel; //} ///// <summary> ///// Gets the resultviewtype from the session ///// </summary> ///// <returns></returns> //public ResultViewType GetResultViewTypeFromSession() //{ // return SessionHandler.ResultViewType; //} ///// <summary> ///// Sets the resultviewtype in the session ///// </summary> //public void SetResultViewTypeInSession(ResultViewType resultViewType) //{ // SessionHandler.ResultViewType = resultViewType; //} ///// <summary> ///// Gets the underlying taxa. Checks for redlist occurence and swedish occurrence. ///// The parent taxon is also included if it have red list category factor. Only taxa with categories below and ///// equal to species are returned. ///// </summary> ///// <param name="parentTaxonId">The parent taxon identifier.</param> ///// <returns>List of <see cref="TaxonListInformation"/> that have red list category factor.</returns> //public List<TaxonListInformation> GetUnderlyingTaxaFromScope(int parentTaxonId) //{ // TaxonList childTaxa = GetUnderlyingTaxa(parentTaxonId); // var taxonIdList = new TaxonIdList(); // // Select all valid taxa ids (from "artfakta db") // HashSet<int> taxonIdsSet = GetAllValidTaxaIds(); // childTaxa.RemoveAll(y => !taxonIdsSet.Contains(y.Id)); // foreach (ITaxon taxon in childTaxa) // { // taxonIdList.Add(new TaxonIdImplementation(taxon.Id)); // } // List<TaxonListInformation> taxonListInformations = TaxonListInformationManager.Instance.GetTaxonListInformation(taxonIdList, false, null); // // Remove data if only redlisted is to be shown // if (SessionHandler.UseOnlyRedlistedData) // { // // Remove other taxa then from result depending on data selection LC/NE/NA taxa could be included or excluded. // RemoveTaxaNotRedlistedOrRedlistedEnsuredFromList(taxonListInformations); // } // // Check for SwedishOccurrence // if (SessionHandler.UseSwedishOccurrence) // { // taxonListInformations = taxonListInformations.Where(x => x.SwedishOccurrenceId > AppSettings.Default.SwedishOccurrenceExist).ToList(); // } // return taxonListInformations; //} /// <summary> /// Gets the underlying taxa. /// </summary> /// <param name="parentTaxonId">The parent taxon identifier.</param> /// <returns>List of taxa that have red list category factor.</returns> public TaxonList GetUnderlyingTaxa(int parentTaxonId) { ITaxon parentTaxon = CoreData.TaxonManager.GetTaxon(mUserContext, parentTaxonId); TaxonList taxonList = parentTaxon.GetChildTaxonTree(mUserContext, true).GetChildTaxa(); taxonList.Insert(0, parentTaxon); return(taxonList); }
/// <summary> /// Merge data object with this list. /// Only objects that are not already in the list /// are added to the list. /// </summary> /// <param name='taxa'>The data to merge.</param> public void Merge(TaxonList taxa) { if (taxa.IsNotEmpty()) { foreach (ITaxon taxon in taxa) { this.Merge(new TaxonIdImplementation(taxon.Id)); } } }
/// <summary> /// Creates the subscriptions view model. /// </summary> /// <param name="taxon">The current taxon.</param> /// <returns>A view model.</returns> public SubscriptionsViewModel CreateSubscriptionsViewModel(ITaxon taxon) { TaxonList taxonList = CoreData.TaxonManager.GetTaxa(_userContext, _taxonIds); List <TaxonViewModel> taxaList = taxonList.GetGenericList().ToTaxonViewModelList(); SubscriptionsViewModel model = new SubscriptionsViewModel(); model.Subscriptions = taxaList; model.CurrentTaxon = TaxonViewModel.CreateFromTaxon(taxon); return(model); }
public void GetTaxonTree(int taxonId) { ITaxon taxon = CoreData.TaxonManager.GetTaxon(UserContext, taxonId); //CoreData.TaxonManager.GetTaxonTrees() ITaxonTreeNode taxonTreeNode = taxon.GetTaxonTree(UserContext, true); TaxonList childTaxa = taxonTreeNode.GetChildTaxa(); ITaxonTreeNode taxonTreeNode2 = taxon.GetChildTaxonTree(UserContext, true); TaxonList childTaxa2 = taxonTreeNode.GetChildTaxa(); }
/// <summary> /// Creates the view model for TimeSeriesDiagramOnSpeciesObservationAbundanceIndex. /// </summary> /// <returns>A view model for TimeSeriesDiagramOnSpeciesObservationAbundanceIndex.</returns> public ResultTimeSeriesOnSpeciesObservationCountsViewModel CreateResultTimeSeriesDiagramOnSpeciesObservationAbundanceIndexViewModel() { var model = new ResultTimeSeriesOnSpeciesObservationCountsViewModel(); SpeciesObservationAbundanceIndexDiagramResultCalculator resultCalculator = new SpeciesObservationAbundanceIndexDiagramResultCalculator(UserContext, MySettings); model.ComplexityEstimate = resultCalculator.GetQueryComplexityEstimate(); model.NoOfTaxa = settings.Filter.Taxa.NumberOfSelectedTaxa; TaxonList taxonList = CoreData.TaxonManager.GetTaxa(UserContext, MySettings.Filter.Taxa.TaxonIds.ToList()); model.SelectedTaxa = taxonList.GetGenericList().ToTaxonViewModelList(); return(model); }
/// <summary> /// Calculates species observation count per polygon and taxa. /// </summary> /// <param name="taxonIds">The taxon ids.</param> /// <returns> /// A dictionary where the key is a polygon description. /// The value is a dictionary where the key is TaxonId and the value is species observation count. /// </returns> public TaxonSpecificSpeciesObservationCountPerPolygonResult CalculateSpeciesObservationCountPerPolygonAndTaxa(List <int> taxonIds) { Dictionary <string, Dictionary <int, long> > speciesObservationData = new Dictionary <string, Dictionary <int, long> >(); FeatureCollection featureCollection = GetFeatureCollection(); List <int> taxonIdList = new List <int>(taxonIds); if (taxonIdList.IsEmpty()) { taxonIdList.Add(0); } if (MySettings.Calculation.SummaryStatistics.WfsSummaryStatisticsLayerId.HasValue && featureCollection != null && featureCollection.Features.Count > 0) { SpeciesObservationSearchCriteriaManager searchCriteriaManager = new SpeciesObservationSearchCriteriaManager(UserContext); SpeciesObservationSearchCriteria searchCriteria = searchCriteriaManager.CreateSearchCriteria(MySettings); DataContext dataContext = new DataContext(UserContext); CoordinateSystem displayCoordinateSystem = MySettings.Presentation.Map.DisplayCoordinateSystem; foreach (Feature feature in featureCollection.Features) { string featureDescription = GetFeatureDescription(feature); List <DataPolygon> dataPolygons = GetDataPolygons(feature); searchCriteria.Polygons = dataPolygons.ToPolygons(dataContext); foreach (int taxonId in taxonIdList) { searchCriteria.TaxonIds = new List <int>(); searchCriteria.TaxonIds.Add(taxonId); long speciesObservationCount = CoreData.AnalysisManager.GetSpeciesObservationCountBySearchCriteria(UserContext, searchCriteria, displayCoordinateSystem); if (!speciesObservationData.ContainsKey(featureDescription)) { speciesObservationData.Add(featureDescription, new Dictionary <int, long>()); } speciesObservationData[featureDescription].Add(taxonId, speciesObservationCount); } } } TaxonList taxonList = CoreData.TaxonManager.GetTaxa(UserContext, taxonIdList); List <TaxonViewModel> taxaList = taxonList.GetGenericList().ToTaxonViewModelList(); TaxonSpecificSpeciesObservationCountPerPolygonResult result = new TaxonSpecificSpeciesObservationCountPerPolygonResult() { Taxa = taxaList, SpeciesObservationCountPerPolygon = speciesObservationData }; return(result); }
public List <ITaxon> GetTaxonAndAllChildren(int taxonId) { List <ITaxon> taxa = new List <ITaxon>(); ITaxon taxon = CoreData.TaxonManager.GetTaxon(UserContext, taxonId); taxa.Add(taxon); ITaxonTreeNode taxonTreeNode = taxon.GetChildTaxonTree(UserContext, true); TaxonList childTaxa = taxonTreeNode.GetChildTaxa(); taxa.AddRange(childTaxa); return(taxa); }
/// <summary> /// Load information about suitable parent taxa. /// </summary> /// <param name="userContext">User context.</param> private void LoadTaxonInformation(IUserContext userContext) { ITaxonSearchCriteria searchCriteria; List <Int32> taxonIds; TaxonList parentTaxa; TaxonNameList allTaxonNames; _italicStringsInAutomaticTaxonomicParagraph = new List <String>(); if (_suitableParents.IsEmpty() && _taxon.IsNotNull()) { searchCriteria = new TaxonSearchCriteria(); taxonIds = new List <Int32>(); taxonIds.Add(_taxon.Id); searchCriteria.TaxonIds = taxonIds; searchCriteria.Scope = TaxonSearchScope.AllParentTaxa; parentTaxa = CoreData.TaxonManager.GetTaxa(userContext, searchCriteria); _suitableParents = new TaxonList(); foreach (ITaxon parent in parentTaxa) { if ((parent.Category.Id == (Int32)(TaxonCategoryId.Kingdom)) || (parent.Category.Id == (Int32)(TaxonCategoryId.Phylum)) || (parent.Category.Id == (Int32)(TaxonCategoryId.Class)) || (parent.Category.Id == (Int32)(TaxonCategoryId.Order)) || (parent.Category.Id == (Int32)(TaxonCategoryId.Family))) { if (parent.Id != (Int32)(TaxonId.Life)) { _suitableParents.Add(parent); } } } } if (_synonyms.IsEmpty() && _taxon.IsNotNull()) { _synonyms = new TaxonNameList(); allTaxonNames = CoreData.TaxonManager.GetTaxonNames(userContext, _taxon); foreach (ITaxonName name in allTaxonNames) { if ((name.Category.Id == 0) && (name.Status.Id == 0) && (!name.IsRecommended) && (name.Name != _taxon.ScientificName)) { _italicStringsInAutomaticTaxonomicParagraph.Add(name.Name); _synonyms.Add(name); } } } }
/// <summary> /// Get a list with corresponding taxon from taxon ids /// </summary> /// <param name="taxonIds">The taxon ids.</param> /// <returns></returns> private List <ITaxon> GetMatches(List <Int32> taxonIds) { var searchCriteria = new TaxonSearchCriteria(); searchCriteria.TaxonIds = new List <int>(); searchCriteria.IsValidTaxon = true; foreach (Int32 id in taxonIds) { searchCriteria.TaxonIds.Add(id); } TaxonList taxa = CoreData.TaxonManager.GetTaxa(_user, searchCriteria); return((List <ITaxon>)taxa.GetGenericList()); }
/// <summary> /// Get ids for taxa that matches search criteria. /// </summary> /// <param name="analysisManager">Analysis manager.</param> /// <param name="searchCriteria">Analysis search critera.</param> /// <param name="taxa"> /// Limit search to these taxa. /// This parameter is ignored if value is null. /// </param> /// <returns>Ids for taxa that matches search criteria.</returns> public static TaxonIdList GetTaxonIds( this IAnalysisManager analysisManager, AnalysisSearchCriteria searchCriteria, TaxonList taxa) { TaxonIdList taxonIds = null; if (taxa.IsNotNull()) { taxonIds = new TaxonIdList(); taxonIds.Merge(taxa); } return(mCache.GetTaxonIds(searchCriteria, taxonIds)); }
public void addTaxonNames(IEnumerable<TaxonName> taxa, TaxonList list) { if (!TaxonList.ValidTableIDs.Contains(list.TableID)) throw new ArgumentException("list"); using (var taxctx = new TaxonDataContext(list.TableID)) { taxctx.TaxonNames.InsertAllOnSubmit(taxa); try { taxctx.SubmitChanges(); } catch (Exception) { System.Diagnostics.Debugger.Break(); //TODO Log } } }
public void GetTaxonNamesByTaxonIds() { Int32 index; List <TaxonNameList> allTaxonNames; TaxonList taxa; TaxonTreeNodeList taxonTrees; ITaxonTreeSearchCriteria searchCriteria; // Test with a few taxa. taxa = new TaxonList(); taxa.Add(GetTaxonDataSource(true).GetTaxon(GetUserContext(), (Int32)(TaxonId.Bear))); taxa.Add(GetTaxonDataSource().GetTaxon(GetUserContext(), (Int32)(TaxonId.Mammals))); allTaxonNames = GetTaxonDataSource().GetTaxonNames(GetUserContext(), taxa); Assert.IsTrue(allTaxonNames.IsNotEmpty()); Assert.AreEqual(taxa.Count, allTaxonNames.Count); for (index = 0; index < taxa.Count; index++) { Assert.IsTrue(allTaxonNames[index].IsNotEmpty()); foreach (ITaxonName taxonName in allTaxonNames[index]) { Assert.AreEqual(taxa[index].Id, taxonName.Taxon.Id); } } // Test with lots of taxa. if (Configuration.IsAllTestsRun) { taxa = new TaxonList(true); searchCriteria = new TaxonTreeSearchCriteria(); searchCriteria.IsValidRequired = true; taxonTrees = CoreData.TaxonManager.GetTaxonTrees(GetUserContext(), searchCriteria); foreach (ITaxonTreeNode taxonTree in taxonTrees) { taxa.Merge(taxonTree.GetTaxa()); } allTaxonNames = GetTaxonDataSource().GetTaxonNames(GetUserContext(), taxa); Assert.IsTrue(allTaxonNames.IsNotEmpty()); Assert.AreEqual(taxa.Count, allTaxonNames.Count); for (index = 0; index < taxa.Count; index++) { Assert.IsTrue(allTaxonNames[index].IsNotEmpty()); foreach (ITaxonName taxonName in allTaxonNames[index]) { Assert.AreEqual(taxa[index].Id, taxonName.Taxon.Id); } } } }
public void addTaxonList(TaxonList list) { if (TaxonList.ValidTableIDs.Contains(list.TableID)) throw new ArgumentException("list"); lock (this) { withSelections(ctx => { var unusedIDs = getUnusedTaxonTableIDs(ctx); if (unusedIDs.Count() > 0) { list.IsSelected = false; list.TableID = unusedIDs.First(); ctx.TaxonLists.InsertOnSubmit(list); ctx.SubmitChanges(); } else throw new InvalidOperationException("No Unused Taxon Table"); }); } }
public IObservable<IEnumerable<Client.TaxonName>> DownloadTaxonListChunked(Client.TaxonList list) { var serviceList = new TaxonList() { DisplayText = list.TableDisplayName, IsPublicList = list.IsPublicList, Table = list.TableName, TaxonomicGroup = list.TaxonomicGroup }; return Observable.Create((IObserver<IEnumerable<Client.TaxonName>> observer) => { int chunk = 1; //First Chunk is 1, not 0! var subscription = DownloadTaxonList.MakeObservableServiceResult(list) .Select(args => args.Result ?? Enumerable.Empty<TaxonName>()) .Select(taxa => taxa.Select( taxon => new Client.TaxonName() { GenusOrSupragenic = taxon.GenusOrSupragenic, InfraspecificEpithet = taxon.InfraspecificEpithet, SpeciesEpithet = taxon.SpeciesEpithet, Synonymy = (Client.Synonymy)Enum.Parse(typeof(Client.Synonymy), taxon.Synonymy, true), TaxonNameCache = taxon.TaxonNameCache, TaxonNameSinAuth = taxon.TaxonNameSinAuth, URI = taxon.URI, AcceptedNameURI = taxon.AcceptedNameURI, AcceptedNameCache = taxon.AcceptedNameCache })) .TakeWhile(taxonChunk => { if (taxonChunk.Any()) { //There might still be more Taxa -> request next chunk WithCredentials(c => _svc.DownloadTaxonListAsync(serviceList, ++chunk, c, list)); return true; } else //Transfer finished return false; }).Subscribe(observer); //Request first chunk WithCredentials(c => _svc.DownloadTaxonListAsync(serviceList, chunk, c, list)); return subscription; }); }
public IList<Model.TaxonList> getAvailableTaxonLists() { ConnectionProfile connectionProfile = null; string userName = null; IDbConnection definitionsConnection = null; IList<TaxonList> res = new List<TaxonList>(); if (Settings != null) { var userSettings = Settings.getOptions(); if (userSettings != null) { connectionProfile = userSettings.CurrentConnection; userName = userSettings.Username; } else _Log.Error("UserOptions are empty."); } else _Log.Error("UserOptionsService not available."); if (Connections != null) { if (Connections.Definitions != null) definitionsConnection = Connections.Definitions.CreateConnection(); else _Log.Error("Definitions Serializer empty."); } else _Log.Error("ConnectionsProvider unavailable."); if (connectionProfile != null && userName != null && definitionsConnection != null) { var taxonListsForUser = "******" + connectionProfile.TaxonNamesInitialCatalog + "].[dbo].[TaxonListsForUser]('" + userName + "')"; string sql = String.Format("SELECT * FROM {0};", taxonListsForUser); try { using (var cmd = definitionsConnection.CreateCommand()) { cmd.CommandText = sql; definitionsConnection.Open(); var rdr = cmd.ExecuteReader(); while (rdr.Read()) { TaxonList tl = new TaxonList(); tl.DataSource = rdr["Datasource"].ToString(); tl.DisplayText = rdr["DisplayText"].ToString(); //tl.IsSelected = false; tl.TaxonomicGroup = rdr["TaxonomicGroup"].ToString(); res.Add(tl); } } } catch (Exception e) { _Log.ErrorFormat("An Error Occured while retrieving available Taxon Lists [{0}]",e); } finally { definitionsConnection.Close(); definitionsConnection.Dispose(); } } return res; }
public void deleteTaxonListIfExists(TaxonList list) { if (list == null || !TaxonList.ValidTableIDs.Contains(list.TableID)) return; using (var isostore = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication()) { var dbFile = TaxonDataContext.getDBPath(list.TableID); if (isostore.FileExists(dbFile)) { isostore.DeleteFile(dbFile); } } withSelections(ctx => { ctx.TaxonLists.Attach(list); ctx.TaxonLists.DeleteOnSubmit(list); ctx.SubmitChanges(); list.TableID = TaxonList.InvalidTableID; }); }