FolderAttachmentStore Class
Assembly: CodeEffects.Rule.Repository.dll
Namespace: CodeEffects.Rule.Repository
Summary
Keeps the files that users attach in the AI Assistant in a folder: one file for each attachment, named by the repository's key, never by the user's file name.
Syntax
public class FolderAttachmentStore : IAttachmentStore
Inheritance
System.Object
- CodeEffects.Rule.Repository.FolderAttachmentStore
The class implements IAttachmentStore.
Assign an instance to AttachmentStore of AssistantSettings.
The folder must exist, and the process that runs the repository must be able to create, read, and delete files in it; on IIS, that is the identity of the application pool. When your application runs on more than one server, the folder must be shared storage that every server reaches. Keep it outside the folders of your web site so that no file in it can be requested from a browser.
Each file is named with its key in lower case and the extension .bin. A file is written under a temporary name first, so a failed write leaves no partial file under the key.
Constructors
Properties
Methods
Delete
Returns: System.Void
public void Delete(string key)
Deletes the file stored under the key. A key with no file is not an error.
Parameters
- key (
System.String) - The key of the file: 32 hexadecimal characters.
Exceptions
Open
Returns: System.IO.Stream - A stream to read the file, or null when no file is stored under the key.
public Stream Open(string key)
Opens the file stored under the key for reading. The caller disposes the stream.
Parameters
- key (
System.String) - The key of the file: 32 hexadecimal characters.
Exceptions
Save
Returns: System.Void
public void Save(string key, Stream content)
Stores a file under the key and replaces a file that is already stored under it. The stream is read to its end.
Parameters
- key (
System.String) - The key to store the file under: 32 hexadecimal characters.
- content (
System.IO.Stream) - The content of the file.
Exceptions
CodeEffects.Rule.Common.RuleException - The folder does not exist or the application cannot reach it (control number CE10242), or the key is not 32 hexadecimal characters (control number CE10243).
Example
using CodeEffects.Rule.Repository;
var configuration = new Configuration
{
Assistant = new AssistantSettings
{
AttachmentStore = new FolderAttachmentStore("/var/data/assistant-files"),
KeepAttachments = true
}
};