|
Home > Archive > BizTalk Server > July 2004 > BTS 2002 Custom Preprocessor
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
BTS 2002 Custom Preprocessor
|
|
| JTnospam@verizon.net 2004-07-09, 3:32 pm |
| Hi all,
I am trying to build a preprocessor for a file Receive Funtion that takes in a EDI message (text file), alters it, and then sends it on to the receive function, which has a pass through flag set to yes. When I try this, I get the error that my preprocess
or (VB.Net) is not returning a valid BTSR. My code is below. As you can see, the vDataOut value that I am returning to the receive function is a string representation of the altered message, which is what I was thinking (evidently erroneously) BTS was l
ooking for. I tried just running the function TrimST on the message and then returning vDataIn (the message file path) from the TrimSt function, but this just gives me a new message containing the message file path. Can someone please educate me on this
? Is this operation possible in a Preprocessor? Would I be better to use a custom pipeline component to do this? What would be the best approach to this when I migrate to BTS 2004? Thanks much.
John
Overridable Sub IBTSCustomProcess_Execute(ByVal vDataIn As Object, ByVal nCodePageIn As Integer, ByVal bIsFilePath As Boolean, ByRef nCodePageOut As Object, ByRef vDataOut As Object) Implements IBTSCustomProcess.Execute
nCodePageOut = nCodePageIn
Try
If bIsFilePath Then
vDataOut = TrimST(vDataIn.ToString)
End If
Catch ex As Exception
ex.ToString()
End Try
End Sub
Private Function TrimST(ByRef InPath As String) As String
Try
'Get a StreamReader for file and allow system to decide
'encoding to use
Dim stRead As New StreamReader(InPath, True)
'Dump stream into a string builder with initial capacity of
'100000 characters
Dim fileContent As New StringBuilder(stRead.ReadToEnd, 100000)
stRead.Close()
'Modify the string within the Stringbuilder
'by getting rid of the extraneous ST segment
With fileContent
If .Length > 0 Then
.Replace("ST*837*0001~ST", "ST")
End If
End With
'Create a StreamWriter to overwrite the file with
'the new file content
Dim stWrite As New StreamWriter(InPath, False)
With stWrite
.Write(fileContent.ToString)
.Flush()
.Close()
End With
Return fileContent.ToString
Catch ex As Exception
ex.ToString()
Finally
End Try
End Function
| |
| Sunghwa Jin [MSFT] 2004-07-09, 3:32 pm |
| I don't recall exactly, but you should set nCodePageOut as 1200 which means
Unicode. I believe nCodePageIn is zero if the data is from file.
Please let me know if you still have the problem.
Thanks,
Sunghwa
--------------------[vbcol=seagreen]
<JTnospamverizonnet@discussions.microsoft.com>[vbcol=seagreen]
in a EDI message (text file), alters it, and then sends it on to the
receive function, which has a pass through flag set to yes. When I try
this, I get the error that my preprocessor (VB.Net) is not returning a
valid BTSR. My code is below. As you can see, the vDataOut value that I
am returning to the receive function is a string representation of the
altered message, which is what I was thinking (evidently erroneously) BTS
was looking for. I tried just running the function TrimST on the message
and then returning vDataIn (the message file path) from the TrimSt
function, but this just gives me a new message containing the message file
path. Can someone please educate me on this? Is this operation possible
in a Preprocessor? Would I be better to use a custom pipeline component to
do this? What would be the best approach to this when I migrate to BTS
2004? Thanks much.[vbcol=seagreen]
nCodePageIn As Integer, ByVal bIsFilePath As Boolean, ByRef nCodePageOut As
Object, ByRef vDataOut As Object) Implements IBTSCustomProcess.Execute[vbcol=seagreen]
This posting is provided "AS IS" with no warranties, and confers no rights.
EBusiness Server Team
| |
| Nick Malik 2004-07-09, 3:32 pm |
| The error is correct... your code does not return a valid BSTR.
Your code throws an error when it attempts to open the file with the
StreamReader. Your error handler throws away the error. Since your routine
does not set the vDataOut parameter before the error is thrown, invalid data
is returned.
I don't remember the exact statement you need to use to open the file for
reading, unfortunately. However, the examples in the toolkit should be
followed EXACTLY if you want it to work.
--- Nick
"JTnospam@verizon.net" <JTnospamverizonnet@discussions.microsoft.com> wrote
in message news:3FBB1E88-EDC8-4B4D-8C92-07E218829C6C@microsoft.com...
> Hi all,
> I am trying to build a preprocessor for a file Receive Funtion that takes
in a EDI message (text file), alters it, and then sends it on to the receive
function, which has a pass through flag set to yes. When I try this, I get
the error that my preprocessor (VB.Net) is not returning a valid BTSR. My
code is below. As you can see, the vDataOut value that I am returning to
the receive function is a string representation of the altered message,
which is what I was thinking (evidently erroneously) BTS was looking for. I
tried just running the function TrimST on the message and then returning
vDataIn (the message file path) from the TrimSt function, but this just
gives me a new message containing the message file path. Can someone please
educate me on this? Is this operation possible in a Preprocessor? Would I
be better to use a custom pipeline component to do this? What would be the
best approach to this when I migrate to BTS 2004? Thanks much.
>
> John
>
>
>
> Overridable Sub IBTSCustomProcess_Execute(ByVal vDataIn As Object, ByVal
nCodePageIn As Integer, ByVal bIsFilePath As Boolean, ByRef nCodePageOut As
Object, ByRef vDataOut As Object) Implements IBTSCustomProcess.Execute
>
> nCodePageOut = nCodePageIn
>
> Try
> If bIsFilePath Then
> vDataOut = TrimST(vDataIn.ToString)
> End If
>
> Catch ex As Exception
> ex.ToString()
> End Try
>
> End Sub
>
> Private Function TrimST(ByRef InPath As String) As String
>
> Try
>
> 'Get a StreamReader for file and allow system to decide
> 'encoding to use
> Dim stRead As New StreamReader(InPath, True)
>
> 'Dump stream into a string builder with initial capacity of
> '100000 characters
> Dim fileContent As New StringBuilder(stRead.ReadToEnd, 100000)
> stRead.Close()
>
> 'Modify the string within the Stringbuilder
> 'by getting rid of the extraneous ST segment
> With fileContent
> If .Length > 0 Then
>
> .Replace("ST*837*0001~ST", "ST")
>
> End If
> End With
>
> 'Create a StreamWriter to overwrite the file with
> 'the new file content
> Dim stWrite As New StreamWriter(InPath, False)
> With stWrite
> .Write(fileContent.ToString)
> .Flush()
> .Close()
> End With
>
> Return fileContent.ToString
>
> Catch ex As Exception
> ex.ToString()
> Finally
> End Try
>
> End Function
| |
| Jeff Lynch 2004-07-09, 3:32 pm |
| Here is the code in C# to open the FileStream. It should be similar in
VB.NET.
// Open Source file
FileStream fs = new FileStream((string)vDataIn, FileMode.Open,
FileAccess.Read, FileShare.ReadWrite);
// Read the source file using the StreamReader
StreamReader sr = new StreamReader(fs);
// Give the data back to BTS after processing
vDataOut = sr.ReadToEnd();
--
Jeff Lynch
"A BizTalk Enthusiast"
"Nick Malik" <nickmalik@hotmail.nospam.com> wrote in message
news:FY7Hc.45427$Oq2.102@attbi_s52...
> The error is correct... your code does not return a valid BSTR.
>
> Your code throws an error when it attempts to open the file with the
> StreamReader. Your error handler throws away the error. Since your
routine
> does not set the vDataOut parameter before the error is thrown, invalid
data
> is returned.
>
> I don't remember the exact statement you need to use to open the file for
> reading, unfortunately. However, the examples in the toolkit should be
> followed EXACTLY if you want it to work.
>
> --- Nick
>
> "JTnospam@verizon.net" <JTnospamverizonnet@discussions.microsoft.com>
wrote
> in message news:3FBB1E88-EDC8-4B4D-8C92-07E218829C6C@microsoft.com...
takes[vbcol=seagreen]
> in a EDI message (text file), alters it, and then sends it on to the
receive
> function, which has a pass through flag set to yes. When I try this, I
get
> the error that my preprocessor (VB.Net) is not returning a valid BTSR. My
> code is below. As you can see, the vDataOut value that I am returning to
> the receive function is a string representation of the altered message,
> which is what I was thinking (evidently erroneously) BTS was looking for.
I
> tried just running the function TrimST on the message and then returning
> vDataIn (the message file path) from the TrimSt function, but this just
> gives me a new message containing the message file path. Can someone
please
> educate me on this? Is this operation possible in a Preprocessor? Would
I
> be better to use a custom pipeline component to do this? What would be
the
> best approach to this when I migrate to BTS 2004? Thanks much.
> nCodePageIn As Integer, ByVal bIsFilePath As Boolean, ByRef nCodePageOut
As
> Object, ByRef vDataOut As Object) Implements IBTSCustomProcess.Execute
>
>
|
|
|
|
|