void ReleaseDesignerOutlets() { if (AccountKey != null) { AccountKey.Dispose(); AccountKey = null; } if (AccountName != null) { AccountName.Dispose(); AccountName = null; } if (Container != null) { Container.Dispose(); Container = null; } if (EndpointSuffix != null) { EndpointSuffix.Dispose(); EndpointSuffix = null; } if (SaveButton != null) { SaveButton.Dispose(); SaveButton = null; } if (ServiceName != null) { ServiceName.Dispose(); ServiceName = null; } if (ShareCredentialsCell != null) { ShareCredentialsCell.Dispose(); ShareCredentialsCell = null; } if (StoreCredentialsCell != null) { StoreCredentialsCell.Dispose(); StoreCredentialsCell = null; } }
private void VerifyCredentials(object sender, EventArgs e) { var name = ServiceName.Text; var invalidCharHit = false; foreach (var character in PathConsts.InvalidCharacters) { if (name?.Contains(character) == true) { invalidCharHit = true; } } if (string.IsNullOrEmpty(name) || invalidCharHit) { this.ShowWarning(this.Localize("Online.BadName"), this.Localize("Online.IllegalName"), () => { ServiceName.BecomeFirstResponder(); }); return; } var endpoint = EndpointSuffix.Text; if (string.IsNullOrEmpty(endpoint)) { this.ShowWarning(this.Localize("Online.BadCredential"), this.Localize("Azure.BadEndpoint"), () => { EndpointSuffix.BecomeFirstResponder(); }); return; } var accountName = AccountName.Text; var accessKey = AccountKey.Text; if (string.IsNullOrEmpty(accessKey)) { this.ShowWarning(this.Localize("Online.BadCredential"), this.Localize("Azure.BadAccountKey"), () => { AccountKey.BecomeFirstResponder(); }); return; } var container = Container.Text; if (string.IsNullOrEmpty(container)) { this.ShowWarning(this.Localize("Online.BadCredential"), this.Localize("Azure.BadContainer"), () => { Container.BecomeFirstResponder(); }); return; } if (!Globals.Database.IsStorageNameUnique(name)) { this.ShowWarning(this.Localize("Online.ServiceAlreadyExists"), this.Localize("Online.ChooseADifferentName"), () => { ServiceName.BecomeFirstResponder(); }); return; } string connection; if (endpoint.Contains(accountName, StringComparison.Ordinal)) { accountName = null; } if (endpoint.StartsWith("http://", StringComparison.Ordinal)) { endpoint = endpoint.Replace("http://", "https://"); } if (endpoint.StartsWith("https://", StringComparison.Ordinal)) { if (string.IsNullOrEmpty(accountName)) { if (string.IsNullOrEmpty(accessKey)) { connection = endpoint; } else { connection = $"BlobEndpoint={endpoint};SharedAccessSignature={accessKey}"; } } else { this.ShowError(this.Localize("Azure.BadAccount"), this.Localize("Azure.EndpointAndNameMismatch")); return; } } else { if (string.IsNullOrEmpty(accountName)) { this.ShowError(this.Localize("Online.BadCredential"), this.Localize("Azure.BadAccountName")); return; } else { connection = $"DefaultEndpointsProtocol=https;AccountName={accountName};AccountKey={accessKey};EndpointSuffix={endpoint}"; } } var hud = MBProgressHUD.ShowHUD(NavigationController.View, true); hud.Label.Text = this.Localize("Online.Verifying"); Task.Run(() => { var config = new AzureBlobConfig { ConnectionString = connection, BlobName = container }; if (config.Verify()) { try { Globals.CloudManager.AddStorageProvider(Globals.CloudManager.PersonalClouds[0].Id, Guid.NewGuid(), name, config, visibility); InvokeOnMainThread(() => { hud.Hide(true); NavigationController.DismissViewController(true, null); }); } catch { InvokeOnMainThread(() => { hud.Hide(true); this.ShowError(this.Localize("Azure.CannotAddService"), this.Localize("Error.Internal")); }); } } else { InvokeOnMainThread(() => { hud.Hide(true); this.ShowError(this.Localize("Error.Authentication"), this.Localize("Azure.Unauthorized")); }); } }); }
private void VerifyCredentials(object sender, EventArgs e) { var name = ServiceName.Text; var invalidCharHit = false; foreach (var character in VirtualFileSystem.InvalidCharacters) { if (name?.Contains(character) == true) { invalidCharHit = true; } } if (string.IsNullOrEmpty(name) || invalidCharHit) { this.ShowAlert(this.Localize("Online.BadName"), this.Localize("Online.IllegalName"), action => { ServiceName.BecomeFirstResponder(); }); return; } var endpoint = EndpointSuffix.Text; if (string.IsNullOrEmpty(endpoint)) { this.ShowAlert(this.Localize("Online.BadCredential"), this.Localize("Azure.BadEndpoint"), action => { EndpointSuffix.BecomeFirstResponder(); }); return; } var accountName = AccountName.Text; /* * if (string.IsNullOrEmpty(accountName) && * (endpoint == "core.windows.net" || endpoint == "blob.core.windows.net" || * endpoint == "core.chinacloudapi.cn" || endpoint == "blob.core.chinacloudapi.cn")) * { * this.ShowAlert(this.Localize("Online.BadCredential"), this.Localize("Azure.BadAccountName"), action => { * AccountName.BecomeFirstResponder(); * }); * return; * } */ var accessKey = AccountKey.Text; if (string.IsNullOrEmpty(accessKey)) { this.ShowAlert(this.Localize("Online.BadCredential"), this.Localize("Azure.BadAccountKey"), action => { AccountKey.BecomeFirstResponder(); }); return; } var container = Container.Text; if (string.IsNullOrEmpty(container)) { this.ShowAlert(this.Localize("Online.BadCredential"), this.Localize("Azure.BadContainer"), action => { Container.BecomeFirstResponder(); }); return; } if (!Globals.Database.IsStorageNameUnique(name)) { this.ShowAlert(this.Localize("Online.ServiceAlreadyExists"), this.Localize("Online.ChooseADifferentName"), action => { ServiceName.BecomeFirstResponder(); }); return; } string connection; if (endpoint.Contains(accountName, StringComparison.Ordinal)) { accountName = null; } if (endpoint.StartsWith("http://", StringComparison.Ordinal)) { endpoint = endpoint.Replace("http://", "https://"); } if (endpoint.StartsWith("https://", StringComparison.Ordinal)) { if (string.IsNullOrEmpty(accountName)) { if (string.IsNullOrEmpty(accessKey)) { connection = endpoint; } else { connection = $"BlobEndpoint={endpoint};SharedAccessSignature={accessKey}"; } } else { this.ShowAlert(this.Localize("Azure.BadAccount"), this.Localize("Azure.EndpointAndNameMismatch")); return; } } else { if (string.IsNullOrEmpty(accountName)) { this.ShowAlert(this.Localize("Online.BadCredential"), this.Localize("Azure.BadAccountName")); return; } else { connection = $"DefaultEndpointsProtocol=https;AccountName={accountName};AccountKey={accessKey};EndpointSuffix={endpoint}"; } } var alert = UIAlertController.Create(this.Localize("Online.Verifying"), null, UIAlertControllerStyle.Alert); PresentViewController(alert, true, () => { Task.Run(() => { var config = new AzureBlobConfig { ConnectionString = connection, BlobName = container }; if (config.Verify()) { try { Globals.CloudManager.AddStorageProvider(Globals.CloudManager.PersonalClouds[0].Id, Guid.NewGuid(), name, config, visibility); InvokeOnMainThread(() => { DismissViewController(true, () => { NavigationController.DismissViewController(true, null); }); }); } catch { InvokeOnMainThread(() => { DismissViewController(true, () => { this.ShowAlert(this.Localize("Azure.CannotAddService"), this.Localize("Error.Internal")); }); }); } } else { InvokeOnMainThread(() => { DismissViewController(true, () => { this.ShowAlert(this.Localize("Error.Authentication"), this.Localize("Azure.Unauthorized")); }); }); } }); }); }