public static int DsnEditor( bool onConnect, string dsnIn, DriverCallbackDelegate delegConnectionTest, DriverCallbackDelegate delegSaveDsn) { Application.EnableVisualStyles(); var form = new DsnEditorForm(onConnect, dsnIn, delegConnectionTest, delegSaveDsn); // instead of Application.Run(form): prevent STA apps from launching a new editor within the same thread form.ShowDialog(); var dsn = form.Builder.ToString(); return(dsn.Length); }
public void Start() { if (callback == null) { callback = new DriverCallbackDelegate(DriverCallback); IntPtr callbackPtr = Marshal.GetFunctionPointerForDelegate(callback); RegisterCallback(callbackPtr); } if (_running) { Stop(); } if (!_running) { int errCode = PortInit(this.ComPortName); ThrowExceptionForErrCode(errCode); _running = true; } }
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 Start() { if (callback == null) { callback = new DriverCallbackDelegate(DriverCallback); IntPtr callbackPtr = Marshal.GetFunctionPointerForDelegate(callback); RegisterCallback(callbackPtr); } if (_running) { Stop(); } if (!_running) { int errCode = PortInit(this.ComPortName); ThrowExceptionForErrCode(errCode); _running = true; } }
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(); }