Exemple #1
0
        public void LoadData()
        {
            WebDataField dataField;

            using (DataReader dataReader = GetContext().GetDatabase().GetLog(null, null, 10))
            {
                if (dataReader.Read() && dataReader.NextUnreadColumn())
                {
                    do
                    {
                        dataField = new WebDataField();
                        dataField.LoadData(dataReader);
                        Assert.IsNotNull(dataField);
                        Assert.IsTrue(dataField.Name.IsNotEmpty());
                    }while (dataReader.NextUnreadColumn());
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Get information about species observations that has changed.
        /// The service contains observations that are aggregated and has start
        /// and end dates that are set to the first and last day of every month.
        /// </summary>
        /// <param name="changedFrom">Start date for changes.</param>
        /// <param name="changedTo">End date for changes.</param>
        /// <param name="mappings">The mappings.</param>
        /// <param name="context">Web service context.</param>
        /// <param name="connectorServer">The connector server.</param>
        /// <returns>
        /// Returns true if there are more species
        /// observations to retrieve for current date.
        /// </returns>
        public Boolean GetSpeciesObservationChange(DateTime changedFrom,
                                                   DateTime changedTo,
                                                   List <HarvestMapping> mappings,
                                                   WebServiceContext context,
                                                   IConnectorServer connectorServer)
        {
            Dictionary <String, WebSpeciesObservation> updatedSpeciesObservations;
            SpeciesObservationChange speciesObservationChange = new SpeciesObservationChange();

            speciesObservationChange.CreatedSpeciesObservations = new List <HarvestSpeciesObservation>();

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            WramProcess wramProcess = new WramProcess();
            WebSpeciesObservationDataProvider dataProvider = GetSpeciesObservationDataProvider(context);
            WebSpeciesObservationChange       webSpeciesObservationChange = WebServiceProxy.WramService.GetSpeciesObservationChangeAsSpecies(DateTime.Now,
                                                                                                                                             false,
                                                                                                                                             DateTime.Now,
                                                                                                                                             false,
                                                                                                                                             dataProvider.MaxChangeId,
                                                                                                                                             true,
                                                                                                                                             Settings.Default.MaxSpeciesObservationsFromWram);

            // Run all created and updated together as one list.
            updatedSpeciesObservations = new Dictionary <String, WebSpeciesObservation>();
            AddSpeciesObservations(updatedSpeciesObservations, webSpeciesObservationChange.UpdatedSpeciesObservations);
            AddSpeciesObservations(updatedSpeciesObservations, webSpeciesObservationChange.CreatedSpeciesObservations);
            List <WebSpeciesObservation> createdAndUpdatedObservations = new List <WebSpeciesObservation>();

            createdAndUpdatedObservations.AddRange(updatedSpeciesObservations.Values);

            // Handle created and updated species observations.
            int noOfCreated = 0, noOfCreatedErrors = 0;

            if (createdAndUpdatedObservations.IsNotEmpty())
            {
                foreach (WebSpeciesObservation wramSpeciesObservation in createdAndUpdatedObservations)
                {
                    WebData webData = new WebData {
                        DataFields = new List <WebDataField>()
                    };
                    foreach (WebSpeciesObservationField webSpeciesObservationField in wramSpeciesObservation.Fields)
                    {
                        WebDataField webDataField = new WebDataField();
                        webDataField.LoadData(webSpeciesObservationField);
                        webData.DataFields.Add(webDataField);
                    }

                    // Map and add webdata to the 'created collection'
                    speciesObservationChange.CreatedSpeciesObservations.Add(wramProcess.ProcessObservation(webData, mappings, context));
                }

                connectorServer.UpdateSpeciesObservations(context, speciesObservationChange.CreatedSpeciesObservations, dataProvider, out noOfCreated, out noOfCreatedErrors);
            }

            // Handle deleted species observtions.
            int noOfDeleted = 0, noOfDeletedErrors = 0;

            speciesObservationChange.DeletedSpeciesObservationGuids = new List <String>();

            if (webSpeciesObservationChange.DeletedSpeciesObservationGuids.IsNotEmpty())
            {
                foreach (String wramSpeciesObservation in webSpeciesObservationChange.DeletedSpeciesObservationGuids)
                {
                    String id = wramSpeciesObservation.Substring(wramSpeciesObservation.LastIndexOf(':') + 1);
                    speciesObservationChange.DeletedSpeciesObservationGuids.Add(id);
                }

                connectorServer.DeleteSpeciesObservations(context, speciesObservationChange.DeletedSpeciesObservationGuids, dataProvider, out noOfDeleted, out noOfDeletedErrors);
            }

            Debug.WriteLine(webSpeciesObservationChange.MaxChangeId + " : count created: " + noOfCreated);

            context.GetSpeciesObservationDatabase().LogHarvestRead(
                context,
                dataProvider,
                changedFrom,
                changedTo,
                stopwatch.ElapsedMilliseconds,
                noOfCreated,
                noOfCreatedErrors,
                0,
                0,
                noOfDeleted,
                noOfDeletedErrors,
                webSpeciesObservationChange.MaxChangeId);
            stopwatch.Stop();

            if (webSpeciesObservationChange.MaxChangeId > 0)
            {
//                context.GetSpeciesObservationDatabase().SetMaxChangeId(dataProvider.Id, webSpeciesObservationChange.MaxChangeId);

                // Testing if WRAM has a problem with handling of change id.
                context.GetSpeciesObservationDatabase().SetMaxChangeId(dataProvider.Id, webSpeciesObservationChange.MaxChangeId - 1);
            }
            // else: No changes was retrieved. There are no more changes available right now.

            return(false);
        }
Exemple #3
0
        /// <summary>
        /// Get information about species observations that has changed.
        /// The service contains observations that are aggregated and has start
        /// and end dates that are set to the first and last day of every month.
        /// </summary>
        /// <param name="changedFrom">Start date for changes.</param>
        /// <param name="changedTo">End date for changes.</param>
        /// <param name="mappings">The mappings.</param>
        /// <param name="context">Web service context.</param>
        /// <param name="connectorServer">The connector server.</param>
        /// <returns>
        /// Returns true if there are more species
        /// observations to retrieve for current date.
        /// </returns>
        public Boolean GetSpeciesObservationChange(DateTime changedFrom,
                                                   DateTime changedTo,
                                                   List <HarvestMapping> mappings,
                                                   WebServiceContext context,
                                                   IConnectorServer connectorServer)
        {
            Dictionary <String, WebSpeciesObservation> updatedSpeciesObservations;
            Int32 minutes;
            Int64 maxChangeId;

            // Wait for MVM service to be ready for use.
            for (minutes = 0; minutes < 60; minutes++)
            {
                if (WebServiceProxy.MvmService.IsReadyToUse())
                {
                    break;
                }
                else
                {
                    // Wait one minute for MVM service to be ready for use.
                    Thread.Sleep(60000);
                }
            }

            if ((minutes == 60) && !(WebServiceProxy.MvmService.IsReadyToUse()))
            {
                // Can not wait any longer for MVM service to be ready.
                return(false);
            }

            SpeciesObservationChange speciesObservationChange = new SpeciesObservationChange();

            speciesObservationChange.CreatedSpeciesObservations = new List <HarvestSpeciesObservation>();
            WebSpeciesObservationChange webSpeciesObservationChange;

            webSpeciesObservationChange = new WebSpeciesObservationChange();
            webSpeciesObservationChange.CreatedSpeciesObservations     = new List <WebSpeciesObservation>();
            webSpeciesObservationChange.DeletedSpeciesObservationGuids = new List <String>();
            webSpeciesObservationChange.UpdatedSpeciesObservations     = new List <WebSpeciesObservation>();

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            MvmProcess mvmProcess = new MvmProcess();
            WebSpeciesObservationDataProvider dataProvider = GetSpeciesObservationDataProvider(context);

            maxChangeId = dataProvider.MaxChangeId;
            for (Int32 index = 0; index < 10; index++)
            {
                WebSpeciesObservationChange webSpeciesObservationChangeTemp = WebServiceProxy.MvmService.GetSpeciesObservationChangeAsSpecies(DateTime.Now,
                                                                                                                                              false,
                                                                                                                                              DateTime.Now,
                                                                                                                                              false,
                                                                                                                                              maxChangeId,
                                                                                                                                              true,
                                                                                                                                              Settings.Default.MaxSpeciesObservationsFromMvm);
                if (webSpeciesObservationChangeTemp.CreatedSpeciesObservations.IsNotEmpty())
                {
                    webSpeciesObservationChange.CreatedSpeciesObservations.AddRange(webSpeciesObservationChangeTemp.CreatedSpeciesObservations);
                }

                if (webSpeciesObservationChangeTemp.DeletedSpeciesObservationGuids.IsNotEmpty())
                {
                    webSpeciesObservationChange.DeletedSpeciesObservationGuids.AddRange(webSpeciesObservationChangeTemp.DeletedSpeciesObservationGuids);
                }

                if (webSpeciesObservationChangeTemp.UpdatedSpeciesObservations.IsNotEmpty())
                {
                    webSpeciesObservationChange.UpdatedSpeciesObservations.AddRange(webSpeciesObservationChangeTemp.UpdatedSpeciesObservations);
                }

                if (maxChangeId < webSpeciesObservationChangeTemp.MaxChangeId)
                {
                    maxChangeId = webSpeciesObservationChangeTemp.MaxChangeId;
                }
                else
                {
                    // No more species observation changes are available.
                    break;
                }
            }

            // Run all created and updated together as one list.
            updatedSpeciesObservations = new Dictionary <String, WebSpeciesObservation>();
            AddSpeciesObservations(updatedSpeciesObservations, webSpeciesObservationChange.UpdatedSpeciesObservations);
            AddSpeciesObservations(updatedSpeciesObservations, webSpeciesObservationChange.CreatedSpeciesObservations);
            List <WebSpeciesObservation> createdAndUpdatedObservations = new List <WebSpeciesObservation>();

            createdAndUpdatedObservations.AddRange(updatedSpeciesObservations.Values);

            // Handle created and updated species observations.
            int noOfCreated = 0, noOfCreatedErrors = 0;

            if (createdAndUpdatedObservations.IsNotEmpty())
            {
                foreach (WebSpeciesObservation mvmSpeciesObservation in createdAndUpdatedObservations)
                {
                    WebData webData = new WebData {
                        DataFields = new List <WebDataField>()
                    };
                    foreach (WebSpeciesObservationField webSpeciesObservationField in mvmSpeciesObservation.Fields)
                    {
                        WebDataField webDataField = new WebDataField();
                        webDataField.LoadData(webSpeciesObservationField);
                        webData.DataFields.Add(webDataField);
                    }

                    // Map and add webdata to the 'created collection'
                    speciesObservationChange.CreatedSpeciesObservations.Add(mvmProcess.ProcessObservation(webData, mappings, context));
                }

                connectorServer.UpdateSpeciesObservations(context, speciesObservationChange.CreatedSpeciesObservations, dataProvider, out noOfCreated, out noOfCreatedErrors);
            }

            // Handle deleted species observtions.
            int noOfDeleted = 0, noOfDeletedErrors = 0;

            speciesObservationChange.DeletedSpeciesObservationGuids = new List <String>();

            if (webSpeciesObservationChange.DeletedSpeciesObservationGuids.IsNotEmpty())
            {
                foreach (String mvmSpeciesObservation in webSpeciesObservationChange.DeletedSpeciesObservationGuids)
                {
                    String id = mvmSpeciesObservation.Substring(mvmSpeciesObservation.LastIndexOf(':') + 1);
                    speciesObservationChange.DeletedSpeciesObservationGuids.Add(id);
                }

                connectorServer.DeleteSpeciesObservations(context, speciesObservationChange.DeletedSpeciesObservationGuids, dataProvider, out noOfDeleted, out noOfDeletedErrors);
            }

            Debug.WriteLine(maxChangeId + " : count created: " + noOfCreated);

            context.GetSpeciesObservationDatabase().LogHarvestRead(
                context,
                dataProvider,
                changedFrom,
                changedTo,
                stopwatch.ElapsedMilliseconds,
                noOfCreated,
                noOfCreatedErrors,
                0,
                0,
                noOfDeleted,
                noOfDeletedErrors,
                maxChangeId);
            stopwatch.Stop();

            if (maxChangeId > 0)
            {
                context.GetSpeciesObservationDatabase().SetMaxChangeId(dataProvider.Id, maxChangeId);
            }
            // else: No changes was retrieved. There are no more changes available right now.

            return(false);
        }