ImageGear .NET v25.1 - Updated
Helper Abstract Classes in ImageGear.Web.Services Assembly
User Guide > How to Work with... > Common Operations > Viewing > Viewing Using ASP.NET > [Legacy] ASP.NET Web.Config Editor Application > Use the Web Configuration Categories Screen > Configuring and Working with Data Providers > Image Data Providers > Implementing Annotations in an Image Data Provider > Enabling Annotation within a Custom Image Data Provider > Helper Abstract Classes in ImageGear.Web.Services Assembly

To assist in handling annotation transactions, the ImageGear.Web.Services assembly provides two abstract classes that must be implemented in your custom image data provider. Your custom image data provider must include derived classes from these two abstract classes regardless of whether your storage implementation is transactional or non-transactional.

The example below shows a code sample high-level view and the relationships between the provider code, TransactionScope, and the server API code during an annotations data save operation in the ImageGear.Web assembly API.  

C#
Copy Code
//The ImageGearAPI calls OpenArtDocument of ImageDataProvider to get an
//ArtDataConnection derived object.For SQL based provider,
//it is recommended that you open a database connection in the
//constructer of the ArtDataConnection derived class.
ImageGear.Web.DataProviders.ArtDataConnection artconnect =
           ImageGear.Web.DataProviders.ImageDataProvider.OpenArtData();
     
//The ImageGearAPI calls the ImageDataProvider ArtDataConnection.Open to open
//the required document
using (ImageGear.Web.DataProviders.ArtDocumentDataConnection document =  artconnect.OpenDocument(documentIdentifier))
{
    //Since the ImageGearAPI needs to save the annotations data, it needs
    //to get a current copy from the repository to do the merge with what
    // has just been updated. After that it needs to update the repository.
    // This operation requires use of a TransactionScope to make sure this
    // data is not updated by another user when this process is taking place.
    using (TransactionScope Scope = new TransactionScope())
    {
           //The ImageGear API reads the document first by calling the
           // provider ArtDocumentDataConnection.Read()
           System.IO.Stream stream =  document.Read();
 
           // The ImageGear API does the merge operations
           // System.IO.Stream artStream = ....;
   
           //The data is merged and now the data is written to the
           //repository by calling the provider
           //artDocumentdataConnection.Write
           document.Write(artStream);
           //This call will cause the data to be finally committed.
           //If you are using non-transactional system for data storage
           //then you must implement the IEnlistmentNotification interface.
           //The system will call Commit member of this interface to store
           //the data. If there is a processing error before this point then
           //this interface’Rollback method will be called in which case
           //annotation data can not be saved. It is not necessary to
           //implement this interface when using transactional repository
           //systems like the transactional databases.
           Scope.Complete();
    }
}
    // The Server API disposes the ArtDocumentDataConnection derived and
    // ArtDataConnection derived Objects. The SQL connections should be
    // disconnected at this point.
    artconnect.Dispose();