-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Alternate method of reading text files, to better handle locked files
- Loading branch information
1 parent
8bc1997
commit adf3354
Showing
10 changed files
with
323 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,53 @@ | ||
Public Class ContextHandlerReadFile | ||
Inherits ContextHandlerBase | ||
|
||
Public Sub New(ByVal context As ContextFactory.Contexts _ | ||
, ByRef state As Dictionary(Of String, Object) _ | ||
, ByRef smallIntValues As Dictionary(Of String, Nullable(Of Short)) _ | ||
, ByRef textValues As Dictionary(Of String, String) _ | ||
, ByRef intValues As Dictionary(Of String, Nullable(Of Integer)) _ | ||
, ByRef decimalValues As Dictionary(Of String, Nullable(Of Decimal)) _ | ||
, ByRef booleanValues As Dictionary(Of String, Nullable(Of Boolean)) _ | ||
, ByRef extendedValues As Dictionary(Of String, Object)) | ||
|
||
MyBase.New(context, state, smallIntValues, textValues, intValues, decimalValues, booleanValues, extendedValues) | ||
End Sub | ||
|
||
|
||
Public Overrides Function Execute() As Boolean | ||
Dim newFile As DownloadedFile = Nothing | ||
Dim regexPattern As String | ||
|
||
If Not m_TextValues.ContainsKey(App.KEY_FILE) Then | ||
m_smallIntValues(App.KEY_ERROR) = ERR_ARGUMENTS | ||
m_TextValues(App.KEY_RESULT) = String.Format("Unknown file name. Text variable '{0}' not set.", App.KEY_FILE) | ||
Return False | ||
End If | ||
|
||
If m_TextValues.ContainsKey(App.KEY_REGEX) Then | ||
regexPattern = m_TextValues(App.KEY_REGEX) | ||
Else | ||
regexPattern = String.Empty | ||
End If | ||
Try | ||
newFile = App.DownloadTextFile(m_TextValues(App.KEY_FILE)) | ||
If newFile.LocalPath.Length = 0 Then | ||
m_smallIntValues(App.KEY_ERROR) = ERR_IO | ||
m_TextValues(App.KEY_RESULT) = String.Format("Error retrieving File '{0}'.", m_TextValues(App.KEY_FILE)) | ||
Return False | ||
End If | ||
Inherits ContextHandlerBase | ||
|
||
Public Sub New(ByVal context As ContextFactory.Contexts _ | ||
, ByRef state As Dictionary(Of String, Object) _ | ||
, ByRef smallIntValues As Dictionary(Of String, Nullable(Of Short)) _ | ||
, ByRef textValues As Dictionary(Of String, String) _ | ||
, ByRef intValues As Dictionary(Of String, Nullable(Of Integer)) _ | ||
, ByRef decimalValues As Dictionary(Of String, Nullable(Of Decimal)) _ | ||
, ByRef booleanValues As Dictionary(Of String, Nullable(Of Boolean)) _ | ||
, ByRef extendedValues As Dictionary(Of String, Object)) | ||
|
||
MyBase.New(context, state, smallIntValues, textValues, intValues, decimalValues, booleanValues, extendedValues) | ||
End Sub | ||
|
||
Dim newFileContent As String = IO.File.ReadAllText(newFile.LocalPath) | ||
m_TextValues(App.KEY_RESULT) = App.LimitResponse(newFileContent, regexPattern) | ||
|
||
Catch ex As Exception | ||
m_smallIntValues(App.KEY_ERROR) = ERR_IO | ||
m_TextValues(App.KEY_RESULT) = String.Format("Error loading file content '{0}' ({1}).", m_TextValues(App.KEY_FILE), ex.Message) | ||
End Try | ||
If newFile.IsTemporary Then App.Settings.AddDownloadedFile(newFile) | ||
Public Overrides Function Execute() As Boolean | ||
Dim newFile As DownloadedFile = Nothing | ||
Dim regexPattern As String | ||
|
||
If Not m_TextValues.ContainsKey(App.KEY_FILE) Then | ||
m_smallIntValues(App.KEY_ERROR) = ERR_ARGUMENTS | ||
m_TextValues(App.KEY_RESULT) = String.Format("Unknown file name. Text variable '{0}' not set.", App.KEY_FILE) | ||
Return False | ||
End If | ||
|
||
If m_TextValues.ContainsKey(App.KEY_REGEX) Then | ||
regexPattern = m_TextValues(App.KEY_REGEX) | ||
Else | ||
regexPattern = String.Empty | ||
End If | ||
Try | ||
newFile = App.DownloadFile(m_TextValues(App.KEY_FILE)) | ||
If newFile.LocalPath.Length = 0 Then | ||
m_smallIntValues(App.KEY_ERROR) = ERR_IO | ||
m_TextValues(App.KEY_RESULT) = String.Format("Error retrieving File '{0}'.", m_TextValues(App.KEY_FILE)) | ||
Return False | ||
End If | ||
|
||
'Dim newFileContent As String = IO.File.ReadAllText(newFile.LocalPath) | ||
Dim newFileContent As String = App.ReadTextFile(newFile.LocalPath) | ||
m_TextValues(App.KEY_RESULT) = App.LimitResponse(newFileContent, regexPattern) | ||
|
||
Catch ex As Exception | ||
m_smallIntValues(App.KEY_ERROR) = ERR_IO | ||
m_TextValues(App.KEY_RESULT) = String.Format("Error loading file content '{0}' ({1}).", m_TextValues(App.KEY_FILE), ex.Message) | ||
End Try | ||
If newFile.IsTemporary Then App.Settings.AddDownloadedFile(newFile) | ||
|
||
Return True | ||
End Function | ||
Return True | ||
End Function | ||
|
||
End Class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 51 additions & 52 deletions
103
VAExtensions/ContextHandlers/ContextHandlerReadStdOut.vb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,53 @@ | ||
Public Class ContextHandlerReadStdOut | ||
Inherits ContextHandlerBase | ||
|
||
Public Sub New(ByVal context As ContextFactory.Contexts _ | ||
, ByRef state As Dictionary(Of String, Object) _ | ||
, ByRef smallIntValues As Dictionary(Of String, Nullable(Of Short)) _ | ||
, ByRef textValues As Dictionary(Of String, String) _ | ||
, ByRef intValues As Dictionary(Of String, Nullable(Of Integer)) _ | ||
, ByRef decimalValues As Dictionary(Of String, Nullable(Of Decimal)) _ | ||
, ByRef booleanValues As Dictionary(Of String, Nullable(Of Boolean)) _ | ||
, ByRef extendedValues As Dictionary(Of String, Object)) | ||
|
||
MyBase.New(context, state, smallIntValues, textValues, intValues, decimalValues, booleanValues, extendedValues) | ||
End Sub | ||
|
||
|
||
Public Overrides Function Execute() As Boolean | ||
Dim newFile As DownloadedFile = Nothing | ||
Dim regexPattern As String | ||
|
||
If Not m_TextValues.ContainsKey(App.KEY_FILE) Then | ||
m_smallIntValues(App.KEY_ERROR) = ERR_CONTEXT | ||
m_TextValues(App.KEY_RESULT) = String.Format("Unknown file name. Text variable '{0}' not set.", App.KEY_FILE) | ||
Return False | ||
End If | ||
|
||
Try | ||
Dim pName As String = m_TextValues(App.KEY_FILE) | ||
Dim pInfo As ProcessStartInfo | ||
Dim pOutput As String | ||
Dim p As Process | ||
|
||
If Not IO.Path.IsPathRooted(pName) Then | ||
pName = IO.Path.Combine(IO.Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly.Location), pName) | ||
End If | ||
pInfo = New ProcessStartInfo(pName) With {.UseShellExecute = False, .CreateNoWindow = True, .RedirectStandardOutput = True} | ||
If Not String.IsNullOrEmpty(m_TextValues(App.KEY_ARGUMENTS)) Then | ||
pInfo.Arguments = m_TextValues(App.KEY_ARGUMENTS) | ||
End If | ||
|
||
p = Process.Start(pInfo) | ||
pOutput = p.StandardOutput.ReadToEnd | ||
p.WaitForExit() | ||
|
||
m_TextValues(App.KEY_RESULT) = App.LimitResponse(pOutput) | ||
Catch ex As Exception | ||
m_smallIntValues(App.KEY_ERROR) = ERR_IO | ||
m_TextValues(App.KEY_RESULT) = String.Format("Error running process '{0}' - {1}.", m_TextValues(App.KEY_FILE), ex.Message) | ||
Return False | ||
End Try | ||
|
||
Return True | ||
End Function | ||
Inherits ContextHandlerBase | ||
|
||
Public Sub New(ByVal context As ContextFactory.Contexts _ | ||
, ByRef state As Dictionary(Of String, Object) _ | ||
, ByRef smallIntValues As Dictionary(Of String, Nullable(Of Short)) _ | ||
, ByRef textValues As Dictionary(Of String, String) _ | ||
, ByRef intValues As Dictionary(Of String, Nullable(Of Integer)) _ | ||
, ByRef decimalValues As Dictionary(Of String, Nullable(Of Decimal)) _ | ||
, ByRef booleanValues As Dictionary(Of String, Nullable(Of Boolean)) _ | ||
, ByRef extendedValues As Dictionary(Of String, Object)) | ||
|
||
MyBase.New(context, state, smallIntValues, textValues, intValues, decimalValues, booleanValues, extendedValues) | ||
End Sub | ||
|
||
|
||
Public Overrides Function Execute() As Boolean | ||
Dim newFile As DownloadedFile = Nothing | ||
|
||
If Not m_TextValues.ContainsKey(App.KEY_FILE) Then | ||
m_smallIntValues(App.KEY_ERROR) = ERR_CONTEXT | ||
m_TextValues(App.KEY_RESULT) = String.Format("Unknown file name. Text variable '{0}' not set.", App.KEY_FILE) | ||
Return False | ||
End If | ||
|
||
Try | ||
Dim pName As String = m_TextValues(App.KEY_FILE) | ||
Dim pInfo As ProcessStartInfo | ||
Dim pOutput As String | ||
Dim p As Process | ||
|
||
If Not IO.Path.IsPathRooted(pName) Then | ||
pName = IO.Path.Combine(IO.Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly.Location), pName) | ||
End If | ||
pInfo = New ProcessStartInfo(pName) With {.UseShellExecute = False, .CreateNoWindow = True, .RedirectStandardOutput = True} | ||
If Not String.IsNullOrEmpty(m_TextValues(App.KEY_ARGUMENTS)) Then | ||
pInfo.Arguments = m_TextValues(App.KEY_ARGUMENTS) | ||
End If | ||
|
||
p = Process.Start(pInfo) | ||
pOutput = p.StandardOutput.ReadToEnd | ||
p.WaitForExit() | ||
|
||
m_TextValues(App.KEY_RESULT) = App.LimitResponse(pOutput) | ||
Catch ex As Exception | ||
m_smallIntValues(App.KEY_ERROR) = ERR_IO | ||
m_TextValues(App.KEY_RESULT) = String.Format("Error running process '{0}' - {1}.", m_TextValues(App.KEY_FILE), ex.Message) | ||
Return False | ||
End Try | ||
|
||
Return True | ||
End Function | ||
End Class |
Oops, something went wrong.