示例#1
0
        /// <summary>
        /// Update species facts in RAM memory
        /// with latest information from data source.
        /// This method works on species facts both with and without id.
        /// </summary>
        /// <param name="userContext">
        /// Information about the user that makes this method call.
        /// </param>
        /// <param name="speciesFacts">Species facts to update.</param>
        public virtual void UpdateSpeciesFacts(IUserContext userContext,
                                               SpeciesFactList speciesFacts)
        {
            SpeciesFactList speciesFactsFromDataSource,
                            updatedSpeciesFacts;

            // Get updated data from web service.
            speciesFactsFromDataSource = GetSpeciesFacts(userContext, speciesFacts);

            // Update species facts.
            updatedSpeciesFacts = new SpeciesFactList();
            if (speciesFactsFromDataSource.IsNotEmpty())
            {
                foreach (ISpeciesFact speciesFactFromDataSource in speciesFactsFromDataSource)
                {
                    // Get species fact.
                    ISpeciesFact speciesFact = speciesFacts.Get(speciesFactFromDataSource.Identifier);

                    // Update species fact.
                    speciesFact.Update(speciesFactFromDataSource.Id,
                                       speciesFactFromDataSource.Reference,
                                       speciesFactFromDataSource.ModifiedDate,
                                       speciesFactFromDataSource.ModifiedBy,
                                       speciesFactFromDataSource.HasField1,
                                       speciesFactFromDataSource.HasField1 ? speciesFactFromDataSource.Field1.GetDoubleValue() : 0,
                                       speciesFactFromDataSource.HasField2,
                                       speciesFactFromDataSource.HasField2 ? speciesFactFromDataSource.Field2.GetDoubleValue() : 0,
                                       speciesFactFromDataSource.HasField3,
                                       speciesFactFromDataSource.HasField3 ? speciesFactFromDataSource.Field3.GetDoubleValue() : 0,
                                       speciesFactFromDataSource.HasField4,
                                       speciesFactFromDataSource.HasField4 ? speciesFactFromDataSource.Field4.GetStringValue() : null,
                                       speciesFactFromDataSource.HasField5,
                                       speciesFactFromDataSource.HasField5 ? speciesFactFromDataSource.Field5.GetStringValue() : null,
                                       speciesFactFromDataSource.Quality);
                    updatedSpeciesFacts.Add(speciesFact);
                }
            }

            // Update species facts that has been deleted.
            foreach (ISpeciesFact speciesFact in speciesFacts)
            {
                if (speciesFact.HasId &&
                    !updatedSpeciesFacts.Exists(speciesFact.Identifier))
                {
                    speciesFact.Reset(userContext);
                }
            }
        }