public async void ConnectToServer (string server)
 {
     var serverDTO = VMCertStoreServerDTO.CreateInstance ();
     Servernode = new VMCertStoreServerNode (serverDTO);
     ProgressWindowController pwc = new ProgressWindowController ();
     IntPtr session = new IntPtr (0);
     LoginWindowController lwc = new LoginWindowController (server);
     NSApplication.SharedApplication.BeginSheet (lwc.Window, this.Window, () => {
     });
     nint result = NSApplication.SharedApplication.RunModalForWindow (lwc.Window);
     try {
         if (result == (nint)VMIdentityConstants.DIALOGOK) {
             Servernode.ServerDTO.Server = lwc.Server;
             NSApplication.SharedApplication.BeginSheet (pwc.Window, this.Window as NSWindow, () => {
             });
             session = NSApplication.SharedApplication.BeginModalSession (pwc.Window);
             await Servernode.ServerDTO.LogintoServer (lwc.UserName, lwc.Password, lwc.DomainName);
             if (Servernode.ServerDTO.IsLoggedIn == true) {
                 InitialiseViews ();
                 NSNotificationCenter.DefaultCenter.PostNotificationName ("ReloadOutlineView", this);
                 Task.Run (() => Servernode.FillServerInfo ());
             } else
                 UIErrorHelper.ShowAlert ("Please check the login details or the user permissions.", "Unable to Login");
         }
     } catch (Exception e) {
         UIErrorHelper.ShowAlert ("", e.Message);
     } finally {
         if (pwc.ProgressBar != null) {
             pwc.ProgressBar.StopAnimation (pwc.Window);
             pwc.Window.Close ();
             NSApplication.SharedApplication.EndModalSession (session);
         }
         Window.EndSheet (lwc.Window);
         lwc.Dispose ();
     }
 }
 public async void ConnectToServer (string server)
 {
     ProgressWindowController pwc = new ProgressWindowController ();
     IntPtr session = new IntPtr (0);
     LoginWindowController lwc = new LoginWindowController (server);
     NSApplication.SharedApplication.BeginSheet (lwc.Window, this.Window, () => {
     });
     nint result = NSApplication.SharedApplication.RunModalForWindow (lwc.Window);
     try {
         if (result == (nint)Constants.DIALOGOK) {
             
             this.Initialise (lwc.Server);
             Servernode.ServerDTO.Server = lwc.Server;
             NSApplication.SharedApplication.BeginSheet (pwc.Window, this.Window as NSWindow, () => {
             });
             session = NSApplication.SharedApplication.BeginModalSession (pwc.Window);
             await Servernode.ServerDTO.LogintoServer (lwc.UserName, lwc.Password, lwc.DomainName);
             if (Servernode.ServerDTO.IsLoggedIn == true) {
                 Servernode.Initialise ();
                 InitialiseViews ();
                 NSNotificationCenter.DefaultCenter.PostNotificationName ("ReloadOutlineView", this);
             } else {
                 UIErrorHelper.ShowAlert ("", "Unable to login! Please validate the connection details.");
             }
         }
     } catch (Exception e) {
         UIErrorHelper.ShowAlert ("", e.Message);
     } finally {
         if (pwc.ProgressBar != null) {
             pwc.ProgressBar.StopAnimation (pwc.Window);
             pwc.Window.Close ();
             NSApplication.SharedApplication.EndModalSession (session);
         }
         Window.EndSheet (lwc.Window);
         lwc.Dispose ();
     }
 }
        public async void ConnectToServer (string server)
        {
            var serverDTO = VMDirServerDTO.CreateInstance ();
            if (!string.IsNullOrWhiteSpace (server))
                serverDTO.Server = server;
            ProgressWindowController pwc = new ProgressWindowController ();
            IntPtr session = new IntPtr (0);
            ConnectToLdapWindowController awc = new ConnectToLdapWindowController (serverDTO);
            NSApplication.SharedApplication.BeginSheet (awc.Window, this.Window, () => {
            });
            nint result = NSApplication.SharedApplication.RunModalForWindow (awc.Window);
            try {
                if (result == VMIdentityConstants.DIALOGOK) {
                    NSApplication.SharedApplication.BeginSheet (pwc.Window, this.Window as NSWindow, () => {
                    });
                    session = NSApplication.SharedApplication.BeginModalSession (pwc.Window);
                    serverNode = new VMDirServerInfo (serverDTO);
                    await serverNode.DoLogin ();
                    InitialiseViews ();

                }
            } catch (Exception e) {
                UIErrorHelper.ShowAlert ("Connection is not successful. " + e.Message, "Alert");
            } finally {
                if (pwc.ProgressBar != null) {
                    pwc.ProgressBar.StopAnimation (pwc.Window);
                    pwc.Window.Close ();
                    NSApplication.SharedApplication.EndModalSession (session);
                }
                Window.EndSheet (awc.Window);
                awc.Dispose ();
            }
        }