Accessing mv.NET configuration data

For someone getting started with mv.NET it’s easy to open an mvAccount, open an mvFile, maybe use an mvSelect on it, then read an mvItem. Some developers want to make more use of the environment, allowing users to select from a list of Login Profiles to access a specific account, then allowing selection of specific files, etc. It’s very easy to do this and I’ve provided the code here.

I wrote this code as a part of another project. I’ve written a Visual Studio Add-in which allows a developer to select a login profile and a DBMS file, and it will generate complete class code (Business Logic Layer = BLL) and Data Access Layer (DAL) using the schema definition from the Data Manager. This can help to get a developer from the MV dictionary direct to a GUI, initially with no special code and no knowledge of mv.NET coding. I’ll comment more on this as it develops.

This code is C# but since the functional code is literally only one line per method I don’t think it’s required to translate to VB.NET (or PHP.NET or COBOL.NET or F# or …) This is a thick client form that populates List Boxes, but can easily be a web form with a tree that shows files under accounts. This is just like what the mv.NET Data Manager does – and that is really nothing more than a Windows Forms application which uses mv.NET to provide access to configuration data, file schema, and data.

To use the code below:

  1. Create a new Windows Forms project.
  2. Set a reference to Core Objects and add this to the top of the form code:
      using BlueFinity.mvNET.CoreObjects;
  3. Drop two listboxes and a label on the form.
  4. Double click the listboxes and the form to create event handlers for them.
  5. Completely replace the event handlers with the code below.

 private void Form1_Load( object sender , EventArgs e )
  {
    try
    {
      listBox1.Items.AddRange(
        ( new mvEnvironment() )
          .Configuration.LoginNames());
    }
    catch ( Exception ) { throw; }
  }

  private void listBox1_SelectedIndexChanged
               ( object sender , EventArgs e )
  {
    try
    {
      listBox2.Items.AddRange(
        new mvAccount(
          listBox1.SelectedItem.ToString())
            .FileList());
    }
    catch ( mvException ) { throw; }
    catch ( Exception ) { throw; } 
  }

  private void listBox2_SelectedIndexChanged
               ( object sender , EventArgs e )
  {
    label1.Text =
        listBox2.SelectedItem.ToString();
  }

There is no exception handling, I leave that to you, but the exceptions are trapped. It’s important to do this. I recommend having two catches per try, as seen in one of the examples, with one that catches mvExceptions and a final block that caches all other Exceptions. I’ll post some notes on mv.NET debugging at another time, including notes on when to Dispose resources and how.

You’ll note that I’ve populated the listbox event handlers with a single line of code. ( For display here in the blog I had to break the code up into multiple physical lines, but each of these blocks is still just one logical line. ) Of course I could have implemented the functionality in many lines, which may be more readable but simply isn’t necessary for small bits of code like this. Let’s break down the functional lines.

  listBox1.Items.AddRange(
    ( new mvEnvironment() )
       .Configuration.LoginNames());

This gets an mvEnvironment object. The Configuration property of that object returns an mvConfiguration object. The LoginNames method of mvConfiguration returns a string array. This string array is a valid object array for use with the ListBox AddRange method.

  listBox2.Items.AddRange(
    new mvAccount(
      listBox1.SelectedItem.ToString())
        .FileList());

The SelectedItem from the listbox of Login Profiles is used to initialize a new mvAccount object. The FileList method of mvAccount returns a string array of files which have been defined for the account via the Data Manager. Again, that string array is used to populate the list through AddRange.

I hope this has been helpful. If there are other aspects of mv.NET development that you’d like to see explored, please let me know. Comments are welcome here, and full discussion is available in our forum.

2 thoughts on “Accessing mv.NET configuration data

    • Have you done anything with the code (product?) to take a login and create the object structure to support it?  I might be interested in buying it to save me from writing my own.

    • Dick – thanks for your interest, as always. I stopped working on that VS2005 addin when I started working on the (as yet unfinished) CodeSmith and .NetTiers providers.  A class definition created with the code mentioned in this blog entry is very basic, and while a good start, it isn’t very robust as an ObjectDataSource, which was my real goal. I don’t remember exactly how it did what it does but I’ll take another look at it within the next 3-4 business days and see if I can package it up for sale.

Leave a Reply