Esempio n. 1
0
        public static string GetDefaultSchema(Backends backend,
                                              DbConnectionStringBuilder connStrBuilder, List <string> schemata)
        {
            switch (backend)
            {
            case Backends.Access:
                return(null);

            case Backends.PostgreSql:
                return("public");

            case Backends.SqlServer:
                return("dbo");

            case Backends.Oracle:
                if ((connStrBuilder != null) && (connStrBuilder.ContainsKey("USER ID")))
                {
                    string userIDstring = DbOracle.GetUserId(connStrBuilder);
                    if ((schemata != null) && (schemata.IndexOf(userIDstring) != -1))
                    {
                        return(userIDstring);
                    }
                }
                return(null);

            default:
                if (connStrBuilder != null)
                {
                    object userID;
                    if ((connStrBuilder.TryGetValue("UID", out userID)) ||
                        (connStrBuilder.TryGetValue("User ID", out userID)))
                    {
                        string userIDstring = userID.ToString();
                        if ((schemata != null) && (schemata.IndexOf(userIDstring) != -1))
                        {
                            return(userIDstring);
                        }
                    }
                }
                return(null);
            }
        }
Esempio n. 2
0
 public override void Initialize(Backends.ToolkitEngineBackend toolit)
 {
     base.Initialize (toolit);
     toolit.RegisterBackend<DesktopBackend, GtkWindowsDesktopBackend> ();
 }
Esempio n. 3
0
        private void LoadSchemata()
        {
            List <String>   schemaList = new List <String>();
            OleDbConnection cn         = null;

            try
            {
                if ((_connStrBuilder != null) && !String.IsNullOrEmpty(_connStrBuilder.ConnectionString))
                {
                    cn = new OleDbConnection(_connStrBuilder.ConnectionString);
                    cn.Open();

                    _backend = DbOleDb.GetBackend(cn);

                    if (_backend != Backends.Access)
                    {
                        OleDbCommand cmd = cn.CreateCommand();
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA" +
                                          " WHERE SCHEMA_NAME <> 'INFORMATION_SCHEMA'";
                        OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
                        DataTable        dbTable = new DataTable();
                        try
                        {
                            adapter.Fill(dbTable);
                            schemaList = (from r in dbTable.AsEnumerable()
                                          let schemaName = r.Field <string>("SCHEMA_NAME")
                                                           select schemaName).OrderBy(s => s).ToList();
                            _defaultSchema = DbBase.GetDefaultSchema(_backend, _connStrBuilder, schemaList);
                        }
                        catch { }
                    }
                }
            }
            catch (Exception ex)
            {
                _connStrBuilder.ConnectionString = String.Empty;
                if (ex is OleDbException)
                {
                    MessageBox.Show(ex.Message, "OleDb Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                else
                {
                    MessageBox.Show(ex.Message, "HLU Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            finally
            {
                if ((cn != null) && (cn.State != ConnectionState.Closed))
                {
                    cn.Close();
                }

                _schemata = schemaList;
                OnPropertyChanged("Schemata");

                if (_schemata.Count == 1)
                {
                    _defaultSchema = _schemata[0];
                }
                OnPropertyChanged("DefaultSchema");
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Returns the list of backends selected to be targeted by processing any
        /// backends with <see cref="TrafficBackend.Group"/> and <see cref="TrafficBackend.GroupLimit"/>
        /// properties configured to dynamically select backend target nodes.
        /// </summary>
        /// <param name="hostGroups">
        /// Dictionary mapping host group names to the list of host node
        /// definitions within the named group.
        /// </param>
        /// <returns>The list of selected backends.</returns>
        /// <remarks>
        /// <note>
        /// This is a somewhat specialized method used by the <b>neon-proxy-manager</b>
        /// when generating HAProxy configuration files.
        /// </note>
        /// <note>
        /// This method will compute the select the first time it's called on an
        /// instance and then return the same selected backends thereafter.
        /// </note>
        /// </remarks>
        public List <TrafficHttpBackend> SelectBackends(Dictionary <string, List <NodeDefinition> > hostGroups)
        {
            Covenant.Requires <ArgumentNullException>(hostGroups != null);

            if (selectedBackends != null)
            {
                return(selectedBackends);   // Return the cached backends
            }

            if (Backends.Count(be => !string.IsNullOrEmpty(be.Group)) == 0)
            {
                // There is no group targeting so we can just return the
                // backend definitions as is.

                return(Backends);
            }

            // We actually need to select backends.  Any backend that doesn't
            // target a group will be added as-is and then we'll need to
            // process group targets to actually select the backend nodes.
            //
            // Note that we're only going to process the first backend that
            // targets any given group (multiple backends targeting the
            // same group will be considered to be a configuration problem).

            // NOTE:
            //
            // I'm treating a targeted host group that doesn't actually exist
            // as an empty group.  A case could be made to signal this as an
            // error or log a warning, but one could also argue that treating
            // this as a empty group makes logical sense (and it's much easier
            // to implement to boot).

            var processedGroups = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase);

            selectedBackends = new List <TrafficHttpBackend>();

            foreach (var backend in Backends)
            {
                if (string.IsNullOrEmpty(backend.Group))
                {
                    selectedBackends.Add(backend);
                }
                else if (!processedGroups.Contains(backend.Group))
                {
                    foreach (var groupNode in backend.SelectGroupNodes(hostGroups).OrderBy(n => n.Name))
                    {
                        var backendClone = NeonHelper.JsonClone(backend);

                        backendClone.Name   = groupNode.Name;
                        backendClone.Server = groupNode.PrivateAddress.ToString();

                        selectedBackends.Add(backendClone);
                    }

                    processedGroups.Add(backend.Group);
                }
            }

            return(selectedBackends);
        }
Esempio n. 5
0
 public override void Initialize(Backends.IPopoverEventSink sink)
 {
     base.Initialize (sink);
     Popover.Shown += RemoveShadow;
 }
        private void LoadSchemata()
        {
            List<String> schemaList = new List<String>();
            OleDbConnection cn = null;

            try
            {
                if ((_connStrBuilder != null) && !String.IsNullOrEmpty(_connStrBuilder.ConnectionString))
                {
                    cn = new OleDbConnection(_connStrBuilder.ConnectionString);
                    cn.Open();

                    _backend = DbOleDb.GetBackend(cn);

                    if (_backend != Backends.Access)
                    {
                        OleDbCommand cmd = cn.CreateCommand();
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA" +
                                            " WHERE SCHEMA_NAME <> 'INFORMATION_SCHEMA'";
                        OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
                        DataTable dbTable = new DataTable();
                        try
                        {
                            adapter.Fill(dbTable);
                            schemaList = (from r in dbTable.AsEnumerable()
                                          let schemaName = r.Field<string>("SCHEMA_NAME")
                                          select schemaName).OrderBy(s => s).ToList();
                            _defaultSchema = DbBase.GetDefaultSchema(_backend, _connStrBuilder, schemaList);
                        }
                        catch { }
                    }
                }
            }
            catch (Exception ex)
            {
                _connStrBuilder.ConnectionString = String.Empty;
                if (ex is OleDbException)
                    MessageBox.Show(ex.Message, "OleDb Error", MessageBoxButton.OK, MessageBoxImage.Error);
                else
                    MessageBox.Show(ex.Message, "HLU Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                if ((cn != null) && (cn.State != ConnectionState.Closed)) cn.Close();

                _schemata = schemaList;
                OnPropertyChanged("Schemata");

                if (_schemata.Count == 1) _defaultSchema = _schemata[0];
                OnPropertyChanged("DefaultSchema");
            }
        }
Esempio n. 7
0
        public static DbBase CreateConnection()
        {
            if (Enum.IsDefined(typeof(ConnectionTypes), Settings.Default.DbConnectionType))
                _connType = (ConnectionTypes)Settings.Default.DbConnectionType;
            else
                _connType = ConnectionTypes.Unknown;

            string connString = Settings.Default.DbConnectionString;
            string defaultSchema = Settings.Default.DbDefaultSchema;
            bool promptPwd = Settings.Default.DbPromptPwd;

            if ((_connType == ConnectionTypes.Unknown) || String.IsNullOrEmpty(connString) ||
                ((DbBase.GetBackend(connString, _connType) != Backends.Access) && String.IsNullOrEmpty(defaultSchema)))
            {
                promptPwd = false;
                SelectConnectionType();
            }

            if (_connType == ConnectionTypes.Unknown) return null;

            DbBase db = null;

            switch (_connType)
            {
                case ConnectionTypes.ODBC:
                    db = new DbOdbc(ref connString, ref defaultSchema, ref promptPwd,
                        Properties.Resources.PasswordMaskString, Settings.Default.UseAutomaticCommandBuilders,
                        true, Settings.Default.DbIsUnicode, Settings.Default.DbUseTimeZone,
                        Settings.Default.DbTextLength, Settings.Default.DbBinaryLength, Settings.Default.DbTimePrecision,
                        Settings.Default.DbNumericPrecision, Settings.Default.DbNumericScale);
                    break;
                case ConnectionTypes.OleDb:
                    db = new DbOleDb(ref connString, ref defaultSchema, ref promptPwd,
                        Properties.Resources.PasswordMaskString, Settings.Default.UseAutomaticCommandBuilders,
                        true, Settings.Default.DbIsUnicode, Settings.Default.DbUseTimeZone, Settings.Default.DbTextLength,
                        Settings.Default.DbBinaryLength, Settings.Default.DbTimePrecision,
                        Settings.Default.DbNumericPrecision, Settings.Default.DbNumericScale);
                    break;
                case ConnectionTypes.Oracle:
                    db = new DbOracle(ref connString, ref defaultSchema, ref promptPwd,
                        Properties.Resources.PasswordMaskString, Settings.Default.UseAutomaticCommandBuilders,
                        true, Settings.Default.DbIsUnicode, Settings.Default.DbUseTimeZone, Settings.Default.DbTextLength,
                        Settings.Default.DbBinaryLength, Settings.Default.DbTimePrecision,
                        Settings.Default.DbNumericPrecision, Settings.Default.DbNumericScale);
                    break;
                case ConnectionTypes.PostgreSQL:
                    db = new DbPgSql(ref connString, ref defaultSchema, ref promptPwd,
                        Properties.Resources.PasswordMaskString, Settings.Default.UseAutomaticCommandBuilders,
                        true, Settings.Default.DbIsUnicode, Settings.Default.DbUseTimeZone, Settings.Default.DbTextLength,
                        Settings.Default.DbBinaryLength, Settings.Default.DbTimePrecision,
                        Settings.Default.DbNumericPrecision, Settings.Default.DbNumericScale);
                    break;
                case ConnectionTypes.SQLServer:
                    db = new DbSqlServer(ref connString, ref defaultSchema, ref promptPwd,
                        Properties.Resources.PasswordMaskString, Settings.Default.UseAutomaticCommandBuilders,
                        true, Settings.Default.DbIsUnicode, Settings.Default.DbUseTimeZone, Settings.Default.DbTextLength,
                        Settings.Default.DbBinaryLength, Settings.Default.DbTimePrecision,
                        Settings.Default.DbNumericPrecision, Settings.Default.DbNumericScale);
                    break;
            }

            _backend = DbBase.GetBackend(connString, _connType);

            if (db != null)
            {
                Settings.Default.DbConnectionType = (int)_connType;
                Settings.Default.DbConnectionString = connString;
                Settings.Default.DbDefaultSchema = defaultSchema;
                Settings.Default.DbPromptPwd = promptPwd;
                Settings.Default.Save();
            }

            return db;
        }
Esempio n. 8
0
        public static DbBase CreateConnection()
        {
            if (Enum.IsDefined(typeof(ConnectionTypes), Settings.Default.DbConnectionType))
            {
                _connType = (ConnectionTypes)Settings.Default.DbConnectionType;
            }
            else
            {
                _connType = ConnectionTypes.Unknown;
            }

            string connString    = Settings.Default.DbConnectionString;
            string defaultSchema = Settings.Default.DbDefaultSchema;
            bool   promptPwd     = Settings.Default.DbPromptPwd;

            if ((_connType == ConnectionTypes.Unknown) || String.IsNullOrEmpty(connString) ||
                ((DbBase.GetBackend(connString, _connType) != Backends.Access) && String.IsNullOrEmpty(defaultSchema)))
            {
                promptPwd = false;
                SelectConnectionType();
            }

            if (_connType == ConnectionTypes.Unknown)
            {
                return(null);
            }

            DbBase db = null;

            switch (_connType)
            {
            case ConnectionTypes.ODBC:
                db = new DbOdbc(ref connString, ref defaultSchema, ref promptPwd,
                                Properties.Resources.PasswordMaskString, Settings.Default.UseAutomaticCommandBuilders,
                                true, Settings.Default.DbIsUnicode, Settings.Default.DbUseTimeZone,
                                Settings.Default.DbTextLength, Settings.Default.DbBinaryLength, Settings.Default.DbTimePrecision,
                                Settings.Default.DbNumericPrecision, Settings.Default.DbNumericScale);
                break;

            case ConnectionTypes.OleDb:
                db = new DbOleDb(ref connString, ref defaultSchema, ref promptPwd,
                                 Properties.Resources.PasswordMaskString, Settings.Default.UseAutomaticCommandBuilders,
                                 true, Settings.Default.DbIsUnicode, Settings.Default.DbUseTimeZone, Settings.Default.DbTextLength,
                                 Settings.Default.DbBinaryLength, Settings.Default.DbTimePrecision,
                                 Settings.Default.DbNumericPrecision, Settings.Default.DbNumericScale);
                break;

            case ConnectionTypes.Oracle:
                db = new DbOracle(ref connString, ref defaultSchema, ref promptPwd,
                                  Properties.Resources.PasswordMaskString, Settings.Default.UseAutomaticCommandBuilders,
                                  true, Settings.Default.DbIsUnicode, Settings.Default.DbUseTimeZone, Settings.Default.DbTextLength,
                                  Settings.Default.DbBinaryLength, Settings.Default.DbTimePrecision,
                                  Settings.Default.DbNumericPrecision, Settings.Default.DbNumericScale);
                break;

            case ConnectionTypes.PostgreSQL:
                db = new DbPgSql(ref connString, ref defaultSchema, ref promptPwd,
                                 Properties.Resources.PasswordMaskString, Settings.Default.UseAutomaticCommandBuilders,
                                 true, Settings.Default.DbIsUnicode, Settings.Default.DbUseTimeZone, Settings.Default.DbTextLength,
                                 Settings.Default.DbBinaryLength, Settings.Default.DbTimePrecision,
                                 Settings.Default.DbNumericPrecision, Settings.Default.DbNumericScale);
                break;

            case ConnectionTypes.SQLServer:
                db = new DbSqlServer(ref connString, ref defaultSchema, ref promptPwd,
                                     Properties.Resources.PasswordMaskString, Settings.Default.UseAutomaticCommandBuilders,
                                     true, Settings.Default.DbIsUnicode, Settings.Default.DbUseTimeZone, Settings.Default.DbTextLength,
                                     Settings.Default.DbBinaryLength, Settings.Default.DbTimePrecision,
                                     Settings.Default.DbNumericPrecision, Settings.Default.DbNumericScale);
                break;
            }

            _backend = DbBase.GetBackend(connString, _connType);

            if (db != null)
            {
                Settings.Default.DbConnectionType   = (int)_connType;
                Settings.Default.DbConnectionString = connString;
                Settings.Default.DbDefaultSchema    = defaultSchema;
                Settings.Default.DbPromptPwd        = promptPwd;
                Settings.Default.Save();
            }

            return(db);
        }