コード例 #1
0
        /// <summary>
        /// Creates the view model for SpeciesObservationMap.
        /// </summary>
        /// <returns>A view model for SpeciesObservationMap.</returns>
        public ResultSpeciesObservationMapViewModel CreateResultSpeciesObservationMapViewModel()
        {
            ResultSpeciesObservationMapViewModel    model            = new ResultSpeciesObservationMapViewModel();
            PagedSpeciesObservationResultCalculator resultCalculator = new PagedSpeciesObservationResultCalculator(UserContext, MySettings);

            model.ComplexityEstimate = resultCalculator.GetQueryComplexityEstimate();

            if (MySettings.Filter.Taxa.TaxonIds.Count > 1)
            {
                TaxonTreeViewManager taxonTreeViewManager = new TaxonTreeViewManager(UserContext, MySettings);
                model.CategoryTaxaList = taxonTreeViewManager.GetCategoryTaxaList(MySettings.Filter.Taxa.TaxonIds.ToList());
            }
            else if (MySettings.Filter.Taxa.TaxonIds.Count == 0)
            {
                model.SelectedTaxaDescription = Resource.MySettingsAllTaxaSelected;
            }
            else if (MySettings.Filter.Taxa.TaxonIds.Count == 1)
            {
                // TaxonList taxa = CoreData.TaxonManager.GetTaxa(UserContext, MySettings.Filter.Taxa.TaxonIds.ToList());
                ITaxon         taxon          = CoreData.TaxonManager.GetTaxon(UserContext, MySettings.Filter.Taxa.TaxonIds.First());
                TaxonViewModel taxonViewModel = TaxonViewModel.CreateFromTaxon(taxon);
                model.SelectedTaxaDescription = taxonViewModel.FullName;

                // List<TaxonViewModel> taxonList = taxa.GetGenericList().ToTaxonViewModelList();

                // List<string> strTaxa = taxonList.Select(taxon => taxon.FullName).ToList();

                // model.SelectedTaxaDescription = String.Join(", ", strTaxa).Substring(0, 100) + "...";
            }

            model.AddSpartialFilterLayer = MySettings.Filter.Spatial.HasSettings && MySettings.Filter.Spatial.IsActive;
            return(model);
        }
コード例 #2
0
        private static TaxonViewModel BuildTaxaTreeBfs(
            Taxon taxon,
            Func <ITaxon, TaxonViewModel> viewModelBuilder,
            Func <IQueryable <Taxon>, IQueryable <Taxon> > sort,
            TaxonomyManager manager,
            int taxaCountLimit,
            ref int currentTaxaCount)
        {
            var            queue         = new Queue <TaxonData>();
            TaxonViewModel rootViewModel = null;

            queue.Enqueue(new TaxonData()
            {
                Taxon = taxon
            });

            while (queue.Count > 0)
            {
                var currentNode = queue.Dequeue();

                var currentViewModel = viewModelBuilder.Invoke(currentNode.Taxon);

                if (currentViewModel != null)
                {
                    // If this is the first created view model, set it to be the root one.
                    if (rootViewModel == null)
                    {
                        rootViewModel = currentViewModel;
                    }

                    if (currentNode.LastKnownParent != null)
                    {
                        currentNode.LastKnownParent.SubTaxa.Add(currentViewModel);
                    }

                    currentTaxaCount++;
                    if (taxaCountLimit > 0 && currentTaxaCount == taxaCountLimit)
                    {
                        return(rootViewModel);
                    }
                }

                // If the current taxon is included in the tree, it should be the parent of the inner taxa.
                var lastKnownParent = currentViewModel ?? currentNode.LastKnownParent;

                var subTaxa       = manager.GetTaxa <Taxon>().Where(t => t.Parent.Id == currentNode.Taxon.Id);
                var sortedSubtaxa = sort.Invoke(subTaxa);

                foreach (var childTaxon in sortedSubtaxa)
                {
                    queue.Enqueue(new TaxonData()
                    {
                        LastKnownParent = lastKnownParent,
                        Taxon           = childTaxon
                    });
                }
            }

            return(rootViewModel);
        }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
        /// <summary>
        /// Converts a list of ITaxon to a list with TaxonViewModel which is used
        /// to present the Taxa on screen.
        /// </summary>
        /// <param name="taxa">The taxa.</param>
        /// <returns></returns>
        public static List <TaxonViewModel> ToTaxonViewModelList(this IEnumerable <ITaxon> taxa)
        {
            var list = new List <TaxonViewModel>();

            if (taxa != null)
            {
                foreach (ITaxon taxon in taxa)
                {
                    list.Add(TaxonViewModel.CreateFromTaxon(taxon));
                }
            }
            return(list);
        }
コード例 #5
0
        public TaxonPage(Taxon taxon)
        {
            InitializeComponent();

            var vm = new TaxonViewModel(taxon);

            vm.Navigation  = Navigation;
            BindingContext = vm;
            //Browser.Source = new UrlWebViewSource() { Url = string.Format("http://www.lepidoptera.se/arter/{0}.aspx", taxon.Name.ToLower().Replace(" ", "_")) };
            Browser.Source = new UrlWebViewSource()
            {
                Url = string.Format("https://www.google.com/search?tbm=isch&q={0}", taxon.ScientificName.Replace(" ", "%20"))
            };
        }
        public List <CategoryTaxaViewModel> GetCategoryTaxaList(int taxonId)
        {
            List <CategoryTaxaViewModel> categoryTaxaList;
            List <ITaxon> taxonAndAllChildren = GetTaxonAndAllChildren(taxonId);
            Dictionary <int, CategoryTaxaViewModel> categoryTaxaDictionary = new Dictionary <int, CategoryTaxaViewModel>();

            foreach (ITaxon taxon in taxonAndAllChildren)
            {
                if (!categoryTaxaDictionary.ContainsKey(taxon.Category.Id))
                {
                    categoryTaxaDictionary.Add(taxon.Category.Id, new CategoryTaxaViewModel(taxon.Category));
                }
                categoryTaxaDictionary[taxon.Category.Id].Taxa.Add(TaxonViewModel.CreateFromTaxon(taxon));
            }
            categoryTaxaList = categoryTaxaDictionary.Values.OrderBy(x => x.CategorySortOrder).ToList();
            return(categoryTaxaList);
        }
        public List <CategoryTaxaViewModel> GetCategoryTaxaList(List <int> taxonIds)
        {
            List <CategoryTaxaViewModel> categoryTaxaList;
            TaxonList      taxonList   = CoreData.TaxonManager.GetTaxa(UserContext, taxonIds);
            IList <ITaxon> genericList = taxonList.GetGenericList();
            Dictionary <int, CategoryTaxaViewModel> categoryTaxaDictionary = new Dictionary <int, CategoryTaxaViewModel>();

            foreach (ITaxon taxon in genericList)
            {
                if (!categoryTaxaDictionary.ContainsKey(taxon.Category.Id))
                {
                    categoryTaxaDictionary.Add(taxon.Category.Id, new CategoryTaxaViewModel(taxon.Category));
                }
                categoryTaxaDictionary[taxon.Category.Id].Taxa.Add(TaxonViewModel.CreateFromTaxon(taxon));
            }
            categoryTaxaList = categoryTaxaDictionary.Values.OrderBy(x => x.CategorySortOrder).ToList();
            return(categoryTaxaList);
        }
コード例 #8
0
        ///// <summary>
        ///// Gets a taxons scientific and common name concatenated.
        ///// </summary>
        ///// <param name="taxon">The taxon.</param>
        ///// <returns>A taxons scientific and common name concatenated</returns>
        //public static string GetScientificAndCommonName(this ITaxon taxon)
        //{
        //    if (taxon.CommonName.IsEmpty() && taxon.ScientificName.IsEmpty())
        //        return "";
        //    if (taxon.CommonName.IsEmpty())
        //        return taxon.ScientificName.IsEmpty() ? taxon.ScientificName : "";
        //    else
        //        return string.Format("{0} ({1})", taxon.ScientificName, taxon.CommonName);
        //}

        ///// <summary>
        ///// Gets a taxons common name or the default value.
        ///// </summary>
        ///// <param name="taxon">The taxon.</param>
        ///// <param name="strDefault">The default value.</param>
        ///// <returns>A taxons common name or the default value.</returns>
        //public static string GetCommonNameOrDefault(this ITaxon taxon, string strDefault)
        //{
        //    return taxon.CommonName.IsNotEmpty() ? taxon.CommonName : strDefault;
        //}

        ///// <summary>
        ///// Gets a string with taxons all synonyms separated by ;.
        ///// </summary>
        ///// <param name="taxon">The taxon.</param>
        ///// <returns>a string with taxons all synonyms separated by ;.</returns>
        //public static string GetScientificSynonymsString(this ITaxon taxon)
        //{
        //    if (taxon == null || taxon.GetSynonyms(CoreData.UserManager.GetCurrentUser()) == null)
        //        return "";
        //    var names = new StringBuilder();

        //    foreach (var taxonName in taxon.GetSynonyms(CoreData.UserManager.GetCurrentUser()))
        //    {
        //        if (names.Length > 0)
        //        {
        //            names.Append("; ");
        //        }

        //        names.Append(taxonName.Name);

        //        if (!string.IsNullOrEmpty(taxonName.Author))
        //        {
        //            names.Append(" ");
        //            names.Append(taxonName.Author);
        //        }
        //    }
        //    return names.ToString();
        //}

        ///// <summary>
        ///// Determines whether the taxon is Biota (life), or not.
        ///// </summary>
        ///// <param name="taxon">The taxon.</param>
        ///// <returns>True if the taxon is Biota, and otherwise false.</returns>
        //public static bool IsLifeTaxon(this ITaxon taxon)
        //{
        //    return taxon.Id == 0;
        //}

        ///// <summary>
        ///// Gets a string with all parents to a taxon separated by ;.
        ///// </summary>
        ///// <param name="taxon">The taxon.</param>
        ///// <param name="userContext">The user context.</param>
        ///// <returns>A string with all parents to a taxon separated by ;.</returns>
        //public static string GetParentTaxaString(this ITaxon taxon, IUserContext userContext)
        //{
        //    if (taxon == null)
        //        return "";
        //    var parents = new StringBuilder();
        //    var parentRelations = taxon.GetAllParentTaxonRelations(userContext, null, false, false);
        //    foreach (var taxonRelation in parentRelations)
        //    {
        //        var relatedTaxon = taxonRelation.ParentTaxon;
        //        if (parents.Length > 0)
        //        {
        //            parents.Append("; ");
        //        }

        //        parents.Append(relatedTaxon.Category.Name);
        //        parents.Append(": ");
        //        parents.Append(relatedTaxon.GetLabel());
        //    }

        //    return parents.ToString();
        //}

        ///// <summary>
        ///// Get taxon names where taxon name category type
        ///// equals IDENTIFIER.
        ///// </summary>
        ///// <param name="taxon">The taxon.</param>
        ///// <param name="userContext">The user context.</param>
        ///// <returns>
        ///// Taxon names where taxon name category type
        ///// equals IDENTIFIER.
        ///// </returns>
        //public static List<ITaxonName> GetAllIdentifiers(this ITaxon taxon, IUserContext userContext)
        //{
        //    var identifiers = new List<ITaxonName>();
        //    foreach (ITaxonName taxonName in taxon.GetTaxonNames(userContext))
        //    {
        //        if (taxonName.NameCategory.Type == TaxonNameCategoryType.Identifier)
        //        {
        //            identifiers.Add(taxonName);
        //        }
        //    }
        //    return identifiers;
        //}

        ///// <summary>
        ///// Get common names that are recommended and approved, but not swedish.
        ///// </summary>
        ///// <param name="taxon">The taxon.</param>
        ///// <param name="userContext">The user context.</param>
        ///// <returns>Common names that are recommended and approved, but not swedish.</returns>
        //public static List<ITaxonName> GetOtherLanguagesNames(this ITaxon taxon, IUserContext userContext)
        //{
        //    // todo - fungerar den här inne i en revision?
        //    var otherLanguagesNames = new List<ITaxonName>();
        //    DateTime today = DateTime.Now;
        //    foreach (ITaxonName taxonName in taxon.GetTaxonNames(userContext))
        //    {

        //        if (taxonName.NameCategory.Type == TaxonNameCategoryType.CommonName &&
        //            taxonName.IsRecommended &&
        //            taxonName.Status.Id == (int)TaxonNameStatusId.ApprovedNaming &&
        //            taxonName.ValidFromDate <= today &&
        //            today <= taxonName.ValidToDate &&
        //            taxonName.NameCategory.Id != (Int32)TaxonNameCategoryId.SwedishName
        //            )
        //        {
        //            otherLanguagesNames.Add(taxonName);
        //        }
        //    }

        //    return otherLanguagesNames;
        //}

        ///// <summary>
        ///// Get common names that are not recommended and not removed. And also
        ///// scientific names that are not approved and not removed.
        ///// </summary>
        ///// <param name="taxon">The taxon.</param>
        ///// <param name="userContext">The user context.</param>
        ///// <returns>Common names that are not recommended and not removed. And also
        ///// scientific names that are not approved and not removed.</returns>
        //public static List<ITaxonName> GetNotRecommendedNames(this ITaxon taxon, IUserContext userContext)
        //{
        //    // todo - fungerar den här inne i en revision?
        //    var notRecommendedNames = new List<ITaxonName>();
        //    DateTime today = DateTime.Now;
        //    foreach (ITaxonName taxonName in taxon.GetTaxonNames(userContext))
        //    {
        //        if (taxonName.NameCategory.Type == TaxonNameCategoryType.CommonName &&
        //            taxonName.IsRecommended == false &&
        //            taxonName.ValidFromDate <= today &&
        //            today <= taxonName.ValidToDate &&
        //            taxonName.Status.Id != (int)TaxonNameStatusId.Removed
        //            )
        //        {
        //            notRecommendedNames.Add(taxonName);
        //        }
        //        else if (taxonName.NameCategory.Type == TaxonNameCategoryType.ScientificName &&
        //            taxonName.IsRecommended == false &&
        //            taxonName.ValidFromDate <= today &&
        //            today <= taxonName.ValidToDate &&
        //            taxonName.Status.Id != (int)TaxonNameStatusId.Removed &&
        //            taxonName.Status.Id != (int)TaxonNameStatusId.ApprovedNaming
        //            )
        //        {
        //            notRecommendedNames.Add(taxonName);
        //        }

        //    }

        //    return notRecommendedNames;
        //}

        ///// <summary>
        ///// Gets the taxon anamorph name or null if it doesn't exist.
        ///// </summary>
        ///// <param name="taxon">The taxon.</param>
        ///// <returns>The taxon anamorph name or null if it doesn't exist.</returns>
        //public static ITaxonName GetAnamorphName(this ITaxon taxon)
        //{
        //    ITaxonName name = null;
        //    foreach (ITaxonName taxonName in taxon.GetTaxonNames(CoreData.UserManager.GetCurrentUser()))
        //    {

        //        if (taxonName.NameCategory.Id == (Int32)TaxonNameCategoryId.AnamorphName)
        //        {
        //            name = taxonName;
        //            if (name.IsRecommended)
        //                break;
        //        }
        //    }
        //    return name;
        //}

        /// <summary>
        /// Converts an ITaxon to a TaxonViewModel which is used
        /// to present the Taxon on screen.
        /// </summary>
        /// <param name="taxon">The taxon.</param>
        /// <returns></returns>
        public static TaxonViewModel ToTaxonViewModel(this ITaxon taxon)
        {
            return(TaxonViewModel.CreateFromTaxon(taxon));
        }