public static void SetRemotingT(string serverURI, RemotingRole remotingRole, bool isReportServer) { IsReportServer = isReportServer; _remotingRoleT = remotingRole; _remotingRoleTStr = _remotingRoleT.ToString(); //Simply used as an indicator that _remotingRoleT has been set. _serverUriT = serverURI; }
///<summary></summary> private string RunWebMethod(Func <string> funcWebMethod) { Exception ex = null; RemotingRole remotingRoleCur = RemotingClient.RemotingRole; //Create an ODThread so that we can safely change the database connection settings without affecting the calling method's connection. ODThread odThread = new ODThread(new ODThread.WorkerDelegate((ODThread o) => { //Change the remoting role to ServerWeb (this will get set back to remotingRoleCur later. RemotingClient.RemotingRole = RemotingRole.ServerWeb; //Set new database connection settings if designated. E.g. some unit tests need to set and utilize userLow and passLow. if (!string.IsNullOrEmpty(_server) && !string.IsNullOrEmpty(_db) && !string.IsNullOrEmpty(_user)) { new DataConnection().SetDbT(_server, _db, _user, _password, _userLow, _passLow, DatabaseType.MySql); } //Execute the func that was passed in now that our remoting role and database connection are correct. o.Tag = funcWebMethod(); })); odThread.AddExceptionHandler(new ODThread.ExceptionDelegate((Exception e) => { ex = e; //Cannot throw exception here due to still being in a threaded context. })); if (ex != null) { throw ex; //Should never happen because this would be a "web exception" as in the ProcessRequest could not even invoke or something like that. } odThread.Name = "threadMiddleTierUnitTestRunWebMethod"; //Set the remoting role back after exiting the thread. odThread.AddExitHandler((e) => RemotingClient.RemotingRole = remotingRoleCur); odThread.Start(true); odThread.Join(System.Threading.Timeout.Infinite); return((string)odThread.Tag); }
public void SecurityLogs_MakeLogEntry_DuplicateEntryParallel() { Patient patient = PatientT.CreatePatient(MethodBase.GetCurrentMethod().Name); //There are lots of bug submissions with exception text like "Duplicate entry 'XXXXX' for key 'PRIMARY'". //OpenDentBusiness.SecurityLogs.MakeLogEntry() seems to be the common theme for most of the submissions. //Spawn parallel threads to insert 200 security logs trying to get a duplicate entry exception. List <Action> listActions = new List <Action>(); for (int i = 0; i < 200; i++) { listActions.Add(() => SecurityLogs.MakeLogEntry(Permissions.Accounting, patient.PatNum, "", 0, DateTime.Now.AddDays(-7))); } //Parallel threads do not support Middle Tier mode when unit testing due to how we have to fake being both the client and the server. RemotingRole remotingRoleOld = RemotingClient.RemotingRole; if (RemotingClient.RemotingRole != RemotingRole.ClientDirect) { RemotingClient.RemotingRole = RemotingRole.ClientDirect; } ODThread.RunParallel(listActions, onException: (ex) => { RemotingClient.RemotingRole = remotingRoleOld; Assert.Fail(ex.Message); }); RemotingClient.RemotingRole = remotingRoleOld; }
///<summary>Perform the given action as a Middle Tier client using OpenDentalServerMockIIS.</summary> public static void RunMiddleTierMock(Action a) { RemotingRole remotingRolePrevious = RemotingClient.RemotingRole; OpenDentBusiness.WebServices.OpenDentalServerMockIIS mockPrevious = OpenDentBusiness.WebServices.OpenDentalServerProxy.MockOpenDentalServerCur; if (mockPrevious == null) { OpenDentBusiness.WebServices.OpenDentalServerProxy.MockOpenDentalServerCur = new OpenDentBusiness.WebServices.OpenDentalServerMockIIS(); } RemotingClient.RemotingRole = RemotingRole.ClientWeb; try { a(); } finally { OpenDentBusiness.WebServices.OpenDentalServerProxy.MockOpenDentalServerCur = mockPrevious; RemotingClient.RemotingRole = remotingRolePrevious; } }
///<summary>Throws an exception to display to the user if anything goes wrong.</summary> public static void TryToConnect(CentralConnection centralConnection, DatabaseType dbType, string connectionString = "", bool noShowOnStartup = false , List <string> listAdminCompNames = null, bool isCommandLineArgs = false) { if (!string.IsNullOrEmpty(centralConnection.ServiceURI)) { LoadMiddleTierProxySettings(); string originalURI = RemotingClient.ServerURI; RemotingClient.ServerURI = centralConnection.ServiceURI; bool useEcwAlgorithm = centralConnection.WebServiceIsEcw; RemotingRole originalRole = RemotingClient.RemotingRole; RemotingClient.RemotingRole = RemotingRole.ClientWeb; try { string password = centralConnection.OdPassword; if (useEcwAlgorithm) { //Userods.HashPassword explicitly goes over to middle tier in order to use it's MD5 algorithm. //It doesn't matter what Security.CurUser is when it is null because we are technically trying to set it for the first time. //It cannot be null before invoking HashPassword because middle needs it to NOT be null when creating the credentials for DtoGetString. if (Security.CurUser == null) { Security.CurUser = new Userod(); } password = Userods.HashPassword(password, true); } string username = centralConnection.OdUser; #if DEBUG if (username == "") { username = "******"; password = "******"; } #endif //ecw requires hash, but non-ecw requires actual password Security.CurUser = Security.LogInWeb(username, password, "", Application.ProductVersion, useEcwAlgorithm); Security.PasswordTyped = password; //for ecw, this is already encrypted. } catch (Exception ex) { RemotingClient.ServerURI = originalURI; RemotingClient.RemotingRole = originalRole; throw ex; } } else { DataConnection.DBtype = dbType; DataConnection dcon = new DataConnection(); if (connectionString.Length > 0) { dcon.SetDb(connectionString, "", DataConnection.DBtype); } else { //Password could be plain text password from the Password field of the config file, the decrypted password from the MySQLPassHash field //of the config file, or password entered by the user and can be blank (empty string) in all cases dcon.SetDb(centralConnection.ServerName, centralConnection.DatabaseName, centralConnection.MySqlUser , centralConnection.MySqlPassword, "", "", DataConnection.DBtype); } //a direct connection does not utilize lower privileges. RemotingClient.RemotingRole = RemotingRole.ClientDirect; } TrySaveConnectionSettings(centralConnection, dbType, connectionString, noShowOnStartup, listAdminCompNames, isCommandLineArgs); }
public static void SetRemotingRoleT(RemotingRole remotingRole) { _remotingRoleT = remotingRole; _remotingRoleTStr = _remotingRoleT.ToString(); //Simply used as an indicator that _remotingRoleT has been set. }
///<summary>Throws an exception to display to the user if anything goes wrong.</summary> public static void TryToConnect(CentralConnection centralConnection, DatabaseType dbType, string connectionString = "", bool noShowOnStartup = false, List <string> listAdminCompNames = null, bool isCommandLineArgs = false, bool useDynamicMode = false, bool allowAutoLogin = true) { if (!string.IsNullOrEmpty(centralConnection.ServiceURI)) { LoadMiddleTierProxySettings(); string originalURI = RemotingClient.ServerURI; RemotingClient.ServerURI = centralConnection.ServiceURI; bool useEcwAlgorithm = centralConnection.WebServiceIsEcw; RemotingRole originalRole = RemotingClient.RemotingRole; RemotingClient.RemotingRole = RemotingRole.ClientWeb; try { string password = centralConnection.OdPassword; if (useEcwAlgorithm) { //It doesn't matter what Security.CurUser is when it is null because we are technically trying to set it for the first time. //It cannot be null before invoking HashPassword for Middle Tier for creating credentials for DTOs. if (Security.CurUser == null) { Security.CurUser = new Userod(); } //Utilize the custom eCW MD5 hashing algorithm if no password hash was passed in via command line arguments. if (string.IsNullOrEmpty(centralConnection.OdPassHash)) { password = Authentication.HashPasswordMD5(password, true); } else //eCW gave us the password already hashed via command line arguments, simply use it. { password = centralConnection.OdPassHash; } } string username = centralConnection.OdUser; //ecw requires hash, but non-ecw requires actual password Security.CurUser = Security.LogInWeb(username, password, "", Application.ProductVersion, useEcwAlgorithm); Security.PasswordTyped = password; //for ecw, this is already encrypted. UserOdPrefs.SetThemeForUserIfNeeded(); } catch (Exception ex) { RemotingClient.ServerURI = originalURI; RemotingClient.RemotingRole = originalRole; throw ex; } } else { DataConnection.DBtype = dbType; DataConnection dcon = new DataConnection(); if (connectionString.Length > 0) { dcon.SetDb(connectionString, "", DataConnection.DBtype); } else { //Password could be plain text password from the Password field of the config file, the decrypted password from the MySQLPassHash field //of the config file, or password entered by the user and can be blank (empty string) in all cases dcon.SetDb(centralConnection.ServerName, centralConnection.DatabaseName, centralConnection.MySqlUser , centralConnection.MySqlPassword, "", "", DataConnection.DBtype); } //a direct connection does not utilize lower privileges. RemotingClient.RemotingRole = RemotingRole.ClientDirect; } //Only gets this far if we have successfully connected, thus, saving connection settings is appropriate. TrySaveConnectionSettings(centralConnection, dbType, connectionString, noShowOnStartup: noShowOnStartup, listAdminCompNames, isCommandLineArgs: isCommandLineArgs, useDynamicMode: useDynamicMode, allowAutoLogin: allowAutoLogin); }