Exemplo n.º 1
0
        /// <summary>
        /// Adds sql server's credentials to the cache.
        /// </summary>
        /// <param name="server">server</param>
        /// <param name="user">user</param>
        /// <param name="password">password</param>
        public void AddCredentials(string server, string user, string password)
        {
            try
            {
                if (server == null || user == null || password == null)
                {
                    throw new ArgumentNullException();
                }

                // if the server exists in cache.
                if (dataCache.Contains(server))
                {
                    throw new ApplicationException(server + "'s credentials already exist");
                }
                // the server added to the cache.
                else
                {
                    DBViewerCacheItem dataItem = new DBViewerCacheItem(user, password);
                    dataCache.Add(server, dataItem);
                }
            }
            catch (Exception e)
            {
                Log.WriteErrorToLog(e.Message);
                throw;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds sql server's DataTable to the cache.
        /// </summary>
        /// <param name="server">server</param>
        /// <param name="database">database</param>
        /// <param name="user">user</param>
        /// <param name="password">password</param>
        /// <param name="table">table</param>
        public void AddData(string server, string database, string user, string password, DataTable table)
        {
            try
            {
                if (server == null || database == null || user == null || password == null)
                {
                    throw new ArgumentNullException();
                }

                DBViewerCacheItem dataItem;

                // if the server exists in the cache.
                if (dataCache.Contains(server))
                {
                    // gets the DBViewerCacheItem
                    dataItem = (DBViewerCacheItem)dataCache[server];
                    // adds the cached table to its database.
                    dataItem.AddData(database, table);
                }
                // the server added to the cache.
                else
                {
                    dataItem = new DBViewerCacheItem(user, password);
                    if (database.Length != 0 && table != null)
                    {
                        dataItem.AddData(database, table);
                    }

                    dataCache.Add(server, dataItem);
                }
            }
            catch (Exception e)
            {
                Log.WriteErrorToLog(e.Message);
                throw;
            }
        }