Esempio n. 1
0
        public void CanReadDataServices()
        {
            //DbOperations dbTools = new DbOperations(Config.DefaultLocalCacheConnection(), DatabaseTypes.SQLite);

            MetadataCacheManagerSQL manager  = new MetadataCacheManagerSQL(DatabaseTypes.SQLite, TestConfig.DefaultLocalCacheConnection);
            IList <DataServiceInfo> services = manager.GetAllServices();
        }
Esempio n. 2
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);
            }
        }
        public static bool CacheHasServiceUrl(string serviceUrl)
        {
            // Trim the query off of the URL
            serviceUrl = serviceUrl.Trim().ToLower();
            int index = serviceUrl.IndexOf("?");

            if (index > -1)
            {
                serviceUrl = serviceUrl.Substring(0, index);
            }

            // Get the services from the metadata cache database
            MetadataCacheManagerSQL cacheManager = GetCacheManager();
            List <DataServiceInfo>  serviceList  = cacheManager.GetAllServices() as List <DataServiceInfo>;

            // Compare service URLs
            foreach (DataServiceInfo serviceInfo in serviceList)
            {
                string existingUrl = serviceInfo.EndpointURL.ToLower().Trim();

                index = existingUrl.IndexOf("?");
                if (index > -1)
                {
                    // Trim the query off of the URL
                    existingUrl = existingUrl.Substring(0, index);
                }

                if (serviceUrl == existingUrl)
                {
                    return(true);
                }
            }

            return(false);
        }
        /// <summary>
        /// Builds a list of Service Endpoint URLs from the metadata cache database
        /// </summary>
        /// <param name="trimUrlParameters">true if parameters (e.g., "?WSDL") should be trimmed from the URLs before adding to the output</param>
        /// <returns>List of Service Endpoint URLs from the metadata cache database</returns>
        public static List <string> GetCacheServiceUrls(bool trimUrlParameters)
        {
            List <string> urls = new List <string> ();

            MetadataCacheManagerSQL cacheManager = GetCacheManager();

            List <DataServiceInfo> serviceList = cacheManager.GetAllServices() as List <DataServiceInfo>;

            foreach (DataServiceInfo serviceInfo in serviceList)
            {
                string url = serviceInfo.EndpointURL.Trim();

                if (trimUrlParameters == true)
                {
                    int index = url.IndexOf("?");
                    if (index > -1)
                    {
                        url = url.Substring(0, index);
                    }
                }

                urls.Add(url);
            }

            return(urls);
        }
Esempio n. 5
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");
        }
Esempio n. 6
0
        public void CanDeleteRecordsForService()
        {
            MetadataCacheManagerSQL manager = TestConfig.MetadataCacheManager;

            IList <DataServiceInfo> services = manager.GetAllServices();

            foreach (DataServiceInfo serv in services)
            {
                int numDeleted = manager.DeleteRecordsForService(serv, false);
            }
        }
Esempio n. 7
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);
        }
        public static DataServiceInfo GetDataServiceFromCache(string serviceUrl)
        {
            // Trim the query off of the URL
            string trimmedServiceUrl = serviceUrl.Trim().ToLower();
            int    index             = trimmedServiceUrl.IndexOf("?");

            if (index > -1)
            {
                trimmedServiceUrl = trimmedServiceUrl.Substring(0, index);
            }

            // Get the services from the metadata cache database
            MetadataCacheManagerSQL cacheManager = GetCacheManager();
            List <DataServiceInfo>  serviceList  = cacheManager.GetAllServices() as List <DataServiceInfo>;

            // Compare service URLs
            foreach (DataServiceInfo serviceInfo in serviceList)
            {
                string existingUrl = serviceInfo.EndpointURL.ToLower().Trim();

                // Trim the query off of the URL
                index = existingUrl.IndexOf("?");
                if (index > -1)
                {
                    existingUrl = existingUrl.Substring(0, index);
                }

                if (trimmedServiceUrl == existingUrl)
                {
                    return(serviceInfo);
                }
            }

            // If we made it this far, a matching service wasn't found
            throw new Exception("Matching data service record not found for given service URL: " + serviceUrl);
        }
Esempio n. 9
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);
        }
Esempio n. 10
0
 public MetadataCacheSearcher()
 {
     _db = new MetadataCacheManagerSQL(DatabaseTypes.SQLite, HydroDesktop.Configuration.Settings.Instance.MetadataCacheConnectionString);
 }
 public MetadataCacheSearcher()
 {
     _db = new MetadataCacheManagerSQL(DatabaseTypes.SQLite, HydroDesktop.Configuration.Settings.Instance.MetadataCacheConnectionString);
 }