Exemplo n.º 1
0
 /// <summary>
 /// Closes the current connection to the mainframe.
 /// </summary>
 public void Close()
 {
     if (currentConnection != null)
     {
         currentConnection.Disconnect();
         currentConnection = null;
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Connect to TN3270 server using the connection details specified.
 /// </summary>
 /// <remarks>
 /// You should set the Audit property to an instance of an object that implements
 /// the IAudit interface if you want to see any debugging information from this function
 /// call.
 /// </remarks>
 /// <param name="host">Host name or IP address. Mandatory</param>
 /// <param name="port">TCP/IP port to connect to (default TN3270 port is 23)</param>
 /// <param name="lu">TN3270E LU to connect to. Specify null for no LU.</param>
 public void Connect(string host, int port, string lu)
 {
     if (currentConnection != null)
     {
         currentConnection.Disconnect();
     }
     //
     //
     try
     {
         mre.AcquireAll(0);
         //
         currentConnection                 = null;
         currentConnection                 = new TN3270API();
         currentConnection.Debug           = mDebug;
         currentConnection.RunScriptEvent += new RunScriptDelegate(currentConnection_RunScriptEvent);
         currentConnection.OnDisconnect   += new OnDisconnectDelegate(currentConnection_OnDisconnect);
         //
         // Debug out our current state
         //
         if (sout != null)
         {
             sout.WriteLine("Open3270 emulator version " + Assembly.GetAssembly(typeof(Open3270.TNEmulator)).GetName().Version);
             sout.WriteLine("(c) 2004-2006 Mike Warriner ([email protected]). All rights reserved");
             sout.WriteLine("");
             //
             if (mFirstTime)
             {
                 mFirstTime = false;
             }
             if (Debug)
             {
                 Config.Dump(sout);
                 sout.WriteLine("Connect to host \"" + host + "\"");
                 sout.WriteLine("           port \"" + port + "\"");
                 sout.WriteLine("           LU   \"" + lu + "\"");
             }
         }
         else
         {
         }
         //
         currentConnection.UseSSL = this.mUseSSL;
         //
         currentConnection.Connect(this.sout, host, port, lu, this.mConnectionConfiguration);
         //
         //
         //
         currentConnection.WaitForConnect(-1);
         _currentScreenXML = null;                 // force refresh // GetScreenAsXML();
     }
     catch (Exception)
     {
         currentConnection = null;
         throw;
     }
     // these don't close the connection
     try
     {
         this.mScreenName = "Start";
         Refresh(true, 40000);
         if (sout != null && Debug == true)
         {
             sout.WriteLine("Debug::Connected");
         }
         //mScreenProcessor.Update_Screen(currentScreenXML, true);
     }
     catch (Exception)
     {
         throw;
     }
     return;
 }
Exemplo n.º 3
0
        protected virtual void Dispose(bool disposing)
        {
            lock (this)
            {
                if (IsDisposed)
                {
                    return;
                }
                isDisposed = true;

                if (sout != null)
                {
                    sout.WriteLine("TNEmulator.Dispose(" + IsDisposed.ToString() + ")");
                }

                if (disposing)
                {
                    //----------------------------
                    // release managed resources

                    if (currentConnection != null)
                    {
                        if (sout != null)
                        {
                            sout.WriteLine("TNEmulator.Dispose() Disposing of currentConnection");
                        }
                        try
                        {
                            currentConnection.Disconnect();

                            if (apiOnDisconnectDelegate != null)
                            {
                                currentConnection.OnDisconnect -= apiOnDisconnectDelegate;
                            }

                            currentConnection.Dispose();
                        }
                        catch
                        {
                            if (sout != null)
                            {
                                sout.WriteLine("TNEmulator.Dispose() Exception during currentConnection.Dispose");
                            }
                        }
                        currentConnection = null;
                    }

                    OnDisconnect = null;

                    if (sout != null)
                    {
                        sout.WriteLine("TNEmulator.Dispose() Disposing of currentScreenXML");
                    }

                    DisposeOfCurrentScreenXML();

                    if (mObjectState != null)
                    {
                        mObjectState = null;
                    }
                    if (mConnectionConfiguration != null)
                    {
                        mConnectionConfiguration = null;
                    }
                    if (mScreenName != null)
                    {
                        mScreenName = null;
                    }
                }

                //------------------------------
                // release unmanaged resources
            }
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Connect to TN3270 server using the connection details specified.
        /// </summary>
        /// <remarks>
        ///     You should set the Audit property to an instance of an object that implements
        ///     the IAudit interface if you want to see any debugging information from this function
        ///     call.
        /// </remarks>
        /// <param name="host">Host name or IP address. Mandatory</param>
        /// <param name="port">TCP/IP port to connect to (default TN3270 port is 23)</param>
        /// <param name="lu">TN3270E LU to connect to. Specify null for no LU.</param>
        public void Connect(string host, int port, string lu)
        {
            if (currentConnection != null)
            {
                currentConnection.Disconnect();
                currentConnection.CursorLocationChanged -= currentConnection_CursorLocationChanged;
            }

            try
            {
                semaphore.Reset();

                currentConnection       = null;
                currentConnection       = new TN3270API();
                currentConnection.Debug = Debug;
                currentConnection.RunScriptRequested    += currentConnection_RunScriptEvent;
                currentConnection.CursorLocationChanged += currentConnection_CursorLocationChanged;
                currentConnection.Disconnected          += apiOnDisconnectDelegate;

                apiOnDisconnectDelegate = currentConnection_OnDisconnect;

                //
                // Debug out our current state
                //
                if (Audit != null)
                {
                    Audit.WriteLine("Open3270 emulator version " +
                                    Assembly.GetAssembly(typeof(TNEmulator)).GetName().Version);
                    Audit.WriteLine("(c) 2004-2006 Mike Warriner ([email protected]). All rights reserved");
                    Audit.WriteLine("");
                    Audit.WriteLine("This is free software; you can redistribute it and/or modify it");
                    Audit.WriteLine("under the terms of the GNU Lesser General Public License as");
                    Audit.WriteLine("published by the Free Software Foundation; either version 2.1 of");
                    Audit.WriteLine("the License, or (at your option) any later version.");
                    Audit.WriteLine("");
                    Audit.WriteLine("This software is distributed in the hope that it will be useful,");
                    Audit.WriteLine("but WITHOUT ANY WARRANTY; without even the implied warranty of");
                    Audit.WriteLine("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU");
                    Audit.WriteLine("Lesser General Public License for more details.");
                    Audit.WriteLine("");
                    Audit.WriteLine("You should have received a copy of the GNU Lesser General Public");
                    Audit.WriteLine("License along with this software; if not, write to the Free");
                    Audit.WriteLine("Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA");
                    Audit.WriteLine("02110-1301 USA, or see the FSF site: http://www.fsf.org.");
                    Audit.WriteLine("");

                    if (firstTime)
                    {
                        firstTime = false;
                    }
                    if (Debug)
                    {
                        Config.Dump(Audit);
                        Audit.WriteLine("Connect to host \"" + host + "\"");
                        Audit.WriteLine("           port \"" + port + "\"");
                        Audit.WriteLine("           LU   \"" + lu + "\"");
                        Audit.WriteLine("     Local IP   \"" + LocalIP + "\"");
                    }
                }

                currentConnection.UseSSL = UseSSL;


                /// Modified CFCJR Feb/29/2008 to support local IP endpoint
                if (!string.IsNullOrEmpty(LocalIP))
                {
                    currentConnection.Connect(Audit, LocalIP, host, port, Config);
                }
                else
                {
                    currentConnection.Connect(Audit, host, port, lu, Config);
                }

                currentConnection.WaitForConnect(-1);
                DisposeOfCurrentScreenXML();
                currentScreenXML = null;
                // Force refresh
                // GetScreenAsXML();
            }
            catch (Exception)
            {
                currentConnection = null;
                throw;
            }

            // These don't close the connection
            try
            {
                mScreenName = "Start";
                Refresh(true, 10000);
                if (Audit != null && Debug)
                {
                    Audit.WriteLine("Debug::Connected");
                }
                //mScreenProcessor.Update_Screen(currentScreenXML, true);
            }
            catch (Exception)
            {
                throw;
            }
        }