This project has moved and is read-only. For the latest updates, please go here.

Fighting with database path and name

Dec 5, 2011 at 6:31 PM


I have some difficulties with naming the database and place it, with the "server" file system.

I try this:

filesystem = new FileSystemDriver(FileName,null,null,@"MySubDirectory/"); 

At first, I had an exception when I gave that directory name: "MyDirectoryName" because there was no "/" at the end. Because ...Sterling.Server.FileSystem.PathProvider.cs line 38 (in release 78667) does this test : "if (!basePath.EndsWith(@"/"))".
I really don't understand the utility of this test. At least I suggest to add an information to the exception, of this kind: "throw new ArgumentOutOfRangeException("basePath","There is no '/' at the end of the directory\n Please add one");", to help programmers.

After having fixed this problem, Sterling (1.5) refuses to take the database name into account, this time.
After some research it appears that:

1. the name is superbly ignored by SterlingDatabase.cs line 270: "driver.DatabaseName = database.Name;"
where database.Name is not the name we provided but the type of the registring class that inherites BaseDatabaseInstance (which is, in my case, a general, but not generic, name absolutely useless to identify the database).

2. Anyway, the name is hashed at the end by ....Sterling.Server.FileSystem.PathProvider.cs at line 108 (in release 78667) :

var path = Path.Combine(RootPath, basePath, databaseName.GetHashCode().ToString()) + "/";"

I do not understand why Sterling does not simply use the databaseName provided by the user as the database sub-directory name (as it should be normally).
This way Sterling would create one directory for the "filesystem", using "basePath", and a sub-directory for each database using "databaseName" (but this one should be provided when calling RegisterDatabase, not FileSystemDriver).

Thank you for your attention, I hope that could help some of you.
(because you can spend hours fighting that way)   ;)

May 23, 2012 at 4:01 PM

I agree with your comment about the exception raised.  The message should give more information about the exception...  There is no '/' at the end of the directory\n Please add one

For point 2, I can't answer for Jeremy, but I believe it's simply because the hash is more "folder name friendly" than a string that might have special characters.  

I'm just curious about the need of the "/" at all... since in Windows the path separators are actually "\" and not "/", and that path.combine and should take care of this.