----------------------------------------------------------------------------------------------------------------------------
Can I only store files in a NFileStorage?
No, the "File" in NFileStorage refers to the fact that the data we store is stored on a file (so the file is used as a storage), it doesn't mean you can only store files in there.
As always its just your imagination that is the limitation of how you use it, and where its practical.
The entire list of persisting items in the FileStorage using C# code is:
- Store an array of bytes
- Store a file from your file system (local file system or network)
- Store a file from the web (mimic-ing the 'save-as' feature from your webbrowser)
- Store a C# object (the object should implement the IDynamiteXML naming-interface; this is an interface without any methods, so should be easy to implement ;)
- Store bytes from a stream
- Store a string
For your information; all above methods eventually are convenience functions/wrappers to the one that stores the array of bytes.
In the same way as you being able to store the information you are also offered a variety of ways to retrieve the information from a filestorage in C#:
- Retrieve an object (IDynamite)
- Retrieve string data
- Retrieve an array of bytes
- Store the contents directly on your file system.
So what other scenarios would you use a FileStorage for?
I used NFileStorage in many situations already where I didn't store files, but simply data like strings, or complex objects;
- Caching of data (rather then using SQL where you need to setup tables, connection strings etc,)
- Persist the state of items that are needed after a restart of your app
- Debugging; in some situations where (remote) debugging is not possible, you often see yourself open a file, and appending lines of text just to get an impression of what's going on. Rather than plumbing around with File I/O's and appending lines, you could consider using NFileStorage.
Just to give you a bit more practical view on an example other than storing files, take a look at the following pseudo code:
StartMe
{
List items = GetAllItems(...)
foreach (item in items)
{
string uniqueName = getName(item)
if (FileStorage.Exists(uniqueName))
{
// save time, and skip it, we already calculated it
}
else
{
result = PerformTimeConsumingOperation()
FileStorage.Store(name, result)
}
}
}
----------------------------------------------------------------------------------------------------------------------------