Exemplo n.º 1
0
        /// <summary>
        /// Return the geokey for a known region
        /// </summary>
        /// <param name="region">Known Api Region</param>
        /// <returns>Geo Key</returns>
        public string GetKnownRegionGeoKey(KnownApiRegion region)
        {
            var regionName = region.ToString().ToLowerInvariant();
            int index      = regionName.IndexOf("_", StringComparison.Ordinal);

            return(regionName.Substring(0, index));
        }
Exemplo n.º 2
0
        /// <summary>	Add host name to the known endpoints. </summary>
        /// <remarks>	Anthony, 4/24/2015. </remarks>
        /// <param name="vendor">	The Vendor. </param>
        /// <param name="region">	The Region. </param>
        /// <param name="apiUrl">	The API URL. </param>
        private void AddHostName(KnownApiVendor vendor, KnownApiRegion region, string apiUrl)
        {
            string key = string.Concat(vendor.ToString(), '-', region.ToString());

            KnownApiHostNames.Add(key, apiUrl);
            KnownVendorEndPointPairs.Add(new KeyValuePair <KnownApiVendor, KnownApiRegion>(vendor, region));
        }
		/// <summary>
		/// Initialises a new instance of the <see cref="ApiHostNotFoundException"/> class.
		/// </summary>
		/// <param name="info">
		/// The info.
		/// </param>
		/// <param name="context">
		/// The context.
		/// </param>
		/// <exception cref="ArgumentNullException">
		/// </exception>
		protected ApiHostNotFoundException(SerializationInfo info, StreamingContext context)
			: base(info, context)
		{
			if (info == null)
				throw new ArgumentNullException("info");

			Vendor = (KnownApiVendor)info.GetValue("Vendor", typeof(KnownApiVendor));
			Region = (KnownApiRegion)info.GetValue("Region", typeof(KnownApiRegion));
		}
Exemplo n.º 4
0
        /// <summary>
        /// The get ftp host.
        /// </summary>
        /// <param name="vendor">
        /// The vendor.
        /// </param>
        /// <param name="region">
        /// The region.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        /// <exception cref="ComputeApiException">
        /// </exception>
        public string GetFtpHost(KnownApiVendor vendor, KnownApiRegion region)
        {
            string key = string.Concat(vendor.ToString(), '-', region.ToString());

            if (!KnownApiHostNames.ContainsKey(key))
            {
                throw new ApiHostNotFoundException(vendor, region);
            }
            return(KnownFtpHostNames[key]);
        }
		/// <summary>
		/// Initialises a new instance of the <see cref="ComputeApiClient"/> class. 
		/// Creates a new CaaS API client using a known vendor and region.
		/// </summary>
		/// <param name="vendor">
		/// The vendor
		/// </param>
		/// <param name="region">
		/// The region
		/// </param>
		public ComputeApiClient(KnownApiVendor vendor, KnownApiRegion region)
		{
			Uri baseUri = KnownApiUri.Instance.GetBaseUri(vendor, region);
			_ftpHost = KnownApiUri.Instance.GetFtpHost(vendor, region);
			
			if (!baseUri.IsAbsoluteUri)
				throw new ArgumentException("Base URI supplied is not an absolute URI", "vendor");

			WebApi = new WebApi(baseUri);
		}
        /// <summary>
        /// Initialises a new instance of the <see cref="ApiHostNotFoundException"/> class.
        /// </summary>
        /// <param name="info">
        /// The info.
        /// </param>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// </exception>
        protected ApiHostNotFoundException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }

            Vendor = (KnownApiVendor)info.GetValue("Vendor", typeof(KnownApiVendor));
            Region = (KnownApiRegion)info.GetValue("Region", typeof(KnownApiRegion));
        }
Exemplo n.º 7
0
        /// <summary>
        /// The get Monitoring url.
        /// </summary>
        /// <param name="vendor">
        /// The vendor.
        /// </param>
        /// <param name="region">
        /// The region.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        /// <exception cref="ComputeApiException">
        /// </exception>
        public Uri GetMonitoringUrl(KnownApiVendor vendor, KnownApiRegion region)
        {
            const string urltemplate = "https://{0}/";
            string       key         = region.ToString();

            if (!KnownMonitoringHostNames.ContainsKey(key))
            {
                throw new ApiHostNotFoundException(vendor, region);
            }
            string apiurl = string.Format(urltemplate, KnownMonitoringHostNames[key]);

            return(new Uri(apiurl));
        }
		/// <summary>
		/// The get ftp host.
		/// </summary>
		/// <param name="vendor">
		/// The vendor.
		/// </param>
		/// <param name="region">
		/// The region.
		/// </param>
		/// <returns>
		/// The <see cref="string"/>.
		/// </returns>
		public static string GetFtpHost(KnownApiVendor vendor, KnownApiRegion region)
		{
			return KnownApiUri.Instance.GetFtpHost(vendor, region);
		}
 /// <summary>	Add host name to the known endpoints. </summary>
 /// <remarks>	Anthony, 4/24/2015. </remarks>
 /// <param name="vendor">	The Vendor. </param>
 /// <param name="region">	The Region. </param>
 /// <param name="apiUrl">	The API URL. </param>
 private void AddHostName(KnownApiVendor vendor, KnownApiRegion region, string apiUrl)
 {
     string key = string.Concat(vendor.ToString(), '-', region.ToString());
     KnownApiHostNames.Add(key, apiUrl);
     KnownVendorEndPointPairs.Add(new KeyValuePair<KnownApiVendor, KnownApiRegion>(vendor, region));
 }
		/// <summary>	The add ftp host name. </summary>
		/// <remarks>	Anthony, 4/24/2015. </remarks>
		/// <param name="vendor">	The vendor. </param>
		/// <param name="region">	The region. </param>
		/// <param name="apiUrl">	The API url. </param>
		private void AddFtpHostName(KnownApiVendor vendor, KnownApiRegion region, string apiUrl)
		{
			string key = string.Concat(vendor.ToString(), '-', region.ToString());
			KnownFtpHostNames.Add(key, apiUrl);
		}
        /// <summary>
        /// Return an known CaaS URI based on vendor and region
        /// </summary>
		/// <param name="vendor">
		/// The vendor
		/// </param>
		/// <param name="region">
		/// The region
		/// </param>
		/// <returns>
		/// The <see cref="Uri"/>.
		/// </returns>
        public Uri GetBaseUri(KnownApiVendor vendor, KnownApiRegion region)
        {
            const string urltemplate = "https://{0}/";
            string key = string.Concat(vendor.ToString(), '-', region.ToString());
	        if (!KnownApiHostNames.ContainsKey(key))
		        throw new ApiHostNotFoundException(vendor, region);


            string apiurl = string.Format(urltemplate, KnownApiHostNames[key]);
            return new Uri(apiurl);
        }
		/// <summary>
		/// The get ftp host.
		/// </summary>
		/// <param name="vendor">
		/// The vendor.
		/// </param>
		/// <param name="region">
		/// The region.
		/// </param>
		/// <returns>
		/// The <see cref="string"/>.
		/// </returns>
		/// <exception cref="ComputeApiException">
		/// </exception>
	    public string GetFtpHost(KnownApiVendor vendor, KnownApiRegion region)
	    {
			string key = string.Concat(vendor.ToString(), '-', region.ToString());
			if (!KnownApiHostNames.ContainsKey(key))
				throw new ApiHostNotFoundException(vendor, region);
			return KnownFtpHostNames[key];
	    }
 /// <summary>
 /// Initialises a new instance of the <see cref="ApiHostNotFoundException"/> class.
 /// </summary>
 /// <param name="vendor">
 /// The vendor.
 /// </param>
 /// <param name="region">
 /// The region.
 /// </param>
 public ApiHostNotFoundException(KnownApiVendor vendor, KnownApiRegion region)
     : base(ComputeApiError.BadRequest, message)
 {
     Vendor = vendor;
     Region = region;
 }
Exemplo n.º 14
0
 /// <summary>	The add vpn host name. </summary>
 /// <param name="region">	The region. </param>
 /// <param name="apiUrl">	The API url. </param>
 private void AddVpnHostName(KnownApiRegion region, string apiUrl)
 {
     KnownVpnHostNames.Add(region.ToString(), apiUrl);
 }
Exemplo n.º 15
0
 /// <summary>	The add monitoring host name. </summary>
 /// <param name="region">	The region. </param>
 /// <param name="apiUrl">	The API url. </param>
 private void AddMonitoringHostName(KnownApiRegion region, string apiUrl)
 {
     KnownMonitoringHostNames.Add(region.ToString(), apiUrl);
 }
Exemplo n.º 16
0
        /// <summary>	The add ftp host name. </summary>
        /// <remarks>	Anthony, 4/24/2015. </remarks>
        /// <param name="vendor">	The vendor. </param>
        /// <param name="region">	The region. </param>
        /// <param name="apiUrl">	The API url. </param>
        private void AddFtpHostName(KnownApiVendor vendor, KnownApiRegion region, string apiUrl)
        {
            string key = string.Concat(vendor.ToString(), '-', region.ToString());

            KnownFtpHostNames.Add(key, apiUrl);
        }
        /// <summary>
        /// Return an known CaaS URI based on vendor and region
        /// </summary>
		/// <param name="vendor">
		/// The vendor
		/// </param>
		/// <param name="region">
		/// The region
		/// </param>
		/// <returns>
		/// The <see cref="Uri"/>.
		/// </returns>
        public Uri GetBaseUri(KnownApiVendor vendor, KnownApiRegion region)
        {
            const string urltemplate = "https://{0}/";
            string key = string.Concat(vendor.ToString(), '-', region.ToString());
			if (!KnownApiHostNames.ContainsKey(key))
				throw new ComputeApiException (
					ComputeApiError.BadRequest, 
					"Known Cloud API hostname not found with this vendor and region combination.", 
					string.Empty, 
					null, 
					string.Empty);


            string apiurl = string.Format(urltemplate, KnownApiHostNames[key]);
            return new Uri(apiurl);
        }
		/// <summary>
		/// The get ftp host.
		/// </summary>
		/// <param name="vendor">
		/// The vendor.
		/// </param>
		/// <param name="region">
		/// The region.
		/// </param>
		/// <returns>
		/// The <see cref="string"/>.
		/// </returns>
		/// <exception cref="ComputeApiException">
		/// </exception>
	    public string GetFtpHost(KnownApiVendor vendor, KnownApiRegion region)
	    {
			string key = string.Concat(vendor.ToString(), '-', region.ToString());
			if (!KnownApiHostNames.ContainsKey(key))
				throw new ComputeApiException(
					ComputeApiError.BadRequest, 
					"Known Cloud API hostname not found with this vendor and region combination.", 
					string.Empty, 
					null, 
					string.Empty);
			return KnownFtpHostNames[key];
	    }
		/// <summary>
		/// Initialises a new instance of the <see cref="ComputeApiClient"/> class. 
		/// Creates a new CaaS API client using a Dimension Data vendor and known region.
		/// </summary>
		/// <param name="region">
		/// The region
		/// </param>
		/// <param name="credentials">
		/// The credentials.
		/// </param>
		/// <param name="organizationId">
		/// The organization Id.
		/// </param>
		/// <returns>
		/// The <see cref="ComputeApiClient"/>.
		/// </returns>
		public static ComputeApiClient GetComputeApiClient(KnownApiRegion region, ICredentials credentials, Guid organizationId = default(Guid))
		{
			Uri baseUri = KnownApiUri.Instance.GetBaseUri(KnownApiVendor.DimensionData, region);
			return GetComputeApiClient(baseUri, credentials);
		}
		public ComputeApiClient(KnownApiRegion region)
		{
			Uri baseUri = KnownApiUri.Instance.GetBaseUri(KnownApiVendor.DimensionData, region);
			_httpClientHandler = new HttpClientHandler();
			var httpClient = new HttpClientAdapter(
				new HttpClient(
					_httpClientHandler, disposeHandler: true)
				{
					BaseAddress = baseUri
				});

			InitializeProperties(httpClient);
		}
		/// <summary>
		/// Initialises a new instance of the <see cref="ApiHostNotFoundException"/> class.
		/// </summary>
		/// <param name="vendor">
		/// The vendor.
		/// </param>
		/// <param name="region">
		/// The region.
		/// </param>
		public ApiHostNotFoundException(KnownApiVendor vendor, KnownApiRegion region)
			: base(ComputeApiError.BadRequest, message)
		{
			Vendor = vendor;
			Region = region;
		}