Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.82 KB | None | 0 0
  1. '7.2.18 - New function added to watch for system folder creation - DropBox support
  2. Private Sub logchange(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs)
  3.  
  4.  
  5. If e.ChangeType = IO.WatcherChangeTypes.Created Then
  6.  
  7. DropBoxFolderActivity = e.FullPath
  8.  
  9. FolderFound = True
  10.  
  11. End If
  12.  
  13. End Sub
  14.  
  15.  
  16.  
  17.  
  18. Private Function WaitForClickNDropResponse()
  19.  
  20. Dim errorCode As Integer = 0
  21. Dim Watcher As New FileSystemWatcher()
  22.  
  23. FolderFound = False
  24. SleepCounter = 0
  25. DropBoxFolderActivity = vbNullString
  26.  
  27. With STATUSbox
  28. .BackColor = Color.Red
  29. .Text = "Waiting on DROPBOX..."
  30. .Refresh()
  31. End With
  32.  
  33. Watcher.Path = DropBoxPath
  34. Watcher.NotifyFilter = NotifyFilters.DirectoryName
  35. AddHandler Watcher.Created, AddressOf OnChanged
  36.  
  37. Watcher.EnableRaisingEvents = True
  38. Me.Cursor = Cursors.WaitCursor
  39. Application.DoEvents()
  40.  
  41. 'Enable Folderwatcher to check to see if DropBox has returned our response file and get the path
  42. While FolderFound = False And SleepCounter < DropBoxTimeout
  43.  
  44. If DropBoxFolderActivity <> vbNullString Then
  45.  
  46. FolderFound = True
  47.  
  48. With STATUSbox
  49. .BackColor = Color.SteelBlue
  50. .Text = "Folder Found... "
  51. .Refresh()
  52. End With
  53.  
  54. Else
  55. With STATUSbox
  56. .BackColor = Color.Red
  57. .Text = "Waiting... " '& SleepCounter / 1000
  58. .Refresh()
  59. End With
  60.  
  61. System.Threading.Thread.Sleep(1000)
  62. SleepCounter += 1000
  63.  
  64. End If
  65.  
  66. End While
  67.  
  68. Watcher.EnableRaisingEvents = False
  69. Me.Cursor = Cursors.Default
  70.  
  71.  
  72. If FolderFound = True Then 'DropBox created a folder for us, let's get the .csv file name now;
  73.  
  74. SleepCounter = 0
  75. ClickNDropFileName = Dir(DropBoxFolderActivity & "\*.csv")
  76.  
  77. 'While ClickNDropFileName <> vbNullString And SleepCounter < CSVFileTimeout
  78. While SleepCounter < CSVFileTimeout
  79.  
  80. If ClickNDropFileName <> vbNullString Then
  81. SleepCounter = CSVFileTimeout
  82.  
  83. Else
  84.  
  85. With STATUSbox
  86. .BackColor = Color.Red
  87. .Text = "Checking CSV... " '& SleepCounter / 1000
  88. .Refresh()
  89. End With
  90.  
  91. System.Threading.Thread.Sleep(1000)
  92. SleepCounter += 1000
  93. ClickNDropFileName = Dir(DropBoxFolderActivity & "\*.csv")
  94.  
  95. End If
  96.  
  97. End While
  98.  
  99.  
  100. If ClickNDropFileName = "" Then
  101. errorCode += 1
  102. errorText += "Error: No DropBox .csv file exists in: " & DropBoxFolderActivity & vbCrLf & CSVFileTimeout / 1000 & " seconds were allotted to return a DropBox Results CSV file."
  103.  
  104. Else
  105. 'there is a .csv file, lets get the tracking number;
  106.  
  107. ClickNDropFileName = DropBoxFolderActivity & "\" & ClickNDropFileName & ""
  108.  
  109. Dim ClickNDropCSVReader As New FileIO.TextFieldParser(ClickNDropFileName)
  110. ClickNDropCSVReader.TextFieldType = FileIO.FieldType.Delimited
  111. ClickNDropCSVReader.SetDelimiters(",")
  112.  
  113. 'Lets try to read!
  114. Dim ReadCSV As String()
  115.  
  116. Try
  117. ClickNDropCSVReader.ReadLine() 'read 1st line, move onto next line
  118. ReadCSV = ClickNDropCSVReader.ReadFields()
  119. 'Console.WriteLine(ReadCSV(5)) '2nd line, column 5 of return CSV contains Tracking code
  120. RMDetails = ReadCSV(5)
  121. RMFurtherDetails = " " 'This should be obsolete, but it appears CWDirect is absorbing this info;
  122. ShipmentResultTextbox.Text = RMDetails
  123.  
  124. Catch ex As FileIO.MalformedLineException
  125. errorCode += 1
  126. errorText += "Line " & ex.Message & " is not valid and will be skipped."
  127. End Try
  128.  
  129. ClickNDropCSVReader.Close()
  130. ClickNDropCSVReader.Dispose()
  131.  
  132. End If
  133.  
  134. Else
  135. errorCode += 1
  136. errorText += "Error: DropBox folder not created! Exceeded the allotted amount of time to wait for a response for this shipment. " & vbCrLf & DropBoxTimeout / 1000 & " seconds were allocated to wait for DropBox to return a results folder." & vbCrLf
  137.  
  138. End If
  139.  
  140. 'Quick order reference: 758447-1
  141.  
  142.  
  143. Watcher.Dispose()
  144.  
  145. Return errorCode
  146.  
  147.  
  148. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement