Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '7.2.18 - New function added to watch for system folder creation - DropBox support
- Private Sub logchange(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs)
- If e.ChangeType = IO.WatcherChangeTypes.Created Then
- DropBoxFolderActivity = e.FullPath
- FolderFound = True
- End If
- End Sub
- Private Function WaitForClickNDropResponse()
- Dim errorCode As Integer = 0
- Dim Watcher As New FileSystemWatcher()
- FolderFound = False
- SleepCounter = 0
- DropBoxFolderActivity = vbNullString
- With STATUSbox
- .BackColor = Color.Red
- .Text = "Waiting on DROPBOX..."
- .Refresh()
- End With
- Watcher.Path = DropBoxPath
- Watcher.NotifyFilter = NotifyFilters.DirectoryName
- AddHandler Watcher.Created, AddressOf OnChanged
- Watcher.EnableRaisingEvents = True
- Me.Cursor = Cursors.WaitCursor
- Application.DoEvents()
- 'Enable Folderwatcher to check to see if DropBox has returned our response file and get the path
- While FolderFound = False And SleepCounter < DropBoxTimeout
- If DropBoxFolderActivity <> vbNullString Then
- FolderFound = True
- With STATUSbox
- .BackColor = Color.SteelBlue
- .Text = "Folder Found... "
- .Refresh()
- End With
- Else
- With STATUSbox
- .BackColor = Color.Red
- .Text = "Waiting... " '& SleepCounter / 1000
- .Refresh()
- End With
- System.Threading.Thread.Sleep(1000)
- SleepCounter += 1000
- End If
- End While
- Watcher.EnableRaisingEvents = False
- Me.Cursor = Cursors.Default
- If FolderFound = True Then 'DropBox created a folder for us, let's get the .csv file name now;
- SleepCounter = 0
- ClickNDropFileName = Dir(DropBoxFolderActivity & "\*.csv")
- 'While ClickNDropFileName <> vbNullString And SleepCounter < CSVFileTimeout
- While SleepCounter < CSVFileTimeout
- If ClickNDropFileName <> vbNullString Then
- SleepCounter = CSVFileTimeout
- Else
- With STATUSbox
- .BackColor = Color.Red
- .Text = "Checking CSV... " '& SleepCounter / 1000
- .Refresh()
- End With
- System.Threading.Thread.Sleep(1000)
- SleepCounter += 1000
- ClickNDropFileName = Dir(DropBoxFolderActivity & "\*.csv")
- End If
- End While
- If ClickNDropFileName = "" Then
- errorCode += 1
- errorText += "Error: No DropBox .csv file exists in: " & DropBoxFolderActivity & vbCrLf & CSVFileTimeout / 1000 & " seconds were allotted to return a DropBox Results CSV file."
- Else
- 'there is a .csv file, lets get the tracking number;
- ClickNDropFileName = DropBoxFolderActivity & "\" & ClickNDropFileName & ""
- Dim ClickNDropCSVReader As New FileIO.TextFieldParser(ClickNDropFileName)
- ClickNDropCSVReader.TextFieldType = FileIO.FieldType.Delimited
- ClickNDropCSVReader.SetDelimiters(",")
- 'Lets try to read!
- Dim ReadCSV As String()
- Try
- ClickNDropCSVReader.ReadLine() 'read 1st line, move onto next line
- ReadCSV = ClickNDropCSVReader.ReadFields()
- 'Console.WriteLine(ReadCSV(5)) '2nd line, column 5 of return CSV contains Tracking code
- RMDetails = ReadCSV(5)
- RMFurtherDetails = " " 'This should be obsolete, but it appears CWDirect is absorbing this info;
- ShipmentResultTextbox.Text = RMDetails
- Catch ex As FileIO.MalformedLineException
- errorCode += 1
- errorText += "Line " & ex.Message & " is not valid and will be skipped."
- End Try
- ClickNDropCSVReader.Close()
- ClickNDropCSVReader.Dispose()
- End If
- Else
- errorCode += 1
- 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
- End If
- 'Quick order reference: 758447-1
- Watcher.Dispose()
- Return errorCode
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement