예제 #1
0
        public void CanSaveMultipleSeries()
        {
            Random random = new Random();
            //string url1 = @"http://his02.usu.edu/littlebearriver/cuahsi_1_0.asmx";
            //string url2 = @"http://icewater.boisestate.edu/dcew2dataservices/cuahsi_1_0.asmx";
            string url3 = @"http://his.crwr.utexas.edu/TXEvap/cuahsi_1_0.asmx";

            MetadataCacheManagerSQL manager = TestConfig.MetadataCacheManager;

            WaterOneFlowClient client = new WaterOneFlowClient(url3);

            IList <Site> siteList = client.GetSites();

            IList <SeriesMetadata> seriesList = new List <SeriesMetadata>();

            DataServiceInfo service = GeDatatService(random.Next());

            manager.SaveDataService(service);

            foreach (Site site in siteList)
            {
                IList <SeriesMetadata> seriesList1 = client.GetSiteInfo(site.Code);
                foreach (SeriesMetadata series in seriesList1)
                {
                    seriesList.Add(series);
                }
            }

            foreach (SeriesMetadata series in seriesList)
            {
                manager.SaveSeries(series, service);
            }
        }
예제 #2
0
        public void CanSaveDataService()
        {
            Random          random  = new Random();
            DataServiceInfo service = GeDatatService(random.Next());

            MetadataCacheManagerSQL manager = TestConfig.MetadataCacheManager;

            manager.SaveDataService(service);

            //Assert.Greater(service.Id, 0, "the id of saved service should be > 0");
        }
예제 #3
0
        public void CanSaveOneSeries()
        {
            Random random = new Random();
            string url    = @"http://his.crwr.utexas.edu/TXEvap/cuahsi_1_0.asmx";

            MetadataCacheManagerSQL manager = TestConfig.MetadataCacheManager;

            WaterOneFlowClient client = new WaterOneFlowClient(url);

            IList <Site> sites = client.GetSites();

            IList <SeriesMetadata> seriesList = client.GetSiteInfo(sites[0].Code);

            SeriesMetadata firstSeries = seriesList[0];

            DataServiceInfo service = GeDatatService(random.Next());

            manager.SaveDataService(service);

            firstSeries.DataService = service;

            manager.SaveSeries(firstSeries, service);
        }
예제 #4
0
        /// <summary>
        /// For each service described in the data grid view, adds records to the metadata cache database to describe the service
        /// </summary>
        /// <param name="servicesToAdd">List of services to add to the metadata cache database</param>
        /// <param name="e">Parameters from the BackgroundWorker</param>
        /// <returns>Parameters (task type, output message, rows that were successfully added) to be processed by a BackgroundWorker event handler</returns>
        private object[] AddServicesToDatabase(List <DataServiceInfo> servicesToAdd, DoWorkEventArgs e)
        {
            // Build parameters to pass to the background worker
            object[] parameters = new object[3];
            parameters[0] = BackgroundWorkerTasks.UpdateDatabase;
            parameters[1] = "Operation cancelled";

            List <int> rowsToSelect = new List <int> ();

            bgwMain.ReportProgress(0, "Getting list of existing WaterOneFlow services from database...");

            // Get a list of existing URLs from the metadata cache databsae
            List <string> existingUrls = DatabaseOperations.GetCacheServiceUrls(true);

            // Add service records to the database
            int totalSteps          = servicesToAdd.Count;
            int currentStep         = 0;
            int countAlreadyExists  = 0;
            int countInvalidService = 0;

            IEqualityComparer <string> comparer = new CaseInsensitiveEqualityComparer();

            MetadataCacheManagerSQL cacheManager = DatabaseOperations.GetCacheManager();

            for (int i = 0; i < servicesToAdd.Count; i++)
            {
                if (bgwMain.CancellationPending)
                {
                    e.Cancel = true;
                    return(parameters);
                }

                currentStep++;
                bgwMain.ReportProgress(100 * currentStep / totalSteps, "Checking service " + currentStep + " of " + totalSteps + "...");

                DataServiceInfo serviceInfo = servicesToAdd[i];

                // Check if the service already exists in the database
                if (existingUrls.Contains(serviceInfo.EndpointURL, comparer) == true)
                {
                    countAlreadyExists += 1;
                    continue;
                }

                // Check that the URL is for a live service
                if (this.mnuCheckForValidService.Checked == true)
                {
                    // Attempt to create a WaterOneFlowServiceClient from the URL.  If the URL is not for a WaterOneFlow service, an error is thrown in the constructor.
                    try
                    {
                        WaterOneFlowClient waterOneFlowClient = new WaterOneFlowClient(serviceInfo.EndpointURL);
                        DataServiceInfo    clientServiceInfo  = waterOneFlowClient.ServiceInfo;

                        serviceInfo.ServiceName = clientServiceInfo.ServiceName;
                        serviceInfo.Protocol    = clientServiceInfo.Protocol;
                        serviceInfo.ServiceType = clientServiceInfo.ServiceType;
                        serviceInfo.Version     = clientServiceInfo.Version;
                    }
                    catch
                    {
                        countInvalidService += 1;
                        continue;
                    }
                }

                // Save the service
                cacheManager.SaveDataService(serviceInfo);

                existingUrls.Add(serviceInfo.EndpointURL);

                rowsToSelect.Add(i);
            }

            // Prepare a message to the user
            string message = "";

            int serviceCount = rowsToSelect.Count;

            if (serviceCount == 0)
            {
                message += "No new services added to metadata cache database.\n\n ";
            }
            else if (serviceCount == 1)
            {
                message += "1 new service added to metadata cache database.\n\n";
            }
            else
            {
                message += serviceCount.ToString() + " new services added to metadata cache database.\n\n";
            }

            if (countAlreadyExists == 1)
            {
                message += "1 service was not added because it already exists in the database.\n\n";
            }
            else if (countAlreadyExists > 1)
            {
                message += countAlreadyExists.ToString() + " services were not added because they already exist in the database.\n\n";
            }

            if (countInvalidService == 1)
            {
                message += "1 service was not added because it does not point to a valid WaterOneFlow service.\n\n";
            }
            else if (countInvalidService > 1)
            {
                message += countInvalidService.ToString() + " services were not added because they do not point to a valid WaterOneFlow service.\n\n";
            }

            if (serviceCount == 1)
            {
                message += "Remember to download metadata for this service in the Metadata Fetcher window.";
            }
            else if (serviceCount > 1)
            {
                message += "Remember to download metadata for these services in the Metadata Fetcher window.";
            }

            parameters[1] = message;
            parameters[2] = rowsToSelect;
            return(parameters);
        }