Nova Explorer and MySql scripting sample - Part V

by Frédéric Colin 10. November 2009 12:30

It's now time to analyze the solution. We do not yet know very well (joke), but when I see a code or an architecture, I used to have a critical eye over. I confess that it is the same for the code I produce. So, here are my thoughts about the developed solution:

  • Deploying MySQL ODBC driver may be acceptable for an small intranet solution but is not acceptable for a full web compliant environment.
  • The direct use of a database from a Web Plugin may be dangerous for the database server since it forces administrators to openthe firewall for a specific port. That's unsecure and it's not the state of the art even if we place the database server in a DMZ. So we should use secured Web Services or Rest Services, i.e. on a standard protocol (http or https). this is what is called a Service-Oriented Architecture (SOA).
  • It will be better to only store the url of the services layer on http instead of a connection string. Url that can be set by the http server that manages the Web Page including the web plugin tag object.
  • I use the root account to access the catalog that I use to store my information. It's dangerous from a security point of view. We should use a dedicated account with less privileges.
  • You'll notice in my script, I hard stored the culture to format the price. On the other hand, we should not make this as a dynamic part since in my database I store Euros and not Dollars. And with the price of the dollar right now, it won't be interesting, except if we manage changes according to the user culture.
  • If you take a look at the database schema, you will notice it is simplistic. Indeed, products may have more data such as categories, keywords, etc. and we should use an integer as a primary key to perform powerful tables joins.
  • The last thing is the way to load once all data from database. What happens if data change in the database after web Plugin loading? Well, nothing in fact because data are not collected when the user interaction is executed.
  • Last but not least, the Web Plugin had to be updated to reference the missing "System.Data.dll" assembly to access "System.Data.Odbc" namespace. This update will be available soon with Nova Explorer auto-update.

Well, you are going to tell me that I coded with my feets ;-). In fact I responded directly to a need that I have been asked for. Moreover, any script may always be improved with time. I develop this solution in a couple of hours (in fact 3 hours). This partly explains it... Now I will attach myself to do things in the rules of art, anyway, as I believe they should be :-)

So in my next post I will show you how to develop a REST Architecture to expose my data and to consume it in a Nova script.

See you soon!

Nova Explorer and MySql scripting sample - Part IV

by Frédéric Colin 9. November 2009 23:13

Well, last but not least post on this topic, let's use this scene with differents clients.

  • Nova Explorer, certainly the most used:

  • A specific Windows Form application that use the .NET Web Player control:

  • The Web Plugin inside Internet Explorer:

The first step is to generate the mxc and the html files by using Nova Explorer Publish menu:

Then, you have just to open the generated Html page:

Just one more thing like will say a friend of mine: since the trust does not exclude some form of control, below here are of the database contents I used.

In my next post, I will talk about architecture and specifically the one that is induced by this complete sample. In other terms, I will talk about its pros and cons.

Nova Explorer and MySql scripting sample - Part III

by Frédéric Colin 9. November 2009 09:06

Enough words. It is time to code! I suppose you installed all the products described in this post.

In terms of functionalities, I decided to load data from database once when the script module is executed. The other solution would have been to load only the needed data from database, i.e., one request for each pickable object with data to display. In order to reduce requests on the database server, I implemented the first solution.

So, the first thing to do is to declare the connection string to the database:

Private ConnectionString As String
= "Driver={MySQL ODBC 5.1 Driver};
Server=192.168.0.103;Port=3306; Database=bCatalog;User=root;Password=bewise31;Option=3"

You will notice that I used the Super Administrator account to connect to the database. Of course, it's bad, and you should have a specific account with only the needed rights.

I decided to store database records in a generic list of Products, to keep them in memory: 

The next step was to access to the database to fill the previous generic list:

DatabaseProducts is the generic List of Products. The reader is a kind of record set read only forward only where you retrieve values from the database, record by record. The database connection must still be opened while reading values. In VB.NET, the syntax "Using ... End Using" is very useful to automatically free the memory by calling Dispose method on the object connection in my sample.

It's now time to talk about the BuildDataPanel method used previously which contains the "intelligent" part of the script that will generate on the fly the needed user interaction to display the data panel:

The first thing to do in this code is to find the corresponding object in the scene. For this, I use the generic list Find method that admits a predicate (in fact a delegate) as a parameter. Please, don't focus on the trick I use to filter records to pass a parameter value corresponding to the filter. The Searcher class is used for that and it just works. Once done, I make the selected object pickable to allow interactions on it.  You will also notice the use of a "DefaultCultureInfo" member that is a CultureInfo instance, set for the French culture to format a decimal in currency (euro).

The next thing is to create the trigger as a user interaction (user click) to attach it the Nova Scene object found previously. Then, on this trigger, we will add a custom action as a Nova static text. It's the widget used to display data within the scene. The next couple lines of code are here to set the action (text to display, visibility duration, colors, etc.)

The last step is to call the Reset Method on the created trigger to initialize the behavior and that's it!

I'm quite sure you will be more interested in the sample code source than my explanation :-). That's why in the following zip, you will find:

  • the mxb file I used,
  • the corresponding nss file,
  • the nsr file that contains the previous scripting in case,
  • MySql database scripting.

    VerticeSample.zip (38.21 kb)

Enjoy!

To be continued ...

 

Nova Explorer and MySql scripting sample - Part II

by Frédéric Colin 8. November 2009 14:56

Well, it is now time for the technical design of our solution.

First of all we have to design our database. We have to store 3 things:

  • The object identifier as a string: I decided to retain the object name as a unique identifier to simplify this sample (I didn't want to use the object internal Guid into the nova scene).
  • The object description as a string: the detail of the object.
  • The object price as a decimal.
So here is the database schema with a catalog called "bCatalog":

I also added a stored procedure called "sSelectProducts" to get all products from the table "tProducts". A stored procedure is a SQL Syntax to query the database. is stored inside the database and can be called with its name. So, informations for my Nova Scene objects are stored in this table and I will match them according to the field "objectID". Only those that have a record in this table will have a description in my Nova Scene.

The next step to design will be how to load data from my MySql database. As I wrote in my previous post, I used the Namespace "System.Data.Odbc" and specifically the following classes inside the .NET Framework:

  • "OdbcConnection" to connect to MySql Database
  • "OdbcCommand" to execute the previous SQL query
  • "OdbcDataReader" to browse records from "tProducts" table

The next step is to design interactions into the scene (click on an object) and to display description and price for each object. You probably know the action builder: the capability to add interactions into a Nova Scene without programming. The solution I developed uses the Action Builder object model to generate on the fly custom interactions. Then I use a static text widget to display data from MySql database. Ultimately, I will manually generate code, as if I had done it directly in the action builder GUI:

You will notice the widget:

  • will appear on a user interaction (mouse click),
  • will display its text during only 3 seconds,
  • is attached to the corresponding object,
  • is linked to the active camera to keep it in front when looking at the object

This interaction generation on the fly will be done with the Nova script editor in VB.NET. Indeed, the generation interactions on the fly requires no hard coding in the scene with the Action Builder and is completely scalable as the object name is unique and is associated with a database record. In other terms, you can add or delete records in the database without any problem with the scene.

Following the next issue...

 

Nova Explorer and MySql scripting sample

by Frédéric Colin 7. November 2009 23:34

Last week during Batimat, I was discussing about Nova Explorer scripting capabilities with a partner. The need was to connect to MySql for displaying a scene panel filled with data from this database engine. The data panel should only be visible on user interactions, one for each object. Well, it's possible and that's what i'm gonna show you in this post!

First of all, I used MySql 5.1.40 community edition. You can download it here. Next, you may wonder how to access this kind of database through Nova Scripting Editor. In fact it's quite simple if you download this connector (Connector/ODBC - MySQL ODBC driver). Moreover, if like me you're not fond of command lines, you should also download this application to administer your MySQL server. Trust me, it's very useful!

You certainly know that Nova range is developped with Microsoft .NET technologies and you may wonder why I used an ODBC Connector in VB.NET instead of a native provider like this one (MySQL Connector/Net — for connecting to MySQL from .NET). That's a good question. In fact, you have to know that Nova Explorer generate a new assembly on the fly and compile it from your VB.NET code. That why you can't dynamically add a reference to a new Assembly. We've just added by default all the necessary references from the Framework .NET. But if you develop a plugin instead of a script, it will be possible to use native .NET connector since you decide in Visual Studio project to add or not a specific reference to an assembly. I will talk about plugin development in another post.

So, here the scene I used. I apologize for the ugliness of the scene but I'm not a designer (thank you Mitch for your help).

Then I added user interactions on each object to display data from MySql database:

You enjoyed this post and you want to know more? Following the next issue ...


RecentComments

Comment RSS
Disclaimer
The opinions expressed herein are the author own personal opinions and do not represent their employers' view in anyway..

© Copyright 2010 Nova by Vertice Team