Пример #1
0
        /// <summary>
        /// Convert a list of WebSpeciesFact instances
        /// to a SpeciesFactList.
        /// </summary>
        /// <param name="userContext">
        /// Information about the user that makes this method call.
        /// </param>
        /// <param name="webSpeciesFacts">List of WebSpeciesFact instances.</param>
        /// <returns>List of SpeciesFact instances.</returns>
        protected virtual SpeciesFactList GetSpeciesFacts(IUserContext userContext, List <WebSpeciesFact> webSpeciesFacts)
        {
            SpeciesFactList        speciesFacts;
            FactorList             factors = CoreData.FactorManager.GetFactors(userContext);
            IndividualCategoryList individualCategories = CoreData.FactorManager.GetIndividualCategories(userContext);
            PeriodList             periods = CoreData.FactorManager.GetPeriods(userContext);
            ReferenceList          references;
            SpeciesFactQualityList speciesFactQualities = CoreData.SpeciesFactManager.GetSpeciesFactQualities(userContext);
            List <Int32>           referenceIds, taxonIds;
            TaxonList taxa;

            speciesFacts = null;
            if (webSpeciesFacts.IsNotEmpty())
            {
                referenceIds = GetReferenceIds(webSpeciesFacts);
                references   = CoreData.ReferenceManager.GetReferences(userContext, referenceIds);
                taxonIds     = GetTaxonIds(webSpeciesFacts);
                taxa         = CoreData.TaxonManager.GetTaxa(userContext, taxonIds);
                speciesFacts = new SpeciesFactList();
                foreach (WebSpeciesFact webSpeciesFact in webSpeciesFacts)
                {
                    speciesFacts.Add(GetSpeciesFact(userContext, webSpeciesFact, factors, individualCategories, periods, references, speciesFactQualities, taxa));
                }
            }

            return(speciesFacts);
        }
 /// <summary>
 /// Set species fact qualities for specified locale.
 /// </summary>
 /// <param name="speciesFactQualities">Individual categories.</param>
 /// <param name="locale">Currently used locale.</param>
 protected override void SetSpeciesFactQualities(SpeciesFactQualityList speciesFactQualities,
                                                 ILocale locale)
 {
     lock (SpeciesFactQualities)
     {
         SpeciesFactQualities[locale.ISOCode] = speciesFactQualities;
     }
 }
        /// <summary>
        /// Get species fact qualities for specified locale.
        /// </summary>
        /// <param name="locale">Currently used locale.</param>
        /// <returns>Species fact qualities for specified locale.</returns>
        protected virtual SpeciesFactQualityList GetSpeciesFactQualities(ILocale locale)
        {
            SpeciesFactQualityList speciesFactQualities = null;

            if (SpeciesFactQualities.ContainsKey(locale.ISOCode))
            {
                speciesFactQualities = (SpeciesFactQualityList)(SpeciesFactQualities[locale.ISOCode]);
            }

            return(speciesFactQualities);
        }
        /// <summary>
        /// Get species fact qualities for specified locale.
        /// </summary>
        /// <param name="locale">Currently used locale.</param>
        /// <returns>Species fact qualities for specified locale.</returns>
        protected override SpeciesFactQualityList GetSpeciesFactQualities(ILocale locale)
        {
            SpeciesFactQualityList speciesFactQualities = null;

            lock (SpeciesFactQualities)
            {
                if (SpeciesFactQualities.ContainsKey(locale.ISOCode))
                {
                    speciesFactQualities = (SpeciesFactQualityList)(SpeciesFactQualities[locale.ISOCode]);
                }
            }

            return(speciesFactQualities);
        }
Пример #5
0
        /// <summary>
        /// Convert a list of WebSpeciesFactQuality instances
        /// to a SpeciesFactQualityList.
        /// </summary>
        /// <param name="userContext">
        /// Information about the user that makes this method call.
        /// </param>
        /// <param name="webSpeciesFactQualities">List of WebSpeciesFactQuality instances.</param>
        /// <returns>Species fact qualities.</returns>
        private SpeciesFactQualityList GetSpeciesFactQualities(IUserContext userContext,
                                                               List <WebSpeciesFactQuality> webSpeciesFactQualities)
        {
            SpeciesFactQualityList speciesFactQualities;

            speciesFactQualities = null;
            if (webSpeciesFactQualities.IsNotEmpty())
            {
                speciesFactQualities = new SpeciesFactQualityList();
                foreach (WebSpeciesFactQuality webSpeciesFactQuality in webSpeciesFactQualities)
                {
                    speciesFactQualities.Add(GetSpeciesFactQuality(userContext, webSpeciesFactQuality));
                }

                speciesFactQualities.Sort();
            }

            return(speciesFactQualities);
        }
        /// <summary>
        /// Read UserDataSet from xml file.
        /// </summary>
        /// <param name='fileName'>File name.</param>
        /// <param name='dictionaryURI'>Path.</param>
        /// <returns>The read UserDataSet.</returns>
        public static UserDataSet Deserialize(String fileName, String dictionaryURI)
        {
            Stream          stream      = File.OpenRead(fileName);
            BinaryFormatter formatter   = new BinaryFormatter();
            UserDataSet     userDataSet = (UserDataSet)formatter.Deserialize(stream);

            stream.Close();


            stream = File.OpenRead(dictionaryURI + @"\Factors.bin");
            FactorList allFactors = ((FactorList)formatter.Deserialize(stream));

            stream.Close();

            stream = File.OpenRead(dictionaryURI + @"\FactorTrees.bin");
            FactorTreeNodeList factorTrees = ((FactorTreeNodeList)formatter.Deserialize(stream));

            stream.Close();

            stream = File.OpenRead(dictionaryURI + @"\SpeciesFactQualities.bin");
            SpeciesFactQualityList speciesFactQualities = ((SpeciesFactQualityList)formatter.Deserialize(stream));

            stream.Close();

            stream = File.OpenRead(dictionaryURI + @"\Periods.bin");
            PeriodList periods = ((PeriodList)formatter.Deserialize(stream));

            stream.Close();

            PeriodManager.InitialisePeriods(periods);
            SpeciesFactManager.InitialiseSpeciesFactQualities(speciesFactQualities);
            FactorManager.InitialiseAllFactors(allFactors, factorTrees);
            SpeciesFactManager.InitAutomatedCalculations(userDataSet.SpeciesFacts);

            return(userDataSet);
        }
 /// <summary>
 /// Set species fact qualities for specified locale.
 /// </summary>
 /// <param name="speciesFactQualities">Species fact qualities.</param>
 /// <param name="locale">Currently used locale.</param>
 protected virtual void SetSpeciesFactQualities(SpeciesFactQualityList speciesFactQualities,
                                                ILocale locale)
 {
     SpeciesFactQualities[locale.ISOCode] = speciesFactQualities;
 }
Пример #8
0
        /// <summary>
        /// Convert a WebSpeciesFact instance into
        /// an ISpeciesFact instance.
        /// </summary>
        /// <param name="userContext">
        /// Information about the user that makes this method call.
        /// </param>
        /// <param name="webSpeciesFact">A WebSpeciesFact instance.</param>
        /// <param name="factors">List of factors.</param>
        /// <param name="individualCategories">List of individual categories.</param>
        /// <param name="periods">List of periods.</param>
        /// <param name="references">List of references.</param>
        /// <param name="speciesFactQualities">List of species fact qualities.</param>
        /// <param name="taxa">Taxa that are used in the species facts.</param>
        /// <returns>An ISpeciesFact instance.</returns>
        private ISpeciesFact GetSpeciesFact(IUserContext userContext,
                                            WebSpeciesFact webSpeciesFact,
                                            FactorList factors,
                                            IndividualCategoryList individualCategories,
                                            PeriodList periods,
                                            ReferenceList references,
                                            SpeciesFactQualityList speciesFactQualities,
                                            TaxonList taxa)
        {
            IFactor      factor;
            IPeriod      period;
            ISpeciesFact speciesFact;
            ITaxon       host, taxon;

            factor = factors.Get(webSpeciesFact.FactorId);
            if (webSpeciesFact.IsHostSpecified)
            {
#if EXAMINE_PROBLEM
                if (!(taxa.Contains(webSpeciesFact.HostId)))
                {
                    throw new Exception("Host with id = " + webSpeciesFact.HostId + " is not in taxon list." + webSpeciesFact.GetString());
                }
#endif

                host = taxa.Get(webSpeciesFact.HostId);
            }
            else
            {
                if (factor.IsTaxonomic)
                {
                    host = CoreData.TaxonManager.GetTaxon(userContext, 0);
                }
                else
                {
                    host = null;
                }
            }

            if (webSpeciesFact.IsPeriodSpecified)
            {
#if EXAMINE_PROBLEM
                if (!(periods.Contains(webSpeciesFact.PeriodId)))
                {
                    throw new Exception("Period with id = " + webSpeciesFact.PeriodId + " is not in period list." + webSpeciesFact.GetString());
                }
#endif

                period = periods.Get(webSpeciesFact.PeriodId);
            }
            else
            {
                period = null;
            }

#if EXAMINE_PROBLEM
            if (!(taxa.Contains(webSpeciesFact.TaxonId)))
            {
                throw new Exception("Taxon with id = " + webSpeciesFact.TaxonId + " is not in taxon list." + webSpeciesFact.GetString());
            }
#endif

            taxon = taxa.Get(webSpeciesFact.TaxonId);
#if EXAMINE_PROBLEM
            if (!(individualCategories.Contains(webSpeciesFact.IndividualCategoryId)))
            {
                throw new Exception("Individual category with id = " + webSpeciesFact.IndividualCategoryId + " is not in individual category list." + webSpeciesFact.GetString());
            }

            if (!(speciesFactQualities.Contains(webSpeciesFact.QualityId)))
            {
                throw new Exception("Quality with id = " + webSpeciesFact.QualityId + " is not in quality list." + webSpeciesFact.GetString());
            }

            if (!(references.Contains(webSpeciesFact.ReferenceId)))
            {
                throw new Exception("Reference with id = " + webSpeciesFact.ReferenceId + " is not in reference list." + webSpeciesFact.GetString());
            }
#endif

            speciesFact = CoreData.SpeciesFactManager.GetSpeciesFact(userContext,
                                                                     webSpeciesFact.Id,
                                                                     taxon,
                                                                     individualCategories.Get(webSpeciesFact.IndividualCategoryId),
                                                                     factor,
                                                                     host,
                                                                     period,
                                                                     webSpeciesFact.FieldValue1,
                                                                     webSpeciesFact.IsFieldValue1Specified,
                                                                     webSpeciesFact.FieldValue2,
                                                                     webSpeciesFact.IsFieldValue2Specified,
                                                                     webSpeciesFact.FieldValue3,
                                                                     webSpeciesFact.IsFieldValue3Specified,
                                                                     webSpeciesFact.FieldValue4,
                                                                     webSpeciesFact.IsFieldValue4Specified,
                                                                     webSpeciesFact.FieldValue5,
                                                                     webSpeciesFact.IsFieldValue5Specified,
                                                                     speciesFactQualities.Get(webSpeciesFact.QualityId),
                                                                     references.Get(webSpeciesFact.ReferenceId),
                                                                     webSpeciesFact.ModifiedBy,
                                                                     webSpeciesFact.ModifiedDate);

            return(speciesFact);
        }