Пример #1
0
        /// <summary>
        /// Connect to the server and authenticate the user
        /// </summary>
        public eLoginEnum ConnectToServer(String AUserName,
                                          String APassword,
                                          out Int32 AProcessID,
                                          out String AWelcomeMessage,
                                          out Boolean ASystemEnabled,
                                          out String AError)
        {
            IPrincipal LocalUserInfo;

            eLoginEnum Result = ConnectToServer(AUserName,
                                                APassword,
                                                out AProcessID,
                                                out AWelcomeMessage,
                                                out ASystemEnabled,
                                                out AError,
                                                out LocalUserInfo);

            if (Result != eLoginEnum.eLoginSucceeded)
            {
                return(Result);
            }

            Ict.Petra.Shared.UserInfo.GUserInfo = (TPetraPrincipal)LocalUserInfo;

            //
            // initialise object that holds references to all our remote object .NET Remoting Proxies
            //
            new TRemote();

            return(eLoginEnum.eLoginSucceeded);
        }
Пример #2
0
        public string LoginClient(string username, string password, string version)
        {
            Version ClientVersion;

            try
            {
                ClientVersion = Version.Parse(version);
            }
            catch (Exception)
            {
                TLogging.Log("LoginClient: invalid version, cannot be parsed: " + version);
                return(THttpBinarySerializer.SerializeObjectWithType(eLoginEnum.eLoginVersionMismatch));
            }

            string     WelcomeMessage;
            bool       SystemEnabled;
            IPrincipal UserInfo;
            Int32      ClientID;
            eLoginEnum Result = LoginInternal(username, password, ClientVersion,
                                              out ClientID, out WelcomeMessage, out SystemEnabled, out UserInfo);

            if (Result != eLoginEnum.eLoginSucceeded)
            {
                return(THttpBinarySerializer.SerializeObjectWithType(Result));
            }

            return(THttpBinarySerializer.SerializeObjectWithType(Result) + "," +
                   THttpBinarySerializer.SerializeObjectWithType(ClientID) + "," +
                   THttpBinarySerializer.SerializeObjectWithType(WelcomeMessage) + "," +
                   THttpBinarySerializer.SerializeObjectWithType(SystemEnabled) + "," +
                   THttpBinarySerializer.SerializeObjectWithType(UserInfo));
        }
Пример #3
0
        /// <summary>
        /// Connect to the server and authenticate the user
        /// </summary>
        public eLoginEnum ConnectToServer(String AUserName,
                                          String APassword,
                                          out Int32 AProcessID,
                                          out String AWelcomeMessage,
                                          out Boolean ASystemEnabled,
                                          out String AError,
                                          out IPrincipal AUserInfo)
        {
            AError = "";
            String ConnectionError;

            AUserInfo       = null;
            ASystemEnabled  = false;
            AWelcomeMessage = string.Empty;
            AProcessID      = -1;

            try
            {
                FClientManager = TConnectionHelper.Connect();

                // register Client session at the PetraServer
                eLoginEnum ReturnValue = ConnectClient(AUserName, APassword,
                                                       out AProcessID,
                                                       out AWelcomeMessage,
                                                       out ASystemEnabled,
                                                       out ConnectionError,
                                                       out AUserInfo);

                if (ReturnValue != eLoginEnum.eLoginSucceeded)
                {
                    AError = ConnectionError;
                    return(ReturnValue);
                }
            }
            catch (System.Net.Sockets.SocketException)
            {
                return(eLoginEnum.eLoginServerNotReachable);
            }
            catch (Exception exp)
            {
                TLogging.Log(exp.ToString() + Environment.NewLine + exp.StackTrace, TLoggingType.ToLogfile);
                throw new EServerConnectionGeneralException(exp.ToString());
            }

            if (TClientSettings.RunAsStandalone)
            {
                FPollClientTasks = null;
            }
            else
            {
                //
                // start the PollClientTasks Thread (which needs to run as long as the Client is running)
                //
                FPollClientTasks = new TPollClientTasks(FClientID);
            }

            return(eLoginEnum.eLoginSucceeded);
        }
Пример #4
0
        public string Login(string username, string password)
        {
            string     WelcomeMessage;
            bool       SystemEnabled;
            IPrincipal UserInfo;
            Int32      ClientID;

            eLoginEnum resultCode = LoginInternal(username, password, TFileVersionInfo.GetApplicationVersion().ToVersion(),
                                                  out ClientID, out WelcomeMessage, out SystemEnabled, out UserInfo);

            Dictionary <string, object> result = new Dictionary <string, object>();

            result.Add("resultcode", resultCode.ToString());
            return(JsonConvert.SerializeObject(result));
        }
Пример #5
0
        /// <summary>
        /// connect the client
        /// </summary>
        /// <param name="AUserName"></param>
        /// <param name="APassword"></param>
        /// <param name="AProcessID"></param>
        /// <param name="AWelcomeMessage"></param>
        /// <param name="ASystemEnabled"></param>
        /// <param name="AError"></param>
        /// <param name="AUserInfo"></param>
        /// <returns></returns>
        virtual protected eLoginEnum ConnectClient(String AUserName,
                                                   String APassword,
                                                   out Int32 AProcessID,
                                                   out String AWelcomeMessage,
                                                   out Boolean ASystemEnabled,
                                                   out String AError,
                                                   out IPrincipal AUserInfo)
        {
            AError          = "";
            ASystemEnabled  = false;
            AWelcomeMessage = "";
            AProcessID      = -1;
            AUserInfo       = null;

            try
            {
                eLoginEnum result = FClientManager.ConnectClient(AUserName, APassword,
                                                                 TClientInfo.ClientComputerName,
                                                                 TClientInfo.ClientIPAddress,
                                                                 new Version(TClientInfo.ClientAssemblyVersion),
                                                                 DetermineClientServerConnectionType(),
                                                                 out FClientID,
                                                                 out AWelcomeMessage,
                                                                 out ASystemEnabled,
                                                                 out AUserInfo);

                if (result != eLoginEnum.eLoginSucceeded)
                {
                    AError = result.ToString();
                }

                return(result);
            }
            catch (Exception Exc)
            {
                if (TExceptionHelper.IsExceptionCausedByUnavailableDBConnectionClientSide(Exc))
                {
                    TExceptionHelper.ShowExceptionCausedByUnavailableDBConnectionMessage(true);

                    AError = Exc.Message;
                    return(eLoginEnum.eLoginFailedForUnspecifiedError);
                }

                TLogging.Log(Exc.ToString() + Environment.NewLine + Exc.StackTrace, TLoggingType.ToLogfile);
                AError = Exc.Message;
                return(eLoginEnum.eLoginFailedForUnspecifiedError);
            }
        }
Пример #6
0
        /// connect to the server
        public static eLoginEnum Connect(string AConfigName, bool AThrowExceptionOnLoginFailure = true)
        {
            TUnhandledThreadExceptionHandler UnhandledThreadExceptionHandler;

            // Set up Handlers for 'UnhandledException'
            // Note: BOTH handlers are needed for a WinForms Application!!!
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(ExceptionHandling.UnhandledExceptionHandler);
            UnhandledThreadExceptionHandler             = new TUnhandledThreadExceptionHandler();

            Application.ThreadException += new ThreadExceptionEventHandler(UnhandledThreadExceptionHandler.OnThreadException);

            new TAppSettingsManager(AConfigName);

            CommonNUnitFunctions.InitRootPath();

            Catalog.Init();
            TClientTasksQueue.ClientTasksInstanceType       = typeof(TClientTaskInstance);
            TConnectionManagementBase.GConnectionManagement = new TConnectionManagement();

            new TClientSettings();
            TClientInfo.InitializeUnit();
            TCacheableTablesManager.InitializeUnit();

            // Set up Data Validation Delegates
            TSharedValidationHelper.SharedGetDataDelegate                           = @TServerLookup.TMCommon.GetData;
            TSharedPartnerValidationHelper.VerifyPartnerDelegate                    = @TServerLookup.TMPartner.VerifyPartner;
            TSharedPartnerValidationHelper.PartnerIsLinkedToCCDelegate              = @TServerLookup.TMPartner.PartnerIsLinkedToCC;
            TSharedPartnerValidationHelper.PartnerOfTypeCCIsLinkedDelegate          = @TServerLookup.TMPartner.PartnerOfTypeCCIsLinked;
            TSharedPartnerValidationHelper.PartnerHasCurrentGiftDestinationDelegate = @TServerLookup.TMPartner.PartnerHasCurrentGiftDestination;
            TSharedFinanceValidationHelper.GetValidPostingDateRangeDelegate         = @TServerLookup.TMFinance.GetCurrentPostingRangeDates;
            TSharedFinanceValidationHelper.GetValidPeriodDatesDelegate              = @TServerLookup.TMFinance.GetCurrentPeriodDates;

            // Ensure we throw away the previous client session cookies!
            THTTPUtils.ResetSession();

            eLoginEnum Result = Connect(TAppSettingsManager.GetValue("AutoLogin"), TAppSettingsManager.GetValue("AutoLoginPasswd"),
                                        TAppSettingsManager.GetInt64("SiteKey"));

            if ((Result != eLoginEnum.eLoginSucceeded) && AThrowExceptionOnLoginFailure)
            {
                throw new Exception("login failed");
            }

            return(Result);
        }
Пример #7
0
        /// <summary>
        /// connect the client, but use some special parameters
        /// </summary>
        public static eLoginEnum Connect(string AConfigName, string AParameters)
        {
            string       tempConfigFile = Path.GetTempFileName();
            StreamReader sr             = new StreamReader(AConfigName);
            string       config         = sr.ReadToEnd();

            sr.Close();

            StreamWriter sw = new StreamWriter(tempConfigFile);

            sw.Write(config.Replace("</appSettings>", AParameters + "</appSettings>"));
            sw.Close();

            eLoginEnum result = TPetraConnector.Connect(tempConfigFile);

            File.Delete(tempConfigFile);

            return(result);
        }
Пример #8
0
        public string Login(string username, string password)
        {
            string WelcomeMessage;
            bool   SystemEnabled;
            Int32  ClientID;
            bool   MustChangePassword;

            eLoginEnum resultCode = LoginInternal(username, password, TFileVersionInfo.GetApplicationVersion().ToVersion(),
                                                  out ClientID, out WelcomeMessage, out SystemEnabled, out MustChangePassword);

            Dictionary <string, object> result = new Dictionary <string, object>();

            result.Add("resultcode", resultCode.ToString());
            result.Add("mustchangepassword", MustChangePassword);

            if (resultCode == eLoginEnum.eLoginSucceeded)
            {
                result.Add("ModulePermissions", UserInfo.GetUserInfo().GetPermissions());
            }

            return(JsonConvert.SerializeObject(result));
        }
Пример #9
0
        /// connect the client to the server
        public eLoginEnum ConnectClient(String AUserName,
                                        String APassword,
                                        String AClientComputerName,
                                        String AClientIPAddress,
                                        System.Version AClientExeVersion,
                                        TClientServerConnectionType AClientServerConnectionType,
                                        out Int32 AClientID,
                                        out String AWelcomeMessage,
                                        out Boolean ASystemEnabled,
                                        out IPrincipal AUserInfo)
        {
            AWelcomeMessage = string.Empty;
            ASystemEnabled  = true;
            AUserInfo       = null;
            AClientID       = -1;

            THttpConnector.InitConnection(TAppSettingsManager.GetValue("OpenPetra.HTTPServer"));
            SortedList <string, object> Parameters = new SortedList <string, object>();

            Parameters.Add("username", AUserName);
            Parameters.Add("password", APassword);
            Parameters.Add("version", AClientExeVersion.ToString());

            List <object> ResultList = THttpConnector.CallWebConnector("SessionManager", "LoginClient", Parameters, "list");
            eLoginEnum    Result     = (eLoginEnum)ResultList[0];

            if (Result != eLoginEnum.eLoginSucceeded)
            {
                // failed login
                return(Result);
            }

            AClientID       = (Int32)ResultList[1];
            AWelcomeMessage = (string)ResultList[2];
            ASystemEnabled  = (Boolean)ResultList[3];
            AUserInfo       = (IPrincipal)ResultList[4];

            return(eLoginEnum.eLoginSucceeded);
        }
Пример #10
0
        /// <summary>
        /// specific things for connecting all the services
        /// </summary>
        /// <param name="AUserName"></param>
        /// <param name="APassword"></param>
        /// <param name="AProcessID"></param>
        /// <param name="AWelcomeMessage"></param>
        /// <param name="ASystemEnabled"></param>
        /// <param name="AError"></param>
        /// <param name="AUserInfo"></param>
        /// <returns></returns>
        protected override eLoginEnum ConnectClient(String AUserName,
                                                    String APassword,
                                                    out Int32 AProcessID,
                                                    out String AWelcomeMessage,
                                                    out Boolean ASystemEnabled,
                                                    out String AError,
                                                    out IPrincipal AUserInfo)
        {
            try
            {
                eLoginEnum result = base.ConnectClient(AUserName,
                                                       APassword,
                                                       out AProcessID,
                                                       out AWelcomeMessage,
                                                       out ASystemEnabled,
                                                       out AError,
                                                       out AUserInfo);

                if (result != eLoginEnum.eLoginSucceeded)
                {
                    return(result);
                }

                Ict.Petra.Shared.UserInfo.GUserInfo = (TPetraPrincipal)AUserInfo;

                return(result);
            }
            catch (ELoginFailedServerTooBusyException)
            {
                throw;
            }
            catch (Exception exp)
            {
                TLogging.Log(exp.ToString() + Environment.NewLine + exp.StackTrace, TLoggingType.ToLogfile);
                throw;
            }
        }
Пример #11
0
        private bool ConnectToPetraServer(String AUserName, String APassWord, out String AError)
        {
            eLoginEnum ReturnValue = eLoginEnum.eLoginFailedForUnspecifiedError;

            ReturnValue = ((TConnectionManagement)TConnectionManagement.GConnectionManagement).ConnectToServer(AUserName, APassWord,
                                                                                                               out FProcessID,
                                                                                                               out FWelcomeMessage,
                                                                                                               out FSystemEnabled,
                                                                                                               out AError);

            if (ReturnValue == eLoginEnum.eLoginSucceeded)
            {
                return(true);
            }
            else if (ReturnValue == eLoginEnum.eLoginVersionMismatch)
            {
                DisplayLoginFailedMessage(Catalog.GetString("OpenPetra Client/Server Program Version Mismatch!"));
                return(false);
            }
            else if (ReturnValue == eLoginEnum.eLoginServerTooBusy)
            {
                DisplayLoginFailedMessage(
                    Catalog.GetString(
                        "The OpenPetra Server is too busy to accept the Login request.\r\n\r\nPlease try again after a short time!"));
                return(false);
            }
            else if (ReturnValue == eLoginEnum.eLoginExceedingConcurrentUsers)
            {
                DisplayLoginFailedMessage(
                    Catalog.GetString(
                        "Too many users are logged in."));
                return(false);
            }
            else if (ReturnValue == eLoginEnum.eLoginServerNotReachable)
            {
                string Message = Catalog.GetString("The OpenPetra Server cannot be reached!");
                string Title   = null;

                // on Standalone, we can find the Server.log file, and check the last 10 lines for "System.Exception: Unsupported upgrade"
                string ServerLog = Path.GetDirectoryName(TLogging.GetLogFileName()) + Path.DirectorySeparatorChar + "Server.log";

                if (File.Exists(ServerLog))
                {
                    int    countExceptionLine = 0;
                    string ErrorMessage       = string.Empty;

                    StreamReader sr = new StreamReader(ServerLog);

                    while (!sr.EndOfStream)
                    {
                        string line = sr.ReadLine();

                        if (line.Contains("Unsupported upgrade"))
                        {
                            countExceptionLine = 12;
                            ErrorMessage       = line.Substring(line.IndexOf("Unsupported upgrade"));
                        }
                        else
                        {
                            countExceptionLine--;
                        }
                    }

                    sr.Close();

                    if (countExceptionLine > 0)
                    {
                        Message = ErrorMessage.Replace('/', Path.DirectorySeparatorChar);
                        Title   = Catalog.GetString("Unsupported upgrade");
                    }
                    else
                    {
                        Message =
                            Catalog.GetString(
                                "The OpenPetra Server cannot be reached!") + Environment.NewLine + StrDetailsInLogfile + ": " +
                            ServerLog;
                        Title = Catalog.GetString("No Server Response");
                    }
                }

                DisplayLoginFailedMessage(Message, Title);

                return(false);
            }
            else if (ReturnValue == eLoginEnum.eLoginAuthenticationFailed)
            {
                DisplayLoginFailedMessage(
                    Catalog.GetString(
                        "Wrong username or password"));
                return(false);
            }
            else if (ReturnValue == eLoginEnum.eLoginUserIsRetired)
            {
                DisplayLoginFailedMessage(
                    Catalog.GetString(
                        "User is retired"));
                return(false);
            }
            else if (ReturnValue == eLoginEnum.eLoginUserRecordLocked)
            {
                DisplayLoginFailedMessage(
                    Catalog.GetString(
                        "User record is locked at the moment"));
                return(false);
            }
            else if (ReturnValue == eLoginEnum.eLoginSystemDisabled)
            {
                DisplayLoginFailedMessage(
                    Catalog.GetString(
                        "The system is disabled at the moment for maintenance"));
                return(false);
            }
            else if (ReturnValue == eLoginEnum.eLoginVersionMismatch)
            {
                DisplayLoginFailedMessage(
                    Catalog.GetString(
                        "Please update the client, the version does not match the server version!"));
                return(false);
            }

            // catching all other login failures, eg. eLoginEnum.eLoginFailedForUnspecifiedError
            DisplayLoginFailedMessage(
                Catalog.GetString(
                    "An error occurred while trying to connect to the OpenPetra Server!") + Environment.NewLine + StrDetailsInLogfile + ": " +
                TLogging.GetLogFileName());
            return(false);
        }
Пример #12
0
        static void Main(string[] args)
        {
            new TLogging("../../log/TestRemotingClient.log");

            try
            {
                new TAppSettingsManager("../../etc/Client.config");

                TLogging.DebugLevel = Convert.ToInt32(TAppSettingsManager.GetValue("Client.DebugLevel", "0"));

                new TClientSettings();

                // initialize the client
                new TRemoteTest();

                // need to call this as well to make the progress dialog work
                new TRemote();

                // allow self signed ssl certificate for test purposes
                ServicePointManager.ServerCertificateValidationCallback = delegate {
                    return(true);
                };

                THttpConnector.InitConnection(TAppSettingsManager.GetValue("OpenPetra.HTTPServer"));

                TClientInfo.InitializeUnit();

                Catalog.Init("en-GB", "en-GB");

                SortedList <string, object> Parameters = new SortedList <string, object>();
                Parameters.Add("username", "demo");
                Parameters.Add("password", "demo");
                Parameters.Add("version", TFileVersionInfo.GetApplicationVersion().ToString());

                List <object> ResultList = THttpConnector.CallWebConnector("SessionManager", "LoginClient", Parameters, "list");
                eLoginEnum    Result     = (eLoginEnum)ResultList[0];

                if (Result != eLoginEnum.eLoginSucceeded)
                {
                    // failed login
                    return;
                }

                IMyUIConnector MyUIConnector = TRemoteTest.MyService.SubNamespace.MyUIConnector();
                TRemoteTest.TMyService.TMySubNamespace test = TRemoteTest.MyService.SubNamespace;

                while (true)
                {
                    try
                    {
                        TLogging.Log("before call");
                        TLogging.Log(TRemoteTest.MyService.HelloWorld("Hello World"));
                        TLogging.Log("after call");
                    }
                    catch (Exception e)
                    {
                        TLogging.Log("problem with MyService HelloWorld: " + Environment.NewLine + e.ToString());
                    }

                    try
                    {
                        DateTime DateTomorrow;
                        TLogging.Log("should show today's date: " + TRemoteTest.MyService.TestDateTime(DateTime.Today,
                                                                                                       out DateTomorrow).ToShortDateString());
                        TLogging.Log("should show tomorrow's date: " + DateTomorrow.ToShortDateString());
                    }
                    catch (Exception e)
                    {
                        TLogging.Log("problem with TestDateTime: " + Environment.NewLine + e.ToString());
                    }

                    try
                    {
                        TLogging.Log(test.HelloSubWorld("Hello SubWorld"));
                    }
                    catch (Exception e)
                    {
                        TLogging.Log("problem with sub namespace HelloSubWorld: " + Environment.NewLine + e.ToString());
                    }

                    try
                    {
                        TLogging.Log(MyUIConnector.HelloWorldUIConnector());
                    }
                    catch (Exception e)
                    {
                        TLogging.Log("problem with HelloWorldUIConnector: " + Environment.NewLine + e.ToString());
                    }

                    // start long running job
                    Thread t = new Thread(() => TRemoteTest.MyService.LongRunningJob());

                    using (TProgressDialog dialog = new TProgressDialog(t))
                    {
                        if (dialog.ShowDialog() == DialogResult.Cancel)
                        {
                            return;
                        }
                    }

                    Console.WriteLine("Press ENTER to say Hello World again... ");
                    Console.WriteLine("Press CTRL-C to exit ...");
                    Console.ReadLine();
                }
            }
            catch (Exception e)
            {
                TLogging.Log(e.ToString());
                Console.ReadLine();
            }
        }