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.ExportToPem(),
                        };
                        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.Alias      = TxtAlias.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();
            if (ExternalIdentityProviderDto.NameIDFormats == null)
            {
                ExternalIdentityProviderDto.NameIDFormats = new List <string> ();
            }

            if (ExternalIdentityProviderDto.SubjectFormats == null)
            {
                ExternalIdentityProviderDto.SubjectFormats = new Dictionary <string, string> ();
            }
            if (ExternalIdentityProviderDto.SsoServices == null)
            {
                ExternalIdentityProviderDto.SsoServices = new List <ServiceEndpointDto> ();
            }
            if (ExternalIdentityProviderDto.SloServices == null)
            {
                ExternalIdentityProviderDto.SloServices = new List <ServiceEndpointDto> ();
            }
            if (ExternalIdentityProviderDto.SigningCertificates == null)
            {
                ExternalIdentityProviderDto.SigningCertificates = new CertificateChainDto {
                    Certificates = new List <CertificateDto>()
                }
            }
            ;
            TxtEntityName.StringValue = (NSString)(string.IsNullOrEmpty(ExternalIdentityProviderDto.EntityID) ? string.Empty : ExternalIdentityProviderDto.EntityID);
            TxtAlias.StringValue      = (NSString)(string.IsNullOrEmpty(ExternalIdentityProviderDto.Alias) ? string.Empty : ExternalIdentityProviderDto.Alias);
            BtnJit.StringValue        = ExternalIdentityProviderDto.JitEnabled ? "1" : "0";
            ReloadTableView(NameFormatTableView, ExternalIdentityProviderDto.NameIDFormats);
            ReloadTableView(SubjectFormatTableView, ExternalIdentityProviderDto.SubjectFormats);
            ReloadCertificates();
            InitializeSsoServices();
            InitializeSloServices();

            BtnViewCertificate.Activated += (object sender, EventArgs e) =>
            {
                if (CertificateTableView.SelectedRows.Count > 0)
                {
                    var row         = CertificateTableView.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);
                }
            };

            EditButton.Activated += (object sender, EventArgs e) => {
                ActionHelper.Execute(delegate() {
                    var form = new AddNewExternalIdentityProviderController
                    {
                        ServerDto  = ServerDto,
                        TenantName = TenantName,
                        ExternalIdentityProviderDto = ExternalIdentityProviderDto
                    };
                    var result = NSApplication.SharedApplication.RunModalForWindow(form.Window);
                    if (result == VMIdentityConstants.DIALOGOK)
                    {
                        if (form.ExternalIdentityProviderDto != null)
                        {
                            UIErrorHelper.ShowAlert("External IDP " + form.ExternalIdentityProviderDto.EntityID + " updated successfully", "Information");
                            Refresh(sender, e);
                        }
                    }
                });
            };
        }