Using the Repository-Mode
In This Topic
With the help of Repositories most of the file accesses could be redirected to an self-defined virtual file system. This allows you to manage all project files and their related files in a database. The implementation of such strategy is described in the following setps. An Overview of the use and functionality of the Repository could be found in namespace combit.Reporting.Repository. Following will be demonstrated how the Repository can be used in List & Label. The supplied programming samples for ASP.NET and WinForms show the usage in detail.
Tip
In the following, code sections are shown which have been reduced to a minimum due to their clarity. Any auxiliary functions shown, but can be viewed in full in the supplied samples, since the following description is based on the implementation of the IRepository interface using an SQLite database and its subsequent use in practice in detail in the examples.
Step 1: Definition of the data retention
The managing of the files in List & Label like project files for the designer, P-files for printer settings, table of contents, drawings, shapefiles etc. are normally controlled by the file system of the operating system. Thus List & Label works on the basis of file names and its paths.
As soon as you decide to use the Repository, you need to deal with that question and find an suitable "storage", because of List & Label does no longer work with file paths rather only with so called Repository-IDs. With the help of these IDs the requested elements could be asked and used. Numerous applications use for their data storage something like databases where SQL databases is often chosen. That is the reason why we will use for simple demonstration an SQLite database. And the namespace System.Data.SQLite from the .NET Framework is used for:
Step 2: Necessary implementation of the interface IRepository
Now the implementation of the interface IRepository need to be done, so you can react individual on the requests of List & Label:
IRepository.ContainsItem
According to the description in IRepository.ContainsItem this function is called to check if an suitable element exists in the Repository. Therefore you need to ask the database if the requested ID exists:
IRepository.CreateOrUpdateItem
According to the description in IRepository.CreateOrUpdateItem this function is called, if a new element will added to the Repository or an existing one should be updated. However this function is also called, if only the meta data of the element should be updated or the meta data should be added independently of the content:
IRepository.DeleteItem
According to the description in IRepository.DeleteItem this function is called, if an element should be deleted from the Repository. Therefore the related record have to be deleted from the SQLite database:
IRepository.GetAllItems
This implementation is called to get all existing elements in the Repository (see also IRepository.GetAllItems):
IRepository.GetItem
To return only one element from the Repository the implementation of IRepository.GetItem is called with the requested ID:
IRepository.LoadItem
If the content of an element is really requested and should be loaded from the Repository, for example to open a project file in the designer, the implementation of IRepository.LoadItem is called and we have to return the content of the requested element as stream:
IRepository.LockItem
If the requirement exists to editing an element exclusively - for example if a project is opening in the designer - an exclusively access with the help of IRepository.LockItem could be implemented to lock the element:
IRepository.UnlockItem
This is required to unlock an element in the Repository if it was locked with the call of IRepository.LockItem before:
Helper function to update the meta data of an Repository element
To be able to update meta data of an element in the Repository like the display name in the designer of a project file, it requires a little helper function which writes this adaptations into the SQLite database:
From now all concerning List & Label files are managed in a SQLite database. How to work with this Repository is shown in "Step 3: Usage of the self-created IRepository implementation".
Step 3: Usage of the self-created IRepository implementation
Helper class for the simple access to the Repository
With the help of this class the access to the self implemented Repository is simplified and it is also the base for the following steps:
Add/Import of existing files from file system into the Repository
In order to be able to import existing files like project files, drawings, shapefiles etc. you can use the supplied helper class RepositoryImportUtil for that:
Creating new elements (new project files) into the Repository
If a new project file should be created and editing in the designer you also can use the helper class RepositoryImportUtil and its suitable function CreateNewProject:
Delete elements from the Repository
To delete elements from the Repository based on their ID you can directly call the provided implementation of IRepository.DeleteItem:
The supplied programming samples show the implementation of the IRepository-Interface based on a SQLite database and its following usage in detail.