public override void AwakeFromNib () { base.AwakeFromNib (); OpenCertificateFileButton.Activated += (object sender, EventArgs e) => { NSOpenPanel openDlg = new NSOpenPanel (); openDlg.CanChooseFiles = true; nint result = openDlg.RunModal (); if (result == (nint)1) { CertificateField.StringValue = openDlg.Url.RelativePath; } }; OpenPrivateKeyFileButton.Activated += (object sender, EventArgs e) => { NSOpenPanel openDlg = new NSOpenPanel (); openDlg.CanChooseFiles = true; nint result = openDlg.RunModal (); if (result == (nint)1) { PrivateKeyField.StringValue = openDlg.Url.RelativePath; } }; AddButton.Activated += OnAddPrivateKey; CancelButton.Activated += (object sender, EventArgs e) => { this.Close (); NSApplication.SharedApplication.StopModalWithCode (0); }; }
public bool Run (AddFileDialogData data) { using (var panel = new NSOpenPanel { CanChooseDirectories = false, CanChooseFiles = true, }) { MacSelectFileDialogHandler.SetCommonPanelProperties (data, panel); var popup = new NSPopUpButton (new CGRect (0, 0, 200, 28), false); var dropdownBox = new MDBox (LayoutDirection.Horizontal, 2, 0) { { new MDLabel (GettextCatalog.GetString ("Override build action:")), true }, { new MDAlignment (popup, true) { MinWidth = 200 } } }; var filterPopup = MacSelectFileDialogHandler.CreateFileFilterPopup (data, panel); if (filterPopup != null) { dropdownBox.Layout (); var box = new MDBox (LayoutDirection.Vertical, 2, 2) { dropdownBox.View, filterPopup, }; box.Layout (); panel.AccessoryView = box.View; if (box.View.Superview != null) box.Layout (box.View.Superview.Frame.Size); } else { dropdownBox.Layout (); panel.AccessoryView = dropdownBox.View; } popup.AddItem (GettextCatalog.GetString ("(Default)")); popup.Menu.AddItem (NSMenuItem.SeparatorItem); foreach (var b in data.BuildActions) { if (b == "--") popup.Menu.AddItem (NSMenuItem.SeparatorItem); else popup.AddItem (b); } if (panel.RunModal () == 0) { GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow); return false; } data.SelectedFiles = MacSelectFileDialogHandler.GetSelectedFiles (panel); var idx = popup.IndexOfSelectedItem - 2; if (idx >= 0) data.OverrideAction = data.BuildActions[idx]; GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow); return true; } }
public void OpenCertFile (object sender, EventArgs eventargs) { NSOpenPanel openDlg = new NSOpenPanel (); openDlg.CanChooseFiles = true; //TODO - what are the cert file types to be shown? //openDlg.AllowedFileTypes = new string[] { "crt" }; nint result = openDlg.RunModal (); if (result == (nint)1) { CertPathTxtField.StringValue = openDlg.Url.RelativePath; AddCertificateDto.Certificate = openDlg.Url.RelativePath; } }
void OpenDocument(NSObject sender) { var panel = new NSOpenPanel () { AllowedFileTypes = new [] {"nupkg"}, AllowsMultipleSelection = false, CanChooseDirectories = false, ShowsHiddenFiles = true, Title = "Open NuGet Package (*.nupkg)" }; if (panel.RunModal () == NSFileHandlingPanelOKButton) { NSUrl file = panel.Url; } }
public override void AwakeFromNib () { base.AwakeFromNib (); SolutionUserDto = SolutionUserDtoOriginal.DeepCopy(); TxtName.StringValue = SolutionUserDto.Name; TxtDescription.StringValue = string.IsNullOrEmpty(SolutionUserDto.Description)?string.Empty:SolutionUserDto.Description; CbDisabled.StringValue = SolutionUserDto.Disabled ? "1" : "0"; Window.Title = SolutionUserDto.Name + " Properties"; var cert = new X509Certificate2 (Encoding.ASCII.GetBytes(SolutionUserDto.Certificate.Encoded)); try { TxtIssuer.StringValue = cert.Issuer; TxtValidFrom.StringValue = cert.NotBefore.ToShortDateString(); TxtValidTo.StringValue = cert.NotAfter.ToShortDateString(); TxtDC.StringValue = cert.IssuerName.Format(true); } catch (Exception) { UtilityService.ShowAlert ("Invalid X509 certificate", "Alert"); } //Events this.BtnSave.Activated += OnClickSaveButton; this.BtnClose.Activated += (object sender, EventArgs e) => { this.Close (); NSApplication.SharedApplication.StopModalWithCode (0); }; this.BtnChangeCertificate.Activated += (object sender, EventArgs e) => { var openPanel = new NSOpenPanel(); openPanel.ReleasedWhenClosed = true; openPanel.Prompt = "Select file"; var result = openPanel.RunModal(); if (result == 1) { var filePath = openPanel.Url.AbsoluteString.Replace("file://",string.Empty); var cert1 = new X509Certificate2 (); try { cert1.Import (filePath); TxtIssuer.StringValue = cert1.Issuer; TxtValidFrom.StringValue = cert1.NotBefore.ToShortDateString(); TxtValidTo.StringValue = cert1.NotAfter.ToShortDateString(); TxtDC.StringValue = cert1.IssuerName.Format(true); } catch (Exception) { UtilityService.ShowAlert ("Invalid X509 certificate", "Alert"); } SolutionUserDto.Certificate.Encoded = cert.ToPem(); } }; }
public override void AwakeFromNib () { base.AwakeFromNib (); SolutionUserDto = SolutionUserDtoOriginal.DeepCopy(); TxtName.StringValue = SolutionUserDto.Name; TxtDescription.StringValue = string.IsNullOrEmpty(SolutionUserDto.Description)?string.Empty:SolutionUserDto.Description; cbDisabled.StringValue = SolutionUserDto.Disabled ? "0" : "1"; _certificate = new X509Certificate2 (Encoding.ASCII.GetBytes(SolutionUserDto.Certificate.Encoded)); ActionHelper.Execute (delegate() { TxtIssuer.StringValue = _certificate.Issuer; TxtValidFrom.StringValue = _certificate.NotBefore.ToShortDateString (); TxtValidTo.StringValue = _certificate.NotAfter.ToShortDateString (); TxtDn.StringValue = _certificate.IssuerName.Format (true); }); //Events this.BtnSave.Activated += OnClickSaveButton; this.BtnChangeCertificate.Activated += (object sender, EventArgs e) => { var openPanel = new NSOpenPanel(); openPanel.ReleasedWhenClosed = true; openPanel.Prompt = "Select file"; var result = openPanel.RunModal(); if (result == 1) { var filePath = openPanel.Url.AbsoluteString.Replace("file://",string.Empty); var cert1 = new X509Certificate2 (); ActionHelper.Execute (delegate() { cert1.Import (filePath); TxtIssuer.StringValue = cert1.Issuer; TxtValidFrom.StringValue = cert1.NotBefore.ToShortDateString(); TxtValidTo.StringValue = cert1.NotAfter.ToShortDateString(); TxtDn.StringValue = cert1.IssuerName.Format(true); _certificate = cert1; }); SolutionUserDto.Certificate.Encoded = _certificate.ToPem(); } }; BtnViewCertificate.Activated += (object sender, EventArgs e) => { CertificateService.DisplayX509Certificate2(this, _certificate ); }; BtnSave.Hidden = !IsSystemDomain; }
public bool Run (SelectFileDialogData data) { NSSavePanel panel = null; try { bool directoryMode = data.Action != Gtk.FileChooserAction.Open; if (data.Action == Gtk.FileChooserAction.Save) { panel = new NSSavePanel (); } else { panel = new NSOpenPanel { CanChooseDirectories = directoryMode, CanChooseFiles = !directoryMode, ResolvesAliases = false, }; } SetCommonPanelProperties (data, panel); if (!directoryMode) { var popup = CreateFileFilterPopup (data, panel); if (popup != null) { panel.AccessoryView = popup; } } if (panel.RunModal () == 0) { GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow); return false; } data.SelectedFiles = GetSelectedFiles (panel); GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow); return true; } finally { if (panel != null) panel.Dispose (); } }
public override void AwakeFromNib () { base.AwakeFromNib (); _certs = new List<string> (); TxtTenantName.Enabled = !UpdateCredentials; txtUsername.Enabled = !UpdateCredentials; TxtPassword.Enabled = !UpdateCredentials; if (UpdateCredentials) TxtTenantName.StringValue = TenantDto.Name; else TenantDto = new TenantDto (); TenantDto.Credentials = new TenantCredentialsDto(){Certificates = new List<CertificateDto>()}; BtnAddCertificate.Activated += (object sender, EventArgs e) => { var openPanel = new NSOpenPanel(); openPanel.ReleasedWhenClosed = true; openPanel.Prompt = "Select file"; var result = openPanel.RunModal(); if (result == 1) { var filePath = openPanel.Url.AbsoluteString.Replace("file://",string.Empty); var cert = new X509Certificate2 (); ActionHelper.Execute (delegate() { cert.Import (filePath); _certs.Add(filePath); var certfificateDto = new CertificateDto { Encoded = cert.ToPem(), }; TenantDto.Credentials.Certificates.Add(certfificateDto); ReloadCertificates(); }); } }; BtnRemoveCertificate.Activated += (object sender, EventArgs e) => { if (CertificateChainTableView.SelectedRows.Count > 0) { foreach (var row in CertificateChainTableView.SelectedRows) { _certs.RemoveAt ((int)row); TenantDto.Credentials.Certificates.RemoveAt ((int)row); } ReloadCertificates(); } }; BtnBrowsePrivateKey.Activated += (object sender, EventArgs e) => { var openPanel = new NSOpenPanel(); openPanel.ReleasedWhenClosed = true; openPanel.Prompt = "Select file"; var result = openPanel.RunModal(); if (result == 1) { var filePath = openPanel.Url.AbsoluteString.Replace("file://",string.Empty); ActionHelper.Execute (delegate() { var text = System.IO.File.ReadAllText(filePath); var privateKey = PrivateKeyHelper.ExtractBase64EncodedPayload(text); TxtPrivateKeyPath.StringValue = filePath; TenantDto.Credentials.PrivateKey = new PrivateKeyDto(){ Algorithm = EncrptionAlgorithm.RSA, Encoded = privateKey }; }); } }; BtnClose.Activated += (object sender, EventArgs e) => { TenantDto = null; this.Close (); NSApplication.SharedApplication.StopModalWithCode (0); }; this.BtnSave.Activated += (object sender, EventArgs e) => { if (!UpdateCredentials && string.IsNullOrEmpty (TxtTenantName.StringValue)) { UIErrorHelper.ShowAlert ("Please enter valid tenant name", "Alert"); } else if (!UpdateCredentials && string.IsNullOrEmpty (txtUsername.StringValue)) { UIErrorHelper.ShowAlert ("Please enter valid username", "Alert"); } else if (!UpdateCredentials && string.IsNullOrEmpty (TxtPassword.StringValue)) { UIErrorHelper.ShowAlert ("Please enter valid password", "Alert"); } else if (string.IsNullOrEmpty (TxtPrivateKeyPath.StringValue)) { UIErrorHelper.ShowAlert ("Please enter valid private key", "Alert"); } else if (_certs.Count < 2) { UIErrorHelper.ShowAlert ("Please enter atleast 2 valid Certificates", "Alert"); } else { TenantDto.Name = TxtTenantName.StringValue; TenantDto.Username = txtUsername.StringValue; TenantDto.Password = TxtPassword.StringValue; this.Close (); NSApplication.SharedApplication.StopModalWithCode (1); } }; }
void OnBrowseCertificate (object sender, EventArgs e) { var openPanel = new NSOpenPanel(); openPanel.ReleasedWhenClosed = true; openPanel.Prompt = "Select file"; var result = openPanel.RunModal(); if (result == 1) { var filePath = openPanel.Url.AbsoluteString.Replace("file://",string.Empty); var cert = new X509Certificate2 (); ActionHelper.Execute (delegate() { cert.Import (filePath); _certificate = cert; }); TxtCertificate.StringValue = filePath; } }
public void OpenKeyFile (object sender, EventArgs eventargs) { NSOpenPanel openDlg = new NSOpenPanel (); openDlg.CanChooseFiles = true; openDlg.AllowedFileTypes = new string[]{ "pem", "key" }; nint result = openDlg.RunModal (); if (result == (int)1) { FilePath.StringValue = openDlg.Url.RelativePath; UIErrorHelper.ShowAlert (openDlg.Filename, "File"); } }
public void OnClickBrowseButton (object sender, EventArgs e) { var openPanel = new NSOpenPanel(); openPanel.ReleasedWhenClosed = true; openPanel.Prompt = "Select file"; var result = openPanel.RunModal(); if (result == 1) { var filePath = openPanel.Url.AbsoluteString.Replace("file://",string.Empty); var cert = new X509Certificate2 (); try { cert.Import (filePath); } catch (Exception) { UIErrorHelper.ShowAlert ("Invalid X509 certificate", "Alert"); } TxtCertificate.StringValue = filePath; } }
public bool Run (OpenFileDialogData data) { NSSavePanel panel = null; try { if (data.Action == FileChooserAction.Save) { panel = new NSSavePanel (); } else { panel = new NSOpenPanel { CanChooseDirectories = (data.Action & FileChooserAction.FolderFlags) != 0, CanChooseFiles = (data.Action & FileChooserAction.FileFlags) != 0, }; } MacSelectFileDialogHandler.SetCommonPanelProperties (data, panel); SelectEncodingPopUpButton encodingSelector = null; NSPopUpButton viewerSelector = null; NSButton closeSolutionButton = null; var box = new MDBox (LayoutDirection.Vertical, 2, 2); List<FileViewer> currentViewers = null; var labels = new List<MDAlignment> (); if ((data.Action & FileChooserAction.FileFlags) != 0) { var filterPopup = MacSelectFileDialogHandler.CreateFileFilterPopup (data, panel); if (filterPopup != null) { var filterLabel = new MDAlignment (new MDLabel (GettextCatalog.GetString ("Show files:")), true); var filterBox = new MDBox (LayoutDirection.Horizontal, 2, 0) { { filterLabel }, { new MDAlignment (filterPopup, true) { MinWidth = 200 } } }; labels.Add (filterLabel); box.Add (filterBox); } if (data.ShowEncodingSelector) { encodingSelector = new SelectEncodingPopUpButton (data.Action != FileChooserAction.Save); encodingSelector.SelectedEncodingId = data.Encoding != null ? data.Encoding.CodePage : 0; var encodingLabel = new MDAlignment (new MDLabel (GettextCatalog.GetString ("Encoding:")), true); var encodingBox = new MDBox (LayoutDirection.Horizontal, 2, 0) { { encodingLabel }, { new MDAlignment (encodingSelector, true) { MinWidth = 200 } } }; labels.Add (encodingLabel); box.Add (encodingBox); } if (data.ShowViewerSelector && panel is NSOpenPanel) { currentViewers = new List<FileViewer> (); viewerSelector = new NSPopUpButton { Enabled = false, }; if (encodingSelector != null || IdeApp.Workspace.IsOpen) { viewerSelector.Activated += delegate { var idx = viewerSelector.IndexOfSelectedItem; bool workbenchViewerSelected = idx == 0 && currentViewers [0] == null; if (encodingSelector != null) encodingSelector.Enabled = !workbenchViewerSelected; if (closeSolutionButton != null) { if (closeSolutionButton.Hidden == workbenchViewerSelected) { closeSolutionButton.Hidden = !workbenchViewerSelected; CenterAccessoryView (box); } } }; } var viewSelLabel = new MDLabel (GettextCatalog.GetString ("Open with:")); var viewSelBox = new MDBox (LayoutDirection.Horizontal, 2, 0) { { viewSelLabel, true }, { new MDAlignment (viewerSelector, true) { MinWidth = 200 } } }; if (IdeApp.Workspace.IsOpen) { closeSolutionButton = new NSButton { Title = GettextCatalog.GetString ("Close current workspace"), Hidden = true, State = NSCellStateValue.On, }; closeSolutionButton.SetButtonType (NSButtonType.Switch); closeSolutionButton.SizeToFit (); viewSelBox.Add (closeSolutionButton, true); } box.Add (viewSelBox); } } if (labels.Count > 0) { float w = labels.Max (l => l.MinWidth); foreach (var l in labels) { l.MinWidth = w; l.XAlign = LayoutAlign.Begin; } } if (box.Count > 0) { box.Layout (); panel.AccessoryView = box.View; } panel.SelectionDidChange += delegate { var selection = MacSelectFileDialogHandler.GetSelectedFiles (panel); bool slnViewerSelected = false; if (viewerSelector != null) { slnViewerSelected = FillViewers (currentViewers, viewerSelector, closeSolutionButton, selection); if (closeSolutionButton != null) closeSolutionButton.Hidden = !slnViewerSelected; CenterAccessoryView (box); } if (encodingSelector != null) encodingSelector.Enabled = !slnViewerSelected; }; if (panel.RunModal () == 0) { GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow); return false; } data.SelectedFiles = MacSelectFileDialogHandler.GetSelectedFiles (panel); if (encodingSelector != null) data.Encoding = encodingSelector.SelectedEncodingId > 0 ? Encoding.GetEncoding (encodingSelector.SelectedEncodingId) : null; if (viewerSelector != null ) { if (closeSolutionButton != null) data.CloseCurrentWorkspace = closeSolutionButton.State != NSCellStateValue.Off; data.SelectedViewer = viewerSelector.IndexOfSelectedItem >= 0 ? currentViewers[(int)viewerSelector.IndexOfSelectedItem] : null; } GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow); } catch (Exception ex) { LoggingService.LogInternalError ("Error in Open File dialog", ex); } finally { if (panel != null) panel.Dispose (); } return true; }
partial void ChangeWatchPath (NSObject sender) { var openPanel = new NSOpenPanel { CanChooseDirectories = true, CanChooseFiles = false }; openPanel.BeginSheet (Window, result => { if (result == 1) { WatchPathTextField.StringValue = openPanel.DirectoryUrl.Path; OnWatchPathChanged (null, null); } }); }
public bool Run(AddFileDialogData data) { using (var panel = new NSOpenPanel() { CanChooseDirectories = false, CanChooseFiles = true, }) { MacSelectFileDialogHandler.SetCommonPanelProperties(data, panel); var popup = new NSPopUpButton(new RectangleF(0, 0, 200, 28), false); var dropdownBox = new MDBox(LayoutDirection.Horizontal, 2, 0) { { new MDLabel(GettextCatalog.GetString("Override build action:")), true }, { new MDAlignment(popup, true) { MinWidth = 200 } } }; var filterPopup = MacSelectFileDialogHandler.CreateFileFilterPopup(data, panel); if (filterPopup != null) { dropdownBox.Layout(); var box = new MDBox(LayoutDirection.Vertical, 2, 2) { dropdownBox.View, filterPopup, }; box.Layout(); panel.AccessoryView = box.View; box.Layout(box.View.Superview.Frame.Size); } else { dropdownBox.Layout(); panel.AccessoryView = dropdownBox.View; } popup.AddItem(GettextCatalog.GetString("(Default)")); popup.Menu.AddItem(NSMenuItem.SeparatorItem); foreach (var b in data.BuildActions) { if (b == "--") { popup.Menu.AddItem(NSMenuItem.SeparatorItem); } else { popup.AddItem(b); } } var action = MacSelectFileDialogHandler.RunPanel(data, panel); if (!action) { GtkQuartz.FocusWindow(data.TransientFor ?? MessageService.RootWindow); return(false); } data.SelectedFiles = MacSelectFileDialogHandler.GetSelectedFiles(panel); var idx = popup.IndexOfSelectedItem - 2; if (idx >= 0) { data.OverrideAction = data.BuildActions[idx]; } GtkQuartz.FocusWindow(data.TransientFor ?? MessageService.RootWindow); return(true); } }
public override void AwakeFromNib () { base.AwakeFromNib (); DtoToView (); this.BtnAuthenticationAddCertificate.Activated += (object sender, EventArgs e) => { var openPanel = new NSOpenPanel(); openPanel.ReleasedWhenClosed = true; openPanel.Prompt = "Select file"; var result = openPanel.RunModal(); if (result == 1) { var filePath = openPanel.Url.AbsoluteString.Replace("file://",string.Empty); var cert = new X509Certificate2 (); ActionHelper.Execute (delegate() { cert.Import (filePath); var certfificateDto = new CertificateDto { Encoded = cert.ToPem(), }; TenantConfigurationDto.AuthenticationPolicy.ClientCertificatePolicy.TrustedCACertificates.Add(certfificateDto); ReloadCertificates(); }); } }; this.BtnAuthenticationRemoveCertificate.Activated += (object sender, EventArgs e) => { if (CertificateTableView.SelectedRows.Count > 0) { foreach (var row in CertificateTableView.SelectedRows) { TenantConfigurationDto.AuthenticationPolicy.ClientCertificatePolicy.TrustedCACertificates.RemoveAt ((int)row); } ReloadCertificates(); } }; BtnAuthenticationPolicyAddPolicyOid.Activated += (object sender, EventArgs e) => { if(string.IsNullOrEmpty(TxtAuthenticationPolicyOid.StringValue)) { UIErrorHelper.ShowAlert ("Policy OID cannot be empty", "Alert"); return; } TenantConfigurationDto.AuthenticationPolicy.ClientCertificatePolicy.CertPolicyOIDs.Add(TxtAuthenticationPolicyOid.StringValue); ReloadTableView(AuthenticationPolicyOidTableView, TenantConfigurationDto.AuthenticationPolicy.ClientCertificatePolicy.CertPolicyOIDs); TxtAuthenticationPolicyOid.StringValue = (NSString)string.Empty; BtnAuthenticationRemovePolicyOid.Enabled = TenantConfigurationDto.AuthenticationPolicy.ClientCertificatePolicy.CertPolicyOIDs != null && TenantConfigurationDto.AuthenticationPolicy.ClientCertificatePolicy.CertPolicyOIDs.Count > 0; }; BtnAuthenticationRemovePolicyOid.Activated += (object sender, EventArgs e) => { if (AuthenticationPolicyOidTableView.SelectedRows.Count > 0) { foreach (var row in AuthenticationPolicyOidTableView.SelectedRows) { TenantConfigurationDto.AuthenticationPolicy.ClientCertificatePolicy.CertPolicyOIDs.RemoveAt((int)row); } ReloadTableView(AuthenticationPolicyOidTableView, TenantConfigurationDto.AuthenticationPolicy.ClientCertificatePolicy.CertPolicyOIDs); BtnAuthenticationRemovePolicyOid.Enabled = TenantConfigurationDto.AuthenticationPolicy.ClientCertificatePolicy.CertPolicyOIDs != null && TenantConfigurationDto.AuthenticationPolicy.ClientCertificatePolicy.CertPolicyOIDs.Count > 0; } }; BtnClose.Activated += (object sender, EventArgs e) => { TenantConfigurationDto = null; this.Close (); NSApplication.SharedApplication.StopModalWithCode (0); }; this.BtnSave.Activated += (object sender, EventArgs e) => { ActionHelper.Execute (delegate() { ViewToDto(); var auth = SnapInContext.Instance.AuthTokenManager.GetAuthToken(ServerDto.ServerName); SnapInContext.Instance.ServiceGateway.Tenant.UpdateConfig(ServerDto,TenantName,TenantConfigurationDto,auth.Token); this.Close (); NSApplication.SharedApplication.StopModalWithCode (1); }); }; this.ChkDisableLogonBanner.Activated += (object sender, EventArgs e) => { CheckLogonBanner(); }; this.BtnUploadContent.Activated += (object sender, EventArgs e) => { var openPanel = new NSOpenPanel(); openPanel.ReleasedWhenClosed = true; openPanel.Prompt = "Select file"; var result = openPanel.RunModal(); if (result == 1) { var filePath = openPanel.Url.AbsoluteString.Replace("file://",string.Empty); ActionHelper.Execute (delegate() { var text = System.IO.File.ReadAllText(filePath); if(!string.IsNullOrEmpty(text)) TxtBrandLogonBanner.StringValue = text; }); } }; CheckLogonBanner (); }
public override void AwakeFromNib () { base.AwakeFromNib (); OidcClientDto = new OidcClientDto { OidcClientMetadataDTO = new OidcClientMetadataDto { RedirectUris=new List<string>(), PostLogoutRedirectUris = new List<string>() } }; BtnSelectCertificate.Activated += (object sender, EventArgs e) => { var openPanel = new NSOpenPanel(); openPanel.ReleasedWhenClosed = true; openPanel.Prompt = "Select file"; var result = openPanel.RunModal(); if (result == 1) { var filePath = openPanel.Url.AbsoluteString.Replace("file://",string.Empty); var cert = new X509Certificate2 (); ActionHelper.Execute (delegate() { cert.Import (filePath); TxtCertificateDN.StringValue = cert.Subject; }); } }; BtnAddRedirectUri.Activated += (object sender, EventArgs e) => { if(string.IsNullOrEmpty(TxtRedirectUri.StringValue)) { UIErrorHelper.ShowAlert ("Redirect Uri cannot be empty", "Alert"); return; } else if(!WebUtil.IsValidHttpUrl(TxtRedirectUri.StringValue)) { UIErrorHelper.ShowAlert ("Redirect Uri is invalid", "Alert"); return; } OidcClientDto.OidcClientMetadataDTO.RedirectUris.Add(TxtRedirectUri.StringValue); ReloadTableView(RedirectUriTableView, OidcClientDto.OidcClientMetadataDTO.RedirectUris); TxtRedirectUri.StringValue = (NSString)string.Empty; }; BtnAddPostLogoutRedirectUri.Activated += (object sender, EventArgs e) => { if(string.IsNullOrEmpty(TxtPostLogoutRedirectUri.StringValue)) { UIErrorHelper.ShowAlert ("Post logout redirect Uri cannot be empty", "Alert"); return; } else if(!WebUtil.IsValidHttpUrl(TxtPostLogoutRedirectUri.StringValue)) { UIErrorHelper.ShowAlert ("Post logout is invalid", "Alert"); return; } OidcClientDto.OidcClientMetadataDTO.PostLogoutRedirectUris.Add(TxtPostLogoutRedirectUri.StringValue); ReloadTableView(PostLogoutUtiTableView, OidcClientDto.OidcClientMetadataDTO.PostLogoutRedirectUris); TxtPostLogoutRedirectUri.StringValue = (NSString)string.Empty; }; BtnRemoveRedirectUri.Activated += (object sender, EventArgs e) => { if (RedirectUriTableView.SelectedRows.Count > 0) { foreach (var row in RedirectUriTableView.SelectedRows) { OidcClientDto.OidcClientMetadataDTO.RedirectUris.RemoveAt((int)row); } ReloadTableView(RedirectUriTableView, OidcClientDto.OidcClientMetadataDTO.RedirectUris); } }; BtnRemovePostLogoutRedirectUri.Activated += (object sender, EventArgs e) => { if (PostLogoutUtiTableView.SelectedRows.Count > 0) { foreach (var row in PostLogoutUtiTableView.SelectedRows) { OidcClientDto.OidcClientMetadataDTO.PostLogoutRedirectUris.RemoveAt((int)row); } ReloadTableView(PostLogoutUtiTableView, OidcClientDto.OidcClientMetadataDTO.PostLogoutRedirectUris); } }; BtnClose.Activated += (object sender, EventArgs e) => { OidcClientDto = null; this.Close (); NSApplication.SharedApplication.StopModalWithCode (0); }; this.BtnSave.Activated += (object sender, EventArgs e) => { if (string.IsNullOrEmpty (TxtCertificateDN.StringValue)) { UIErrorHelper.ShowAlert ("Please choose a valid certificate", "Alert"); } else if (string.IsNullOrEmpty (TxtLogoutUri.StringValue) || !WebUtil.IsValidHttpUrl(TxtLogoutUri.StringValue)) { UIErrorHelper.ShowAlert ("Please enter valid logout uri", "Alert"); } else if (OidcClientDto.OidcClientMetadataDTO.RedirectUris.Count == 0) { UIErrorHelper.ShowAlert ("Please enter a valid redirect URI", "Alert"); } else if (OidcClientDto.OidcClientMetadataDTO.PostLogoutRedirectUris.Count == 0) { UIErrorHelper.ShowAlert ("Please enter a valid post logout redirect URI", "Alert"); }else { OidcClientDto.OidcClientMetadataDTO.LogoutUri = TxtLogoutUri.StringValue; OidcClientDto.OidcClientMetadataDTO.TokenEndpointAuthMethod = (NSString)CbAuthTokenMethod.SelectedValue; OidcClientDto.OidcClientMetadataDTO.CertSubjectDN = TxtCertificateDN.StringValue; this.Close (); NSApplication.SharedApplication.StopModalWithCode (1); } }; CbAuthTokenMethod.SelectItem (0); }
public bool Run(OpenFileDialogData data) { NSSavePanel panel = null; try { bool directoryMode = data.Action != Gtk.FileChooserAction.Open && data.Action != Gtk.FileChooserAction.Save; if (data.Action == Gtk.FileChooserAction.Save) { panel = new NSSavePanel(); } else { panel = new NSOpenPanel { CanChooseDirectories = directoryMode, CanChooseFiles = !directoryMode, }; } MacSelectFileDialogHandler.SetCommonPanelProperties(data, panel); SelectEncodingPopUpButton encodingSelector = null; NSPopUpButton viewerSelector = null; NSButton closeSolutionButton = null; var box = new MDBox(LayoutDirection.Vertical, 2, 2); List <FileViewer> currentViewers = null; var labels = new List <MDAlignment> (); if (!directoryMode) { var filterPopup = MacSelectFileDialogHandler.CreateFileFilterPopup(data, panel); if (filterPopup != null) { var filterLabel = new MDAlignment(new MDLabel(GettextCatalog.GetString("Show files:")), true); var filterBox = new MDBox(LayoutDirection.Horizontal, 2, 0) { { filterLabel }, { new MDAlignment(filterPopup, true) { MinWidth = 200 } } }; labels.Add(filterLabel); box.Add(filterBox); } if (data.ShowEncodingSelector) { encodingSelector = new SelectEncodingPopUpButton(data.Action != Gtk.FileChooserAction.Save); encodingSelector.SelectedEncodingId = data.Encoding != null ? data.Encoding.CodePage : 0; var encodingLabel = new MDAlignment(new MDLabel(GettextCatalog.GetString("Encoding:")), true); var encodingBox = new MDBox(LayoutDirection.Horizontal, 2, 0) { { encodingLabel }, { new MDAlignment(encodingSelector, true) { MinWidth = 200 } } }; labels.Add(encodingLabel); box.Add(encodingBox); } if (data.ShowViewerSelector && panel is NSOpenPanel) { currentViewers = new List <FileViewer> (); viewerSelector = new NSPopUpButton { Enabled = false, }; if (encodingSelector != null || IdeApp.Workspace.IsOpen) { viewerSelector.Activated += delegate { var idx = viewerSelector.IndexOfSelectedItem; bool workbenchViewerSelected = idx == 0 && currentViewers [0] == null; if (encodingSelector != null) { encodingSelector.Enabled = !workbenchViewerSelected; } if (closeSolutionButton != null) { if (closeSolutionButton.Hidden == workbenchViewerSelected) { closeSolutionButton.Hidden = !workbenchViewerSelected; CenterAccessoryView(box); } } }; } var viewSelLabel = new MDLabel(GettextCatalog.GetString("Open with:")); var viewSelBox = new MDBox(LayoutDirection.Horizontal, 2, 0) { { viewSelLabel, true }, { new MDAlignment(viewerSelector, true) { MinWidth = 200 } } }; if (IdeApp.Workspace.IsOpen) { closeSolutionButton = new NSButton { Title = GettextCatalog.GetString("Close current workspace"), Hidden = true, State = NSCellStateValue.On, }; closeSolutionButton.SetButtonType(NSButtonType.Switch); closeSolutionButton.SizeToFit(); viewSelBox.Add(closeSolutionButton, true); } box.Add(viewSelBox); } } if (labels.Count > 0) { float w = labels.Max(l => l.MinWidth); foreach (var l in labels) { l.MinWidth = w; l.XAlign = LayoutAlign.Begin; } } if (box.Count > 0) { box.Layout(); panel.AccessoryView = box.View; } panel.SelectionDidChange += delegate { var selection = MacSelectFileDialogHandler.GetSelectedFiles(panel); bool slnViewerSelected = false; if (viewerSelector != null) { slnViewerSelected = FillViewers(currentViewers, viewerSelector, closeSolutionButton, selection); if (closeSolutionButton != null) { closeSolutionButton.Hidden = !slnViewerSelected; } CenterAccessoryView(box); } if (encodingSelector != null) { encodingSelector.Enabled = !slnViewerSelected; } }; if (panel.RunModal() == 0) { GtkQuartz.FocusWindow(data.TransientFor ?? MessageService.RootWindow); return(false); } data.SelectedFiles = MacSelectFileDialogHandler.GetSelectedFiles(panel); if (encodingSelector != null) { data.Encoding = encodingSelector.SelectedEncodingId > 0 ? Encoding.GetEncoding(encodingSelector.SelectedEncodingId) : null; } if (viewerSelector != null) { if (closeSolutionButton != null) { data.CloseCurrentWorkspace = closeSolutionButton.State != NSCellStateValue.Off; } data.SelectedViewer = viewerSelector.IndexOfSelectedItem >= 0 ? currentViewers[(int)viewerSelector.IndexOfSelectedItem] : null; } GtkQuartz.FocusWindow(data.TransientFor ?? MessageService.RootWindow); } catch (Exception ex) { LoggingService.LogInternalError("Error in Open File dialog", ex); } finally { if (panel != null) { panel.Dispose(); } } return(true); }
public bool Run (OpenFileDialogData data) { NSSavePanel panel = null; try { bool directoryMode = data.Action != Gtk.FileChooserAction.Open && data.Action != Gtk.FileChooserAction.Save; if (data.Action == Gtk.FileChooserAction.Save) { panel = new NSSavePanel (); } else { panel = new NSOpenPanel { CanChooseDirectories = directoryMode, CanChooseFiles = !directoryMode, }; } MacSelectFileDialogHandler.SetCommonPanelProperties (data, panel); SelectEncodingPopUpButton encodingSelector = null; NSPopUpButton viewerSelector = null; NSButton closeSolutionButton = null; var box = new MDBox (LayoutDirection.Vertical, 2, 2); List<FileViewer> currentViewers = null; var labels = new List<MDAlignment> (); if (!directoryMode) { var filterPopup = MacSelectFileDialogHandler.CreateFileFilterPopup (data, panel); if (filterPopup != null) { var filterLabel = new MDAlignment (new MDLabel (GettextCatalog.GetString ("Show files:")), true); var filterBox = new MDBox (LayoutDirection.Horizontal, 2, 0) { { filterLabel }, { new MDAlignment (filterPopup, true) { MinWidth = 200 } } }; labels.Add (filterLabel); box.Add (filterBox); } if (data.ShowEncodingSelector) { encodingSelector = new SelectEncodingPopUpButton (data.Action != Gtk.FileChooserAction.Save); encodingSelector.SelectedEncodingId = data.Encoding != null ? data.Encoding.CodePage : 0; var encodingLabel = new MDAlignment (new MDLabel (GettextCatalog.GetString ("Encoding:")), true); var encodingBox = new MDBox (LayoutDirection.Horizontal, 2, 0) { { encodingLabel }, { new MDAlignment (encodingSelector, true) { MinWidth = 200 } } }; labels.Add (encodingLabel); box.Add (encodingBox); } if (data.ShowViewerSelector && panel is NSOpenPanel) { currentViewers = new List<FileViewer> (); viewerSelector = new NSPopUpButton { Enabled = false, }; if (encodingSelector != null) { viewerSelector.Activated += delegate { var idx = viewerSelector.IndexOfSelectedItem; encodingSelector.Enabled = ! (idx == 0 && currentViewers [0] == null); }; } var viewSelLabel = new MDLabel (GettextCatalog.GetString ("Open with:")); var viewSelBox = new MDBox (LayoutDirection.Horizontal, 2, 0) { { viewSelLabel, true }, { new MDAlignment (viewerSelector, true) { MinWidth = 200 } } }; if (IdeApp.Workspace.IsOpen) { closeSolutionButton = new NSButton { Title = GettextCatalog.GetString ("Close current workspace"), Hidden = true, State = NSCellStateValue.On, }; closeSolutionButton.SetButtonType (NSButtonType.Switch); closeSolutionButton.SizeToFit (); viewSelBox.Add (closeSolutionButton, true); } box.Add (viewSelBox); } } if (labels.Count > 0) { float w = labels.Max (l => l.MinWidth); foreach (var l in labels) { l.MinWidth = w; l.XAlign = LayoutAlign.Begin; } } if (box.Count > 0) { box.Layout (); panel.AccessoryView = box.View; } panel.SelectionDidChange += delegate { var selection = MacSelectFileDialogHandler.GetSelectedFiles (panel); bool slnViewerSelected = false; if (viewerSelector != null) { FillViewers (currentViewers, viewerSelector, closeSolutionButton, selection); if (currentViewers.Count == 0 || currentViewers [0] != null) { if (closeSolutionButton != null) closeSolutionButton.Hidden = true; slnViewerSelected = false; } else { if (closeSolutionButton != null) closeSolutionButton.Hidden = false; slnViewerSelected = true; } box.Layout (); //re-center the accessory view in its parent, Cocoa does this for us initially and after //resizing the window, but we need to do it again after altering its layout var superFrame = box.View.Superview.Frame; var frame = box.View.Frame; //not sure why it's ceiling, but this matches the Cocoa layout frame.X = (float)Math.Ceiling ((superFrame.Width - frame.Width) / 2); frame.Y = (float)Math.Ceiling ((superFrame.Height - frame.Height) / 2); box.View.Frame = frame; } if (encodingSelector != null) encodingSelector.Enabled = !slnViewerSelected; }; if (panel.RunModal () == 0) { GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow); return false; } data.SelectedFiles = MacSelectFileDialogHandler.GetSelectedFiles (panel); if (encodingSelector != null) data.Encoding = encodingSelector.SelectedEncodingId > 0 ? Encoding.GetEncoding (encodingSelector.SelectedEncodingId) : null; if (viewerSelector != null ) { if (closeSolutionButton != null) data.CloseCurrentWorkspace = closeSolutionButton.State != NSCellStateValue.Off; data.SelectedViewer = viewerSelector.IndexOfSelectedItem >= 0 ? currentViewers[(int)viewerSelector.IndexOfSelectedItem] : null; } GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow); } catch (Exception ex) { LoggingService.LogInternalError ("Error in Open File dialog", ex); } finally { if (panel != null) panel.Dispose (); } return true; }
public override void AwakeFromNib () { base.AwakeFromNib (); ExternalIdentityProviderDto = new ExternalIdentityProviderDto () { NameIDFormats = new List<string>(), SubjectFormats = new Dictionary<string, string>(), SsoServices = new List<ServiceEndpointDto>(), SloServices = new List<ServiceEndpointDto>(), SigningCertificates = new CertificateChainDto{ Certificates = new List<CertificateDto>() } }; // Name Id formats BtnAddNameIdFormat.Activated += (object sender, EventArgs e) => { if(string.IsNullOrEmpty(TxtNameIdFormat.StringValue)) { UIErrorHelper.ShowAlert ("Name Id format cannot be empty", "Alert"); return; } ExternalIdentityProviderDto.NameIDFormats.Add(TxtNameIdFormat.StringValue); ReloadTableView(LstNameIdFormat, ExternalIdentityProviderDto.NameIDFormats); TxtNameIdFormat.StringValue = (NSString)string.Empty; }; BtnRemoveNameIdFormat.Activated += (object sender, EventArgs e) => { if (LstNameIdFormat.SelectedRows.Count > 0) { foreach (var row in LstNameIdFormat.SelectedRows) { ExternalIdentityProviderDto.NameIDFormats.RemoveAt((int)row); } ReloadTableView(LstNameIdFormat, ExternalIdentityProviderDto.NameIDFormats); } }; ReloadTableView(LstNameIdFormat, ExternalIdentityProviderDto.NameIDFormats); // Subject formats BtnAddSubjectFormat.Activated += (object sender, EventArgs e) => { if(string.IsNullOrEmpty(TxtSubjectFormatName.StringValue)) { UIErrorHelper.ShowAlert ("Subject format name cannot be empty", "Alert"); return; } if(string.IsNullOrEmpty(TxtSubjectFormatValue.StringValue)) { UIErrorHelper.ShowAlert ("Subject format value cannot be empty", "Alert"); return; } if(ExternalIdentityProviderDto.SubjectFormats.ContainsKey(TxtSubjectFormatName.StringValue)) { UIErrorHelper.ShowAlert ("Subject format name already exists", "Alert"); return; } ExternalIdentityProviderDto.SubjectFormats.Add(TxtSubjectFormatName.StringValue, TxtSubjectFormatValue.StringValue); ReloadTableView(LstSubjectFormat, ExternalIdentityProviderDto.SubjectFormats); TxtSubjectFormatName.StringValue = (NSString)string.Empty; TxtSubjectFormatValue.StringValue = (NSString)string.Empty; }; BtnRemoveSubjectFormat.Activated += (object sender, EventArgs e) => { if (LstSubjectFormat.SelectedRows.Count > 0) { foreach (var row in LstSubjectFormat.SelectedRows) { var source = LstSubjectFormat.DataSource as DictionaryDataSource; var name = source.Entries[(int)row]; ExternalIdentityProviderDto.SubjectFormats.Remove(name); } ReloadTableView(LstSubjectFormat, ExternalIdentityProviderDto.SubjectFormats); } }; ReloadTableView(LstSubjectFormat, ExternalIdentityProviderDto.SubjectFormats); // Certificates BtnAddCertificate.Activated += (object sender, EventArgs e) => { var openPanel = new NSOpenPanel(); openPanel.ReleasedWhenClosed = true; openPanel.Prompt = "Select file"; var result = openPanel.RunModal(); if (result == 1) { var filePath = openPanel.Url.AbsoluteString.Replace("file://",string.Empty); var cert = new X509Certificate2 (); ActionHelper.Execute (delegate() { cert.Import (filePath); var certfificateDto = new CertificateDto { Encoded = cert.ToPem(), }; ExternalIdentityProviderDto.SigningCertificates.Certificates.Add(certfificateDto); ReloadCertificates(); }); } }; BtnRemoveCertificate.Activated += (object sender, EventArgs e) => { if (LstCertificates.SelectedRows.Count > 0) { foreach (var row in LstCertificates.SelectedRows) { ExternalIdentityProviderDto.SigningCertificates.Certificates.RemoveAt ((int)row); } ReloadCertificates(); } }; ReloadCertificates (); // Sso Services BtnAddSso.Activated += OnAddSsoServices; BtnRemoveSso.Activated += OnRemoveSsoServices; InitializeSsoServices (); // Slo Services BtnAddSlo.Activated += OnAddSloServices; BtnRemoveSlo.Activated += OnRemoveSloServices; InitializeSloServices (); this.BtnSave.Activated += (object sender, EventArgs e) => { if (string.IsNullOrEmpty (TxtUniqueId.StringValue)) { UIErrorHelper.ShowAlert ("Please choose a Unique Id", "Alert"); } else if (ExternalIdentityProviderDto.NameIDFormats.Count() < 1) { UIErrorHelper.ShowAlert ("Please choose a Name Id format", "Alert"); } else if (ExternalIdentityProviderDto.SubjectFormats.Count() < 1) { UIErrorHelper.ShowAlert ("Please choose a Subject Id format", "Alert"); } else if (ExternalIdentityProviderDto.SsoServices.Count() < 1) { UIErrorHelper.ShowAlert ("Please choose a Sso Service", "Alert"); } else if (ExternalIdentityProviderDto.SloServices.Count() < 1) { UIErrorHelper.ShowAlert ("Please choose a Slo service", "Alert"); } else if (ExternalIdentityProviderDto.SigningCertificates.Certificates.Count() < 1) { UIErrorHelper.ShowAlert ("Please choose a certificate", "Alert"); } else { ExternalIdentityProviderDto.EntityID = TxtUniqueId.StringValue; ExternalIdentityProviderDto.JitEnabled = ChkJit.StringValue == "1"; ActionHelper.Execute(delegate { var auth = SnapInContext.Instance.AuthTokenManager.GetAuthToken(ServerDto.ServerName); SnapInContext.Instance.ServiceGateway.ExternalIdentityProvider.Create(ServerDto,TenantName,ExternalIdentityProviderDto,auth.Token); this.Close (); NSApplication.SharedApplication.StopModalWithCode (1); }); } }; BtnClose.Activated += (object sender, EventArgs e) => { this.Close (); NSApplication.SharedApplication.StopModalWithCode (0); }; BtnViewCertificate.Activated += (object sender, EventArgs e) => { if (LstCertificates.SelectedRows.Count > 0) { var row = LstCertificates.SelectedRows.First(); var encoded = ExternalIdentityProviderDto.SigningCertificates.Certificates[(int)row].Encoded; var bytes = System.Text.Encoding.ASCII.GetBytes (encoded); var certificate = new X509Certificate2(bytes); CertificateService.DisplayX509Certificate2(this, certificate); } }; }
public override void AwakeFromNib () { base.AwakeFromNib (); //Events this.BtnAcquireToken.Activated += OnClickAddButton; this.BtnClose.Activated += (object sender, EventArgs e) => { this.Close (); NSApplication.SharedApplication.StopModalWithCode (0); }; this.BtnSelectCertificate.Activated += (object sender, EventArgs e) => { var openPanel = new NSOpenPanel(); openPanel.ReleasedWhenClosed = true; openPanel.Prompt = "Select file"; var result = openPanel.RunModal(); if (result == 1) { var filePath = openPanel.Url.AbsoluteString.Replace("file://",string.Empty); var cert1 = new X509Certificate2 (); ActionHelper.Execute (delegate() { cert1.Import (filePath); TxtCertificate.StringValue = filePath; }); } }; this.BtnSelectPrivateKey.Activated += (object sender, EventArgs e) => { var openPanel = new NSOpenPanel(); openPanel.ReleasedWhenClosed = true; openPanel.Prompt = "Select file"; var result = openPanel.RunModal(); if (result == 1) { var filePath = openPanel.Url.AbsoluteString.Replace("file://",string.Empty); ActionHelper.Execute (delegate() { TxtPrivateKey.StringValue = filePath; }); } }; this.BtnBrowseTokenFile.Activated += (object sender, EventArgs e) => { var openPanel = new NSOpenPanel(); openPanel.ReleasedWhenClosed = true; openPanel.Prompt = "Select file"; var result = openPanel.RunModal(); if (result == 1) { var filePath = openPanel.Url.AbsoluteString.Replace("file://",string.Empty); ActionHelper.Execute (delegate() { TxtTokenFile.StringValue = filePath; }); } }; this.CbSaml.Activated += (object sender, EventArgs e) => { var legacy = this.CbSaml.StringValue == "1"; this.TxtStsUrl.Hidden = !legacy; this.LblStsUrl.Hidden = !legacy; SetUrl(this,EventArgs.Empty); PnlJwt.Hidden = legacy; PnlSaml.Hidden = !legacy; }; this.RdoTypeGroup.Activated += (object sender, EventArgs e) => { SetGroupControls(); }; this.TxtServer.Changed += SetUrl; this.TxtPort.Changed += SetUrl; this.TxtStsUrl.Changed += SetUrl; this.TxtTenant.Changed += SetUrl; this.CbSsl.Activated += SetUrl; var saml = false; this.RdoTypeGroup.SelectCellWithTag (1); SetGroupControls (); if (ServerDto != null) { this.TxtServer.StringValue = ServerDto.ServerName; this.TxtStsUrl.StringValue = ServerDto.TokenType == TokenType.SAML ? (string.IsNullOrEmpty(ServerDto.StsUrl) ? "sts/STSService" : ServerDto.StsUrl) : "sts/STSService" ; this.TxtPort.StringValue = ServerDto.Port; this.TxtTenant.StringValue = ServerDto.Tenant; saml = ServerDto.TokenType == TokenType.SAML; var auth = SnapInContext.Instance.AuthTokenManager.GetAuthToken (ServerDto.ServerName); if (auth != null && auth.Login != null) { TxtUsername.StringValue = auth.Login.User; TxtDomain.StringValue = auth.Login.DomainName; this.TxtTenant.StringValue = auth.Login.DomainName; } } this.CbSaml.StringValue = saml ? "1" : "0"; PnlJwt.Hidden = saml; PnlSaml.Hidden = !saml; TxtStsUrl.Hidden = !saml; LblStsUrl.Hidden = !saml; SetUrl (this,EventArgs.Empty); }
// This is called when the user select open from the file menu. public new int runModalOpenPanel_forTypes(NSOpenPanel openPanel, NSArray types) { openPanel.setTreatsFilePackagesAsDirectories(true); int result = SuperCall(NSDocumentController.Class, "runModalOpenPanel:forTypes:", openPanel, types).To<int>(); if (result == Enums.NSOKButton) { uint count = openPanel.URLs().count(); if (!NSApplication.sharedApplication().delegate_().Call("shouldOpenFiles:", count).To<bool>()) result = Enums.NSCancelButton; } return result; }
public override void AwakeFromNib () { base.AwakeFromNib (); OidcClientDto = new OidcClientDto { ClientId = OidcClientDtoOriginal.ClientId, OidcClientMetadataDTO = new OidcClientMetadataDto { RedirectUris = OidcClientDtoOriginal.OidcClientMetadataDTO.RedirectUris, PostLogoutRedirectUris = OidcClientDtoOriginal.OidcClientMetadataDTO.PostLogoutRedirectUris, CertSubjectDN = OidcClientDtoOriginal.OidcClientMetadataDTO.CertSubjectDN, LogoutUri = OidcClientDtoOriginal.OidcClientMetadataDTO.LogoutUri, TokenEndpointAuthMethod = OidcClientDtoOriginal.OidcClientMetadataDTO.TokenEndpointAuthMethod } }; TxtName.StringValue = OidcClientDtoOriginal.ClientId; var authIndex = OidcClientDtoOriginal.OidcClientMetadataDTO.TokenEndpointAuthMethod == "none" ? 0 : 1; CbTokenAuthMethod.SelectItem (authIndex); TxtLogoutUrl.StringValue = string.IsNullOrEmpty (OidcClientDtoOriginal.OidcClientMetadataDTO.LogoutUri) ? string.Empty : OidcClientDtoOriginal.OidcClientMetadataDTO.LogoutUri; TxtCertificateDN.StringValue = string.IsNullOrEmpty (OidcClientDtoOriginal.OidcClientMetadataDTO.CertSubjectDN) ? string.Empty : OidcClientDtoOriginal.OidcClientMetadataDTO.CertSubjectDN; ReloadTableView(RedirectUriTableView, OidcClientDto.OidcClientMetadataDTO.RedirectUris); ReloadTableView(PostLogoutRedirectUriTableView, OidcClientDto.OidcClientMetadataDTO.PostLogoutRedirectUris); BtnBrowseCertificate.Activated += (object sender, EventArgs e) => { var openPanel = new NSOpenPanel(); openPanel.ReleasedWhenClosed = true; openPanel.Prompt = "Select file"; var result = openPanel.RunModal(); if (result == 1) { var filePath = openPanel.Url.AbsoluteString.Replace("file://",string.Empty); var cert = new X509Certificate2 (); ActionHelper.Execute (delegate() { cert.Import (filePath); TxtCertificateDN.StringValue = cert.Subject; }); } }; BtnAddRedirectUri.Activated += (object sender, EventArgs e) => { if(string.IsNullOrEmpty(TxtRedirectUri.StringValue)) { UIErrorHelper.ShowAlert ("Redirect Uri cannot be empty", "Alert"); return; } else if(!WebUtil.IsValidHttpUrl(TxtRedirectUri.StringValue)) { UIErrorHelper.ShowAlert ("Redirect Uri is invalid", "Alert"); return; } OidcClientDto.OidcClientMetadataDTO.RedirectUris.Add(TxtRedirectUri.StringValue); ReloadTableView(RedirectUriTableView, OidcClientDto.OidcClientMetadataDTO.RedirectUris); TxtRedirectUri.StringValue = (NSString)string.Empty; }; BtnAddPostLogoutRedirectUri.Activated += (object sender, EventArgs e) => { if(string.IsNullOrEmpty(TxtPostLogoutRedirectUri.StringValue)) { UIErrorHelper.ShowAlert ("Post logout redirect Uri cannot be empty", "Alert"); return; } else if(!WebUtil.IsValidHttpUrl(TxtPostLogoutRedirectUri.StringValue)) { UIErrorHelper.ShowAlert ("Post logout is invalid", "Alert"); return; } OidcClientDto.OidcClientMetadataDTO.PostLogoutRedirectUris.Add(TxtPostLogoutRedirectUri.StringValue); ReloadTableView(PostLogoutRedirectUriTableView, OidcClientDto.OidcClientMetadataDTO.PostLogoutRedirectUris); TxtPostLogoutRedirectUri.StringValue = (NSString)string.Empty; }; BtnRemoveRedirectUri.Activated += (object sender, EventArgs e) => { if (RedirectUriTableView.SelectedRows.Count > 0) { foreach (var row in RedirectUriTableView.SelectedRows) { OidcClientDto.OidcClientMetadataDTO.RedirectUris.RemoveAt((int)row); } ReloadTableView(RedirectUriTableView, OidcClientDto.OidcClientMetadataDTO.RedirectUris); } }; BtnRemovePostLogoutRedirectUri.Activated += (object sender, EventArgs e) => { if (PostLogoutRedirectUriTableView.SelectedRows.Count > 0) { foreach (var row in PostLogoutRedirectUriTableView.SelectedRows) { OidcClientDto.OidcClientMetadataDTO.PostLogoutRedirectUris.RemoveAt((int)row); } ReloadTableView(PostLogoutRedirectUriTableView, OidcClientDto.OidcClientMetadataDTO.PostLogoutRedirectUris); } }; this.BtnApply.Activated += (object sender, EventArgs e) => { ActionHelper.Execute (delegate() { if (string.IsNullOrEmpty (TxtCertificateDN.StringValue)) { UIErrorHelper.ShowAlert ("Please choose a valid certificate", "Alert"); } else if (string.IsNullOrEmpty (TxtLogoutUrl.StringValue) || !WebUtil.IsValidHttpUrl(TxtLogoutUrl.StringValue)) { UIErrorHelper.ShowAlert ("Please enter valid logout uri", "Alert"); } else if (OidcClientDto.OidcClientMetadataDTO.RedirectUris.Count == 0) { UIErrorHelper.ShowAlert ("Please enter a valid redirect URI", "Alert"); } else if (OidcClientDto.OidcClientMetadataDTO.PostLogoutRedirectUris.Count == 0) { UIErrorHelper.ShowAlert ("Please enter a valid post logout redirect URI", "Alert"); } else { OidcClientDto.OidcClientMetadataDTO.LogoutUri = TxtLogoutUrl.StringValue; OidcClientDto.OidcClientMetadataDTO.TokenEndpointAuthMethod = (NSString)CbTokenAuthMethod.SelectedValue; OidcClientDto.OidcClientMetadataDTO.CertSubjectDN = TxtCertificateDN.StringValue; var auth = SnapInContext.Instance.AuthTokenManager.GetAuthToken (ServerDto.ServerName); OidcClientDto = SnapInContext.Instance.ServiceGateway.OidcClient.Update (ServerDto, TenantName, OidcClientDto.ClientId, OidcClientDto.OidcClientMetadataDTO, auth.Token); NSNotificationCenter.DefaultCenter.PostNotificationName ("RefreshTableView", this); } }); }; }
void OpenCertificateFile (object sender, EventArgs args) { NSOpenPanel openDlg = new NSOpenPanel (); openDlg.CanChooseFiles = true; nint result = openDlg.RunModal (); if (result == (nint)1) { CertificateField.StringValue = openDlg.Url.RelativePath; } }
public override void AwakeFromNib () { base.AwakeFromNib (); _certificates = new List<CertificateDto> (); _currentStep = WizardSteps.One; SetWizardStep (); ReloadCertificates (); //Events this.BtnTestConnection.Activated += TestConnection; this.BtnNext.Activated += OnClickNextButton; this.BtnBack.Activated += OnClickBackButton; this.BtnAddCertificate.Activated += (object sender, EventArgs e) => { var openPanel = new NSOpenPanel(); openPanel.ReleasedWhenClosed = true; openPanel.Prompt = "Select file"; var result = openPanel.RunModal(); if (result == 1) { var filePath = openPanel.Url.AbsoluteString.Replace("file://",string.Empty); var cert = new X509Certificate2 (); ActionHelper.Execute (delegate() { cert.Import (filePath); var certfificateDto = new CertificateDto { Encoded = cert.ToPem(), Chain = cert.GetFormattedThumbPrint()}; _certificates.Add(certfificateDto); ReloadCertificates(); }); } }; this.RdoIdentitySource.Activated += (object sender, EventArgs e) => { SetSpnControls(); }; this.RdoDomainController.Activated += (object sender, EventArgs e) => { var anyDc = RdoDomainController.SelectedTag == 1; if(anyDc) { SetConnectionString(); } else { TxtLdapConnection.StringValue = (NSString) string.Empty; } ChkProtect.Enabled = anyDc; EnableDisableConnectionString(!anyDc); }; this.BtnRemoveCertificate.Activated += (object sender, EventArgs e) => { if (LstCertificates.SelectedRows.Count > 0) { foreach (var row in LstCertificates.SelectedRows) { _certificates.RemoveAt ((int)row); } ReloadCertificates(); } }; this.BtnPrimaryImport.Activated += (object sender, EventArgs e) => { }; this.BtnSecondaryImport.Activated += (object sender, EventArgs e) => { }; this.TxtDomainName.Changed += (object sender, EventArgs e) => { SetConnectionString(); }; this.ChkProtect.Activated += (object sender, EventArgs e) => { SetConnectionString(); }; this.RdoSpn.Activated += (object sender, EventArgs e) => { SetSpnControls(); }; BtnPrimaryImport.Enabled = false; BtnSecondaryImport.Enabled = false; this.TxtPrimaryUrl.Activated += (object sender, EventArgs e) => { BtnPrimaryImport.Enabled = this.TxtPrimaryUrl.StringValue!= null && this.TxtPrimaryUrl.StringValue.StartsWith("ldaps://"); }; this.TxtSecondaryConnection.Activated += (object sender, EventArgs e) => { BtnSecondaryImport.Enabled = this.TxtSecondaryConnection.StringValue!= null && this.TxtSecondaryConnection.StringValue.StartsWith("ldaps://"); }; BtnPrimaryImport.Activated += (object sender, EventArgs e) => { ImportCertificates(TxtPrimaryUrl.StringValue); }; BtnSecondaryImport.Activated += (object sender, EventArgs e) => { ImportCertificates(TxtSecondaryConnection.StringValue); }; if (IdentityProviderDto != null) DtoToView (); else IdentityProviderDto = new IdentityProviderDto (); this.BtnAdvanced.Activated += (object sender, EventArgs e) => { var form = new ExternalDomainAdvancedSettingsController () { IdentityProviderDto = new IdentityProviderDto { Schema = IdentityProviderDto.Schema == null ? new Dictionary<string, SchemaObjectMappingDto>() :new Dictionary<string, SchemaObjectMappingDto>(IdentityProviderDto.Schema), AttributesMap = IdentityProviderDto.AttributesMap == null ? new Dictionary<string, string>() : new Dictionary<string, string>(IdentityProviderDto.AttributesMap), BaseDnForNestedGroupsEnabled = IdentityProviderDto.BaseDnForNestedGroupsEnabled, MatchingRuleInChainEnabled = IdentityProviderDto.MatchingRuleInChainEnabled, DirectGroupsSearchEnabled = IdentityProviderDto.DirectGroupsSearchEnabled } }; var result = NSApplication.SharedApplication.RunModalForWindow (form.Window); if(result == 1) { IdentityProviderDto.Schema = GetSchema(form.IdentityProviderDto.Schema); IdentityProviderDto.AttributesMap = new Dictionary<string, string>(form.IdentityProviderDto.AttributesMap); IdentityProviderDto.BaseDnForNestedGroupsEnabled = form.IdentityProviderDto.BaseDnForNestedGroupsEnabled; IdentityProviderDto.MatchingRuleInChainEnabled = form.IdentityProviderDto.MatchingRuleInChainEnabled; IdentityProviderDto.DirectGroupsSearchEnabled = form.IdentityProviderDto.DirectGroupsSearchEnabled; } }; SetSpnControls (); }
public override void AwakeFromNib() { base.AwakeFromNib(); ExternalIdentityProviderDto = new ExternalIdentityProviderDto() { NameIDFormats = new List <string>(), SubjectFormats = new Dictionary <string, string>(), SsoServices = new List <ServiceEndpointDto>(), SloServices = new List <ServiceEndpointDto>(), SigningCertificates = new CertificateChainDto { Certificates = new List <CertificateDto>() } }; // Name Id formats BtnAddNameIdFormat.Activated += (object sender, EventArgs e) => { if (string.IsNullOrEmpty(TxtNameIdFormat.StringValue)) { UIErrorHelper.ShowAlert("Name Id format cannot be empty", "Alert"); return; } ExternalIdentityProviderDto.NameIDFormats.Add(TxtNameIdFormat.StringValue); ReloadTableView(LstNameIdFormat, ExternalIdentityProviderDto.NameIDFormats); TxtNameIdFormat.StringValue = (NSString)string.Empty; }; BtnRemoveNameIdFormat.Activated += (object sender, EventArgs e) => { if (LstNameIdFormat.SelectedRows.Count > 0) { foreach (var row in LstNameIdFormat.SelectedRows) { ExternalIdentityProviderDto.NameIDFormats.RemoveAt((int)row); } ReloadTableView(LstNameIdFormat, ExternalIdentityProviderDto.NameIDFormats); } }; ReloadTableView(LstNameIdFormat, ExternalIdentityProviderDto.NameIDFormats); // Subject formats BtnAddSubjectFormat.Activated += (object sender, EventArgs e) => { if (string.IsNullOrEmpty(TxtSubjectFormatName.StringValue)) { UIErrorHelper.ShowAlert("Subject format name cannot be empty", "Alert"); return; } if (string.IsNullOrEmpty(TxtSubjectFormatValue.StringValue)) { UIErrorHelper.ShowAlert("Subject format value cannot be empty", "Alert"); return; } if (ExternalIdentityProviderDto.SubjectFormats.ContainsKey(TxtSubjectFormatName.StringValue)) { UIErrorHelper.ShowAlert("Subject format name already exists", "Alert"); return; } ExternalIdentityProviderDto.SubjectFormats.Add(TxtSubjectFormatName.StringValue, TxtSubjectFormatValue.StringValue); ReloadTableView(LstSubjectFormat, ExternalIdentityProviderDto.SubjectFormats); TxtSubjectFormatName.StringValue = (NSString)string.Empty; TxtSubjectFormatValue.StringValue = (NSString)string.Empty; }; BtnRemoveSubjectFormat.Activated += (object sender, EventArgs e) => { if (LstSubjectFormat.SelectedRows.Count > 0) { foreach (var row in LstSubjectFormat.SelectedRows) { var source = LstSubjectFormat.DataSource as DictionaryDataSource; var name = source.Entries[(int)row]; ExternalIdentityProviderDto.SubjectFormats.Remove(name); } ReloadTableView(LstSubjectFormat, ExternalIdentityProviderDto.SubjectFormats); } }; ReloadTableView(LstSubjectFormat, ExternalIdentityProviderDto.SubjectFormats); // Certificates BtnAddCertificate.Activated += (object sender, EventArgs e) => { var openPanel = new NSOpenPanel(); openPanel.ReleasedWhenClosed = true; openPanel.Prompt = "Select file"; var result = openPanel.RunModal(); if (result == 1) { var filePath = openPanel.Url.AbsoluteString.Replace("file://", string.Empty); var cert = new X509Certificate2(); ActionHelper.Execute(delegate() { cert.Import(filePath); var certfificateDto = new CertificateDto { Encoded = cert.ToPem(), }; ExternalIdentityProviderDto.SigningCertificates.Certificates.Add(certfificateDto); ReloadCertificates(); }); } }; BtnRemoveCertificate.Activated += (object sender, EventArgs e) => { if (LstCertificates.SelectedRows.Count > 0) { foreach (var row in LstCertificates.SelectedRows) { ExternalIdentityProviderDto.SigningCertificates.Certificates.RemoveAt((int)row); } ReloadCertificates(); } }; ReloadCertificates(); // Sso Services BtnAddSso.Activated += OnAddSsoServices; BtnRemoveSso.Activated += OnRemoveSsoServices; InitializeSsoServices(); // Slo Services BtnAddSlo.Activated += OnAddSloServices; BtnRemoveSlo.Activated += OnRemoveSloServices; InitializeSloServices(); this.BtnSave.Activated += (object sender, EventArgs e) => { if (string.IsNullOrEmpty(TxtUniqueId.StringValue)) { UIErrorHelper.ShowAlert("Please choose a Unique Id", "Alert"); } else if (ExternalIdentityProviderDto.NameIDFormats.Count() < 1) { UIErrorHelper.ShowAlert("Please choose a Name Id format", "Alert"); } else if (ExternalIdentityProviderDto.SubjectFormats.Count() < 1) { UIErrorHelper.ShowAlert("Please choose a Subject Id format", "Alert"); } else if (ExternalIdentityProviderDto.SsoServices.Count() < 1) { UIErrorHelper.ShowAlert("Please choose a Sso Service", "Alert"); } else if (ExternalIdentityProviderDto.SloServices.Count() < 1) { UIErrorHelper.ShowAlert("Please choose a Slo service", "Alert"); } else if (ExternalIdentityProviderDto.SigningCertificates.Certificates.Count() < 1) { UIErrorHelper.ShowAlert("Please choose a certificate", "Alert"); } else { ExternalIdentityProviderDto.EntityID = TxtUniqueId.StringValue; ExternalIdentityProviderDto.JitEnabled = ChkJit.StringValue == "1"; ActionHelper.Execute(delegate { var auth = SnapInContext.Instance.AuthTokenManager.GetAuthToken(ServerDto.ServerName); SnapInContext.Instance.ServiceGateway.ExternalIdentityProvider.Create(ServerDto, TenantName, ExternalIdentityProviderDto, auth.Token); this.Close(); NSApplication.SharedApplication.StopModalWithCode(1); }); } }; BtnClose.Activated += (object sender, EventArgs e) => { this.Close(); NSApplication.SharedApplication.StopModalWithCode(0); }; BtnViewCertificate.Activated += (object sender, EventArgs e) => { if (LstCertificates.SelectedRows.Count > 0) { var row = LstCertificates.SelectedRows.First(); var encoded = ExternalIdentityProviderDto.SigningCertificates.Certificates[(int)row].Encoded; var bytes = System.Text.Encoding.ASCII.GetBytes(encoded); var certificate = new X509Certificate2(bytes); CertificateService.DisplayX509Certificate2(this, certificate); } }; }