Friday, September 21, 2007

Invoking Lotus Notes Session in C#

For the record, this is how to invoke Lotus Notes Session in C#.NET:

 

Procedure 1:

        public static bool InitLotusNotesSessionPDS()

        {

            try

            {

                bStatus = SetLoginUserPDS(PDS_SMS_Pgm_Main.PDSPromINIFilePath + "Spec.id", PDS_SMS_Pgm_Main.sCurrUserID);

                if (bStatus == true)

                {

                    bStatus = InitLNotesSessionPDS();

                    if (bStatus == true)

                    {

                        bStatus = SetLoginUserPDS(PDS_SMS_Pgm_Main.sCurrUserID, PDS_SMS_Pgm_Main.sNewUserID);

                        return true;

                    }

                    else { return false; }

                }

                else { return false; }

            }

            catch (Exception ex)

            { Console.WriteLine(ex.Message); return false; }

        }

 

Procedure 2:

        public static bool SetLoginUserPDS(string myNewUserID, string myCurrUserID)

        {

            try

            {

                string sNotesIniFile = "";

                string INIFile = "PDS_and_Prom_Intfc.ini";

                Aux_IniFile_Handler objINI = new Aux_IniFile_Handler();

 

                objINI.Path = PDS_SMS_Pgm_Main.PDSPromINIFilePath + INIFile;

                objINI.Section = "LOTUS_NOTES";

                objINI.myDefault = "NOT AVAILABLE";

                objINI.Key = "INI_FILE";

                sNotesIniFile = objINI.myValue;

 

                if (sNotesIniFile != "NOT AVAILABLE")

                {

                    objINI.Path = sNotesIniFile;

                    objINI.Section = "Notes";

                    objINI.myDefault = "NOT AVAILABLE";

                    objINI.Key = "KeyFilename";

                    myCurrUserID = objINI.myValue;

                    if (PDS_SMS_Pgm_Main.sCurrUserID != "NOT AVAILABLE")

                    { objINI.myValue = myNewUserID; }

                    else

                    { return false; }

                }

                else { return false; }

 

                PDS_SMS_Pgm_Main.sNewUserID = myNewUserID;

                PDS_SMS_Pgm_Main.sCurrUserID = myCurrUserID;

                return true;

            }

            catch (Exception ex)

            {

                Console.WriteLine(ex.Message);

                return false;

            }

        }

 

Procedure 3:

        public static bool InitLNotesSessionPDS()

        {

            try

            {

                // define a session in order to capture the System.Type

                NotesSession gobjSession0 = new NotesSession();

                Type lnType = gobjSession0.GetType();

                // create now the instance to be used

                gobjSession = (Domino.NotesSession)Activator.CreateInstance(lnType);

                gobjSession.Initialize(PDS_SMS_Pgm_Main.myPDSPassWord);

                gobjDB = gobjSession.GetDatabase(PDS_SMS_Pgm_Main.myPDSServer, PDS_SMS_Pgm_Main.myPDSdBase, false);

                if (gobjDB.IsOpen) { }

                else { gobjDB.Open(); }

                return true;

            }

            catch (Exception ex)

            { Console.WriteLine(ex.Message); return false; }

        }

 

Brief Description:

1. SetLoginUser is the procedure that captures the current LN user, and replaces it with the user ID (Spec.ID), the account that the program uses. It is reading the data set from the .ini file.

2. gobjSession is a Domino.NotesSession-type variable/object.

3. gobjDB is a Domino.NotesDatabase-type variable/object.

4. NOTE: the difference between VB.NET and C#.NET is that an additional Domino.NotesSession object (gobjSession0) is first created, and used to capture the Object Type of Domino.NotesSession, which is assigned to another additional variable, lnType. This is then used to create an instance of the gobjSession NotesSession in gobjSession = (Domino.NotesSession)Activator.CreateInstance(lnType);. These are all not required in VB.NET.

 

No comments: