| Grovah |
| Member |
|
| Sweden |
|
|
| Male |
|
| Friday, May 27, 2011 |
| Tuesday, August 13, 2019 1:02:02 PM |
10 [0.05% of all post / 0.00 posts per day] |
|
Hello
I have created a C# DLL with on public static function returning byte[] (see attached code). When loading the DLL in MapForce, the function is not listed in the librarys pane. However, changing the return type to string, the function is listed in MapForce and is executable (just like the Format example provided with MapForce and the function Hello() in the attached code). Does not MapForce support byte[] as return type for custom C# library functions?
I have examined the documentation topic "Create a C# library" and as far as I can see byte[] shuld be a valid return type for a C# function and is the type to use when the result should be saved to a xs:Base64Binary element in the Mapping.
For info, the function GetFileData() should take a string parameter containg a file path (to a PDF or whatever) and return the content as byte[]. The return value will then be set to a XML element of Base64Binary in the result XML file.
Regards /Grovah
|
For information The problem with the closed stream is confirmed by Altova to be a bug (#38755) and will be adressed in future release.
Solved it temporary by using string as input and stringbulder as output from the mapping instead of streams.
/Grovah
|
Hello!
I have two MapForce mappings, one xml-->xml, and one xml-->text. Both mappings are generated code for and compiled to DLL:s.
In VS10 (C#), I execute the mappings using memory streams as input and output: xmlToXmlMapping.CloseObjectsAfterRun = false; MemoryStream resultStream = new MemoryStream(); MemoryStream myMemoryStream = new MemoryStream(); myMemoryStream = GetMemStreamFromObject(obj); Altova.IO.StreamInput inputStream = new Altova.IO.StreamInput(myMemoryStream); Altova.IO.StreamOutput outputStream = new Altova.IO.StreamOutput(resultStream); xmlToXmlMapping.Run(inputStream, outputStream); //Here outputStream is open and readable
xmlToTxtMapping.CloseObjectsAfterRun = false; MemoryStream resultStream = new MemoryStream(); MemoryStream myMemoryStream = new MemoryStream(); myMemoryStream = GetMemStreamFromObject(obj); Altova.IO.StreamInput inputStream = new Altova.IO.StreamInput(myMemoryStream); Altova.IO.StreamOutput outputStream = new Altova.IO.StreamOutput(resultStream); xmlToTxtMapping.Run(inputStream, outputStream); //Here outputStream is closed
For the xml-->xml mapping, the output stream is open and readable after executing the Run method. For the xml-->text mapping, the output stream is closed when its returned from the mapping.
To eliminate that it is the mappings that fails, I have executed both theese mappings from code using strings as input with the file paths to the Run method. That works fine and the mappings creates the resultfile as it should. I have also used StringInput/StringOutput as parameters and that also works as it should, I get a StringBuilder object back from the Run method with the desired content from the mappings. Could this be a bug or is it me doing something wrong here when calling the xml-->text mapping?
Regards /Grovah
EDIT: This is the exception when checking the length on the stream returned from the XML-->text mapping: "Exception: System.ObjectDisposedException: Det går inte att komma åt en stängd dataström (in english: It is not possible to reach a closed data stream). vid System.IO.__Error.StreamIsClosed() vid System.IO.MemoryStream.get_Length() vid Engine.FileConverterRunner.ExecuteMapForceJob(FileConverterJob job)"
As described in the original post, calling the xml-->xml mapping, the stream is open and I can check the length property without exception.
|
Vlad,
First, thank you for taking your time and help me!
I cant find variables in my version of MapForce, it seems like its a feature itroduced from version 2011 r3. I am using Enterprise 2010 r2. I also have some issues with using the sum() function to sum the GRWEIGHT. Suppose a variable would probably solve that to. Besides from upgrading MapForce, do you have any ideas of a workaround? The upgrading of Mapforce is not in my power to decide Im afraid. At least it will take long time and effort to convince the client of that.
Maybe my FlexText model is inadequately designed, but I really dont see how to solve it diffrent though.
Regards /Grovah
EDIT: The sum issue is solved, I just messed it up.. The concat-issue is still an issue though.
|
Sorry about that, I added it now to my previos post!
Thanks
/Grovah
|
Vlad,
Thanks for the reply. The files are attached to this post. The indata.txt is a file with tag-->Value on each line.
The file consist of a head level, item level (repeats 1..999 under header level), invoice head level (repeats 1..999 under head level) and invoice line level (repeats 1..999999 under invoice head level).
Head level starts with: REFNO -->Each Goods item starts with: GOODSLINEGEN -->Each Invoice head starts with: IVNO ---->Invoice line starts with: ITEMLINE
As you can see in the FlexText definition I have splitted the different levels, and finally swithed the tag/value pairs.
What I want is to concat CZCORGNO and CZORGNO to Job/Invoice/Seller/EORI (giving "SE1234567890") but using the concat function returns null. Mapping CZCORGNO and CZORGNO individually works. I suppose the problem is that the CZCORGNO and CZORGNO values are in diffrent "levels" and are not in scope at the same time (split once 13 and 14). Any suggestions to solve this would be much appreciated. I am using Mapforce 2010 rel 2.
Regards
/Grovah
|
Hello.
I have a textfile with a TAG=VALUE on each line, ex:
CNORGNO=123456789 CNCCORGNO=SE
I have used repeated SWITCH and SPLITONCE in FlexText to format the file. Now I would like to concat the two values above in mapforce, see attached file. Since the two values are on different values, the concat returns null. Is there any best practice to solve such a problem?
/Grovah
|
I managed to solve my problem today at last. Used a combination of Switch in FlextText and group-adjacent in Mapforce so it was a matter of understanding the tools, as always. ;) But thanks for taking time to answer me! And now I know how to add files/screenshots so next time I can be more accurate describing the problem. Thanks for your help.
Regards /Grovah
|
Vlad, thank you for the fast reply. It really helped med to handle the file in FlexText.
I have a question though, about handling the kind of data I have in MapForce. My file, which is some kind of home made "XML-lookalike" have fieldme=value pairs on each row. In addition, field/value pairs can be in arbitrary order within a record. Maybe its my lack of knowledge of MapForce that is the problem but for me it seems that MapForce prefers that data stored as indvidual fields on each row and thereby each field vill be "visible" and directly mapable in MapForce. All examples and tutorials for mapping text files in MapForce all have the data stored as separated/fixed length records.
For each fieldname/value I check for the field name, and if it is the one I want, I map its value to a XML element. But this feels a bit cumbersome, making the mapping very complex. And I also have problems with the levels, making too many elemnts in the destination XML-file. It feels like that I in some way should transform the field/value pairs to a single record, instead for having each field/value as it own record.
So, if there is any well known best practices, examples or other info that I can study, I would be wery grateful.
I could of course write a program that transforms the file, but I really want to try handling it with MapForce/FlexTex first.
Ps. tried to add a screenshot to this post, is it not possible to attach files?
Regards
/Magnus
|
Hello,
I am an beginner with FlexText and MapForce and I have som problems with the file below. I trying to use FlexText to make the file "mapable" in MapForce but I have trouble with the begin and end record delimiters. Any suggestions or examples of similar solutions on how to handle the file in FlexText would be very much appreciated! Please note the dependencies between the ih, il, ic and ill records. /Grovah
File structure, idented and commented for clarity, see test data below for "real" data as it appears in the orginal file:
Code: job_begin //only one job per file version=110 customerId=186785 jobDate=20110514 jobTime=113040 tr_begin //transport record 1..n pickup=20110501 deliv=20110502 tr_end ih_begin //Invoice head record 1..n InvoiceDate=20110514 exporterorderno=989898 currency=EUR totpackages=33 ih_end il_begin //Invoice line record 1..n, connected to previous ih record lineNo=1 quantity=3 unit=PCS grossWeight=426 netWeight=198 price=10 il_end ic_begin //Invoice line additional info record 1..n, connected to previous il record infotype=NewDescr infocode=New description ic_end ic_begin //Invoice line additional info record 1..n, connected to previous il record infotype=NewDescr2 infocode=Another description ic_end ill_begin //Invoice line license info record 1..n, connected to previous il record ID=12345 value=100 ill_end ill_begin //Invoice line license info record 1..n, connected to previous il record ID=775544 value=500 ill_end il_begin //Invoice line record 1..n, connected to previous ih record. lineNo=2 quantity=3 unit=PCS grossWeight=225 price=20 il_end job_end
//Test data as it appears in the file: job_begin version=110 customerId=186785 jobDate=20110514 jobTime=113040 tr_begin pickup=20110501 deliv=20110502 tr_end ih_begin InvoiceDate=20110514 exporterorderno=989898 currency=EUR totpackages=33 ih_end il_begin lineNo=1 quantity=3 unit=PCS grossWeight=426 netWeight=198 price=10 il_end ic_begin infotype=NewDescr infocode=New description ic_end ic_begin infotype=NewDescr2 infocode=Another description ic_end ill_begin ID=12345 value=100 ill_end ill_begin ID=775544 value=500 ill_end il_begin lineNo=2 quantity=3 unit=PCS grossWeight=225 price=20 il_end il_begin lineNo=3 quantity=1 unit=PCS grossWeight=55 netWeight=55 price=25 il_end ic_begin infotype=NewDescr infocode=New description ic_end ic_begin infotype=NewDescr2 infocode=Another description ic_end ill_begin ID=8877 value=500 ill_end ill_begin ID=5544 value=50 ill_end job_end
|
|