예제 #1
0
		///<summary>Returns true if the connectionName entry has been loaded; otherwise returns false.</summary>
		public static bool HasSingleEntry(ConnectionNames connectionName) {
			bool ret=false;
			lock (_lock) {
				ret=_dictCentConnUnsafe!=null&&_dictCentConnUnsafe.ContainsKey(connectionName);
			}
			return ret;
		}
        /// <summary>
        /// Accepts the edited connection by assigning all changes
        /// from the EditItem to the DataItem and persisting the changes.
        /// </summary>
        public void Accept()
        {
            if (ConnectionNames != null && ConnectionNames.Any(x => x == EditItem.Name) && !Runtime.ShowConfirm(
                    "A connection with the same name already exists. Would you like to overwrite the existing connection?",
                    MessageBoxButton.YesNo))
            {
                return;
            }

            // Reset saved SSL protocol
            EditItem.SecurityProtocol = 0;

            // Get selected SSL protocols
            SecurityProtocols
            .Where(x => x.IsEnabled && x.IsSelected)
            .ForEach(x => EditItem.SecurityProtocol |= x.Protocol);

            TestConnection()
            .ContinueWith(x =>
            {
                if (x.Result || Runtime.Invoke(() => Runtime.ShowConfirm("Connection failed.\n\nDo you wish to save the connection settings anyway?", MessageBoxButton.YesNo)))
                {
                    AcceptConnectionChanges();
                }
            });
        }
예제 #3
0
        private string GetConnectionString(ConnectionNames connectionName)
        {
            switch (connectionName)
            {
            case ConnectionNames.HomeGame1:
                return(Settings.Default.HomeGame1ConnectionString);

            case ConnectionNames.HomeGameTmp2:
                return(Settings.Default.HomeGameTmp2ConnectionString);

            case ConnectionNames.HomeGameTmp3:
                return(Settings.Default.HomeGameTmp3ConnectionString);


            case ConnectionNames.AzureGameMain:
            case ConnectionNames.AzureGameDemo1:
                return(Settings.Default.AzureGameMainConnectionString);

            case ConnectionNames.AzureGameDev1:
                return(Settings.Default.AzureGameDev1ConnectionString);

            case ConnectionNames.AzureGameDev2:
                return(Settings.Default.AzureGameDev2ConnectionString);


            default:
                throw new ArgumentException("ConnectionName is Wrong");
            }
        }
예제 #4
0
		///<summary>Get a central connection by name.</summary>
		public static OpenDentBusiness.CentralConnection GetConnection(ConnectionNames name) {
			Dictionary<ConnectionNames,OpenDentBusiness.CentralConnection> dict=_dictCentConnSafe;
			if(dict==null || !dict.ContainsKey(name)) {
				throw new Exception("Connection name not found: "+name);
			}
			return dict[name];
		}
예제 #5
0
		///<summary>Sets the connection of the current thread to the ConnectionName indicated. Connection details will be retrieved from ConnectionStore.xml.</summary>
		public static OpenDentBusiness.CentralConnection SetDbT(ConnectionNames dbName) {
			OpenDentBusiness.CentralConnection conn=GetConnection(dbName);
			if(!string.IsNullOrEmpty(conn.ServiceURI)) {
				RemotingClient.SetRemotingT(conn.ServiceURI,RemotingRole.ClientWeb,(dbName==ConnectionNames.DentalOfficeReportServer));
			}
			else {
				new OpenDentBusiness.DataConnection().SetDbT(conn.ServerName,conn.DatabaseName,conn.MySqlUser,conn.MySqlPassword,"","",OpenDentBusiness.DatabaseType.MySql,true);
			}
			return conn;
		}
예제 #6
0
 ///<summary>Overrides any current connection with the connection passed in.  This should rarely be used.  E.g. used in Unit Testing.</summary>
 public static void OverrideConnection(ConnectionNames name, CentralConnection centralConnection)
 {
     lock (_lock) {
         if (_dictCentConnUnsafe == null)
         {
             _dictCentConnUnsafe = new Dictionary <ConnectionNames, CentralConnection>();
         }
         _dictCentConnUnsafe[name] = centralConnection;
     }
 }
예제 #7
0
		///<summary>Sets the connection of the current thread to the ConnectionName indicated. Connection details will be retrieved from ConnectionStore.xml.</summary>
		public static OpenDentBusiness.CentralConnection SetDb(ConnectionNames dbName) {
			CentralConnection conn=GetConnection(dbName);
			if(!string.IsNullOrEmpty(conn.ServiceURI)) {
				RemotingClient.ServerURI=conn.ServiceURI;
			}
			else {
				new DataConnection().SetDb(conn.ServerName,conn.DatabaseName,conn.MySqlUser,conn.MySqlPassword,"","",DatabaseType.MySql);
			}
			return conn;
		}
예제 #8
0
        ///<summary>Perform the given function in the context of the given connectionName db and return a T.</summary>
        public static T GetT <T>(Func <T> fn, ConnectionNames connectionName)
        {
            T ret = default(T);

            ExecuteThread(new ODThread((o) => {
                using (DataConnection dataConn = new DataConnection()) {
                    ConnectionStore.SetDbT(connectionName, dataConn: dataConn);
                    ret = fn();
                }
            }));
            return(ret);
        }
 private void _setConnectionNames(bool useLocal)
 {
     if (useLocal)
     {
         _authConnectionName          = ConnectionNames.HomeAuthTest;
         DbProvider.AppConnectionName = ConnectionNames.HomeDev;
     }
     else
     {
         _authConnectionName          = ConnectionNames.AzureAuthDev;
         DbProvider.AppConnectionName = ConnectionNames.AzureGameDev;
     }
 }
예제 #10
0
 ///<summary>Adds a PrefCache for the given database connection. Used by UnitTestsWeb.</summary>
 public static void AddCache(ConnectionNames connName)
 {
     DataAction.Run(() => {
         PrefCache cache = new PrefCache();
         if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
         {
             DataTable table = GetTableFromCache(false);
             cache.FillCacheFromTable(table);
         }
         else
         {
             cache.GetTableFromCache(true);
         }
         _dictCachesForDbs[connName] = cache;
     }, connName);
 }
예제 #11
0
        ///<summary>Returns a JSON serialized version of a connection override dictionary based off of gridConnection.
        ///Users can edit cells of the grid to change the site overrides and this method returns what should be saved to the db.</summary>
        private string GetConnectionOverrides()
        {
            string retVal = "";
            Dictionary <ConnectionNames, CentralConnection> dictConnDefaults  = DataAction.GetHqConnections();
            Dictionary <ConnectionNames, CentralConnection> dictConnOverrides = new Dictionary <ConnectionNames, CentralConnection>();

            foreach (GridRow row in gridConnections.ListGridRows)
            {
                ConnectionNames connName = (ConnectionNames)row.Tag;
                if (!dictConnDefaults.ContainsKey(connName))
                {
                    continue;                    //Should never happen.
                }
                CentralConnection connectionDefault = dictConnDefaults[connName];
                //Read in the cell text and create an override if any of the values differ from the default.
                string serverName    = row.Cells[1].Text;
                string databaseName  = row.Cells[2].Text;
                string mySqlUser     = row.Cells[3].Text;
                string mySqlPassword = row.Cells[4].Text;
                if (serverName.IsNullOrEmpty() &&
                    databaseName.IsNullOrEmpty() &&
                    mySqlUser.IsNullOrEmpty() &&
                    mySqlPassword.IsNullOrEmpty())
                {
                    continue;                    //Do not add an override, this will cause the connection to go back to using the default.
                }
                if (serverName != connectionDefault.ServerName ||
                    databaseName != connectionDefault.DatabaseName ||
                    mySqlUser != connectionDefault.MySqlUser ||
                    mySqlPassword != connectionDefault.MySqlPassword)
                {
                    dictConnOverrides[connName] = new CentralConnection()
                    {
                        ServerName    = serverName,
                        DatabaseName  = databaseName,
                        MySqlUser     = mySqlUser,
                        MySqlPassword = mySqlPassword
                    };
                }
            }
            if (dictConnOverrides.Count > 0)
            {
                retVal = GetOverridesSerialized(dictConnOverrides);
            }
            return(retVal);
        }
예제 #12
0
        /// <summary>
        /// Accepts the edited connection by assigning all changes
        /// from the EditItem to the DataItem and persisting the changes.
        /// </summary>
        public void Accept()
        {
            if (ConnectionNames != null && ConnectionNames.Any(x => x == EditItem.Name) && !Runtime.ShowConfirm(
                    "A connection with the same name already exists. Would you like to overwrite the existing connection?",
                    MessageBoxButton.YesNo))
            {
                return;
            }

            TestConnection()
            .ContinueWith(x =>
            {
                if (x.Result || Runtime.Invoke(() => Runtime.ShowConfirm("Connection failed.\n\nDo you wish to save the connection settings anyway?", MessageBoxButton.YesNo)))
                {
                    AcceptConnectionChanges();
                }
            });
        }
예제 #13
0
 ///<summary>Sets the connection of the current thread to the ConnectionName indicated. Connection details will be retrieved from ConnectionStore.xml.</summary>
 public static OpenDentBusiness.CentralConnection SetDbT(ConnectionNames dbName, DataConnection dataConn = null)
 {
     dataConn = dataConn ?? new DataConnection();
     OpenDentBusiness.CentralConnection conn = GetConnection(dbName);
     _currentConnectionT = dbName;
     if (!string.IsNullOrEmpty(conn.ServiceURI))
     {
         RemotingClient.SetRemotingT(conn.ServiceURI, RemotingRole.ClientWeb, (dbName == ConnectionNames.DentalOfficeReportServer));
     }
     else if (!string.IsNullOrEmpty(conn.ConnectionString))
     {
         dataConn.SetDbT(conn.ConnectionString, "", DatabaseType.MySql);
     }
     else
     {
         dataConn.SetDbT(conn.ServerName, conn.DatabaseName, conn.MySqlUser, conn.MySqlPassword, "", "", DatabaseType.MySql, true);
     }
     return(conn);
 }
예제 #14
0
        private void ButDefault_Click(object sender, EventArgs e)
        {
            if (gridConnections.GetSelectedIndex() == -1)
            {
                MsgBox.Show("Please select a row.");
                return;
            }
            ConnectionNames connName = gridConnections.SelectedTag <ConnectionNames>();
            Dictionary <ConnectionNames, CentralConnection> dictConnOverrides = _siteLink.DictConnectionSettingsHQOverrides;

            if (!dictConnOverrides.ContainsKey(connName))
            {
                return;
            }
            //Update the site link object so that it does not have an override anymore.
            dictConnOverrides.Remove(connName);
            _siteLink.ConnectionSettingsHQOverrides = GetOverridesSerialized(dictConnOverrides);
            FillGridConnections();
        }
예제 #15
0
        private string GetJsonSerializedConnectionOverride(ConnectionNames connName, string serverName, string databaseName, string mySqlUser,
                                                           string mySqlPassword)
        {
            Dictionary <ConnectionNames, CentralConnection> dictHqConnectionOverrides = new Dictionary <ConnectionNames, CentralConnection>()
            {
                {
                    connName,
                    new CentralConnection()
                    {
                        ServerName    = serverName,
                        DatabaseName  = databaseName,
                        MySqlUser     = mySqlUser,
                        MySqlPassword = mySqlPassword,
                    }
                }
            };
            JsonSerializerSettings settings = new JsonSerializerSettings();

            settings.DefaultValueHandling = DefaultValueHandling.Ignore;
            return(JsonConvert.SerializeObject(dictHqConnectionOverrides, settings));
        }
예제 #16
0
 public static string GetConnectionString(this IConfiguration configuration, ConnectionNames connectionName) => configuration.GetSection($"{nameof(DbConnectionOptions)}:{ connectionName.ToString()}").Value;
예제 #17
0
 ///<summary>Perform the given function in the context of the given connectionName db and return a string. Typed extension of GetT.</summary>
 public static string GetString(Func <string> fn, ConnectionNames connectionName)
 {
     //String is a reference type and will be set to null if the method happens to fail. Correct that to empty string since OD does not typically expect string to be null.
     return(GetT <string>(fn, connectionName) ?? "");
 }
예제 #18
0
 ///<summary>Perform the given function in the context of the given connectionName db and return a long. Typed extension of GetT.</summary>
 public static long GetLong(Func <long> fn, ConnectionNames connectionName)
 {
     return(GetT <long>(fn, connectionName));
 }
예제 #19
0
 protected virtual T CreateContext(ConnectionNames name)
 {
     return(CreateContext(GetConnectionString()));
 }
예제 #20
0
 protected DataContextProvider(ConnectionNames name)
 {
     _connectionName = name;
 }
예제 #21
0
 ///<summary>Perform the given action in the context of the given connectionName db.</summary>
 public static void Run(Action a, ConnectionNames connectionName)
 {
     GetT(new Func <object>(() => { a(); return(null); }), connectionName);
 }
예제 #22
0
 ///<summary>Returns the connection settings (default or user override) for the type passed in.
 ///Returns null if a corresponding connection could not be found.</summary>
 public static CentralConnection GetHqConnection(ConnectionNames connName)
 {
     FillDictHqCentralConnections();
     _dictHqCentralConnections.TryGetValue(connName, out CentralConnection centralConnection);
     return(centralConnection);
 }
예제 #23
0
 public GameDataContextProvider(ConnectionNames сonnectionName) : base(сonnectionName)
 {
 }
예제 #24
0
 ///<summary>Perform the given function in the context of the given connectionName db and return an int. Typed extension of GetT.</summary>
 public static int GetInt(Func <int> fn, ConnectionNames connectionName)
 {
     return(GetT <int>(fn, connectionName));
 }
예제 #25
0
 ///<summary>Perform the given function in the context of the given connectionName db and return a T.</summary>
 public static T GetT <T>(Func <T> fn, ConnectionNames connectionName)
 {
     return(GetT(fn, new Action(() => { ConnectionStore.SetDbT(connectionName); })));
 }
예제 #26
0
 protected T ChangeConnection(ConnectionNames name)
 {
     throw new NotImplementedException();
 }
예제 #27
0
 ///<summary>Perform the given function in the context of the given connectionName db and return a DataTable. Typed extension of GetT.</summary>
 public static DataTable GetDataTable(Func <DataTable> fn, ConnectionNames connectionName)
 {
     return(GetT <DataTable>(fn, connectionName));
 }
예제 #28
0
 private string _getConnectionString(ConnectionNames?connectionName = null)
 {
     _activeConnection = connectionName ?? AppConnectionName;
     return(_connections[_activeConnection]);
 }