public void Indexer_Driver_Empty()
        {
            OdbcConnectionStringBuilder builder = new OdbcConnectionStringBuilder();

            builder ["Driver"] = string.Empty;
            Assert.AreEqual(string.Empty, builder.Driver, "#A1");
            Assert.AreEqual(string.Empty, builder ["Driver"], "#A2");
            Assert.IsTrue(builder.ContainsKey("Driver"), "#A3");
            Assert.AreEqual("Driver=", builder.ConnectionString, "#A4");
            builder.Driver = "X";
            Assert.AreEqual("X", builder.Driver, "#B1");
            Assert.AreEqual("X", builder ["Driver"], "#B2");
            Assert.IsTrue(builder.ContainsKey("Driver"), "#B3");
            Assert.AreEqual("Driver={X}", builder.ConnectionString, "#B4");
            builder ["Driver"] = string.Empty;
            Assert.AreEqual(string.Empty, builder.Driver, "#C1");
            Assert.AreEqual(string.Empty, builder ["Driver"], "#C2");
            Assert.IsTrue(builder.ContainsKey("Driver"), "#C3");
            Assert.AreEqual("Driver=", builder.ConnectionString, "#C4");
            builder.Driver = "A";
            Assert.AreEqual("A", builder.Driver, "#D1");
            Assert.AreEqual("A", builder ["Driver"], "#D2");
            Assert.IsTrue(builder.ContainsKey("Driver"), "#D3");
            Assert.AreEqual("Driver={A}", builder.ConnectionString, "#D4");
            builder ["Driver"] = " ";
            Assert.AreEqual(" ", builder.Driver, "#E1");
            Assert.AreEqual(" ", builder ["Driver"], "#E2");
            Assert.IsTrue(builder.ContainsKey("Driver"), "#E3");
            Assert.AreEqual("Driver={ }", builder.ConnectionString, "#E4");
        }
        public void Add()
        {
            OdbcConnectionStringBuilder builder = new OdbcConnectionStringBuilder();

            builder.Add("driverid", "420");
            builder.Add("driverid", "560");
            builder.Add("DriverID", "840");
            Assert.AreEqual("840", builder ["driverId"], "#A1");
            Assert.IsTrue(builder.ContainsKey("driverId"), "#A2");
            builder.Add("Driver", "OdbcDriver");
            Assert.AreEqual("OdbcDriver", builder.Driver, "#B1");
            Assert.AreEqual("OdbcDriver", builder ["Driver"], "#B2");
            Assert.IsTrue(builder.ContainsKey("Driver"), "#B3");
            builder.Add("Driver", "{OdbcDriver");
            Assert.AreEqual("{OdbcDriver", builder.Driver, "#C1");
            Assert.AreEqual("{OdbcDriver", builder ["Driver"], "#C2");
            Assert.IsTrue(builder.ContainsKey("Driver"), "#C3");
            builder.Add("Dsn", "MyDsn");
            Assert.AreEqual("MyDsn", builder.Dsn, "#D1");
            Assert.AreEqual("MyDsn", builder ["Dsn"], "#D2");
            Assert.IsTrue(builder.ContainsKey("Dsn"), "#D3");
            builder.Add("dsN", "MyDsn2");
            Assert.AreEqual("MyDsn2", builder.Dsn, "#E1");
            Assert.AreEqual("MyDsn2", builder ["Dsn"], "#E2");
            Assert.IsTrue(builder.ContainsKey("Dsn"), "#E3");
        }
        public void Indexer_Value_Null()
        {
            OdbcConnectionStringBuilder builder = new OdbcConnectionStringBuilder();

            builder ["DriverID"] = null;
            Assert.AreEqual(string.Empty, builder.ConnectionString, "#A1");
            try {
                object value = builder ["DriverID"];
                Assert.Fail("#A2:" + value);
            } catch (ArgumentException ex) {
                // Keyword not supported: 'DriverID'
                Assert.AreEqual(typeof(ArgumentException), ex.GetType(), "#A3");
                Assert.IsNull(ex.InnerException, "#A4");
                Assert.IsNotNull(ex.Message, "#A5");
                Assert.IsTrue(ex.Message.IndexOf("'DriverID'") != -1, "#A6:" + ex.Message);
                Assert.IsNull(ex.ParamName, "#A7");
            }
            Assert.IsFalse(builder.ContainsKey("DriverID"), "#A8");
            Assert.AreEqual(string.Empty, builder.ConnectionString, "#A9");

            builder ["DriverID"] = "A";
            Assert.AreEqual("DriverID=A", builder.ConnectionString, "#B1");
            builder ["DriverID"] = null;
            Assert.IsFalse(builder.ContainsKey("DriverID"), "#B2");
            Assert.AreEqual(string.Empty, builder.ConnectionString, "#B3");
        }
        public void Clear()
        {
            OdbcConnectionStringBuilder builder = new OdbcConnectionStringBuilder();

            builder ["Dbq"] = "C:\\Data.xls";
            builder.Driver  = "SQL Server";
            builder.Dsn     = "AdventureWorks";
            builder.Add("Port", "56");
            builder.Clear();
            Assert.AreEqual(string.Empty, builder.ConnectionString, "#1");
            Assert.IsFalse(builder.ContainsKey("Dbq"), "#2");
            Assert.AreEqual(string.Empty, builder.Driver, "#3");
            Assert.AreEqual(string.Empty, builder.Dsn, "#4");
            Assert.IsFalse(builder.ContainsKey("Port"), "#5");
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Converts ODBC connection string to the SQL Client (.NET).
        /// </summary>
        public static string OdbcToSqlClient(this string odbcString)
        {
            if (string.IsNullOrEmpty(odbcString))
            {
                return(null);
            }
            try {
                var odbc     = new OdbcConnectionStringBuilder(odbcString);
                var server   = odbc.GetValue(OdbcServerKey);
                var database = odbc.GetValue(OdbcDatabaseKey);
                if (!string.IsNullOrWhiteSpace(server) && !string.IsNullOrWhiteSpace(database))
                {
                    var sql = new SqlConnectionStringBuilder();
                    sql.DataSource     = server;
                    sql.InitialCatalog = database;

                    if (odbc.ContainsKey(OdbcUidKey))
                    {
                        //Standard Connection
                        sql.IntegratedSecurity = false;
                        sql.UserID             = odbc.GetValue(OdbcUidKey);
                        sql.Password           = odbc.GetValue(OdbcPasswordKey);
                    }
                    else
                    {
                        //Trusted Connection
                        sql.IntegratedSecurity = true;
                    }
                    return(sql.ConnectionString);
                }
            } catch (ArgumentException) { }
            return(null);
        }
        public void Indexer_Keyword_Invalid()
        {
            string [] invalid_keywords = new string []
            {
                string.Empty,
                " ",
                " abc",
                "abc ",
                "\r",
                "ab\rc",
                ";abc",
                "a\0b"
            };

            OdbcConnectionStringBuilder builder = new OdbcConnectionStringBuilder();

            for (int i = 0; i < invalid_keywords.Length; i++)
            {
                string keyword = invalid_keywords [i];
                try
                {
                    builder [keyword] = "abc";
                    Assert.Fail("#A1:" + i);
                }
                catch (ArgumentException ex)
                {
                    // Invalid keyword, contain one or more of 'no characters',
                    // 'control characters', 'leading or trailing whitespace'
                    // or 'leading semicolons'
                    Assert.AreEqual(typeof(ArgumentException), ex.GetType(), "#A2:" + i);
                    Assert.IsNull(ex.InnerException, "#A3:" + i);
                    Assert.IsNotNull(ex.Message, "#A4:" + i);
                    Assert.IsTrue(ex.Message.IndexOf("'" + keyword + "'") == -1, "#A5:" + i);
                    Assert.AreEqual(keyword, ex.ParamName, "#A6:" + i);
                }

                builder [keyword] = null;
                Assert.IsFalse(builder.ContainsKey(keyword), "#B");

                try
                {
                    object value = builder [keyword];
                    Assert.Fail("#C1:" + value + " (" + i + ")");
                }
                catch (ArgumentException ex)
                {
                    // Keyword not supported: '...'
                    Assert.AreEqual(typeof(ArgumentException), ex.GetType(), "#C2:" + i);
                    Assert.IsNull(ex.InnerException, "#C3:" + i);
                    Assert.IsNotNull(ex.Message, "#C4:" + i);
                    Assert.IsTrue(ex.Message.IndexOf("'" + keyword + "'") != -1, "#C5:" + i);
                    Assert.IsNull(ex.ParamName, "#C6:" + i);
                }
            }
        }
Ejemplo n.º 7
0
        public static void SetSettings(string ConnectionString, int ID_rodzaj)
        {
            Settings.ConnectionString = ConnectionString;
            Settings.ID_rodzaj        = ID_rodzaj;

            ReadOnlyMode           = false;
            ReadOnlyModeForCatalog = false;
            MonthNumber            = 1;
            Interval = 1;

            try
            {
                OdbcConnectionStringBuilder OdCB = new OdbcConnectionStringBuilder(ConnectionString);

                Settings.ConnectionStringSql = "Server = " + OdCB["server"].ToString() + ";Database = " + OdCB["database"].ToString() + ";";

                if (OdCB.ContainsKey("TrusteD_Connection"))
                {
                    Settings.ConnectionStringSql += "Trusted_Connection = " + OdCB["Trusted_Connection"].ToString();
                }
                else if (OdCB.ContainsKey("Uid"))
                {
                    Settings.ConnectionStringSql += "Uid = " + OdCB["Uid"].ToString() + "; Pwd = " + OdCB["Pwd"].ToString();
                }
                else if (OdCB.ContainsKey("User Id"))
                {
                    Settings.ConnectionStringSql += "User Id = " + OdCB["User Id"].ToString() + "; Password = "******"Password"].ToString();
                }
            }
            catch
            { }

            try
            {
                Settings.ID_rodzaj = ID_rodzaj;
            }
            catch { }

            Connection = new SqlConnection(Settings.ConnectionString);

            Settings.ReadOnlyMode = false;
        }
Ejemplo n.º 8
0
        protected override void SetConnectionString(string value)
        {
            OdbcConnectionStringBuilder builder = new OdbcConnectionStringBuilder(value);

            FillDataSources();
            if (String.IsNullOrEmpty(value))
            {
                rbDsName.Checked = true;
            }
            else if (builder.ContainsKey("Dsn"))
            {
                string dsn = builder["Dsn"] as string;
                if (cbxDsName.Items.Contains(dsn))
                {
                    cbxDsName.SelectedIndex = cbxDsName.Items.IndexOf(dsn);
                    rbDsName.Checked        = true;
                }
                else
                {
                    rbConnectionString.Checked = true;
                }
            }

            if (builder.ContainsKey("uid"))
            {
                tbUserName.Text = builder["uid"] as string;
                builder.Remove("uid");
            }
            if (builder.ContainsKey("pwd"))
            {
                tbPassword.Text = builder["pwd"] as string;
                builder.Remove("pwd");
            }

            // display the string w/o uid, pwd
            tbConnectionString.Text = builder.ToString();

            // update the enabled state
            rbDsName_CheckedChanged(this, EventArgs.Empty);
        }
        public void Indexer_Dsn_Empty()
        {
            OdbcConnectionStringBuilder builder = new OdbcConnectionStringBuilder();

            builder ["Dsn"] = string.Empty;
            Assert.AreEqual(string.Empty, builder.Dsn, "#A1");
            Assert.AreEqual(string.Empty, builder ["Dsn"], "#A2");
            Assert.IsTrue(builder.ContainsKey("Dsn"), "#A3");
            builder.Dsn = "X";
            Assert.AreEqual("X", builder.Dsn, "#B1");
            Assert.AreEqual("X", builder ["Dsn"], "#B2");
            Assert.AreEqual("X", builder ["dsN"], "#B3");
            Assert.IsTrue(builder.ContainsKey("Dsn"), "#B4");
            Assert.IsTrue(builder.ContainsKey("dSn"), "#B5");
            builder ["Dsn"] = string.Empty;
            Assert.AreEqual(string.Empty, builder.Dsn, "#C1");
            Assert.AreEqual(string.Empty, builder ["Dsn"], "#C2");
            Assert.IsTrue(builder.ContainsKey("Dsn"), "#C3");
            builder.Dsn = "A";
            Assert.AreEqual("A", builder.Dsn, "#D1");
            Assert.AreEqual("A", builder ["Dsn"], "#D2");
            Assert.IsTrue(builder.ContainsKey("Dsn"), "#D3");
            builder ["Dsn"] = " ";
            Assert.AreEqual(" ", builder.Dsn, "#E1");
            Assert.AreEqual(" ", builder ["Dsn"], "#E2");
            Assert.IsTrue(builder.ContainsKey("Dsn"), "#E3");
        }
        public void Dsn()
        {
            OdbcConnectionStringBuilder builder = new OdbcConnectionStringBuilder();

            Assert.IsTrue(builder.ContainsKey("Dsn"), "#A1");
            Assert.AreEqual(string.Empty, builder ["Dsn"], "#A2");
            Assert.AreEqual(string.Empty, builder.Dsn, "#A3");

            builder.Dsn = "myDsn";
            Assert.AreEqual("Dsn=myDsn", builder.ConnectionString, "#B1");
            Assert.IsTrue(builder.ContainsKey("Dsn"), "#B2");
            Assert.AreEqual("myDsn", builder ["Dsn"], "#B3");
            Assert.AreEqual("myDsn", builder.Dsn, "#B4");

            builder.Clear();

            builder ["Dsn"] = "myDsn";
            Assert.AreEqual("Dsn=myDsn", builder.ConnectionString, "#C1");
            Assert.IsTrue(builder.ContainsKey("Dsn"), "#C2");
            Assert.AreEqual("myDsn", builder ["Dsn"], "#C3");
            Assert.AreEqual("myDsn", builder.Dsn, "#C4");
        }
Ejemplo n.º 11
0
        public static void SetSettings(string CString, int ID_rodzaj)
        {
            ConnectionString = CString;
            try
            {
                OdbcConnectionStringBuilder OdCB = new OdbcConnectionStringBuilder(ConnectionString);

                Settings.ConnectionStringSql = "Server = " + OdCB["server"].ToString() + ";Database = " + OdCB["database"].ToString() + ";";

                if (OdCB.ContainsKey("TrusteD_Connection"))
                {
                    Settings.ConnectionStringSql += "Trusted_Connection = " + OdCB["Trusted_Connection"].ToString();
                }
                else if (OdCB.ContainsKey("Uid"))
                {
                    Settings.ConnectionStringSql += "Uid = " + OdCB["Uid"].ToString() + "; Pwd = " + OdCB["Pwd"].ToString();
                }
                else if (OdCB.ContainsKey("User Id"))
                {
                    Settings.ConnectionStringSql += "User Id = " + OdCB["User Id"].ToString() + "; Password = "******"Password"].ToString();
                }
                else
                {
                    Settings.ConnectionStringSql += "; persist security info = True; integrated security = SSPI";
                }
            }
            catch
            { }

            try
            {
                Settings.ID_rodzaj = ID_rodzaj;
            }
            catch { }

            Settings.ReadOnlyMode = false;
            employeeID            = "-1";
        }
Ejemplo n.º 12
0
    static void Main()
    {
        OdbcConnectionStringBuilder builder = new OdbcConnectionStringBuilder();

        builder.Driver        = "Microsoft Visual FoxPro Driver";
        builder["SourceType"] = "DBC";

        // Keys that you have provided return true.
        Console.WriteLine(builder.ContainsKey("SourceType"));

        // Comparison is case insensitive.
        Console.WriteLine(builder.ContainsKey("sourcetype"));

        // Keys added by the provider return false. This method
        // only examines keys added explicitly.
        Console.WriteLine(builder.ContainsKey("DNS"));

        // Keys that do not exist return false.
        Console.WriteLine(builder.ContainsKey("MyKey"));

        Console.WriteLine("Press Enter to continue.");
        Console.ReadLine();
    }
        public void Remove()
        {
            OdbcConnectionStringBuilder builder = new OdbcConnectionStringBuilder();

            Assert.IsFalse(builder.Remove("Dsn"), "#A1");
            Assert.IsFalse(builder.Remove("Driver"), "#A2");
            builder.Add("DriverID", "790");
            builder ["DefaultDir"] = "C:\\";
            Assert.IsTrue(builder.Remove("DriverID"), "#B1");
            Assert.IsFalse(builder.ContainsKey("DriverID"), "#B2");
            Assert.IsFalse(builder.Remove("DriverID"), "#B3");
            Assert.IsFalse(builder.ContainsKey("DriverID"), "#B4");
            Assert.IsTrue(builder.Remove("defaulTdIr"), "#B5");
            Assert.IsFalse(builder.ContainsKey("DefaultDir"), "#B6");
            Assert.IsFalse(builder.Remove("defaulTdIr"), "#B7");
            Assert.IsFalse(builder.Remove("userid"), "#B8");
            Assert.IsFalse(builder.Remove(string.Empty), "#B9");
            Assert.IsFalse(builder.Remove("\r"), "#B10");
            Assert.IsFalse(builder.Remove("a;"), "#B11");
            builder.Dsn = "myDsn";
            Assert.IsTrue(builder.Remove("dSn"), "#C1");
            Assert.IsTrue(builder.ContainsKey("dSn"), "#C2");
            Assert.IsTrue(builder.ContainsKey("Dsn"), "#C3");
            Assert.AreEqual(string.Empty, builder.Dsn, "#C4");
            Assert.IsFalse(builder.Remove("Dsn"), "#C5");
            builder.Driver = "SQL Server";
            Assert.IsTrue(builder.Remove("driVer"), "#D1");
            Assert.IsTrue(builder.ContainsKey("driVer"), "#D2");
            Assert.IsTrue(builder.ContainsKey("Driver"), "#D3");
            Assert.AreEqual(string.Empty, builder.Driver, "#D4");
            Assert.IsFalse(builder.Remove("Driver"), "#D5");
            builder ["Dsn"] = "myDsn";
            Assert.IsTrue(builder.Remove("Dsn"), "#E1");
            Assert.IsTrue(builder.ContainsKey("Dsn"), "#E2");
            Assert.AreEqual(string.Empty, builder.Dsn, "#E3");
            Assert.IsFalse(builder.Remove("Dsn"), "#E4");
            builder ["Driver"] = "SQL Server";
            Assert.IsTrue(builder.Remove("Driver"), "#F1");
            Assert.IsTrue(builder.ContainsKey("Driver"), "#F2");
            Assert.AreEqual(string.Empty, builder.Driver, "#F3");
            Assert.IsFalse(builder.Remove("Driver"), "#F4");
        }
        public void ContainsKey_Keyword_Null()
        {
            OdbcConnectionStringBuilder builder = new OdbcConnectionStringBuilder();

            builder ["SourceType"] = "DBC";
            try {
                builder.ContainsKey(null);
                Assert.Fail("#1");
            } catch (ArgumentNullException ex) {
                Assert.AreEqual(typeof(ArgumentNullException), ex.GetType(), "#2");
                Assert.IsNull(ex.InnerException, "#3");
                Assert.IsNotNull(ex.Message, "#4");
                Assert.AreEqual("keyword", ex.ParamName, "#5");
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Converts ODBC connection string to the SQL Client (.NET).
        /// </summary>
        public static string OdbcToSqlClient(this string odbcString)
        {
            if (string.IsNullOrEmpty(odbcString))
            {
                return(null);
            }
            try {
                var odbc     = new OdbcConnectionStringBuilder(odbcString);
                var server   = odbc.GetValue(OdbcServerKey);
                var database = odbc.GetValue(OdbcDatabaseKey);
                if (!string.IsNullOrWhiteSpace(server) && !string.IsNullOrWhiteSpace(database))
                {
                    var sql = new SqlConnectionStringBuilder {
                        DataSource     = server,
                        InitialCatalog = database,
                    };

                    var userId = odbc.GetValue(OdbcUidKey);
                    if (!string.IsNullOrEmpty(userId))
                    {
                        sql.UserID = odbc.GetValue(OdbcUidKey);
                    }

                    var password = odbc.GetValue(OdbcPasswordKey);
                    if (!string.IsNullOrEmpty(password))
                    {
                        sql.Password = password;
                    }

                    // If no password and user name, assume integrated authentication
                    sql.IntegratedSecurity     = string.IsNullOrEmpty(sql.UserID) && string.IsNullOrEmpty(sql.Password);
                    sql.TrustServerCertificate = string.Compare(odbc.GetValue(OdbcTrustServerCertificateKey), "yes", StringComparison.OrdinalIgnoreCase) == 0;

                    // Translate authentication method
                    if (odbc.ContainsKey(OdbcAuthenticationKey))
                    {
                        SqlAuthenticationMethod authMethod;
                        if (Enum.TryParse(odbc.GetValue(OdbcAuthenticationKey), out authMethod))
                        {
                            sql.Authentication = authMethod;
                        }
                    }

                    return(sql.ConnectionString);
                }
            } catch (ArgumentException) { }
            return(null);
        }
        public DsnEditorForm(
            bool onConnect,
            string dsn,
            DriverCallbackDelegate connectionTest,
            DriverCallbackDelegate dsnSave)
        {
            InitializeComponent();

            // Wire up default button behaviours
            AcceptButton = saveButton;
            CancelButton = cancelButton;

            isConnecting   = onConnect;
            testConnection = connectionTest;
            saveDsn        = dsnSave;

            // If connecting then disable some user inputs
            if (isConnecting)
            {
                textName.ReadOnly = textDescription.ReadOnly = true;
                textName.Enabled  = textDescription.Enabled = false;
            }

            // If this is a call serving a connect request, name the button "Connect", otherwise it's a DSN editing, so it's going to be a "Save".
            saveButton.Text = onConnect ? "Connect" : "Save";

            // Parse DSN into the builder
            Builder.ConnectionString = dsn;

            // Basic Panel
            textName.Text          = Builder.ContainsKey("dsn") ? Builder["dsn"].ToString().StripBraces() : string.Empty;
            textDescription.Text   = Builder.ContainsKey("description") ? Builder["description"].ToString().StripBraces() : string.Empty;
            textUsername.Text      = Builder.ContainsKey("uid") ? Builder["uid"].ToString().StripBraces() : string.Empty;
            textPassword.Text      = Builder.ContainsKey("pwd") ? Builder["pwd"].ToString().StripBraces() : string.Empty;
            textCloudID.Text       = Builder.ContainsKey("cloudid") ? Builder["cloudid"].ToString().StripBraces() : string.Empty;
            textHostname.Text      = Builder.ContainsKey("server") ? Builder["server"].ToString().StripBraces() : string.Empty;
            numericUpDownPort.Text = Builder.ContainsKey("port") ? Builder["port"].ToString().StripBraces() : string.Empty;

            toolTipName.SetToolTip(textName, "The name the DSN will be referred by.");
            toolTipDescription.SetToolTip(textDescription, "Allows arbitrary text, generally used for short notes about the configured connection.");
            toolTipCloudID.SetToolTip(textCloudID, "The Cloud ID, if connecting to Elastic Cloud. Settings will be automatically configured.");
            toolTipHostname.SetToolTip(textHostname, "IP address or a resolvable DNS name of the Elasticsearch instance that the driver will connect to.");
            toolTipPort.SetToolTip(numericUpDownPort, "The port which the Elasticsearch listens on.");
            toolTipUsername.SetToolTip(textUsername, "If security is enabled, the username configured to access the REST SQL endpoint.");
            toolTipPassword.SetToolTip(textPassword, "If security is enabled, the password configured to access the REST SQL endpoint.");

            // Security Panel
            textCertificatePath.Text         = Builder.ContainsKey("capath") ? Builder["capath"].ToString().StripBraces() : string.Empty;
            radioEnabledNoValidation.Checked = true;             // Default setting
            if (Builder.ContainsKey("secure"))
            {
                var result = int.TryParse(Builder["secure"].ToString(), out int val);
                if (result)
                {
                    switch (val)
                    {
                    case 0: radioButtonDisabled.Checked = true; break;

                    case 1: radioEnabledNoValidation.Checked = true; break;

                    case 2: radioEnabledNoHostname.Checked = true; break;

                    case 3: radioEnabledHostname.Checked = true; break;

                    case 4: radioEnabledFull.Checked = true; break;
                    }
                }
            }

            toolTipDisabled.SetToolTip(radioButtonDisabled,
                                       "The communication between the driver and the Elasticsearch instance is performed over a clear-text connection." + Environment.NewLine
                                       + "This setting can expose the access credentials to a 3rd party intercepting the network traffic and is not recommended.");

            toolTipEnabledNoValidation.SetToolTip(radioEnabledNoValidation,
                                                  "The connection encryption is enabled, but the certificate of the server is not validated." + Environment.NewLine
                                                  + "This setting allows a 3rd party to act with ease as a man-in-the-middle and thus intercept all communications.");

            toolTipEnabledNoHostname.SetToolTip(radioEnabledNoHostname,
                                                "The connection encryption is enabled and the driver verifies that server's certificate is valid," + Environment.NewLine
                                                + "but it does not verify if the certificate is running on the server it was meant for." + Environment.NewLine
                                                + "This setting allows a 3rd party that had access to server's certificate to act as a man-in-the-middle" + Environment.NewLine
                                                + "and thus intercept all the communications.");

            toolTipEnabledHostname.SetToolTip(radioEnabledHostname,
                                              "The connection encryption is enabled and the driver verifies that both the certificate is valid," + Environment.NewLine
                                              + "as well as that it is being deployed on the server that the certificate was meant for.");

            toolTipEnabledFull.SetToolTip(radioEnabledFull,
                                          "This setting is equivalent to the previous one, with one additional check against certificate's revocation." + Environment.NewLine
                                          + "This offers the strongest security option and is the recommended setting for production deployments.");

            toolTipCertificatePath.SetToolTip(textCertificatePath,
                                              "In case the server uses a certificate that is not part of the PKI, for example using a self-signed certificate," + Environment.NewLine
                                              + "you can configure the path to a X509 certificate file that will be used by the driver to validate server's offered certificate.");

            // Logging Panel
            textLogDirectoryPath.Text   = Builder.ContainsKey("tracefile") ? Builder["tracefile"].ToString().StripBraces() : string.Empty;
            comboLogLevel.Text          = "DEBUG";    // Default setting
            checkLoggingEnabled.Checked = true;       // Default setting
            if (Builder.ContainsKey("tracelevel"))
            {
                switch (Builder["tracelevel"].ToString().ToUpperInvariant())
                {
                case "DEBUG": comboLogLevel.Text = "DEBUG"; break;

                case "INFO": comboLogLevel.Text = "INFO"; break;

                case "WARN": comboLogLevel.Text = "WARN"; break;

                case "ERROR": comboLogLevel.Text = "ERROR"; break;
                }
            }
            if (Builder.ContainsKey("traceenabled"))
            {
                var result = int.TryParse(Builder["traceenabled"].ToString(), out int val);
                if (result)
                {
                    switch (val)
                    {
                    case 0: checkLoggingEnabled.Checked = false; break;

                    default: checkLoggingEnabled.Checked = true; break;
                    }
                }
            }
            else
            {
                checkLoggingEnabled.Checked = false;
            }

            toolTipLoggingEnabled.SetToolTip(checkLoggingEnabled,
                                             "Ticking this will enable driver's logging. A logging directory is also mandatory when this option is enabled," + Environment.NewLine
                                             + "however the specified logging directory will be saved in the DSN if provided, even if logging is disabled.");

            toolTipLogDirectoryPath.SetToolTip(textLogDirectoryPath, "Specify which directory to write the log files in.");
            toolTipLogLevel.SetToolTip(comboLogLevel, "Configure the verbosity of the logs.");

            // Misc Panel
            numericUpDownTimeout.Text      = Builder.ContainsKey("Timeout") ? Builder["Timeout"].ToString().StripBraces() : "0";
            numericUpDownFetchSize.Text    = Builder.ContainsKey("MaxFetchSize") ? Builder["MaxFetchSize"].ToString().StripBraces() : "1000";
            numericUpDownBodySize.Text     = Builder.ContainsKey("MaxBodySizeMB") ? Builder["MaxBodySizeMB"].ToString().StripBraces() : "100";
            numericUpDownVarcharLimit.Text = Builder.ContainsKey("VarcharLimit") ? Builder["VarcharLimit"].ToString().StripBraces() : "0";
            comboBoxFloatsFormat.Text      = Builder.ContainsKey("ScientificFloats") ? Builder["ScientificFloats"].ToString().StripBraces() : "default";
            comboBoxDataEncoding.Text      = Builder.ContainsKey("Packing") ? Builder["Packing"].ToString() : "CBOR";
            comboBoxDataCompression.Text   = Builder.ContainsKey("Compression") ? Builder["Compression"].ToString() : "auto";

            string[] noes = { "no", "false", "0" };
            checkBoxFollowRedirects.Checked    = !noes.Contains(Builder.ContainsKey("Follow") ? Builder["Follow"].ToString().StripBraces() : "yes");
            checkBoxApplyTZ.Checked            = !noes.Contains(Builder.ContainsKey("ApplyTZ") ? Builder["ApplyTZ"].ToString().StripBraces() : "no");
            checkBoxAutoEscapePVA.Checked      = !noes.Contains(Builder.ContainsKey("AutoEscapePVA") ? Builder["AutoEscapePVA"].ToString().StripBraces() : "yes");
            checkBoxEarlyExecution.Checked     = !noes.Contains(Builder.ContainsKey("EarlyExecution") ? Builder["EarlyExecution"].ToString().StripBraces() : "yes");
            checkBoxMultiFieldLenient.Checked  = !noes.Contains(Builder.ContainsKey("MultiFieldLenient") ? Builder["MultiFieldLenient"].ToString().StripBraces() : "yes");
            checkBoxIndexIncludeFrozen.Checked = !noes.Contains(Builder.ContainsKey("IndexIncludeFrozen") ? Builder["IndexIncludeFrozen"].ToString().StripBraces() : "no");

            toolTipTimeout.SetToolTip(numericUpDownTimeout, "The maximum number of seconds for a request to the server. The value 0 disables the timeout.");
            toolTipFetchSize.SetToolTip(numericUpDownFetchSize, "The maximum number of rows that Elasticsearch SQL server should send back to the driver for one page.");
            toolTipBodySize.SetToolTip(numericUpDownBodySize, "The maximum number of megabytes that the driver will accept for one page.");
            toolTipVarcharLimit.SetToolTip(numericUpDownVarcharLimit, "The maximum number of characters that the string type (TEXT, KEYWORD etc.) columns will exhibit. "
                                           + "The value 0 disables the driver limitation.");
            toolTipFloatsFormat.SetToolTip(comboBoxFloatsFormat, "How should the floating point numbers be printed, when these are converted to string by the driver.");
            toolTipDataEncoding.SetToolTip(comboBoxDataEncoding, "How should the data between the server and the driver be encoded as.");
            toolTipDataCompression.SetToolTip(comboBoxDataCompression, "Should the data between the server and the driver be compressed?");
            toolTipFollowRedirects.SetToolTip(checkBoxFollowRedirects, "Should the driver follow HTTP redirects of the requests to the server?");
            toolTipApplyTZ.SetToolTip(checkBoxApplyTZ, "Should the driver use machine's local timezone? The default is UTC.");
            toolTipAutoEscapePVA.SetToolTip(checkBoxAutoEscapePVA, "Should the driver auto-escape the pattern-value arguments?");
            toolTipMultiFieldLenient.SetToolTip(checkBoxMultiFieldLenient, "Should the server return one value out of a multi-value field (instead of rejecting the request)?");
            toolTipEarlyExecution.SetToolTip(checkBoxEarlyExecution, "Should a query be executed already at preparation time? This will only happen if the query lacks parameters.");
            toolTipIndexIncludeFrozen.SetToolTip(checkBoxIndexIncludeFrozen, "Should the server consider the frozen indices when servicing a request?");

            // Set initial state of action buttons.
            EnableDisableActionButtons();
        }
        public void ContainsKey()
        {
            OdbcConnectionStringBuilder builder = new OdbcConnectionStringBuilder();

            builder ["SourceType"] = "DBC";
            builder.Add("Port", "56");
            Assert.IsTrue(builder.ContainsKey("SourceType"), "#1");
            Assert.IsTrue(builder.ContainsKey("Port"), "#2");
            Assert.IsTrue(builder.ContainsKey("Dsn"), "#3");
            Assert.IsTrue(builder.ContainsKey("Driver"), "#4");
            Assert.IsFalse(builder.ContainsKey("xyz"), "#5");
            builder.Dsn = "myDsn";
            Assert.IsTrue(builder.ContainsKey("Dsn"), "#6");
            builder.Driver = "SQL Server";
            Assert.IsTrue(builder.ContainsKey("Driver"), "#7");
            builder ["Dsn"] = "myDsn";
            Assert.IsTrue(builder.ContainsKey("Dsn"), "#8");
            builder ["Driver"] = "SQL Server";
            Assert.IsTrue(builder.ContainsKey("Driver"), "#9");
            builder ["abc"] = "pqr";
            Assert.IsTrue(builder.ContainsKey("ABC"), "#10");
            Assert.IsFalse(builder.ContainsKey(string.Empty), "#11");
        }
Ejemplo n.º 18
0
        public DsnEditorForm(
            bool onConnect,
            string dsn,
            DriverCallbackDelegate connectionTest,
            DriverCallbackDelegate dsnSave)
        {
            InitializeComponent();

            // Wire up default button behaviours
            AcceptButton = saveButton;
            CancelButton = cancelButton;

            isConnecting   = onConnect;
            testConnection = connectionTest;
            saveDsn        = dsnSave;

            // If connecting then disable some user inputs
            if (isConnecting)
            {
                textName.ReadOnly = textDescription.ReadOnly = true;
                textName.Enabled  = textDescription.Enabled = false;
            }

            // If this is a call serving a connect request, name the button "Connect", otherwise it's a DSN editing, so it's going to be a "Save".
            saveButton.Text = onConnect ? "Connect" : "Save";

            // Parse DSN into the builder
            Builder.ConnectionString = dsn;

            // Basic Panel
            textName.Text          = Builder.ContainsKey("dsn") ? Builder["dsn"].ToString().StripBraces() : string.Empty;
            textDescription.Text   = Builder.ContainsKey("description") ? Builder["description"].ToString().StripBraces() : string.Empty;
            textUsername.Text      = Builder.ContainsKey("uid") ? Builder["uid"].ToString().StripBraces() : string.Empty;
            textPassword.Text      = Builder.ContainsKey("pwd") ? Builder["pwd"].ToString().StripBraces() : string.Empty;
            textCloudID.Text       = Builder.ContainsKey("cloudid") ? Builder["cloudid"].ToString().StripBraces() : string.Empty;
            textHostname.Text      = Builder.ContainsKey("server") ? Builder["server"].ToString().StripBraces() : string.Empty;
            numericUpDownPort.Text = Builder.ContainsKey("port") ? Builder["port"].ToString().StripBraces() : string.Empty;

            toolTipName.SetToolTip(textName, "The name the DSN will be referred by.");
            toolTipDescription.SetToolTip(textDescription, "Allows arbitrary text, generally used for short notes about the configured connection.");
            toolTipCloudID.SetToolTip(textCloudID, "The Cloud ID, if connecting to Elastic Cloud. Settings will be automatically configured.");
            toolTipHostname.SetToolTip(textHostname, "IP address or a resolvable DNS name of the Elasticsearch instance that the driver will connect to.");
            toolTipPort.SetToolTip(numericUpDownPort, "The port which the Elasticsearch listens on.");
            toolTipUsername.SetToolTip(textUsername, "If security is enabled, the username configured to access the REST SQL endpoint.");
            toolTipPassword.SetToolTip(textPassword, "If security is enabled, the password configured to access the REST SQL endpoint.");

            // Security Panel
            textCertificatePath.Text         = Builder.ContainsKey("capath") ? Builder["capath"].ToString().StripBraces() : string.Empty;
            radioEnabledNoValidation.Checked = true;             // Default setting
            if (Builder.ContainsKey("secure"))
            {
                var result = int.TryParse(Builder["secure"].ToString(), out int val);
                if (result)
                {
                    switch (val)
                    {
                    case 0: radioButtonDisabled.Checked = true; break;

                    case 1: radioEnabledNoValidation.Checked = true; break;

                    case 2: radioEnabledNoHostname.Checked = true; break;

                    case 3: radioEnabledHostname.Checked = true; break;

                    case 4: radioEnabledFull.Checked = true; break;
                    }
                }
            }

            toolTipDisabled.SetToolTip(radioButtonDisabled,
                                       "The communication between the driver and the Elasticsearch instance is performed over a clear-text connection." + Environment.NewLine
                                       + "This setting can expose the access credentials to a 3rd party intercepting the network traffic and is not recommended.");

            toolTipEnabledNoValidation.SetToolTip(radioEnabledNoValidation,
                                                  "The connection encryption is enabled, but the certificate of the server is not validated." + Environment.NewLine
                                                  + "This setting allows a 3rd party to act with ease as a man-in-the-middle and thus intercept all communications.");

            toolTipEnabledNoHostname.SetToolTip(radioEnabledNoHostname,
                                                "The connection encryption is enabled and the driver verifies that server's certificate is valid," + Environment.NewLine
                                                + "but it does not verify if the certificate is running on the server it was meant for." + Environment.NewLine
                                                + "This setting allows a 3rd party that had access to server's certificate to act as a man-in-the-middle" + Environment.NewLine
                                                + "and thus intercept all the communications.");

            toolTipEnabledHostname.SetToolTip(radioEnabledHostname,
                                              "The connection encryption is enabled and the driver verifies that both the certificate is valid," + Environment.NewLine
                                              + "as well as that it is being deployed on the server that the certificate was meant for.");

            toolTipEnabledFull.SetToolTip(radioEnabledFull,
                                          "This setting is equivalent to the previous one, with one additional check against certificate's revocation." + Environment.NewLine
                                          + "This offers the strongest security option and is the recommended setting for production deployments.");

            toolTipCertificatePath.SetToolTip(textCertificatePath,
                                              "In case the server uses a certificate that is not part of the PKI, for example using a self-signed certificate," + Environment.NewLine
                                              + "you can configure the path to a X509 certificate file that will be used by the driver to validate server's offered certificate.");

            // Logging Panel
            textLogDirectoryPath.Text   = Builder.ContainsKey("tracefile") ? Builder["tracefile"].ToString().StripBraces() : string.Empty;
            comboLogLevel.Text          = "DEBUG";    // Default setting
            checkLoggingEnabled.Checked = true;       // Default setting
            if (Builder.ContainsKey("tracelevel"))
            {
                switch (Builder["tracelevel"].ToString().ToUpperInvariant())
                {
                case "DEBUG": comboLogLevel.Text = "DEBUG"; break;

                case "INFO": comboLogLevel.Text = "INFO"; break;

                case "WARN": comboLogLevel.Text = "WARN"; break;

                case "ERROR": comboLogLevel.Text = "ERROR"; break;
                }
            }
            if (Builder.ContainsKey("traceenabled"))
            {
                var result = int.TryParse(Builder["traceenabled"].ToString(), out int val);
                if (result)
                {
                    switch (val)
                    {
                    case 0: checkLoggingEnabled.Checked = false; break;

                    default: checkLoggingEnabled.Checked = true; break;
                    }
                }
            }
            else
            {
                checkLoggingEnabled.Checked = false;
            }

            toolTipLoggingEnabled.SetToolTip(checkLoggingEnabled,
                                             "Ticking this will enable driver's logging. A logging directory is also mandatory when this option is enabled," + Environment.NewLine
                                             + "however the specified logging directory will be saved in the DSN if provided, even if logging is disabled.");

            toolTipLogDirectoryPath.SetToolTip(textLogDirectoryPath, "Specify which directory to write the log files in.");
            toolTipLogLevel.SetToolTip(comboLogLevel, "Configure the verbosity of the logs.");

            // Set initial state of action buttons.
            EnableDisableActionButtons();
        }
        public void Driver()
        {
            OdbcConnectionStringBuilder builder = new OdbcConnectionStringBuilder();

            Assert.IsTrue(builder.ContainsKey("Driver"), "#A1");
            Assert.AreEqual(string.Empty, builder ["Driver"], "#A2");
            Assert.AreEqual(string.Empty, builder.Driver, "#A3");

            builder.Driver = "SQL Server";
            Assert.AreEqual("Driver={SQL Server}", builder.ConnectionString, "#B1");
            Assert.IsTrue(builder.ContainsKey("Driver"), "#B2");
            Assert.AreEqual("SQL Server", builder ["Driver"], "#B3");
            Assert.AreEqual("SQL Server", builder.Driver, "#B4");

            builder.Clear();

            builder.Driver = "{SQL Server";
            Assert.AreEqual("Driver={{SQL Server}", builder.ConnectionString, "#C1");
            Assert.IsTrue(builder.ContainsKey("Driver"), "#C2");
            Assert.AreEqual("{SQL Server", builder ["Driver"], "#C3");
            Assert.AreEqual("{SQL Server", builder.Driver, "#C4");

            builder.Clear();

            builder.Driver = "{SQL Server}";
            Assert.AreEqual("Driver={SQL Server}", builder.ConnectionString, "#D1");
            Assert.IsTrue(builder.ContainsKey("Driver"), "#D2");
            Assert.AreEqual("{SQL Server}", builder ["Driver"], "#D3");
            Assert.AreEqual("{SQL Server}", builder.Driver, "#D4");

            builder.Clear();

            builder.Driver = string.Empty;
            Assert.AreEqual("Driver=", builder.ConnectionString, "#E1");
            Assert.IsTrue(builder.ContainsKey("Driver"), "#E2");
            Assert.AreEqual(string.Empty, builder ["Driver"], "#E3");
            Assert.AreEqual(string.Empty, builder.Driver, "#E4");

            builder.Clear();

            builder ["Driver"] = "SQL Server";
            Assert.AreEqual("Driver={SQL Server}", builder.ConnectionString, "#F1");
            Assert.IsTrue(builder.ContainsKey("Driver"), "#F2");
            Assert.AreEqual("SQL Server", builder ["Driver"], "#F3");
            Assert.AreEqual("SQL Server", builder.Driver, "#F4");

            builder.Clear();

            builder ["Driver"] = "{SQL Server";
            Assert.AreEqual("Driver={{SQL Server}", builder.ConnectionString, "#G1");
            Assert.IsTrue(builder.ContainsKey("Driver"), "#G2");
            Assert.AreEqual("{SQL Server", builder ["Driver"], "#G3");
            Assert.AreEqual("{SQL Server", builder.Driver, "#G4");

            builder.Clear();

            builder ["Driver"] = "{SQL Server}";
            Assert.AreEqual("Driver={SQL Server}", builder.ConnectionString, "#H1");
            Assert.IsTrue(builder.ContainsKey("Driver"), "#H2");
            Assert.AreEqual("{SQL Server}", builder ["Driver"], "#H3");
            Assert.AreEqual("{SQL Server}", builder.Driver, "#H4");

            builder.Clear();

            builder ["Driver"] = string.Empty;
            Assert.AreEqual("Driver=", builder.ConnectionString, "#I1");
            Assert.IsTrue(builder.ContainsKey("Driver"), "#I2");
            Assert.AreEqual(string.Empty, builder ["Driver"], "#I3");
            Assert.AreEqual(string.Empty, builder.Driver, "#I4");
        }