public void GetSpeciesFactsByIdentifier()
        {
            List <WebSpeciesFact> changeSpeciesFacts;
            List <WebSpeciesFact> oldSpeciesFacts;
            List <WebSpeciesFact> speciesFacts;

            // Get same species facts again.
            oldSpeciesFacts = GetSomeSpeciesFacts(GetContext());
            speciesFacts    = SpeciesFactManager.GetSpeciesFactsByIdentifier(GetContext(), oldSpeciesFacts);
            Assert.AreEqual(oldSpeciesFacts.Count, speciesFacts.Count);

            // Delete some species facts.
            changeSpeciesFacts = new List <WebSpeciesFact>();
            changeSpeciesFacts.Add(speciesFacts[0]);
            changeSpeciesFacts.Add(speciesFacts[1]);
            changeSpeciesFacts.Add(speciesFacts[2]);
            SpeciesFactManager.UpdateSpeciesFacts(GetContext(), null, changeSpeciesFacts, null);
            speciesFacts = SpeciesFactManager.GetSpeciesFactsByIdentifier(GetContext(), oldSpeciesFacts);
            Assert.AreEqual(oldSpeciesFacts.Count - 3, speciesFacts.Count);

            // Create some species facts.
            SpeciesFactManager.UpdateSpeciesFacts(GetContext(), changeSpeciesFacts, null, null);
            speciesFacts = SpeciesFactManager.GetSpeciesFactsByIdentifier(GetContext(), oldSpeciesFacts);
            Assert.AreEqual(oldSpeciesFacts.Count, speciesFacts.Count);
        }
        public void GetEndangeredLists()
        {
            List <WebEndangeredList> endangeredLists;

            endangeredLists = SpeciesFactManager.GetEndangeredLists(GetContext());
            Assert.IsTrue(endangeredLists.IsNotEmpty());
        }
예제 #3
0
        public void GetDouble()
        {
            Double value, defaultValue;

            defaultValue = 53545.543;
            try
            {
                SpeciesFactManager.AddUserSelectedSpeciesFacts(GetContext(), SpeciesFactManagerTest.GetSomeSpeciesFactIds(GetContext()), UserSelectedSpeciesFactUsage.Output);
                using (DataReader dataReader = DataServer.GetSpeciesFactsById(GetContext()))
                {
                    while (dataReader.Read())
                    {
                        if (dataReader.IsDBNull(SpeciesFactData.FIELD_VALUE_1))
                        {
                            value = dataReader.GetDouble(SpeciesFactData.FIELD_VALUE_1, defaultValue);
                            Assert.AreEqual(value, defaultValue);
                        }
                        else
                        {
                            value = dataReader.GetDouble(SpeciesFactData.FIELD_VALUE_1);
                            Assert.AreNotEqual(value, defaultValue);
                            value = dataReader.GetDouble(SpeciesFactData.FIELD_VALUE_1, defaultValue);
                            Assert.AreNotEqual(value, defaultValue);
                        }
                    }
                }
            }
            finally
            {
                SpeciesFactManager.DeleteUserSelectedSpeciesFacts(GetContext());
            }
        }
        private void UpdateSpeciesFacts(WebSpeciesFact speciesFact)
        {
            List <WebSpeciesFact> speciesFacts;

            speciesFacts = new List <WebSpeciesFact>();
            speciesFacts.Add(speciesFact);
            SpeciesFactManager.UpdateSpeciesFacts(GetContext(), null, null, speciesFacts);
        }
        private WebSpeciesFact GetSpeciesFact(WebSpeciesFact speciesFact)
        {
            List <Int32> speciesFactIds;

            speciesFactIds = new List <Int32>();
            speciesFactIds.Add(speciesFact.Id);
            return(SpeciesFactManager.GetSpeciesFactsById(GetContext(), speciesFactIds)[0]);
        }
        public static List <WebSpeciesFact> GetSomeSpeciesFacts(WebServiceContext context)
        {
            WebUserParameterSelection userParameterSelection;

            userParameterSelection          = new WebUserParameterSelection();
            userParameterSelection.TaxonIds = TaxonManagerTest.GetSomeTaxonIds();
            return(SpeciesFactManager.GetSpeciesFactsByUserParameterSelection(context, userParameterSelection));
        }
        public void GetSpeciesFactQualities()
        {
            List <WebSpeciesFactQuality> speciesFactQualities;

            speciesFactQualities = SpeciesFactManager.GetSpeciesFactQualities(GetContext());
            Assert.IsNotNull(speciesFactQualities);
            Assert.IsTrue(speciesFactQualities.IsNotEmpty());
        }
 public void DeleteUserSelectedHosts()
 {
     foreach (UserSelectedTaxonUsage hostUsage in Enum.GetValues(typeof(UserSelectedTaxonUsage)))
     {
         SpeciesFactManager.AddUserSelectedHosts(GetContext(), TaxonManagerTest.GetSomeTaxonIds(), hostUsage);
         SpeciesFactManager.DeleteUserSelectedHosts(GetContext());
     }
 }
        private void UpdateDyntaxaSpeciesFacts(WebSpeciesFact speciesFact)
        {
            List <WebSpeciesFact> speciesFacts;

            speciesFacts = new List <WebSpeciesFact>();
            speciesFacts.Add(speciesFact);
            SpeciesFactManager.UpdateDyntaxaSpeciesFacts(GetContext(), null, null, speciesFacts, "Dyntaxa Kindvall");
        }
        public void GetSpeciesFactsByUserParameterSelectionToManyError()
        {
            List <WebSpeciesFact>     speciesFacts;
            WebUserParameterSelection userParameterSelection;

            userParameterSelection = new WebUserParameterSelection();
            speciesFacts           = SpeciesFactManager.GetSpeciesFactsByUserParameterSelection(GetContext(), userParameterSelection);
            Assert.IsTrue(speciesFacts.IsNotEmpty());
        }
        public static WebTaxonCountyOccurrence GetOneTaxonCountyOccurrence(WebServiceContext context)
        {
            Int32 taxonId;
            List <WebTaxonCountyOccurrence> countyOccurrencies;

            taxonId            = BEAR_TAXON_ID;
            countyOccurrencies = SpeciesFactManager.GetTaxonCountyOccurence(context, taxonId);
            return(countyOccurrencies[0]);
        }
예제 #12
0
        /// <summary>
        /// A method that obtains red list information.
        /// </summary>
        private void LoadRedListInformation()
        {
            SpeciesFactList        speciesFacts;
            UserParameterSelection parameters;

            if (_organismGroupName.IsNull())
            {
                _organismGroupName          = String.Empty;
                _redlistCategoryName        = String.Empty;
                _redlistCategoryShortString = String.Empty;
                _redlistCriteria            = String.Empty;

                parameters = new UserParameterSelection();
                parameters.Taxa.Add(_taxon);
                parameters.Factors.Add(FactorManager.GetFactor(FactorId.RedlistCategory));
                parameters.Factors.Add(FactorManager.GetFactor(FactorId.RedlistCriteriaString));
                parameters.Factors.Add(FactorManager.GetFactor(FactorId.Redlist_OrganismLabel1));
                parameters.Periods.Add(_period);
                speciesFacts = SpeciesFactManager.GetSpeciesFactsByUserParameterSelection(parameters);
                if (speciesFacts.IsNotEmpty())
                {
                    foreach (SpeciesFact speciesFact in speciesFacts)
                    {
                        switch (speciesFact.Factor.Id)
                        {
                        case (Int32)FactorId.RedlistCategory:
                            if (speciesFact.HasField1)
                            {
                                _redlistCategoryName = speciesFact.Field1.EnumValue.OriginalLabel;
                                _redlistCategoryName = _redlistCategoryName.Remove(_redlistCategoryName.Length - 5);
                            }
                            if (speciesFact.HasField4)
                            {
                                _redlistCategoryShortString = speciesFact.Field4.StringValue;
                            }
                            break;

                        case (Int32)FactorId.RedlistCriteriaString:
                            if (speciesFact.HasField4 &&
                                speciesFact.Field4.StringValue.IsNotEmpty())
                            {
                                _redlistCriteria = speciesFact.Field4.StringValue.Trim();
                            }
                            break;

                        case (Int32)FactorId.Redlist_OrganismLabel1:
                            if (speciesFact.MainField.HasValue)
                            {
                                _organismGroupName = speciesFact.MainField.EnumValue.OriginalLabel;
                            }
                            break;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Update species fact with new data from database.
        /// </summary>
        /// <param name="id">Id of the species fact</param>
        /// <param name="referenceId">Reference id of the species fact</param>
        /// <param name="updateDate">Update date of the species fact</param>
        /// <param name="updateUserFullName">Full Name of the pdate user of the species fact</param>
        /// <param name="hasFieldValue1">Indicates if field 1 has a value.</param>
        /// <param name="fieldValue1">Field value of field 1 for the species fact</param>
        /// <param name="hasFieldValue2">Indicates if field 2 has a value.</param>
        /// <param name="fieldValue2">Field value of field 2 for the species fact</param>
        /// <param name="hasFieldValue3">Indicates if field 3 has a value.</param>
        /// <param name="fieldValue3">Field value of field 3 for the species fact</param>
        /// <param name="hasFieldValue4">Indicates if field 4 has a value.</param>
        /// <param name="fieldValue4">Field value of field 4 for the species fact</param>
        /// <param name="hasFieldValue5">Indicates if field 5 has a value.</param>
        /// <param name="fieldValue5">Field value of field 5 for the species fact</param>
        /// <param name="qualityId">Quality Id of the species fact</param>
        internal void Update(Int32 id,
                             Int32 referenceId,
                             DateTime updateDate,
                             String updateUserFullName,
                             Boolean hasFieldValue1,
                             Double fieldValue1,
                             Boolean hasFieldValue2,
                             Double fieldValue2,
                             Boolean hasFieldValue3,
                             Double fieldValue3,
                             Boolean hasFieldValue4,
                             String fieldValue4,
                             Boolean hasFieldValue5,
                             String fieldValue5,
                             Int32 qualityId)
        {
            UpdateId(id);
            _hasId              = true;
            _quality            = SpeciesFactManager.GetSpeciesFactQuality(qualityId);
            _oldQuality         = _quality;
            _reference          = ReferenceManager.GetReference(referenceId);
            _oldReference       = _reference;
            _updateUserFullName = updateUserFullName;
            _updateDate         = updateDate;
            _hasUpdateDate      = true;

            foreach (SpeciesFactField field in _fields)
            {
                switch (field.Index)
                {
                case 0:
                    field.Update(hasFieldValue1, fieldValue1);
                    break;

                case 1:
                    field.Update(hasFieldValue2, fieldValue2);
                    break;

                case 2:
                    field.Update(hasFieldValue3, fieldValue3);
                    break;

                case 3:
                    field.Update(hasFieldValue4, fieldValue4);
                    break;

                case 4:
                    field.Update(hasFieldValue5, fieldValue5);
                    break;

                default:
                    throw new Exception("Unknown data field!");
                }
            }
        }
        public void GetSpeciesFactsById()
        {
            List <WebSpeciesFact> speciesFacts;
            List <Int32>          speciesFactIds;

            speciesFactIds = new List <Int32>();
            speciesFactIds.Add(1);
            speciesFacts = SpeciesFactManager.GetSpeciesFactsById(GetContext(), speciesFactIds);
            Assert.IsNotNull(speciesFacts);
            Assert.AreEqual(speciesFacts.Count, speciesFactIds.Count);
        }
        private SpeciesFactManager GetSpeciesFactManager(Boolean refresh = false)
        {
            if (_speciesFactManager.IsNull() || refresh)
            {
                _speciesFactManager = new SpeciesFactManager {
                    DataSource = new SpeciesFactDataSource()
                };
            }

            return(_speciesFactManager);
        }
        public void GetSpeciesFactsByIdentifierToManyError()
        {
            Int32 speciesFactIndex;
            List <WebSpeciesFact> speciesFacts;

            speciesFacts = GetSomeSpeciesFacts(GetContext());
            for (speciesFactIndex = 0; speciesFactIndex < (SpeciesFactManager.MAX_SPECIES_FACTS + 2); speciesFactIndex++)
            {
                speciesFacts.Add(speciesFacts[0]);
            }
            speciesFacts = SpeciesFactManager.GetSpeciesFactsByIdentifier(GetContext(), speciesFacts);
            Assert.IsNotNull(speciesFacts);
        }
        public void GetTaxonCountyOccurrence()
        {
            Int32 taxonId;
            List <WebTaxonCountyOccurrence> countyOccurrencies;

            taxonId            = BEAR_TAXON_ID;
            countyOccurrencies = SpeciesFactManager.GetTaxonCountyOccurence(GetContext(), taxonId);
            Assert.IsTrue(countyOccurrencies.IsNotEmpty());
            foreach (WebTaxonCountyOccurrence countyOccurrence in countyOccurrencies)
            {
                Assert.IsNotNull(countyOccurrence);
                Assert.AreEqual(taxonId, countyOccurrence.TaxonId);
            }
        }
        public void GetSpeciesFactsByIdToManyError()
        {
            Int32 speciesFactIdIndex;
            List <WebSpeciesFact> speciesFacts;
            List <Int32>          speciesFactIds;

            speciesFactIds = new List <Int32>();
            for (speciesFactIdIndex = 0; speciesFactIdIndex < (SpeciesFactManager.MAX_SPECIES_FACTS + 2); speciesFactIdIndex++)
            {
                speciesFactIds.Add(speciesFactIdIndex);
            }
            speciesFacts = SpeciesFactManager.GetSpeciesFactsById(GetContext(), speciesFactIds);
            Assert.IsNotNull(speciesFacts);
            Assert.AreEqual(speciesFacts.Count, speciesFactIds.Count);
        }
 /// <summary>
 /// Reset species fact that has been deleted from database.
 /// Set all values to default or null.
 /// </summary>
 internal void Reset()
 {
     UpdateId(-1);
     _hasId              = false;
     _quality            = SpeciesFactManager.GetDefaultSpeciesFactQuality();
     _oldQuality         = _quality;
     _reference          = null;
     _oldReference       = null;
     _updateUserFullName = null;
     _updateDate         = DateTime.MinValue;
     _hasUpdateDate      = false;
     foreach (SpeciesFactField field in _fields)
     {
         field.Reset();
     }
 }
예제 #20
0
 public void GetDoubleColumnNameError()
 {
     try
     {
         SpeciesFactManager.AddUserSelectedSpeciesFacts(GetContext(), SpeciesFactManagerTest.GetSomeSpeciesFactIds(GetContext()), UserSelectedSpeciesFactUsage.Output);
         using (DataReader dataReader = DataServer.GetSpeciesFactsById(GetContext()))
         {
             Assert.IsTrue(dataReader.Read());
             dataReader.GetDouble("No column name");
         }
     }
     finally
     {
         SpeciesFactManager.DeleteUserSelectedSpeciesFacts(GetContext());
     }
 }
예제 #21
0
        /// <summary>
        /// Get species facts with species document information.
        /// </summary>
        private void GetSpeciesFacts()
        {
            UserParameterSelection parameters = new UserParameterSelection();
            TaxonList taxa = new TaxonList();

            taxa.Add(_taxon);
            parameters.Taxa = taxa;
            FactorSearchCriteria criteria  = new FactorSearchCriteria();
            List <Int32>         factorIds = new List <Int32>();

            factorIds.Add((Int32)FactorId.SpeciesInformationDocumentGroup);
            criteria.RestrictSearchToFactorIds = factorIds;
            criteria.RestrictReturnToScope     = ArtDatabanken.Data.WebService.FactorSearchScope.LeafFactors;
            parameters.Factors = FactorManager.GetFactorsBySearchCriteria(criteria);
            _speciesFacts      = SpeciesFactManager.GetSpeciesFactsByUserParameterSelection(parameters);
        }
        public static DataTable GetNewSpeciesFactTable(WebServiceContext context)
        {
            WebSpeciesFact        speciesFact;
            List <WebSpeciesFact> speciesFacts;

            // Create new species fact with random values.
            speciesFact                        = GetOneSpeciesFact(context);
            speciesFact.FactorId               = 10;
            speciesFact.FieldValue1            = 10;
            speciesFact.IsFieldValue1Specified = true;
            speciesFact.IndividualCategoryId   = 2;
            speciesFact.TaxonId                = 209210;

            speciesFacts = new List <WebSpeciesFact>();
            speciesFacts.Add(speciesFact);
            return(SpeciesFactManager.GetSpeciesFactTable(context, speciesFacts, DateTime.Now, ""));
        }
        /// <summary>
        /// Save UserDataSet to xml file.
        /// </summary>
        /// <param name='fileName'>File name.</param>
        /// <param name='userDataSet'>UserDataSet to save.</param>
        /// <param name='dictionaryURI'>Path.</param>
        /// <param name='renewCommonDefinitions'>Indicates if common definitions should be updated.</param>
        public static void Serialize(String fileName, UserDataSet userDataSet, String dictionaryURI, Boolean renewCommonDefinitions)
        {
            BinaryFormatter formatter = new BinaryFormatter();

            Stream stream = File.OpenWrite(fileName);

            formatter.Serialize(stream, userDataSet);
            stream.Close();

            if (renewCommonDefinitions)
            {
                String factorFileName = dictionaryURI + @"\Factors.bin";
                stream = File.OpenWrite(factorFileName);
                FactorList allFactors = FactorManager.GetFactors();
                formatter.Serialize(stream, allFactors);
                stream.Close();

                FactorTreeSearchCriteria searchCriteria = new FactorTreeSearchCriteria();
                FactorTreeNodeList       factorTrees    = new FactorTreeNodeList();

                foreach (Factor factor in allFactors)
                {
                    List <Int32> factorIds = new List <Int32>();
                    factorIds.Add(factor.Id);
                    searchCriteria.RestrictSearchToFactorIds = factorIds;
                }


                String factorTreeFileName = dictionaryURI + @"\FactorTrees.bin";
                stream = File.OpenWrite(factorTreeFileName);
                formatter.Serialize(stream, factorTrees);
                stream.Close();

                String speciesFactQualityFileName = dictionaryURI + @"\SpeciesFactQualities.bin";
                stream = File.OpenWrite(speciesFactQualityFileName);
                formatter.Serialize(stream, SpeciesFactManager.GetSpeciesFactQualities());
                stream.Close();

                String periodsFileName = dictionaryURI + @"\Periods.bin";
                stream = File.OpenWrite(periodsFileName);
                formatter.Serialize(stream, PeriodManager.GetPeriods());
                stream.Close();
            }
        }
        /// <summary>
        /// Get species fact with the same, Taxon, IndividualCategory,
        /// Host and Period as this species fact but with
        /// another factor.
        /// </summary>
        /// <param name="speciesFacts">
        /// List of species facts from where the requested
        /// species are fetched.
        /// </param>
        /// <param name="factor">Factor to use in species fact identifier.</param>
        /// <returns>Requested species fact.</returns>
        protected SpeciesFact GetSpeciesFact(SpeciesFactList speciesFacts,
                                             Factor factor)
        {
            Int32  hostId = 0, periodId = 0;
            String speciesFactIdentifier;

            if (HasHost)
            {
                hostId = Host.Id;
            }
            if (HasPeriod)
            {
                periodId = Period.Id;
            }
            speciesFactIdentifier = SpeciesFactManager.GetSpeciesFactIdentifier(Taxon.Id,
                                                                                IndividualCategory.Id,
                                                                                factor.Id,
                                                                                HasHost,
                                                                                hostId,
                                                                                HasPeriod && factor.IsPeriodic,
                                                                                periodId);
            return(speciesFacts.Get(speciesFactIdentifier));
        }
        /// <summary>
        /// Creates a species fact instance with no data from web service.
        /// </summary>
        /// <param name="taxon">Taxon object of the species fact</param>
        /// <param name="individualCategory">Individual category object of the species fact</param>
        /// <param name="factor">Factor object of the species fact</param>
        /// <param name="host">Host taxon object of the species fact</param>
        /// <param name="period">Period object of the species fact</param>
        public SpeciesFact(
            Taxon taxon,
            IndividualCategory individualCategory,
            Factor factor,
            Taxon host,
            Period period)
            : base(-1, -1)
        {
            Int32 fieldIndex;

            _fields            = null;
            _substantialFields = null;
            _mainField         = null;
            _hasId             = false;

            _identifier = SpeciesFactManager.GetSpeciesFactIdentifier(
                taxon,
                individualCategory,
                factor,
                host,
                period);

            _taxon = taxon;
            _individualCategory = individualCategory;
            _factor             = factor;
            _host               = host;
            _hasHost            = _host.IsNotNull();
            _period             = period;
            _hasPeriod          = _period.IsNotNull();
            _quality            = SpeciesFactManager.GetDefaultSpeciesFactQuality();
            _oldQuality         = _quality;
            _reference          = null;
            _oldReference       = null;
            _updateUserFullName = null;
            _updateDate         = DateTime.MinValue;
            _hasUpdateDate      = false;

            if (!_factor.FactorUpdateMode.IsHeader)
            {
                _fields            = new SpeciesFactFieldList();
                _substantialFields = new SpeciesFactFieldList();
                _fieldArray        = new SpeciesFactField[FactorManager.GetFactorFieldMaxCount()];
                for (fieldIndex = 0; fieldIndex < FactorManager.GetFactorFieldMaxCount(); fieldIndex++)
                {
                    _fieldArray[fieldIndex] = null;
                }

                foreach (FactorField factorField in _factor.FactorDataType.Fields)
                {
                    SpeciesFactField field;

                    field = new SpeciesFactField(this, factorField, false, null);
                    _fields.Add(field);
                    _fieldArray[field.Index] = field;

                    if (factorField.IsSubstantial)
                    {
                        _substantialFields.Add(field);
                    }

                    if (factorField.IsMain)
                    {
                        _mainField = field;
                    }
                }
            }
            _shouldBeSaved = AllowUpdate;
        }
        /// <summary>
        /// Creates a species fact instance with data from web service.
        /// </summary>
        /// <param name="id">Id of the species fact</param>
        /// <param name="sortOrder">Sort order of the species fact</param>
        /// <param name="taxon">Taxon of the species fact</param>
        /// <param name="individualCategoryId">Individual Category Id of the species fact</param>
        /// <param name="factorId">Foctor Id of the species fact</param>
        /// <param name="host">Host taxon associated with the species fact</param>
        /// <param name="hasHost">Indicates if this species fact has a host.</param>
        /// <param name="periodId">Period Id of the species fact</param>
        /// <param name="hasPeriod">Indicates if this species fact has a period.</param>
        /// <param name="fieldValue1">Field value of field 1 for the species fact</param>
        /// <param name="hasFieldValue1">Indicates if field 1 has a value.</param>
        /// <param name="fieldValue2">Field value of field 2 for the species fact</param>
        /// <param name="hasFieldValue2">Indicates if field 2 has a value.</param>
        /// <param name="fieldValue3">Field value of field 3 for the species fact</param>
        /// <param name="hasFieldValue3">Indicates if field 3 has a value.</param>
        /// <param name="fieldValue4">Field value of field 4 for the species fact</param>
        /// <param name="hasFieldValue4">Indicates if field 4 has a value.</param>
        /// <param name="fieldValue5">Field value of field 5 for the species fact</param>
        /// <param name="hasFieldValue5">Indicates if field 5 has a value.</param>
        /// <param name="qualityId">Quality Id of the species fact</param>
        /// <param name="referenceId">Reference id of the species fact</param>
        /// <param name="updateUserFullName">Full Name of the pdate user of the species fact</param>
        /// <param name="updateDate">Update date of the species fact</param>
        public SpeciesFact(
            Int32 id,
            Int32 sortOrder,
            Taxon taxon,
            Int32 individualCategoryId,
            Int32 factorId,
            Taxon host,
            Boolean hasHost,
            Int32 periodId,
            Boolean hasPeriod,
            Double fieldValue1,
            Boolean hasFieldValue1,
            Double fieldValue2,
            Boolean hasFieldValue2,
            Double fieldValue3,
            Boolean hasFieldValue3,
            String fieldValue4,
            Boolean hasFieldValue4,
            String fieldValue5,
            Boolean hasFieldValue5,
            Int32 qualityId,
            Int32 referenceId,
            String updateUserFullName,
            DateTime updateDate)
            : base(id, sortOrder)
        {
            Int32 hostId;
            Int32 fieldIndex;

            _fields            = null;
            _substantialFields = null;
            _mainField         = null;
            _hasId             = true;
            hostId             = 0;
            if (hasHost)
            {
                hostId = host.Id;
            }

            _identifier = SpeciesFactManager.GetSpeciesFactIdentifier(
                taxon.Id,
                individualCategoryId,
                factorId,
                hasHost,
                hostId,
                hasPeriod,
                periodId);

            _taxon = taxon;
            _individualCategory = IndividualCategoryManager.GetIndividualCategory(individualCategoryId);
            _factor             = FactorManager.GetFactor(factorId);

            if (hasHost)
            {
                _host    = host;
                _hasHost = hasHost;
            }
            else
            {
                if (_factor.IsTaxonomic)
                {
                    _host = TaxonManager.GetTaxon(0, TaxonInformationType.Basic);
                }
                else
                {
                    _host = null;
                }
                _hasHost = _host.IsNotNull();
            }



            if (hasPeriod)
            {
                _period = PeriodManager.GetPeriod(periodId);
            }
            else
            {
                _period = null;
            }
            _hasPeriod = hasPeriod;

            _quality            = SpeciesFactManager.GetSpeciesFactQuality(qualityId);
            _oldQuality         = _quality;
            _reference          = ReferenceManager.GetReference(referenceId);
            _oldReference       = _reference;
            _updateUserFullName = updateUserFullName;
            _updateDate         = updateDate;
            _hasUpdateDate      = true;

            if (!_factor.FactorUpdateMode.IsHeader)
            {
                _fields            = new SpeciesFactFieldList();
                _substantialFields = new SpeciesFactFieldList();
                _fieldArray        = new SpeciesFactField[FactorManager.GetFactorFieldMaxCount()];
                for (fieldIndex = 0; fieldIndex < FactorManager.GetFactorFieldMaxCount(); fieldIndex++)
                {
                    _fieldArray[fieldIndex] = null;
                }

                foreach (FactorField factorField in _factor.FactorDataType.Fields)
                {
                    Boolean          hasFieldValue;
                    SpeciesFactField field;
                    Object           fieldValue;

                    switch (factorField.Index)
                    {
                    case 0:
                        fieldValue    = fieldValue1;
                        hasFieldValue = hasFieldValue1;
                        break;

                    case 1:
                        fieldValue    = fieldValue2;
                        hasFieldValue = hasFieldValue2;
                        break;

                    case 2:
                        fieldValue    = fieldValue3;
                        hasFieldValue = hasFieldValue3;
                        break;

                    case 3:
                        fieldValue    = fieldValue4;
                        hasFieldValue = hasFieldValue4;
                        break;

                    case 4:
                        fieldValue    = fieldValue5;
                        hasFieldValue = hasFieldValue5;
                        break;

                    default:
                        throw new Exception("Unknown data field!");
                    }

                    field = new SpeciesFactField(this, factorField, hasFieldValue, fieldValue);
                    _fields.Add(field);
                    _fieldArray[field.Index] = field;

                    if (factorField.IsSubstantial)
                    {
                        _substantialFields.Add(field);
                    }

                    if (factorField.IsMain)
                    {
                        _mainField = field;
                    }
                }
            }
            _shouldBeSaved = AllowUpdate;
        }
        public void UpdateDyntaxaSpeciesFacts()
        {
            DateTime oldUpdateDate;
            Double   doubleValue;
            Int32    oldReferenceId, oldQualityId;
            List <WebSpeciesFact> oldSpeciesFacts;
            List <WebSpeciesFact> speciesFacts;
            String         oldUpdateUser;
            String         stringValue;
            WebReference   reference;
            WebSpeciesFact speciesFact;

            // Delete species facts.
            oldSpeciesFacts = GetSomeSpeciesFacts(GetContext());
            oldUpdateUser   = oldSpeciesFacts[0].UpdateUserFullName;
            Assert.IsTrue(oldSpeciesFacts.IsNotEmpty());
            SpeciesFactManager.UpdateDyntaxaSpeciesFacts(GetContext(), null, oldSpeciesFacts, null, "Dyntaxa Test");
            speciesFacts = GetSomeSpeciesFacts(GetContext());
            Assert.IsTrue(speciesFacts.IsEmpty());

            // Create species facts.
            SpeciesFactManager.UpdateDyntaxaSpeciesFacts(GetContext(), oldSpeciesFacts, null, null, "Dyntaxa Test");
            speciesFacts = GetSomeSpeciesFacts(GetContext());
            Assert.IsTrue(speciesFacts.IsNotEmpty());
            Assert.AreEqual(oldSpeciesFacts.Count, speciesFacts.Count);

            // Test change of reference id.
            speciesFact             = GetOneSpeciesFact(GetContext());
            oldReferenceId          = speciesFact.ReferenceId;
            reference               = ReferenceManager.GetReferences(GetContext())[3];
            speciesFact.ReferenceId = reference.Id;
            UpdateDyntaxaSpeciesFacts(speciesFact);
            speciesFact = GetSpeciesFact(speciesFact);
            Assert.AreNotEqual(oldReferenceId, speciesFact.ReferenceId);
            Assert.AreEqual(reference.Id, speciesFact.ReferenceId);

            // Test change of update date.
            oldUpdateDate = speciesFact.UpdateDate;
            Thread.Sleep(200);
            UpdateDyntaxaSpeciesFacts(speciesFact);
            speciesFact = GetSpeciesFact(speciesFact);
            Assert.IsTrue(oldUpdateDate <= speciesFact.UpdateDate);

            // Test change of update user.
            Assert.AreNotEqual(oldUpdateUser, speciesFact.UpdateUserFullName);

            // Test change of field values.
            doubleValue                        = 4324;
            speciesFact.FieldValue1            = doubleValue;
            speciesFact.IsFieldValue1Specified = true;
            UpdateDyntaxaSpeciesFacts(speciesFact);
            speciesFact = GetSpeciesFact(speciesFact);
            Assert.IsTrue(speciesFact.IsFieldValue1Specified);
            Assert.AreEqual(doubleValue, speciesFact.FieldValue1);

            doubleValue                       *= Math.PI;
            speciesFact.FieldValue2            = doubleValue;
            speciesFact.IsFieldValue2Specified = true;
            UpdateDyntaxaSpeciesFacts(speciesFact);
            speciesFact = GetSpeciesFact(speciesFact);
            Assert.IsTrue(speciesFact.IsFieldValue2Specified);
            Assert.IsTrue((doubleValue - speciesFact.FieldValue2) < 0.0001);

            doubleValue                       *= Math.PI;
            speciesFact.FieldValue3            = doubleValue;
            speciesFact.IsFieldValue3Specified = true;
            UpdateDyntaxaSpeciesFacts(speciesFact);
            speciesFact = GetSpeciesFact(speciesFact);
            Assert.IsTrue(speciesFact.IsFieldValue3Specified);
            Assert.IsTrue((doubleValue - speciesFact.FieldValue3) < 0.0001);

            stringValue                        = null;
            speciesFact.FieldValue4            = stringValue;
            speciesFact.IsFieldValue4Specified = false;
            UpdateDyntaxaSpeciesFacts(speciesFact);
            speciesFact = GetSpeciesFact(speciesFact);
            Assert.IsFalse(speciesFact.IsFieldValue4Specified);
            Assert.IsNull(speciesFact.FieldValue4);
            stringValue                        = "testing time";
            speciesFact.FieldValue4            = stringValue;
            speciesFact.IsFieldValue4Specified = true;
            UpdateDyntaxaSpeciesFacts(speciesFact);
            speciesFact = GetSpeciesFact(speciesFact);
            Assert.IsTrue(speciesFact.IsFieldValue4Specified);
            Assert.AreEqual(stringValue, speciesFact.FieldValue4);

            stringValue                        = null;
            speciesFact.FieldValue5            = stringValue;
            speciesFact.IsFieldValue5Specified = false;
            UpdateDyntaxaSpeciesFacts(speciesFact);
            speciesFact = GetSpeciesFact(speciesFact);
            Assert.IsFalse(speciesFact.IsFieldValue5Specified);
            Assert.IsNull(speciesFact.FieldValue5);
            stringValue                        = "testing time";
            speciesFact.FieldValue5            = stringValue;
            speciesFact.IsFieldValue5Specified = true;
            UpdateDyntaxaSpeciesFacts(speciesFact);
            speciesFact = GetSpeciesFact(speciesFact);
            Assert.IsTrue(speciesFact.IsFieldValue5Specified);
            Assert.AreEqual(stringValue, speciesFact.FieldValue5);

            // Test change of quality.
            oldQualityId           = speciesFact.QualityId;
            speciesFact.QualityId += 1;
            UpdateDyntaxaSpeciesFacts(speciesFact);
            speciesFact = GetSpeciesFact(speciesFact);
            Assert.AreNotEqual(oldQualityId, speciesFact.QualityId);
            Assert.AreEqual(oldQualityId + 1, speciesFact.QualityId);
        }
 public SpeciesFactManagerTest()
 {
     _speciesFactManager = null;
 }