How to dynamically create business connection services

We are trying to deploy a business connection model (BCS) solution in which the properties of the model depend on the data structure exposed by the web service.

Ideally, the BCS model will provide a collection of key / value pairs, which will then be converted to columns in the sharepoint list later, as this will mean that the same model can be used for several different data sets, however, from what we can say about This is not the case as the BCS models were designed, because they rely on a model that will be strongly typed to reflect the imported object.

So, we are considering a solution that allows the user to “create” a new external list by providing the URL to the remote dataset via a user page in the central sharepoint admin center, which will then automatically build the BCS model of the project (by changing the project template) and then compile and releasing the resulting function on the fly.

In this way, we can create a “fixed” class with properties that represent the structure of the imported data.

For example, data source A can set

<cars> <car> <color>blue</color> <make>ford</make> </car> <car> <color>red</color> <make>lotus</make> </car> </cars> 

in this case, we need a BCS model for the "car", which has two public properties, color and make however data source B can set

 <invoices> <invoice> <amount>£34.00</amount> </invoice> <invoice> <amount>£34.00</amount> </invoice> </invoices> 

in this case, we need a BCS invoice model with a single public property for the amount.

Thank you for any feedback on this approach or “best practice” for achieving this.

+4
source share
1 answer

[I had experience doing something similar in .Net - I'm not sure how appropriate this is for you.]

I had to write an import tool that could handle any file format. To handle this correctly, I wrote a small class that would accept an XML format definition (name, data type, format string, custom parser, etc.) and generate a class that could read the file and set IQueryable<FileFormat> , and some additional metadata.

It is worth noting that in order to make it completely flexible, I had to allow the definition of the format to provide lambda C # / VB, which would be compiled and executed (for example, when the input date format was non-standard and required its own parser). This is clearly a security risk - so when I created the dynamic class, I did it in a separate AppDomain with very few privileges. This may not apply in your situation.

We used our own template engine to generate the code, which was then compiled using the System.Codedom.Compiler namespace. This allowed us to create assemblies and cache them until the definition changes. Perhaps you should consider modeling Razor templates if you do something like this.

The only real problems that we encountered due to coding with an unknown data type. Having created our own class, we implement our own IImportFile interface, which exposes metadata in a standard way (in fact, the same information as in the xml specification), we could get around this without much effort.

We are fortunate that this is a tool for trusted users (at least only trusted users can provide a new file format specification), so the security risks were limited. If you compile code based on user input, make sure that you have adequate precautions.

+1
source

Source: https://habr.com/ru/post/1394582/


All Articles