2

I can connect to a FileStore via a RavenDBServer instance in my MVC application provided the FS is initialized, so (for example), I create a RavenDBServer with the DataDirectory set:

To be clear: this is running as an embedded instance.

var config = new RavenConfiguration
{
    DataDirectory = "~\\App_Data\\Database",
    DatabaseName = "test"
};

var server = new RavenDbServer(config);
server.UseEmbeddedHttpServer = true;

Then go to the Raven UI, add a FS called test-fs, add the following to the initialization code:

server.FilesStore.DefaultFileSystem = "test-fs";
server.FilesStore.Initialize();

Then when I call:

server.FileStore.OpenAsyncSession("test-fs");

we're all good.

Ideally, I don't want to have to go about doing that as it's cumbersome, and involves changing code. SO. I put this in:

server.FilesStore.AsyncFilesCommands.Admin.CreateOrUpdateFileSystemAsync(new FileSystemDocument(), "test-fs");

but this never creates the FileSystems folder in the App_Data folder, and any attempt to OpenAsyncSession always results in an error stating that the test-fs could not be opened.

How can I create the FS on initialisation? I'm doing this within an MVC (5.2) application.

Charlotte Skardon
  • 6,220
  • 2
  • 31
  • 42

2 Answers2

2

See this thread on the RavenDB Mailing List.

You could do it like this:

var store = new EmbeddableDocumentStore {
    RunInMemory = true,
    EnlistInDistributedTransactions = false
};
store.Initialize();
RavenServer = store;

var createFs = Task.Run(async () => {
    await store.FilesStore.AsyncFilesCommands.Admin.CreateOrUpdateFileSystemAsync(
    new FileSystemDocument {
        Settings = {
            { "Raven/FileSystem/DataDir", "~/App_Data/FileSystem/default" }
        }
    },
    "default"
    ).ConfigureAwait(false);
});
createFs.Wait();

The next version should support in-memory file stores.

dusky
  • 1,133
  • 7
  • 12
  • Hi Dusky, I'll give this a go in a short while - may I ask why the comments about in memory? I'm not attempting to run RavenFS InMemory, just as embedded. – Charlotte Skardon Jan 05 '15 at 11:09
  • Just in case. Some use an embedded in-memory instance for unit tests. Others may find this information useful. – dusky Jan 05 '15 at 12:55
0

I use static FileStoreHolder to provide FilesStore. As is recomended for DocumentStore.

 internal class FilesStoreHolder
{
    private static readonly Lazy<IFilesStore> Store = new Lazy<IFilesStore>(CreateStore);
    public static IFilesStore FilesStore
    {
        get { return Store.Value; }
    }

    private static IFilesStore CreateStore()
    {
        var store = new FilesStore
        {
          ConnectionStringName = "ConnStr",
          DefaultFileSystem = "MyFS"
        }.Initialize();

        return store;
    }
}

then when I need FS session I get it this way:

 using (var fsSession = FilesStoreHolder.FilesStore.OpenAsyncSession())
        {
            return await fsSession.DownloadAsync(Folder + name);
        }
Kreso Jurisic
  • 100
  • 2
  • 9
  • 1
    Hi, Thanks! You are using a `new FileStore()` instance, which is fine if you're running as a server and I should make it clearer that the question - but I am attempting to do this in an *embedded* mode. – Charlotte Skardon Dec 09 '14 at 11:17