static NulData Login string  username,
string  password,
string  host,
string  port
[static]
 

Allows to perform an login request.

This method allows to perform asynchronous and synchronous login operations. Here is an example on how to make a synchronous login operation.

using System;
using AfArch.AfDal;
using System.Threading;

public class TestAfDal {

        public static void Main (string [] args) {

                // init afdal
                AfDal.Init ();
                Console.WriteLine ("AfDal initialized");

                // Ask for user data
                Console.Write ("User: "); 
                string user = Console.ReadLine ();
                Console.Write ("Pass: ");
                string pass = Console.ReadLine ();
                Console.Write ("Host: ");
                string host = Console.ReadLine ();
                Console.Write ("Port: ");
                string port = Console.ReadLine ();
                
                
                

                // make synchronous login
                Console.WriteLine ("Making login petition..");
                NulData data   = Session.Login (user, pass, host, port);

                Console.WriteLine ("Login process returns: {0} with {1}", 
                                   data.State, data.Response);
                
                if (data.State == State.Ok) {
                        NulData data2 = Session.Logout ();

                        Console.WriteLine ("Logout process returns: {0} with {1}",
                                           data2.State, data2.Response);
                }

                return;
        }
}

On the previous example, the login request will block caller until login request is completed.

Here is an example on how to make a asynchronous login:

using System;
using AfArch.AfDal;
using System.Threading;


public class TestAfDalAsync {

        public static void LoginProc (IAsyncResult ar) {

                AsyncLogin dlgt = ar.AsyncState as AsyncLogin;
                NulData data    = dlgt.EndInvoke (ar);
                
                Console.WriteLine ("Login response recieved: {0} and {1}", 
                                   data.State, data.Response);

                
                return;

        }

        public static void LogoutProc (IAsyncResult ar) {

                AsyncLogout dlgt = ar.AsyncState as AsyncLogout;
                NulData data     = dlgt.EndInvoke (ar);

                Console.WriteLine ("Logout response recieved(2): {0} and {1}", 
                                   data.State, data.Response);
                return;
        }

        public static void Main (string [] args) {

                // init afdal
                AfDal.Init ();
                Console.WriteLine ("AfDal initialized");

                // Ask for user data
                Console.Write ("User: "); 
                string user = Console.ReadLine ();
                Console.Write ("Pass: ");
                string pass = Console.ReadLine ();
                Console.Write ("Host: ");
                string host = Console.ReadLine ();
                Console.Write ("Port: ");
                string port = Console.ReadLine ();
                
                
                // make asynchronous login
                AsyncLogin  dlgt = new AsyncLogin (Session.Login);
                IAsyncResult ar  = dlgt.BeginInvoke (user, pass, 
                                                     host, port, 
                                                     new AsyncCallback (LoginProc), dlgt);

                // wait until finished 
                ar.AsyncWaitHandle.WaitOne ();

                // make asynchronous logout
                AsyncLogout dlgt2 = new AsyncLogout (Session.Logout);
                ar                = dlgt2.BeginInvoke (new AsyncCallback (LogoutProc), 
                                                       dlgt2);

                // wait until finished
                ar.AsyncWaitHandle.WaitOne ();
                
                return;
        }
}

Please check also documenation for afdal_session_login function from C layer which gives a more detailed examplation about using Async or Sync methods.

Parameters:
username The username to be used on login process.
password The password to be used on login process.
host The host where is located the af-kernel server.
port The port where is located the af-kernel server.
Returns:
A NulData object.