Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DSN GUI editor #32

Merged
merged 33 commits into from
Oct 26, 2018
Merged

DSN GUI editor #32

merged 33 commits into from
Oct 26, 2018

Conversation

bpintea
Copy link
Collaborator

@bpintea bpintea commented Oct 15, 2018

This PR adds a .NET DSN editor.
The editor is being invoked in two circumstances:

  • the user wants to configure a set of connection parameters through a DSN management application (like ODBC Data Source Administrator);
  • a 3rd party application wants to connect and prompts the user for connection details (or editing the existing ones).

The editor lives now under dsneditor folder and brings two more DLLs to the driver:

  • a .NET assembly, which contains the entire logic for rendering the editor form (EsOdbcDsnEditor subfolder, a C# project);
  • a binding/bridging library which contains the entry point accessible to the driver and that loads the .NET assembly (EsOdbcDsnBinding subfolder, a C++/CLI project).

The interface between the driver and the editor consists of a main function EsOdbcDsnEdit() (defined in the binding project). The function takes as parameters (among others):

  • a string, which is an ODBC connection string; this is serialized by the driver and deserialized by the editor.
  • two callbacks, which allows user actions to trigger code running within the driver: one for connection testing (check if current specified parameters are usable) and another one for saving (of current parameters); these are mapped onto the respective buttons of the form. These callbacks also use connection strings as arguments.

The driver does the validation of the parameters and returns any error message back through callbacks' output parameters.

bpintea and others added 28 commits September 28, 2018 00:09
- implement prompt_user_config() based on EsOdbcDsnEdit() entry point.;
- implement the callbacks on the GUI actions;
- implement DSN bundle serializing to 00-list (which is going to be the
  way to send/receive the DSN at interfacing point).
- start a unit test on the 'dsn' module.
- check for minimum requirements when configuring a DSN (it's name and
  server location); also perform a DBC configuration with the data, to
  prevent incomplete data be saved; the connection could still fail
  later, though, this is just a consistency check with no reachability
  checks.
- perform a connection test in handler when prompting from
  SQLDriverConnect(), to fail there, rather than later in the function
  when the error message will not be forwarded back to the user.
- implement prompt_user_config() based on EsOdbcDsnEdit() entry point.;
- implement the callbacks on the GUI actions;
- implement DSN bundle serializing to 00-list (which is going to be the
  way to send/receive the DSN at interfacing point).
- start a unit test on the 'dsn' module.
- check for minimum requirements when configuring a DSN (it's name and
  server location); also perform a DBC configuration with the data, to
  prevent incomplete data be saved; the connection could still fail
  later, though, this is just a consistency check with no reachability
  checks.
- perform a connection test in handler when prompting from
  SQLDriverConnect(), to fail there, rather than later in the function
  when the error message will not be forwarded back to the user.
- documentation indicates that last parameter returns number of written
  bytes, but it's actually characters.

Also:
- rename 'list00' paramter to 'dsn_str' since the GUI-driver interface
  will now pass connection strings (since .net framework has a parser for
  it);
- add more DSN validation and fill in the default values for attributs
  not provided by user.
- Add an editor that is able to edit the DSN as a connection string.
- Add it into CMakeLists.txt as a "custom" target, that is also
  target-aware.
- change the build.bat to "recognize" on subsequent invocations the
  initially set build type.
- add the editor DLLs into the unit tests running dir
In count mode (output string is NULL), the function is supposed to
return the min size of a buffer that could accomodate the connection
string. This commit fixes it's calculation.

A unittest was added for it, too.
- place all functionality in one function

Also:
- fix registry writing for update and new DSN addition.
- bubble up more error messages from DSN validation through DBC
  configuration;
- connection testing and DSN saving callbacks now use the DSN validation
  function to do most of their work;

Also:
- add []-framing to IPv6 addresses in URLs
- make connection string printing more robust in case destination buffer
  is too small for the result.
Disable name and description on edit - fixes #28
…tname / name. Partially fixes #29

Don't clear the connection string Builder on form close (fixes connection bug)
Mask password box.
Refactor StripBraces() method.
Added [STAThread] attribute to the factory method.
- now UTF8
- remove BOM
- this fixes the file chooser issue;
- DSN form now rendered with .ShowDialog() to prevent calling app
  allow the user to re-invoke the bridge (which would fail, it running
  as an STA)

fixes #25
- in case STA init'ing fails, create a new thread for the form;
- also, make the window handler a static member of the binding class.

closes #25
… the user that the operation is underway and that they should wait. Fixes #30
- this will be used to enable/disable the per-dbc logging

- the tick-box in the GUI is now left unchecked if the corresponding
  parameter is missing from the connection string.
@bpintea bpintea mentioned this pull request Oct 15, 2018
Closed
@@ -140,14 +152,38 @@ namespace EsOdbcDsnBinding {
}

public:int EsOdbcDsnEditor()
{
Thread ^ t;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work!

#ifdef __cplusplus
extern "C"
#endif /* __cpluplus */
#ifdef _WINDLL
Copy link
Contributor

@droberts195 droberts195 Oct 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is _WINDLL the correct choice of macro to decide whether the function is being imported or exported?

If this header were included into a file destined for a DLL but NOT the DLL containing the function definition then the function would need to be imported, not exported.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for that. I've pushed a fix for it, to use the dedicated DRIVER_BUILD macro (the _WINDLL had stayed there from the PoC time, when I was using a simple app for the form).

- use DRIVER_BUILD macro, which signals a driver build
- add Elastic's license to all source files
@droberts195
Copy link
Contributor

droberts195 commented Oct 17, 2018

Some of the C++ files have a .cc extension while others have a .cpp extension. It would be nice to be consistent within a single repo.

- rename EsOdbcDsnBinding.cpp to EsOdbcDsnBinding.cc, to be consistent
  with the rest of the repo (.cc test files)
@bpintea
Copy link
Collaborator Author

bpintea commented Oct 17, 2018

Thanks for pointing that out, renamed the .cpp file.

@droberts195
Copy link
Contributor

I don't really know enough about C# to sensibly review those parts. If @codebrain is happy with the C# parts I'm happy to merge the whole PR.

@codebrain codebrain requested a review from russcam October 19, 2018 14:31
@codebrain
Copy link
Contributor

codebrain commented Oct 19, 2018

@russcam - I am happy with the C# parts (there isn't a huge amount of code). If you are able to give it a review on (or before!) Monday (22nd October) sometime that would be really appreciated.

Copy link

@russcam russcam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left some general comments.

I see that there are no tests for the configuration editor - will this be covered by integration tests?

I also think that it would be good to consolidate the GUI editor projects with the installer project, under a single solution; This may also make it easier to automate the complete build

dsneditor/EsOdbcDsnEditor/DSNEditorForm.cs Show resolved Hide resolved
dsneditor/EsOdbcDsnEditor/DSNEditorForm.cs Show resolved Hide resolved
return true;
}

MessageBox.Show("Log directory invalid", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should indicate why the directory is invalid

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error now reads: Log directory invalid, path does not exist

private bool ValidateCertificateFile(string file)
{
if (string.IsNullOrEmpty(file)
|| (File.Exists(file) && File.ReadAllBytes(file).Length > 0))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe

new FileInfo(file).Length

instead of

File.ReadAllBytes(file).Length

Can also use the FileInfo for the .Exists call then too.

Should the certificate be validated here as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ to the fileinfo change.

Currently not implementing the certificate validation - at the moment as long as the file exists and is > 0 bytes then we'll let Elasticsearch handle any errors.

{
Application.EnableVisualStyles();
DsnEditorForm form = new DsnEditorForm(onConnect, dsnIn, delegConnectionTest, delegSaveDsn);
form.ShowDialog(); // Instead of Application.Run(form);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could probably do with a comment for why .ShowDialog() is used instead of Application.Run(...). I can guess, but I think a one line comment may help

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a short explanation on it.

dsneditor/EsOdbcDsnEditor/ExtensionMethods.cs Show resolved Hide resolved
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Elasticserach DSN Editor")]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spelling

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks.

[assembly: AssemblyTitle("EsOdbcDsnEditorLauncher")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add Company name

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

bpintea and others added 2 commits October 23, 2018 11:39
- add an explanation as to why the editor form is rendered with
  .ShowDialog() instead of Application.Run().
@codebrain
Copy link
Contributor

@russcam - There are no tests for the editor yet. I was in two minds about how to acheive this, either via UI automation tests or moving to MVVM / MVC in Winforms (not great...). I think for alpha its OK to roll without tests - something to be addressed next.

@russcam
Copy link

russcam commented Oct 26, 2018

Just had a look over the changes, and they LGTM. IMO, it would be good to have some tests, even for alpha.

Is it also worth including some logging for the UI, for users to be able to provide in the event of exceptions?

@bpintea
Copy link
Collaborator Author

bpintea commented Oct 26, 2018

IMO, it would be good to have some tests, even for alpha.

@russcam It would be indeed good to add tests and testing will be my goal for the rest of the remaining weeks till releasing.

Is it also worth including some logging for the UI, for users to be able to provide in the event of exceptions?

That's an interesting thought. I'll work with @codebrain to see what we could do here.

@bpintea bpintea merged commit 0d3ec79 into elastic:master Oct 26, 2018
@bpintea bpintea deleted the feature/gui_config branch October 26, 2018 09:04
@bpintea bpintea added >feature Applicable to PRs adding new functionality v6.5.0 labels May 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>feature Applicable to PRs adding new functionality v6.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants