예제 #1
0
 /// <summary>
 /// Initialize analysis cache.
 /// </summary>
 /// <param name="userContext">The user context.</param>
 public void Init(IUserContext userContext)
 {
     CachedDate = DateTime.Now;
     //Biotope = new BiotopeCache(userContext);
     //Biotope.Init(userContext);
     //SwedishOccurrence = new SwedishOccurrenceCache(userContext);
     //SwedishOccurrence.Init(userContext);
     //CountyOccurrence = new CountyOccurrenceCache(userContext);
     //CountyOccurrence.Init(userContext);
     //Host = new HostCache(userContext);
     //Host.Init(userContext);
     //Impact = new ImpactCache(userContext);
     //Impact.Init(userContext);
     //LandscapeType = new LandscapeTypeCache(userContext);
     //LandscapeType.Init(userContext);
     //LifeForm = new LifeFormCache(userContext);
     //LifeForm.Init(userContext);
     //OrganismGroup = new OrganismGroupCache(userContext);
     //OrganismGroup.Init(userContext);
     RedListCategory = new RedListCategoryCache();
     RedListCategory.Init(userContext);
     //TaxonScope = new TaxonScopeCache();
     //TaxonScope.Init(userContext);
     //Substrate = new SubstrateCache(userContext);
     //Substrate.Init(userContext);
     //ThematicLists = new ThematicListCache();
     //ThematicLists.Init(userContext);
     Version = CURRENT_VERSION;
 }
        //public static void InitSwedishOccurrenceInformation(this SearchViewModel searchViewModel)
        //{
        //    if (mSearchViewModelFromSession.IsNotNull() && mSearchViewModelFromSession.SwedishOccurrences.IsNotNull())
        //    {
        //        searchViewModel.IsSwedishOccurrenceEnabled = mSearchViewModelFromSession.IsSwedishOccurrenceEnabled;
        //        searchViewModel.SwedishOccurrenceTitle = mSearchViewModelFromSession.SwedishOccurrenceTitle;
        //        searchViewModel.SwedishOccurrences = mSearchViewModelFromSession.SwedishOccurrences;
        //    }
        //    else
        //    {
        //        searchViewModel.SwedishOccurrences = new List<RedListSwedishOccurrenceItemViewModel>();

        //        // Get swedish occurrence factor
        //        FactorList swedishOccurrenceFactors = SwedishOccurrenceCache.GetFactors(mUser);

        //        // Populate swedish occurrence
        //        foreach (var swedishOccurrenceFactor in swedishOccurrenceFactors)
        //        {
        //            foreach (var swedishOccurrenceItem in swedishOccurrenceFactor.DataType.Field1.Enum.Values)
        //            {
        //                // The level of swedish occurrence is defined in the appsettings
        //                if (swedishOccurrenceItem.KeyInt.HasValue && swedishOccurrenceItem.KeyInt.Value > AppSettings.Default.SwedishOccurrenceExist)
        //                {
        //                    var redListSwedishOccurrenceItemViewModel = new RedListSwedishOccurrenceItemViewModel
        //                    {
        //                        Id = swedishOccurrenceItem.KeyInt.Value,
        //                        Name = swedishOccurrenceItem.OriginalLabel,
        //                        Selected = true,
        //                    };
        //                    searchViewModel.SwedishOccurrences.Add(redListSwedishOccurrenceItemViewModel);
        //                }
        //            }
        //        }

        //        // Set swedish occurrences to true as default
        //        searchViewModel.IsSwedishOccurrenceEnabled = true;
        //    }
        //}

        ///// <summary>
        ///// Init Biotopes information.
        ///// </summary>
        ///// <param name="searchViewModel">Search criteria view model.</param>
        //public static void InitBiotopeInformation(this SearchViewModel searchViewModel)
        //{
        //    if (mSearchViewModelFromSession.IsNotNull() && mSearchViewModelFromSession.Biotopes.IsNotNull())
        //    {
        //        searchViewModel.IsBiotopeEnabled = mSearchViewModelFromSession.IsBiotopeEnabled;
        //        searchViewModel.IsBiotopeImportant = mSearchViewModelFromSession.IsBiotopeImportant;
        //        searchViewModel.BiotopeOperator = mSearchViewModelFromSession.BiotopeOperator;
        //        searchViewModel.Biotopes = mSearchViewModelFromSession.Biotopes;
        //        searchViewModel.BiotopesTitle = mSearchViewModelFromSession.BiotopesTitle;
        //    }
        //    else
        //    {
        //        searchViewModel.Biotopes = new List<RedListBiotopeItemViewModel>();

        //        // Get superior factor for biotopes.
        //        IFactor superiorFactor = CoreData.FactorManager.GetFactor(mUser, FactorId.Biotopes);

        //        // Get biotope factors
        //        FactorList biotopeFactors = BiotopeCache.GetFactors(mUser);

        //        // Set title for biotopes, from factor.
        //        searchViewModel.BiotopesTitle = superiorFactor.Label;

        //        // Populate biotopes
        //        foreach (var biotopeFactor in biotopeFactors)
        //        {
        //            var redListBiotopeItemViewModel = new RedListBiotopeItemViewModel
        //            {
        //                Id = biotopeFactor.Id,
        //                Name = biotopeFactor.Name
        //            };

        //            searchViewModel.Biotopes.Add(redListBiotopeItemViewModel);
        //        }

        //        searchViewModel.BiotopeOperator = LogicalOperator.Or;
        //    }
        //}

        ///// <summary>
        ///// Init CountyOccurrences information.
        ///// </summary>
        ///// <param name="searchViewModel">Search criteria view model.</param>
        //public static void InitCountyOccurrencesInformation(this SearchViewModel searchViewModel)
        //{
        //    if (mSearchViewModelFromSession.IsNotNull() && mSearchViewModelFromSession.CountyOccurrences.IsNotNull())
        //    {
        //        searchViewModel.IsCountyOccurrenceEnabled = mSearchViewModelFromSession.IsCountyOccurrenceEnabled;
        //        searchViewModel.CountyOccurrences = mSearchViewModelFromSession.CountyOccurrences;
        //        searchViewModel.CountyOccurrencesTitle = mSearchViewModelFromSession.CountyOccurrencesTitle;
        //    }
        //    else
        //    {
        //        searchViewModel.CountyOccurrences = new List<RedListCountyOccurrenceItemViewModel>();

        //        // Get superior factor, for county occurrence.
        //        IFactor superiorFactor = CoreData.FactorManager.GetFactor(mUser, FactorId.CountyOccurrence);

        //        // Get county occurrence factors
        //        FactorList countyOccurenceFactors = CountyOccurrenceCache.GetFactors(mUser);

        //        // Set title for county occurrence, from factor.
        //        searchViewModel.CountyOccurrencesTitle = superiorFactor.Label;

        //        // Populate county occurrence
        //        foreach (var countyOccurenceFactor in countyOccurenceFactors)
        //        {
        //            var redListCountyOccurrenceItemViewModel = new RedListCountyOccurrenceItemViewModel
        //            {
        //                Id = countyOccurenceFactor.Id,
        //                Name = countyOccurenceFactor.Name
        //            };

        //            searchViewModel.CountyOccurrences.Add(redListCountyOccurrenceItemViewModel);
        //        }
        //    }
        //}

        ///// <summary>
        ///// Init ThematicLists information.
        ///// </summary>
        ///// <param name="searchViewModel">Search criteria view model.</param>
        //public static void InitThematicListInformation(this SearchViewModel searchViewModel)
        //{
        //    searchViewModel.ThematicLists = new List<RedListThematicListItemViewModel>();
        //    if (mSearchViewModelFromSession.IsNotNull() && mSearchViewModelFromSession.ThematicLists.IsNotNull())
        //    {
        //        searchViewModel.IsThematicListEnabled = mSearchViewModelFromSession.IsThematicListEnabled;
        //        searchViewModel.ThematicListOperator = mSearchViewModelFromSession.ThematicListOperator;
        //        searchViewModel.ThematicLists = mSearchViewModelFromSession.ThematicLists;
        //    }
        //    else
        //    {
        //        foreach (ThematicListEnum @enum in Enum.GetValues(typeof(ThematicListEnum)).Cast<ThematicListEnum>())
        //        {
        //            var redListThematicListItemViewModel = new RedListThematicListItemViewModel();
        //            switch (@enum)
        //            {
        //                case ThematicListEnum.ContinuousDecline:
        //                    redListThematicListItemViewModel.Id = (int)@enum;
        //                    redListThematicListItemViewModel.Name = RedListResource.TaxonSearchThematicListContinuousDecline;
        //                    break;
        //                case ThematicListEnum.ExtremeFluctuations:
        //                    redListThematicListItemViewModel.Id = (int)@enum;
        //                    redListThematicListItemViewModel.Name = RedListResource.TaxonSearchThematicListExtremeFluctuations;
        //                    break;
        //                case ThematicListEnum.SevereleyFragmented:
        //                    redListThematicListItemViewModel.Id = (int)@enum;
        //                    redListThematicListItemViewModel.Name = RedListResource.TaxonSearchThematicListSeverelyFragmented;
        //                    break;
        //                case ThematicListEnum.SmallPopulationOrDistribution:
        //                    redListThematicListItemViewModel.Id = (int)@enum;
        //                    redListThematicListItemViewModel.Name = RedListResource.TaxonSearchThematicListSmallPopulationOrDistribution;
        //                    break;
        //            }

        //            searchViewModel.ThematicLists.Add(redListThematicListItemViewModel);
        //        }

        //        searchViewModel.ThematicListOperator = LogicalOperator.Or;
        //    }
        //}

        /// <summary>
        /// Init RedListCategories information.
        /// </summary>
        /// <param name="searchViewModel">Search criteria view model.</param>
        public static void InitRedListCategories(this SearchViewModel searchViewModel)
        {
            if (mSearchViewModelFromSession.IsNotNull() && mSearchViewModelFromSession.RedListCategories.IsNotNull())
            {
                searchViewModel.IsRedListCategoriesEnabled = mSearchViewModelFromSession.IsRedListCategoriesEnabled;
                searchViewModel.RedListCategories          = mSearchViewModelFromSession.RedListCategories;
                searchViewModel.RedListCategoriesTitle     = mSearchViewModelFromSession.RedListCategoriesTitle;
            }
            else
            {
                var otherListedGroupCategoryIds = new List <int>();

                // Get red list category factor
                FactorList redListCategoryFactors = RedListCategoryCache.GetFactors(mUser);

                // Set red list categories title, from factor.
                searchViewModel.RedListCategoriesTitle = redListCategoryFactors[0].Label;

                // Group a limited list of red list categories; "red listed group"
                var        categories = RedListedHelper.GetRedListCategoriesDdToNt();
                List <int> redListedGroupCategoryIds = categories.Select(cat => (int)cat).ToList();

                // Group a limited list of red list categories; "other group"
                RedListCategory redListCategory;
                for (redListCategory = RedListCategory.LC; redListCategory <= RedListCategory.NE; redListCategory++)
                {
                    otherListedGroupCategoryIds.Add((int)redListCategory);
                }

                searchViewModel.RedListCategories = new List <RedListCategoryItemViewModel>();

                // Populate red list categories
                RedListCategoryItemViewModel redListCategoryItemViewModel;
                foreach (var redListCategoryFactor in redListCategoryFactors)
                {
                    foreach (var redListCategoryItem in redListCategoryFactor.DataType.Field1.Enum.Values)
                    {
                        if (redListCategoryItem.KeyInt.HasValue && redListedGroupCategoryIds.Contains(redListCategoryItem.KeyInt.Value))
                        {
                            redListCategoryItemViewModel = new RedListCategoryItemViewModel
                            {
                                Id               = redListCategoryItem.Id,
                                Name             = redListCategoryItem.OriginalLabel,
                                OrderNumber      = redListCategoryItem.KeyInt.Value,
                                Selected         = true,
                                InRedListedGroup = true,
                                InOtherGroup     = false
                            };
                            searchViewModel.RedListCategories.Add(redListCategoryItemViewModel);
                        }
                        if (redListCategoryItem.KeyInt.HasValue && otherListedGroupCategoryIds.Contains(redListCategoryItem.KeyInt.Value))
                        {
                            redListCategoryItemViewModel = new RedListCategoryItemViewModel
                            {
                                Id               = redListCategoryItem.Id,
                                Name             = redListCategoryItem.OriginalLabel,
                                OrderNumber      = redListCategoryItem.KeyInt.Value,
                                Selected         = false,
                                InRedListedGroup = false,
                                InOtherGroup     = true
                            };
                            searchViewModel.RedListCategories.Add(redListCategoryItemViewModel);
                        }
                    }
                }

                const bool ShowNonCategorizedTaxa = true;
                const int  NonCategorizedTaxaId   = 1000;

                // Add value for non categorized taxa. Ie taxa that dont have category 743
                if (ShowNonCategorizedTaxa)
                {
                    redListCategoryItemViewModel = new RedListCategoryItemViewModel
                    {
                        Id               = NonCategorizedTaxaId,
                        Name             = "Non categorized taxa -TEST", //RedListResource.TaxonSearchNonCategorizedTaxaLabel,
                        OrderNumber      = NonCategorizedTaxaId,
                        Selected         = false,
                        InRedListedGroup = false,
                        InOtherGroup     = true
                    };
                    searchViewModel.RedListCategories.Add(redListCategoryItemViewModel);
                }

                // Preselect red list category group as default
                searchViewModel.IsRedListCategoriesEnabled = true;
            }
        }