Custom importer: replacing the File Importer
This example describes how you can replace the File Importer iPart with custom code, so that you can import order, product, contact, and payment information for simple gifts into iMIS.
Another option is to simply extend the File Importer instead of replacing it. For more information, see Custom importer – Extending the File Importer.
- The following example is meant to demonstrate that creating a custom import file format is achievable, but the example might not be completely compatible with your iMIS version. The code examples used in this tutorial can be found in a GitHub repository. To follow along, download the appropriate file, and open it in Visual Studio.
If you do not want to use the File Importer content item, you can replace it with your own code. To replace the File Importer, but still use the File Viewer and Log Viewer content items, do the following:
- Decide on a file format you want to support.
- Construct a collection of SOA data contracts.
- Package the data contracts into an ImportBatch.
- Send the ImportBatch to SOA.
Once completed, this process allows your code to work properly with the FileViewer and LogViewer content items.
Example: Replacing the File Importer
This example supports the import of simple donations. The example project consists of a Windows console application with 99 lines of code. The input format for each row in the supported import file will looks like the following:
18106, 42.00, WATER
Where 18106 is the iMIS ID, 42.00 is the donation dollar amount, and WATER is the fund to which the donation is being credited.
The first step is to read each of the lines, and then build a collection of data contracts. The main function in the example project parses each line into three pieces, then calls the BuildComboOrder method to build a simple ComboOrder for each line in the file.
To make the code short for this example, there are a few simplifying assumptions. For example:
- We aren’t doing much syntax checking of the file
- We are assuming the contact and GiftItem are present in the database
- We are hard coding the authentication data for SOA
- The currency is hard-coded to be US dollars
- The payment method is Cash.
Nevertheless, in these few lines of code, a collection of ComboOrder objects sufficient to be added through SOA is built.
- Build an OrderData contract with the minimal amount of details needed.
- Add the order to ComboOrder.
- Build a RemittanceData contract with the minimal amount of payment information, and add it to the ComboOrder.
The second step is to add each ComboOrder to an ImportBatchData and send it to SOA. This creates a new XML file on the server containing each of the ComboOrders. This file is ready to be viewed and imported using the File Viewer and Log Viewer content items.
While this example is a simple console application, you can likely think of other more useful or interesting ways to package this sort of logic. For instance, you could write a Windows service that monitors updates to the file system, looks for new files to import, and automatically adds ImportBatch objects based on what it finds.
Updated about 3 years ago