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.

 

Invoking Lotus Notes Session in VB.NET

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

 

Procedure 1:

    Private Sub InitLotusNotesSession()

        bStatus = SetLoginUser(INIFilePath & "Spec.id", sCurrUserID)

        If (bStatus = True) Then

            bStatus = InitGUINotesSession()

            If (bStatus = True) Then

                bStatus = SetLoginUser(sCurrUserID, sNewUserID)

            Else

                Exit Sub

            End If

        Else

            Exit Sub

        End If

    End Sub

 

Procedure 2:

    Private Function SetLoginUser(ByVal myNewUserID As String, ByVal myCurrentUserID As String) As Boolean

        Dim sNotesIniFile As String

        Dim objINI As New _IniFile

        Dim INIFile As String = "Intfc.ini"

        With objINI

            .Path = INIFilePath & INIFile

            .Section = "LOTUS_NOTES"

            .myDefault = "NOT AVAILABLE"

            .Key = "INI_FILE"

            sNotesIniFile = .myValue

            Debug.WriteLine(.Success)

        End With

        If (sNotesIniFile <> "NOT AVAILABLE") Then

            With objINI

                .Path = sNotesIniFile

                .Section = "Notes"

                .myDefault = "NOT AVAILABLE"

                .Key = "KeyFilename"

                myCurrentUserID = .myValue

                If (sCurrUserID <> "NOT AVAILABLE") Then

                    .myValue = myNewUserID

                Else

                    SetLoginUser = False

                    Exit Function

                End If

            End With

        Else

            SetLoginUser = False

            Exit Function

        End If

        SetLoginUser = True

        sNewUserID = myNewUserID

        sCurrUserID = myCurrentUserID

    End Function

 

Procedure 3:

    Private Function InitGUINotesSession() As Boolean

        Try

            InitGUINotesSession = False

            gobjSession = CreateObject("Lotus.NotesSession")

            Call gobjSession.Initialize(myPassword)

            gobjDB = gobjSession.GetDatabase(myServer, mydBase)

            InitGUINotesSession = True

            Exit Function

        Catch ex As Exception

            'MsgBox(ex.ToString & vbCrLf & vbCrLf & " Error in Initializing Notes Session!")

            Logger.LogWithDate(LogFile, ex.ToString & vbCrLf & vbCrLf & " Error in Initializing Notes Session!")

            InitGUINotesSession = False

        End Try

    End Function

 

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.

 

Thursday, September 20, 2007

Whatever Your Cross May Be!

Don't miss the poem at the end …

















Whatever your cross,
whatever your pain,
there will always be sunshine,
after the rain ....
 
Perhaps you may stumble,
perhaps even fall,
But God's always ready,
To answer your call ...
 
He knows every heartache,
sees every tear,
A word from His lips,
can calm every fear ...
 
Your sorrows may linger,
throughout the night,
But suddenly vanish,
in dawn's early light ...
 
The Savior is waiting,
To give you His grace,
and send you His love...
 
Whatever your cross,
whatever your pain,
"God always sends rainbows ....
after the rain ... "
 

 

To get out of difficulty, one must usually go through it! 

 

How Great is the Father's Love...

Yesterday, and the few days and weeks before, I have been training some colleagues

on the system that we use in our company. Purpose of the training is to have some

back-ups in times of need, whether or not I am present.

 

And one thing struck me: in my years of doing the job, I have accumulated vast knowledge

and have also honed my skills in analyzing systems and developing solutions using softwares.

 

I remember how I started. I had the desire to learn, and I had the resources. More than literatures

and printed materials, I have the very, very seasoned developers in our IT group. And most

importantly, I have the problem to solve, or the targetted goal. More or less, I knew the end in mind.

This is very important – focus will always be aligned towards this objective.

 

Thus I began, reading, coding, trying… endless hours of typing and being infront of the computer.

And this also started the endless stream of asking questions to our senior programmers. Which paid off.

 

5 years or so after, I find that I am the one in the senior level, and I am now passing on the baton

to the next generation. And I’ve come to the realization that I have gone so far from my first step years back.

 

The reflection? Like a father teaching a child; all the experiences and age-ripened wisdom and knowledge applied.

The father would be very patient in the process, being careful not to use terms and language that the child doesn’t

understand – simly because the child hasn’t matured. And yet the father continues on with the end in mind that

one day, the child will also become mature, like him.

 

The impression? Like God, drawing back sinful man to Him. Even though God knew that the gap is such that

it would seem impossible to be bridged, God did what only He can do, as our Father. He sent His Son to die for us,

and bring us back to Him, in His fellowship.

 

“But God commends his own love toward us,

 in that while we were yet sinners, Christ died for us.”

Romans 5:8