Although the purpose of the NFileStorage project definately is NOT to create a client console application, its quite practical to have it in place, as it allows us to access the data in a File Storage from the command prompt. The console client binary can be found in the release v1.1 files, or you can ofcourse build it yourself. The console application takes advantage of the NConsoler library, which you can find here: http://nconsoler.csharpus.com/

The executable has the following subcommands;

usage: FileStorageCmd <subcommand> args
Type 'FileStorageCmd help <subcommand>' for help on a specific subcommand.

Available subcommands:
createnewfilestorage
storefile
showfilecount
showfileidentifiers
mergecontainers
restoreindexfile
dumpalltofilesystem
dumpfiletofilesystem

createnewfilestorage

H:\Proj\CodePlex\NFileStorage\FileStorageCmd\bin\Debug>FileStorageCmd.exe createnewfilestorage "test"
This operation took 0 msecs

The system will have created two files

02/10/2009 12:15 AM 100 test.FileStorage.data.fc
02/10/2009 12:15 AM 2,148 test.FileStorage.index.fc

storefile

In this case I decided to store the FileStorageCmd.exe itself in the file storage we've just created (practically this doesn't make any sense, but its just an example).

H:\Proj\CodePlex\NFileStorage\FileStorageCmd\bin\Debug>FileStorageCmd.exe storefile "test" "FileStorageCmd.exe"
Storing file identifier 11111111-2222-3333-4444-555555555555
This operation took 15.625 msecs

Since i didn't specify the guid myself on the command prompt, the guid defaults to 11111111-2222-3333-4444-555555555555. After the command succeeds, the files of the File Storage have grown;

02/10/2009 12:22 AM 8,848 test.FileStorage.data.fc
02/10/2009 12:22 AM 32,868 test.FileStorage.index.fc

As you can see, the index file in this case is bigger than the actual data file. Note NFileStorage is currently not implemented to be efficient regarding byte consumption on the file system; in fact its byte greedy :) The index file, however, is just an index filer (nothing more nothing less), and can even be removed, and reconstructed later on, based upon the data file.

showfilecount

H:\Proj\CodePlex\NFileStorage\FileStorageCmd\bin\Debug>FileStorageCmd.exe showfilecount "test"
1 files found
This operation took 0 msecs

So we can see that there's actually one file stored in the FileStorage.

showfileidentifiers

H:\Proj\CodePlex\NFileStorage\FileStorageCmd\bin\Debug>FileStorageCmd.exe showfileidentifiers "test"
1 files found
This operation took 15.625 msecs
11111111-2222-3333-4444-555555555555
This operation took 0 msecs

restoreindexfile and mergecontainers

In my particular situation I have a bunch of files stored in a File Storage serving data in production. At another environment I create a new File Storage, that contains supplements (increments) to the data in the File Storage in production. Rather than merging the increment directly in the production file, and replacing the old production file with the new one, I decided it would be best if File Storages can be merged. If you want to transfer your incremental File Storage to another server, you ONLY need to transfer the data file. The index file (which is likely the biggest of the two as you will find out) only contains "pointers" (offsets) to the information in the data file. If you decide to transfer both the data and index file, that's ok too ofcourse.

02/10/2009 12:22 AM 32,868 test.FileStorage.index.fc

del *.index.fc

H:\Proj\CodePlex\NFileStorage\FileStorageCmd\bin\Debug>FileStorageCmd.exe restoreindexfile "test"
This operation took 15.625 msecs

Files in index (after restore)
1 files found
This operation took 0 msecs

As you will see, the index file is restored:

02/10/2009 12:37 AM 32,868 test.FileStorage.index.fc

We now create a target File Storage;

H:\Proj\CodePlex\NFileStorage\FileStorageCmd\bin\Debug>FileStorageCmd.exe createnewfilestorage "mergetarget"
This operation took 15.625 msecs

Now we have 2 file storages, we can merge the items from one target to another:

H:\Proj\CodePlex\NFileStorage\FileStorageCmd\bin\Debug>FileStorageCmd.exe mergecontainers test mergetarget true
Source test
1 files found
This operation took 15.625 msecs
Destination mergetarget
0 files found
This operation took 0 msecs

Press enter to start merging (files will be overriden when they already exist) ...

This operation took 31.25 msecs

Destination (after merge)
1 files found
This operation took 0 msecs

We can dump all files from the filestorage to the filesystem

H:\Proj\CodePlex\NFileStorage\FileStorageCmd\bin\Debug>filestoragecmd dumpalltofilesystem mergetarget exe
Dumping ...
.Finished
1 files found
This operation took 31.25 msecs

H:\Proj\CodePlex\NFileStorage\FileStorageCmd\bin\Debug>dir

02/13/2009 09:54 PM 8,704 11111111-2222-3333-4444-555555555555.exe

And we can see the executable was restored correctly;

H:\Proj\CodePlex\NFileStorage\FileStorageCmd\bin\Debug>11111111-2222-3333-4444-555555555555.exe
usage: FileStorageCmd <subcommand> args
Type 'FileStorageCmd help <subcommand>' for help on a specific subcommand.

Available subcommands:
createnewfilestorage
storefile
showfilecount
showfileidentifiers
mergecontainers
restoreindexfile
dumpalltofilesystem
dumpfiletofilesystem

H:\Proj\CodePlex\NFileStorage\FileStorageCmd\bin\Debug>

Last edited Feb 13, 2009 at 8:56 PM by barkgj, version 8

Comments

No comments yet.