If current endpoint exists in endpoints list then select it automatically

This commit is contained in:
Jaex 2017-03-21 09:31:47 +03:00
parent 00833dd640
commit 87a421a9ed
5 changed files with 46 additions and 30 deletions

View file

@ -61,25 +61,25 @@ public sealed class AmazonS3 : FileUploader
{
private const string DefaultRegion = "us-east-1";
public static List<AmazonS3Region> Endpoints { get; } = new List<AmazonS3Region>()
public static List<AmazonS3Endpoint> Endpoints { get; } = new List<AmazonS3Endpoint>()
{
new AmazonS3Region("Asia Pacific (Tokyo)", "s3-ap-northeast-1.amazonaws.com", "ap-northeast-1"),
new AmazonS3Region("Asia Pacific (Seoul)", "s3.ap-northeast-2.amazonaws.com", "ap-northeast-2"),
new AmazonS3Region("Asia Pacific (Mumbai)", "s3.ap-south-1.amazonaws.com", "ap-south-1"),
new AmazonS3Region("Asia Pacific (Singapore)", "s3-ap-southeast-1.amazonaws.com", "ap-southeast-1"),
new AmazonS3Region("Asia Pacific (Sydney)", "s3-ap-southeast-2.amazonaws.com", "ap-southeast-2"),
new AmazonS3Region("Canada (Central)", "s3.ca-central-1.amazonaws.com", "ca-central-1"),
new AmazonS3Region("EU Central (Frankfurt)", "s3.eu-central-1.amazonaws.com", "eu-central-1"),
new AmazonS3Region("EU West (Ireland)", "s3-eu-west-1.amazonaws.com", "eu-west-1"),
new AmazonS3Region("EU West (London)", "s3.eu-west-2.amazonaws.com", "eu-west-2"),
new AmazonS3Region("South America (Sao Paulo)", "s3-sa-east-1.amazonaws.com", "sa-east-1"),
new AmazonS3Region("US East (Virginia)", "s3.amazonaws.com", "us-east-1"),
new AmazonS3Region("US East (Ohio)", "s3.us-east-2.amazonaws.com", "us-east-2"),
new AmazonS3Region("US West (N. California)", "s3-us-west-1.amazonaws.com", "us-west-1"),
new AmazonS3Region("US West (Oregon)", "s3-us-west-2.amazonaws.com", "us-west-2"),
new AmazonS3Region("China (Beijing)", "s3.cn-north-1.amazonaws.com.cn", "cn-north-1"),
new AmazonS3Region("US GovCloud West (Oregon)", "s3-us-gov-west-1.amazonaws.com", "us-gov-west-1"),
new AmazonS3Region("DreamObjects", "objects-us-west-1.dream.io")
new AmazonS3Endpoint("Asia Pacific (Tokyo)", "s3-ap-northeast-1.amazonaws.com", "ap-northeast-1"),
new AmazonS3Endpoint("Asia Pacific (Seoul)", "s3.ap-northeast-2.amazonaws.com", "ap-northeast-2"),
new AmazonS3Endpoint("Asia Pacific (Mumbai)", "s3.ap-south-1.amazonaws.com", "ap-south-1"),
new AmazonS3Endpoint("Asia Pacific (Singapore)", "s3-ap-southeast-1.amazonaws.com", "ap-southeast-1"),
new AmazonS3Endpoint("Asia Pacific (Sydney)", "s3-ap-southeast-2.amazonaws.com", "ap-southeast-2"),
new AmazonS3Endpoint("Canada (Central)", "s3.ca-central-1.amazonaws.com", "ca-central-1"),
new AmazonS3Endpoint("EU Central (Frankfurt)", "s3.eu-central-1.amazonaws.com", "eu-central-1"),
new AmazonS3Endpoint("EU West (Ireland)", "s3-eu-west-1.amazonaws.com", "eu-west-1"),
new AmazonS3Endpoint("EU West (London)", "s3.eu-west-2.amazonaws.com", "eu-west-2"),
new AmazonS3Endpoint("South America (Sao Paulo)", "s3-sa-east-1.amazonaws.com", "sa-east-1"),
new AmazonS3Endpoint("US East (Virginia)", "s3.amazonaws.com", "us-east-1"),
new AmazonS3Endpoint("US East (Ohio)", "s3.us-east-2.amazonaws.com", "us-east-2"),
new AmazonS3Endpoint("US West (N. California)", "s3-us-west-1.amazonaws.com", "us-west-1"),
new AmazonS3Endpoint("US West (Oregon)", "s3-us-west-2.amazonaws.com", "us-west-2"),
new AmazonS3Endpoint("China (Beijing)", "s3.cn-north-1.amazonaws.com.cn", "cn-north-1"),
new AmazonS3Endpoint("US GovCloud West (Oregon)", "s3-us-gov-west-1.amazonaws.com", "us-gov-west-1"),
new AmazonS3Endpoint("DreamObjects", "objects-us-west-1.dream.io")
};
private AmazonS3Settings Settings { get; set; }

View file

@ -25,19 +25,19 @@
namespace ShareX.UploadersLib.FileUploaders
{
public class AmazonS3Region
public class AmazonS3Endpoint
{
public string Name { get; set; }
public string Endpoint { get; set; }
public string Region { get; set; }
public AmazonS3Region(string name, string endpoint)
public AmazonS3Endpoint(string name, string endpoint)
{
Name = name;
Endpoint = endpoint;
}
public AmazonS3Region(string name, string endpoint, string region)
public AmazonS3Endpoint(string name, string endpoint, string region)
{
Name = name;
Endpoint = endpoint;

View file

@ -515,6 +515,14 @@ public void LoadSettings()
txtAmazonS3AccessKey.Text = Config.AmazonS3Settings.AccessKeyID;
txtAmazonS3SecretKey.Text = Config.AmazonS3Settings.SecretAccessKey;
cbAmazonS3Endpoints.Items.AddRange(AmazonS3.Endpoints.ToArray());
for (int i = 0; i < cbAmazonS3Endpoints.Items.Count; i++)
{
if (((AmazonS3Endpoint)cbAmazonS3Endpoints.Items[i]).Endpoint.Equals(Config.AmazonS3Settings.Endpoint, StringComparison.InvariantCultureIgnoreCase))
{
cbAmazonS3Endpoints.SelectedIndex = i;
break;
}
}
txtAmazonS3Endpoint.Text = Config.AmazonS3Settings.Endpoint;
txtAmazonS3Region.Text = Config.AmazonS3Settings.Region;
cbAmazonS3UsePathStyle.Checked = Config.AmazonS3Settings.UsePathStyle;
@ -1977,12 +1985,12 @@ private void txtAmazonS3SecretKey_TextChanged(object sender, EventArgs e)
private void cbAmazonS3Endpoints_SelectedIndexChanged(object sender, EventArgs e)
{
AmazonS3Region region = cbAmazonS3Endpoints.SelectedItem as AmazonS3Region;
AmazonS3Endpoint endpoint = cbAmazonS3Endpoints.SelectedItem as AmazonS3Endpoint;
if (region != null)
if (endpoint != null)
{
txtAmazonS3Region.Text = region.Region;
txtAmazonS3Endpoint.Text = region.Endpoint;
txtAmazonS3Region.Text = endpoint.Region;
txtAmazonS3Endpoint.Text = endpoint.Endpoint;
}
}

View file

@ -115,7 +115,7 @@
<Compile Include="BaseServices\IUploaderService.cs" />
<Compile Include="BaseUploaders\GenericUploader.cs" />
<Compile Include="FileUploaders\AmazonS3.cs" />
<Compile Include="FileUploaders\AmazonS3Region.cs" />
<Compile Include="FileUploaders\AmazonS3Endpoint.cs" />
<Compile Include="FileUploaders\AmazonS3Settings.cs" />
<Compile Include="FileUploaders\AzureStorage.cs" />
<Compile Include="FileUploaders\Box.cs" />

View file

@ -466,15 +466,23 @@ private static void RunUploaderBackwardCompatibilityTasks()
if (!string.IsNullOrEmpty(UploadersConfig.AmazonS3Settings.Endpoint))
{
foreach (AmazonS3Region region in AmazonS3.Endpoints)
bool endpointFound = false;
foreach (AmazonS3Endpoint endpoint in AmazonS3.Endpoints)
{
if (region.Region.Equals(UploadersConfig.AmazonS3Settings.Endpoint, StringComparison.InvariantCultureIgnoreCase))
if (endpoint.Region.Equals(UploadersConfig.AmazonS3Settings.Endpoint, StringComparison.InvariantCultureIgnoreCase))
{
UploadersConfig.AmazonS3Settings.Endpoint = region.Endpoint;
UploadersConfig.AmazonS3Settings.Region = region.Region;
UploadersConfig.AmazonS3Settings.Endpoint = endpoint.Endpoint;
UploadersConfig.AmazonS3Settings.Region = endpoint.Region;
endpointFound = true;
break;
}
}
if (!endpointFound)
{
UploadersConfig.AmazonS3Settings.Endpoint = "";
}
}
}
}