Example #1
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="ACantDisconnectReason"></param>
        /// <returns></returns>
        public Boolean DisconnectFromServer(out String ACantDisconnectReason)
        {
            Boolean ReturnValue = false;

            ACantDisconnectReason = "";
            try
            {
                if (FKeepAlive != null)
                {
                    TEnsureKeepAlive.StopKeepAlive();
                }

                if (FPollClientTasks != null)
                {
                    FPollClientTasks.StopPollClientTasks();
                    RemotingServices.Disconnect((MarshalByRefObject)FRemotePollClientTasks);
                }

                if (FRemote != null)
                {
                    ReturnValue = TRemoteBase.ClientManager.DisconnectClient(FClientID, out ACantDisconnectReason);
                    TRemoteBase.Disconnect();
                }
            }
            catch (System.Net.Sockets.SocketException)
            {
                throw;
            }
            catch (System.Runtime.Remoting.RemotingException)
            {
                throw;
            }
            return(ReturnValue);
        }
        /// <summary>
        /// todoComment
        /// </summary>
        public bool ConnectToServer(String AUserName,
            String APassword,
            out Int32 AProcessID,
            out String AWelcomeMessage,
            out Boolean ASystemEnabled,
            out String AError,
            out IPrincipal AUserInfo)
        {
            AError = "";
            String ConnectionError;

            if (FConnector == null)
            {
                FConnector = (TConnector)Activator.CreateInstance(ConnectorType);
            }

            try
            {
                if (TAppSettingsManager.ConfigFileName.Length > 0)
                {
                    // connect to the PetraServer's ClientManager
                    FConnector.GetRemoteServerConnection(TAppSettingsManager.ConfigFileName, out FClientManager);
                }
                else
                {
                    // connect to the PetraServer's ClientManager
                    FConnector.GetRemoteServerConnection(Environment.GetCommandLineArgs()[0] + ".config", out FClientManager);
                }

                // register Client session at the PetraServer
                bool ReturnValue = ConnectClient(AUserName, APassword, FClientManager,
                    out AProcessID,
                    out AWelcomeMessage,
                    out ASystemEnabled,
                    out ConnectionError,
                    out AUserInfo);
                TRemoteBase.ClientManager = FClientManager;

                if (!ReturnValue)
                {
                    AError = ConnectionError;
                    return ReturnValue;
                }
            }
            catch (System.Net.Sockets.SocketException)
            {
                throw new EServerConnectionServerNotReachableException();
            }
            catch (EDBConnectionNotEstablishedException exp)
            {
                if (exp.Message.IndexOf("Access denied") != -1)
                {
                    // Prevent passing out stack trace in case the PetraServer cannot connect
                    // a Client (to make this happen, somebody would have tampered with the
                    // DB Password decryption routines...)
                    throw new EServerConnectionGeneralException("PetraServer misconfiguration!");
                }
                else
                {
                    throw;
                }
            }
            catch (EClientVersionMismatchException)
            {
                throw;
            }
            catch (ELoginFailedServerTooBusyException)
            {
                throw;
            }
            catch (Exception exp)
            {
                TLogging.Log(exp.ToString() + Environment.NewLine + exp.StackTrace, TLoggingType.ToLogfile);
                throw new EServerConnectionGeneralException(exp.ToString());
            }

            //
            // acquire .NET Remoting Proxy objects for remoted Server objects
            //

            FRemotePollClientTasks =
                (IPollClientTasksInterface)FConnector.GetRemoteObject(FRemotingURL_PollClientTasks, typeof(IPollClientTasksInterface));

            //
            // start the KeepAlive Thread (which needs to run as long as the Client is running)
            //
            FKeepAlive = new TEnsureKeepAlive();

            //
            // start the PollClientTasks Thread (which needs to run as long as the Client is running)
            //
            FPollClientTasks = new TPollClientTasks(FClientID, FRemotePollClientTasks);

            //
            // initialise object that holds references to all our remote object .NET Remoting Proxies
            //
            FRemote = new TRemoteBase(FClientManager);
            return true;
        }
Example #3
0
        /// <summary>
        /// todoComment
        /// </summary>
        public bool ConnectToServer(String AUserName,
                                    String APassword,
                                    out Int32 AProcessID,
                                    out String AWelcomeMessage,
                                    out Boolean ASystemEnabled,
                                    out String AError,
                                    out IPrincipal AUserInfo)
        {
            AError = "";
            String ConnectionError;

            if (FConnector == null)
            {
                FConnector = (TConnector)Activator.CreateInstance(ConnectorType);
            }

            try
            {
                if (TAppSettingsManager.ConfigFileName.Length > 0)
                {
                    // connect to the PetraServer's ClientManager
                    FConnector.GetRemoteServerConnection(TAppSettingsManager.ConfigFileName, out FClientManager);
                }
                else
                {
                    // connect to the PetraServer's ClientManager
                    FConnector.GetRemoteServerConnection(Environment.GetCommandLineArgs()[0] + ".config", out FClientManager);
                }

                // register Client session at the PetraServer
                bool ReturnValue = ConnectClient(AUserName, APassword, FClientManager,
                                                 out AProcessID,
                                                 out AWelcomeMessage,
                                                 out ASystemEnabled,
                                                 out ConnectionError,
                                                 out AUserInfo);
                TRemoteBase.ClientManager = FClientManager;

                if (!ReturnValue)
                {
                    AError = ConnectionError;
                    return(ReturnValue);
                }
            }
            catch (System.Net.Sockets.SocketException)
            {
                throw new EServerConnectionServerNotReachableException();
            }
            catch (EDBConnectionNotEstablishedException exp)
            {
                if (exp.Message.IndexOf("Access denied") != -1)
                {
                    // Prevent passing out stack trace in case the PetraServer cannot connect
                    // a Client (to make this happen, somebody would have tampered with the
                    // DB Password decryption routines...)
                    throw new EServerConnectionGeneralException("PetraServer misconfiguration!");
                }
                else
                {
                    throw;
                }
            }
            catch (EClientVersionMismatchException)
            {
                throw;
            }
            catch (ELoginFailedServerTooBusyException)
            {
                throw;
            }
            catch (Exception exp)
            {
                TLogging.Log(exp.ToString() + Environment.NewLine + exp.StackTrace, TLoggingType.ToLogfile);
                throw new EServerConnectionGeneralException(exp.ToString());
            }

            //
            // acquire .NET Remoting Proxy objects for remoted Server objects
            //

            FRemotePollClientTasks =
                (IPollClientTasksInterface)FConnector.GetRemoteObject(FRemotingURL_PollClientTasks, typeof(IPollClientTasksInterface));

            //
            // start the KeepAlive Thread (which needs to run as long as the Client is running)
            //
            FKeepAlive = new TEnsureKeepAlive();

            //
            // start the PollClientTasks Thread (which needs to run as long as the Client is running)
            //
            FPollClientTasks = new TPollClientTasks(FClientID, FRemotePollClientTasks);

            //
            // initialise object that holds references to all our remote object .NET Remoting Proxies
            //
            FRemote = new TRemoteBase(FClientManager);
            return(true);
        }