Example #1
0
        public static bool Register(ref string showmessage, bool loadbalance)
        {
            bool isWeb = string.Compare(fClientSystem, "Web", true) == 0;
            if (RemotingConfiguration.IsWellKnownClientType(typeof(EEPRemoteModule)) != null)
            {
                EEPRemoteModule module = new EEPRemoteModule();
                try
                {
                    module.ToString();
                    return true;
                }
                catch
                {
                    try
                    {
                        //EEPListenerService.StartupEEPNetServer();
                        LoadServer();
                        module.ToString();
                        return true;
                    }
                    catch
                    {
                        try
                        {
                            showmessage = SysMsg.GetSystemMessage(fClientLang, "EEPWebNetClient", "WinSysMsg", "msg_CanNotFindServer", isWeb);
                        }
                        catch
                        {
                            showmessage = "Unable to connect to the remote server";
                        }
                        return false;
                    }
                }
            }

            if (string.Compare(fRemoteIP, "127.0.0.1") != 0 && string.Compare(fRemoteIP, "localhost", true) != 0)
            {
                LoginService loginService = Activator.GetObject(typeof(LoginService),
                        string.Format("http://{0}:{1}/Srvtools.rem", fRemoteIP, fRemotePort)) as LoginService;
            GetLoginService:
                try
                {
                    object[] rtn = loginService.GetServerIP(loadbalance);
                    string newip = rtn[0].ToString();
                    if (newip == null || newip.Trim() == "")
                    {
                        try
                        {
                            showmessage = SysMsg.GetSystemMessage(fClientLang, "EEPWebNetClient", "WinSysMsg", "msg_BusyService", isWeb);
                        }
                        catch
                        {
                            showmessage = "System Busy, try again later";
                        }
                        return false;
                    }
                    else if (newip == "000")
                    {
                        try
                        {
                            if (fClientSystem == "Web")
                            {
                                showmessage = SysMsg.GetSystemMessage(fClientLang, "Web", "InfoLogin", "ExceedsMax", isWeb);
                            }
                            else
                            {
                                showmessage = SysMsg.GetSystemMessage(fClientLang, "EEPNetClient", "FrmClientMain", "ExceedsMax", isWeb);
                            }
                        }
                        catch
                        {
                            showmessage = "The current number of users exceeds the max number set by the AP server!try again?";
                        }
                        return false;
                    }
                    else if (newip != "001")  //has redirect to another server
                    {
                        fRemoteIP = newip;
                        fRemotePort = (int)rtn[1];
                    }
                }
                catch (WebException E)
                {
                    if (E.Status == WebExceptionStatus.ConnectFailure)
                    {
                        if (fRemoteIP != reserveServerIP)
                        {
                            if (LoadServer())
                            {
                                goto GetLoginService;
                            }
                            else if (reserveServerIP.Length > 0)
                            {
                                fRemoteIP = reserveServerIP;
                                fRemotePort = reserveServerPort;
                                return Register(ref showmessage, loadbalance);
                            }
                        }

                        string message = E.Message;
                        if (E.Message == "Unable to connect to the remote server")
                        {
                            try
                            {
                                message = SysMsg.GetSystemMessage(fClientLang, "EEPWebNetClient", "WinSysMsg", "msg_CanNotFindServer", isWeb);
                            }
                            catch
                            {
                                message = "Unable to connect to the remote server";
                            }
                        }
                        showmessage = message;
                        return false;
                    }
                    else
                    {
                        showmessage = E.Message;
                        return false;
                    }
                }

                try
                {
                    EEPRemoteModule module = Activator.GetObject(typeof(EEPRemoteModule),
                        string.Format("http://{0}:{1}/InfoRemoteModule.rem", fRemoteIP, fRemotePort)) as EEPRemoteModule;
                    module.ToString();
                }
                catch
                {
                    loginService.DeRegisterRemoteServer(fRemoteIP, fRemotePort);
                    goto GetLoginService;
                }
            }
            else// local host do not load banlance
            {
                try
                {
                    EEPRemoteModule module = Activator.GetObject(typeof(EEPRemoteModule),
                        string.Format("http://{0}:{1}/InfoRemoteModule.rem", fRemoteIP, fRemotePort)) as EEPRemoteModule;
                    module.ToString();
                }
                catch (Exception e)
                {
                    try
                    {
                        //EEPListenerService.StartupEEPNetServer();
                        LoadServer();
                        EEPRemoteModule module = Activator.GetObject(typeof(EEPRemoteModule),
                         string.Format("http://{0}:{1}/InfoRemoteModule.rem", fRemoteIP, fRemotePort)) as EEPRemoteModule;
                        module.ToString();
                    }
                    catch
                    {
                        string message = e.Message;
                        try
                        {
                            message = SysMsg.GetSystemMessage(fClientLang, "EEPWebNetClient", "WinSysMsg", "msg_CanNotFindServer", isWeb);
                        }
                        catch
                        {
                            message = "Unable to connect to the remote server";
                        }
                        showmessage = message;
                        return false;
                    }
                }
            }

            // Register EEPRemoteModule on the server
            WellKnownClientTypeEntry clientEntry = new WellKnownClientTypeEntry(typeof(EEPRemoteModule),
                string.Format("http://{0}:{1}/InfoRemoteModule.rem", fRemoteIP, fRemotePort));
            RemotingConfiguration.RegisterWellKnownClientType(clientEntry);
            return true;
        }