Hide menu Last updated: Jul 25 2017
Area: Episerver Add-ons Applies to versions: 4.6.1 and higher

Creating a new data storage mechanism

Note: Episerver Forms is only supported by MVC-based websites and HTML5-compliant browsers.

This topic introduces general guidelines about using Episerver APIs to replace Dynamic Data Store (DDS) with another data storage system.

Episerver Forms uses DDS as its default storage mechanism. This may cause performance-related issues in special cases. You can base an alternative data storage scheme on MSSQL or another data provider to try different solutions. This topic uses MongoDB as an alternative storage provider, but you can use any data storage system.

Comparison between DDS and MongoDB

To implement a MongoDB data storage approach, first prepare your environment for Mongo. See https://docs.mongodb.com.

Required NuGet packages

  • MongoDB.Bson
  • MongoDB.Driver
  • MongoDB.Driver.Core
  • EPiServer.Forms.Core 4.6.1 (or higher)

A guide to the PermanentStorage class

PermanentStorage is the base class for data storage. This class exposes the necessary APIs for developers to manipulate form data with their data storage.

  1. Create a new class inheriting the PermanentStorage class. Put the ServiceConfiguration attribute on top as shown in the following example.
    [ServiceConfiguration(ServiceType = typeof(IPermanentStorage))]
    public class YourDataStorage: PermanentStorage
  2. Within the newly-created class constructor, set up initial storage information, such as connection string, configuration, and so on.
  3. Override the five functions below.
    • SaveToStorage(FormIdentity formIden, Submission submission). This function saves data at the first step of a form. This may also be the last step, if a form only has one step. Using this method, based on these two parameters, developers can save data into database::
      • formIden. Contains form information, such as form id or language.
      • submission. Contains form submission data.
    • UpdateToStorage(Guid formSubmissionId, FormIdentity formIden, Submission submission). This function is for saving data at the next steps or updating data at previous ones. Within this method, based on these two parameters, developers can update data in the database.
      • submission. Contains form submission data.
      • formIden. Contains form information, such as form id or language.
    • LoadSubmissionFromStorage(FormIdentity formIden, DateTime beginDate, DateTime endDate, bool finalizedOnly = false)LoadSubmissionFromStorage. This function loads form submission data from the database within a specific time period and the status finalized.
    • LoadSubmissionFromStorage(FormIdentity formIden, string[] submissionIds). Loads form submission data only based on the ids of the submission.
    • Delete(FormIdentity formIden, string submissionId). Deletes a form submission based on submission Id.

Example of using MongoDB as a data storage mechanism

Use the following example to replace DDS with MongoDB for data manipulation. The MongoDbPermanentStorage class implements the storage.

MongoDB uses the concept of "collection" as a table in Microsoft SQL. Each form has one collection, which stores form submission data. The collection also supports indexing, which significantly improves the performance of data queries. MongoDB's storage details are below.

  • MongoDbPermanentStorage(). Set the constructor of the storage. Within the constructor, you set up a connection string for the database connection, database name for data storage, and form configurations.
  • GetFormCollection (FormIdentity formIden). Creates a collection for a specific form, based on form id. If a form was previously associated with a collection, it is returned and no new collection is created.
  • IsCollectionExisted(IMongoDatabase database, string collectionName). Checks whether a collection exists in the database based on its name.
  • SaveToStorage(FormIdentity formIden, Submission submission). Gets the collection associated with form submission data as a new item, and then saves it to the MongoDB.
  • UpdateToStorage(Guid formSubmissionId, FormIdentity formIden, Submission submission). Updates the collection associated with the forms update submission data previously stored into it.
  • LoadSubmissionFromStorage(FormIdentity formIden, DateTime beginDate, DateTime endDate, bool finalizedOnly = false). Loads submission from the collection associated with the form during a time  period.
  • LoadSubmissionFromStorage(FormIdentity formIden, string[] submissionIds). Loads submission from the collectionassociated with the form, based on the list of submission ids.
  • Delete(FormIdentity formIden, string submissionId). Deletes a submission previously stored in the collection.

Beta version of MongoDBPermanentStorage

Configuring the new database provider

The following example sets up the MongoDB configuration in the forms.config file:

  1. Use the <add> element to add a storage provider.
  2. Enter values for the properties below:
    • "name". For example, MongoDBPermanentStorage.
    • type. The full namespace of your project's data storage and namespace. Use a comma to separate two values.
    • connectionUri. Database connection string.
    • databaseName. Your database name.
  3. Use new provider as the defaultProvider of the storage.

This is a sample forms.config file.

Mongo configuration

Comments