Example #1
0
        /// <summary>
        ///     Gets all of the sensor networks in NRDC. Populates the Data and Infrastructure Url dictionaries.
        /// </summary>
        /// <returns>A Network Container with either the list of all networks in a list or a failure message</returns>
        public static Container <Network> GetNetworkList()
        {
            string uri         = Config.NetworkDiscoveryUrl;
            string message     = GetHttpContent(uri);
            var    networkList = JsonConvert.DeserializeObject <Container <Network> >(message, Config.DefaultDeserializationSettings);

            if (networkList.Success)
            {
                // Populate dictionaries with network Urls
                DataUrlDict.Clear();
                InfrastructureUrlDict.Clear();
                foreach (var network in networkList.Data)
                {
                    network.DataUrl                      = network.DataUrl.Replace("sensor.nevada.edu", "134.197.38.160");
                    network.InfrastructureUrl            = network.InfrastructureUrl.Replace("sensor.nevada.edu", "134.197.38.160");
                    DataUrlDict[network.Alias]           = network.DataUrl;
                    InfrastructureUrlDict[network.Alias] = network.InfrastructureUrl;
                }
                return(networkList);
            }
            else
            {
                return(new Container <Network>("Unable to retrieve network list. Message from API: " + networkList.Message));
            }
        }
Example #2
0
        /// <summary>
        ///     Returns the Infrastructure Url for the specified sensor network. Returns empty string if no Url was found.
        /// </summary>
        /// <param name="networkAlias"></param>
        /// <returns>String container with the URL or an error message</returns>
        private static Container <string> GetInfrastructureUrl(string networkAlias)
        {
            string infrastructureUrl;

            // Check for url in dictionary
            if (!InfrastructureUrlDict.TryGetValue(networkAlias, out infrastructureUrl))
            {
                // Couldn't find in dictionary, call GetNetworks to populate dictionaries and try again
                var networkList = GetNetworkList();
                if (networkList.Success)
                {
                    // Try the dictionary again
                    if (InfrastructureUrlDict.TryGetValue(networkAlias, out infrastructureUrl))
                    {
                        return(new Container <string>(infrastructureUrl, true));
                    }
                }
                // Still couldn't find url, return empty string
                return(new Container <string>("Couldn't find Infrastructure Services Url for Sensor Network: " + networkAlias));
            }
            // Url was in dictionary
            return(new Container <string>(infrastructureUrl, true));
        }