Chrome DevTools SetTimeZoneOverRideCommand cannot change system time - vb.net

I have problem using Chrome DevTools SetTimeZoneOverrideCommand according to IP timezone.
But when I check in Whoer.net still shows is system time.
In here have 3 problem:
I using in selenium proxy is Rotate Proxy so is that posiible maintain same proxy by usin other function to check IP?
SetTimeZoneOverride cannot change spoof my system same as IP timezone time.
In Whoer.net is that possible change that DNS route
Imports System
Imports System.IO
Imports System.Text.RegularExpressions
Imports OpenQA.Selenium
Imports OpenQA.Selenium.Chrome
Imports Zu.ChromeDevTools
Module Program
Sub Main(args As String())
Console.WriteLine("Current IP: " & GetCurrentIP())
Dim browser_option As New ChromeOptions
Dim NewUAC As String = Random_UAC()
browser_option.AddArgument("user-agent=" & NewUAC)
browser_option.AddArgument("--window-size=800,600")
browser_option.AddArgument("--incognito")
browser_option.AddArgument("--disable-infobars")
browser_option.AddArgument("--disable-blink-features=AutomationControlled")
Dim Proxy As New Proxy With {
.Kind = ProxyKind.Manual,
.IsAutoDetect = False,
.HttpProxy = "p.webshare.io:9999",
.SslProxy = "p.webshare.io:9999"}
browser_option.Proxy = Proxy
Dim driverService = ChromeDriverService.CreateDefaultService
driverService.HideCommandPromptWindow = True
Dim browser As New ChromeDriver(driverService, browser_option)
browser.Navigate.GoToUrl("https://whoer.net")
Dim CurrentIP As String
Dim sHTML As String = browser.PageSource
CurrentIP = Mid(sHTML, sHTML.IndexOf("<strong data-clipboard-target=" & Chr(34) & ".your-ip" & Chr(34) & " class=" & Chr(34) & "your-ip" & Chr(34) & ">") + 59, 20)
CurrentIP = Regex.Match(CurrentIP, "\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b").ToString
Threading.Thread.Sleep(5000)
Console.WriteLine("Changed IP: " & CurrentIP)
Console.WriteLine("Current Loc: " & Get_TimeZone_GeoLocation(CurrentIP))
Dim CurrentGeo() As String
CurrentGeo = Get_TimeZone_GeoLocation(CurrentIP).Split(",")
Dim ChromeGeoLocation As New Zu.ChromeDevTools.Emulation.SetGeolocationOverrideCommand
ChromeGeoLocation.Latitude = CurrentGeo(0)
ChromeGeoLocation.Longitude = CurrentGeo(1)
ChromeGeoLocation.Accuracy = 1
Dim ChromeTimeZone As New Zu.ChromeDevTools.Emulation.SetTimezoneOverrideCommand
ChromeTimeZone.TimezoneId = CurrentGeo(2)
browser.Navigate.GoToUrl("https://whoer.net")
End Sub
Function GetCurrentIP() As String
Dim DetectAddress As String = "https://whoer.net"
Dim CurrentIP As String
Dim objHttpRequest As System.Net.HttpWebRequest
Dim objHttpResponse As System.Net.HttpWebResponse
Dim objProxy As New System.Net.WebProxy
objHttpRequest = System.Net.HttpWebRequest.Create(DetectAddress)
objHttpResponse = objHttpRequest.GetResponse
Dim objStrmReader As New StreamReader(objHttpResponse.GetResponseStream)
Dim sHTML As String
sHTML = objStrmReader.ReadToEnd()
CurrentIP = Mid(sHTML, sHTML.IndexOf("<strong data-clipboard-target=" & Chr(34) & ".your-ip" & Chr(34) & " class=" & Chr(34) & "your-ip" & Chr(34) & ">") + 59, 20)
CurrentIP = Regex.Match(CurrentIP, "\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b").ToString
Return CurrentIP
End Function
Function Get_TimeZone_GeoLocation(ByVal CurrentIP As String) As String
Dim DetectAddress As String = "http://ip-api.com/csv/" & CurrentIP
Dim CurrentLocation As String
Dim objHttpRequest As System.Net.HttpWebRequest
Dim objHttpResponse As System.Net.HttpWebResponse
objHttpRequest = System.Net.HttpWebRequest.Create(DetectAddress)
objHttpResponse = objHttpRequest.GetResponse
Dim objStrmReader As New StreamReader(objHttpResponse.GetResponseStream)
Dim sHTML As String
sHTML = objStrmReader.ReadToEnd()
Dim sHTML_Item() As String
sHTML_Item = sHTML.Split(",")
CurrentLocation = sHTML_Item.Length
Dim latitude, longitude, timezone As String
latitude = sHTML_Item(7)
longitude = sHTML_Item(8)
timezone = sHTML_Item(9)
CurrentLocation = latitude & "," & longitude & "," & timezone
Return CurrentLocation
End Function
Function Random_UAC() As String
Dim strUACs As String = IO.File.ReadAllText("UAC_List.txt")
Dim strUAC_Split As String()
strUAC_Split = strUACs.Split(vbCrLf)
Dim n As Integer = strUAC_Split.Length
Dim RandomUAC As Integer
RandomUAC = Math.Ceiling(Rnd() * n) - 1
'Console.WriteLine(RandomUAC & " - " & strUAC_Split(RandomUAC))
Return strUAC_Split(RandomUAC)
End Function
End Module

Related

how to add filters on vb HttpWebRequest

This code, is working perfectly (getting data with web request) :
Protected Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim oauth_token = "8e269b44b2d7d73eb0b46112af5f4xxx"
Dim oauth_token_secret = "80da1edadcba1e66e47d2e20f075cxxx"
Dim oauth_consumer_key = "3626311748bcf2072da2bd475fccfxxx"
Dim oauth_consumer_secret = "0cbb0df8d840e22b96d4f80449e7exxx"
Dim oauth_version = "1.0"
Dim oauth_signature_method = "HMAC-SHA1"
Dim oauth_nonce = Convert.ToBase64String(New ASCIIEncoding().GetBytes(DateTime.Now.Ticks.ToString()))
Dim timeSpan = DateTime.UtcNow - New DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)
Dim oauth_timestamp = Convert.ToInt64(timeSpan.TotalSeconds).ToString()
Dim resource_url = "http://www.inart.com/api/rest/products/store/1"
Dim baseFormat = "oauth_consumer_key={0}&oauth_nonce={1}&oauth_signature_method={2}" + "&oauth_timestamp={3}&oauth_token={4}&oauth_version={5}"
Dim baseString = String.Format(baseFormat, oauth_consumer_key, oauth_nonce, oauth_signature_method, oauth_timestamp, oauth_token, oauth_version)
baseString = String.Concat("GET&", Uri.EscapeDataString(resource_url), "&", Uri.EscapeDataString(baseString))
Dim compositeKey = String.Concat(Uri.EscapeDataString(oauth_consumer_secret), "&", Uri.EscapeDataString(oauth_token_secret))
Dim oauth_signature As String
Using hasher As New HMACSHA1(ASCIIEncoding.ASCII.GetBytes(compositeKey))
oauth_signature = Convert.ToBase64String(hasher.ComputeHash(ASCIIEncoding.ASCII.GetBytes(baseString)))
End Using
Dim headerFormat = "OAuth oauth_nonce=""{0}"", oauth_signature_method=""{1}"", " + "oauth_timestamp=""{2}"", oauth_consumer_key=""{3}"",
" + "oauth_token=""{4}"", oauth_signature=""{5}"", " + "oauth_version=""{6}"""
Dim authHeader = String.Format(headerFormat, Uri.EscapeDataString(oauth_nonce), Uri.EscapeDataString(oauth_signature_method), Uri.EscapeDataString(oauth_timestamp),
Uri.EscapeDataString(oauth_consumer_key), Uri.EscapeDataString(oauth_token), Uri.EscapeDataString(oauth_signature), Uri.EscapeDataString(oauth_version))
ServicePointManager.Expect100Continue = True
Dim request As HttpWebRequest = DirectCast(WebRequest.Create(resource_url), HttpWebRequest)
request.Headers.Add("Authorization", authHeader)
request.Method = "GET"
request.ContentType = "application/json"
request.Accept = "application/json"
Try
Dim response As WebResponse = request.GetResponse()
Dim datastream As Stream = response.GetResponseStream
Dim reader As StreamReader = New StreamReader(datastream)
Dim responsefromserver As String = reader.ReadToEnd
If responsefromserver = Nothing Then
TextBox1.Text = "No response from server"
Else
Dim json As String = responsefromserver
Dim ser As JObject = JObject.Parse(json)
Dim data As List(Of JToken) = ser.Children().ToList
Dim output As String = ""
Dim successReq As Boolean = False
Dim avDom As String = ""
Dim counter As Integer = 0
For Each item As JProperty In data
item.CreateReader()
output += "|-" & item.Name.ToString & " : " & item.Value.ToString & "-"
output += Environment.NewLine
counter += 1
Next
TextBox1.Text = output
TextBox1.Text += Environment.NewLine + counter.ToString
reader.Close()
response.Close()
End If
Catch ex As Exception
TextBox1.Text = ex.Message.ToString
End Try
End Sub
When i try to add some filters, it fails. for example, I try to add the limit filter this way : Dim resource_url = "http://www.inart.com/api/rest/products/store/1?limit=1".
I am sure that the filter is ok because i tried at postman application and it is working! see print screen
What should I change or add?
Thank you.
Dim url As String = "http://www.inart.com/api/rest/products/store/1?limit=1&page=2"
Dim oauthconsumerkey As String = "3626311748bcf2072da2bd475fccssss"
Dim oauthconsumersecret As String = "0cbb0df8d840e22b96d4f80449sssss"
Dim oauthtoken As String = "8e269b44b2d7d73essss2af5f454e"
Dim oauthtokensecret As String = "80da1edadcba1e66e47d2e2sssss"
Dim oauthsignaturemethod As String = "HMAC-SHA1"
Dim oauthversion As String = "1.0"
Dim oauthnonce As String = Convert.ToBase64String(New ASCIIEncoding().GetBytes(DateTime.Now.Ticks.ToString()))
Dim timeSpan As TimeSpan = DateTime.UtcNow - New DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)
Dim oauthtimestamp As String = Convert.ToInt64(timeSpan.TotalSeconds).ToString()
Dim basestringParameters As SortedDictionary(Of String, String) = New SortedDictionary(Of String, String)()
basestringParameters.Add("limit", "1")
basestringParameters.Add("page", "2")
basestringParameters.Add("oauth_version", oauthversion)
basestringParameters.Add("oauth_consumer_key", oauthconsumerkey)
basestringParameters.Add("oauth_nonce", oauthnonce)
basestringParameters.Add("oauth_signature_method", oauthsignaturemethod)
basestringParameters.Add("oauth_timestamp", oauthtimestamp)
basestringParameters.Add("oauth_token", oauthtoken)
Dim baseString As StringBuilder = New StringBuilder()
baseString.Append("GET" & "&")
baseString.Append(EncodeCharacters(Uri.EscapeDataString(url.Split("?"c)(0)) & "&"))
For Each entry As KeyValuePair(Of String, String) In basestringParameters
baseString.Append(EncodeCharacters(Uri.EscapeDataString(entry.Key & "=" + entry.Value & "&")))
Next
Dim finalBaseString As String = baseString.ToString().Substring(0, baseString.Length - 3)
Dim signingKey As String = EncodeCharacters(Uri.EscapeDataString(oauthconsumersecret)) & "&" + EncodeCharacters(Uri.EscapeDataString(oauthtokensecret))
Dim hasher As HMACSHA1 = New HMACSHA1(New ASCIIEncoding().GetBytes(signingKey))
Dim oauthsignature As String = Convert.ToBase64String(hasher.ComputeHash(New ASCIIEncoding().GetBytes(finalBaseString)))
ServicePointManager.Expect100Continue = False
Dim wRequest As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
Dim authorizationHeaderParams As StringBuilder = New StringBuilder()
authorizationHeaderParams.Append("OAuth ")
authorizationHeaderParams.Append("oauth_nonce=" & """" + Uri.EscapeDataString(oauthnonce) & """,")
authorizationHeaderParams.Append("oauth_signature_method=" & """" + Uri.EscapeDataString(oauthsignaturemethod) & """,")
authorizationHeaderParams.Append("oauth_timestamp=" & """" + Uri.EscapeDataString(oauthtimestamp) & """,")
authorizationHeaderParams.Append("oauth_consumer_key=" & """" + Uri.EscapeDataString(oauthconsumerkey) & """,")
If Not String.IsNullOrEmpty(oauthtoken) Then authorizationHeaderParams.Append("oauth_token=" & """" + Uri.EscapeDataString(oauthtoken) & """,")
authorizationHeaderParams.Append("oauth_signature=" & """" + Uri.EscapeDataString(oauthsignature) & """,")
authorizationHeaderParams.Append("oauth_version=" & """" + Uri.EscapeDataString(oauthversion) & """")
wRequest.Headers.Add("Authorization", authorizationHeaderParams.ToString)
wRequest.Method = "GET"
wRequest.ContentType = "application/json"
wRequest.Accept = "application/json"
Try
Dim wResponse As WebResponse = wRequest.GetResponse()
Dim dataStream As Stream = wResponse.GetResponseStream()
Dim reader As StreamReader = New StreamReader(dataStream)
Dim responseFromServer As String = reader.ReadToEnd()
If responseFromServer = Nothing Then
TextBox1.Text = "No response from server"
Else
Dim json As String = responseFromServer
Dim ser As JObject = JObject.Parse(json)
Dim data As List(Of JToken) = ser.Children().ToList
Dim output As String = ""
Dim successReq As Boolean = False
Dim avDom As String = ""
For Each item As JProperty In data
item.CreateReader()
output += "|-" & item.Name.ToString & " : " & item.Value.ToString & "-"
output += Environment.NewLine
Next
TextBox1.Text = output
End If
Catch ex As Exception
TextBox1.Text = ex.Message.ToString
End Try
Private Function EncodeCharacters(ByVal data As String) As String
If data.Contains("!") Then data = data.Replace("!", "%21")
If data.Contains("'") Then data = data.Replace("'", "%27")
If data.Contains("(") Then data = data.Replace("(", "%28")
If data.Contains(")") Then data = data.Replace(")", "%29")
If data.Contains("*") Then data = data.Replace("*", "%2A")
If data.Contains(",") Then data = data.Replace(",", "%2C")
Return data
End Function
This example is working

Why can't my GetManifestResourceStream find my image?

I'm currently attempting to layer several images into a single composite, built from several body face pieces for a player's portrait.
Usually for grabbing images from the resources and putting them into a picturebox/etc I'd simply ".Image = My.Resources.ResourceManager.GetObject(filename)".
However I need to transfer to a Bitmap, which doesn't accept objects. I've found the below code from a couple of google results, but the file is bugging out as "Value of null is not valid for 'stream' ", and the pHead is "Nothing". As such I'm presuming the code can't find the file.
The break is causing on the final line of the below code.
Any help or simpler alternatives would be much welcome.
Dim GenderText As String = ""
Select Case ListCharacter(ActiveChar).Gender
Case eGender.Male : GenderText = "masc"
Case eGender.Female : GenderText = "fem"
End Select
Dim Prefix As String = ""
Dim Suffix As String = ".png"
Dim myAsm As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()
' Load Head Image
' e.g. prt_fem_head_1_white.png
Dim headImageName As String = "prt_" & GenderText & "_head_" & CharApp.HeadStyle & "_" & CharApp.SkinColour
Dim pHead As Bitmap = New Bitmap(myAsm.GetManifestResourceStream(Me.GetType, headImageName & Suffix))
ps. Also bugs out with/without the suffix.
Edit #1;
I've found the prefix required, as far as I can tell, to the whereabouts of the resources root. However, that still isn't working to any variation.
Edit #2;
I've double checked the resource location via its properties.
"C:\Users\CLEO\Documents\Visual Studio 2015\Projects\Storytime\Storytime\Resources\prt_fem_head_1_white.png"
Solved. I changed the code out for a simpler one I found in my Resources Designer code. The below is very raw and needs tidying, but this is how I was able to make several images build into one picturebox.
' Load Face
Dim PortraitLocation As New Point(573, 51)
Dim CharApp As New Character.cAppearance : CharApp = ListCharacter(ActiveChar).Appearance
' Dim pHead, pEyes, pNose, pMouth, pBase, pHair As New PictureBox
Dim FaceCanvas As New PictureBox
Dim GenderText As String = ""
Select Case ListCharacter(ActiveChar).Gender
Case eGender.Male : GenderText = "masc"
Case eGender.Female : GenderText = "fem"
End Select
Dim resourceCulture As Global.System.Globalization.CultureInfo
Dim headImageName As String = "prt_" & GenderText & "_head_" & CharApp.HeadStyle & "_" & CharApp.SkinColour
Dim obj As Object = My.Resources.ResourceManager.GetObject(headImageName, resourceCulture)
Dim phead As Bitmap = CType(obj, System.Drawing.Bitmap)
Dim eyesImageName As String = "prt_" & GenderText & "_eyes_" & CharApp.EyeStyle & "_" & CharApp.SkinColour
Dim obj2 As Object = My.Resources.ResourceManager.GetObject(eyesImageName, resourceCulture)
Dim pEyes As Bitmap = CType(obj2, System.Drawing.Bitmap)
Dim noseImageName As String = "prt_" & GenderText & "_nose_" & CharApp.NoseStyle & "_" & CharApp.SkinColour
Dim obj3 As Object = My.Resources.ResourceManager.GetObject(noseImageName, resourceCulture)
Dim pNose As Bitmap = CType(obj3, System.Drawing.Bitmap)
Dim mouthImageName As String = "prt_" & GenderText & "_mouth_" & CharApp.MouthStyle & "_" & CharApp.SkinColour
Dim obj4 As Object = My.Resources.ResourceManager.GetObject(mouthImageName, resourceCulture)
Dim pMouth As Bitmap = CType(obj4, System.Drawing.Bitmap)
Dim hairImageName As String = "prt_" & GenderText & "_hair_" & CharApp.HairStyle & "_" & CharApp.HairColour
Dim obj5 As Object = My.Resources.ResourceManager.GetObject(hairImageName, resourceCulture)
Dim pHair As Bitmap = CType(obj5, System.Drawing.Bitmap)
Dim bodyImageName As String = "prt_" & GenderText & "_body_" & CharApp.SkinColour
Dim obj6 As Object = My.Resources.ResourceManager.GetObject(bodyImageName, resourceCulture)
Dim pBody As Bitmap = CType(obj6, System.Drawing.Bitmap)
Dim g As Graphics = Graphics.FromImage(pBody)
g.DrawImage(phead, 0, 0)
g.DrawImage(pEyes, 0, 0)
g.DrawImage(pNose, 0, 0)
g.DrawImage(pMouth, 0, 0)
g.DrawImage(pHair, 0, 0)
With FaceCanvas
.Location = PortraitLocation
.Size = New Size(50, 50)
.Image = pBody
.BackColor = Color.Transparent
End With
Me.Controls.Add(FaceCanvas)

Crystal Reports Missing Parameter Values

I am running the version of crystal that comes with Visual Studio 2010. I have a report that has three sub reports. There are parameters that are passed from the main report to the sub-reports. I am able to run the report in the development environment by clicking on Main Report Preview.
The problem is when I try to execute it at run time. I get the error “Missing parameter values”. I need some hints as to how to debug this problem. The error doesn’t tell you which parameter is the problem or which sub-report is involved.
Any hint will be appreciated.
I am editing this to respond to some of the questions. I am using subreports links which is where I think the problem might be. In the pass by fiddling with the settings I was able to get it to work. It seems like it was just trial and error.
I am posting a portion of the code here based on the request in the comments
Public Function GetReportOutput(iDatabaseIndicator As eDatabaseIndicatorEnum, ReportName As String, ReportOutputtype As eReportOutputtype, ReportParameters As System.Collections.Generic.List(Of clsReportParam)) As clsReturn Implements IsvcEDReports.GetReportOutput
Dim l_crRep As New CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim l_clsReturn As clsReturn = New clsReturn
Dim l_ExportFormatType As ExportFormatType
Dim l_strReport As String = ""
Dim l_strReportName As String = ""
Dim l_strOutputFile As String = ""
Dim l_strFullPathName As String = ""
Dim l_strReportOutputPath As String = ConfigurationManager.AppSettings.Get(IIf(ConfigurationManager.AppSettings.Get("Environment") = 1, "ReportOutputPath_Dev", "ReportOutputPath_Prod"))
Dim l_strReportPath As String = ConfigurationManager.AppSettings.Get(IIf(ConfigurationManager.AppSettings.Get("Environment") = 1, "ReportPath_Dev", "ReportPath_Prod"))
Dim l_udtReport As CrystalDecisions.CrystalReports.Engine.ReportDocument = Nothing
Dim l_intCount As Integer = 0
Dim l_fsReturn As FileStream = Nothing
Dim l_binFilestream As BinaryReader = Nothing
Dim l_bytFile As Byte() = Nothing
Dim l_expOptions As New CrystalDecisions.Shared.ExportOptions
Dim l_expExcFmtOptions As New CrystalDecisions.Shared.ExcelFormatOptions
Dim l_tblParameters As New DataTable("Parameters")
Dim l_aryParams(1)
Dim udtSubReport As ReportDocument
Dim udtSubReportOpened As ReportDocument
Try
iDatabaseIndicator = iDatabaseIndicator
InitDataController(iDatabaseIndicator)
m_strReport = (l_strReportPath & "\" & ReportName)
l_strReportName = ReportName
l_strReport = m_strReport
l_strOutputFile = Regex.Replace(ReportName, " ", "_") & "_" & Format(Now(), "MMddyyyy_hhmmss")
m_strOutputFilename = l_strOutputFile
With l_crRep
.Load(l_strReport, CrystalDecisions.Shared.OpenReportMethod.OpenReportByDefault)
If .IsLoaded Then
For Each udtSubReport In .Subreports
udtSubReportOpened = .OpenSubreport(udtSubReport.Name)
SetDatabase(udtSubReportOpened, False)
SetParameters(udtSubReportOpened, ReportParameters, False)
Next
SetDatabase(l_crRep)
SetParameters(l_crRep, ReportParameters)
Select Case ReportOutputtype
'Case eReportOutputtype.rptOutputType_RPT
' l_strOutputFile = l_strOutputFile & ".rpt"
' l_ExportFormatType = ExportFormatType.CrystalReport
Case eReportOutputtype.rptOutputType_XLS
l_strOutputFile = l_strOutputFile & ".xls"
'ReportOutputFile = ReportOutputFile & ".xls"
With l_expExcFmtOptions
.ExcelConstantColumnWidth = 125
.ExcelUseConstantColumnWidth = True
End With
With l_expOptions
.ExportFormatOptions = l_expExcFmtOptions
End With
l_ExportFormatType = ExportFormatType.Excel
Case eReportOutputtype.rptOutputType_PDF
l_strOutputFile = l_strOutputFile & ".pdf"
' ReportOutputFile = ReportOutputFile & ".pdf"
l_ExportFormatType = ExportFormatType.PortableDocFormat
Case eReportOutputtype.rptOutputType_DOC
l_strOutputFile = l_strOutputFile & ".doc"
' ReportOutputFile = ReportOutputFile & ".doc"
l_ExportFormatType = ExportFormatType.WordForWindows
Case eReportOutputtype.rptOutputType_CSV
l_strOutputFile = l_strOutputFile & ".csv"
' ReportOutputFile = ReportOutputFile & ".csv"
l_ExportFormatType = ExportFormatType.CharacterSeparatedValues
Case eReportOutputtype.rptOutputType_TXT
l_strOutputFile = l_strOutputFile & ".txt"
' ReportOutputFile = ReportOutputFile & ".txt"
l_ExportFormatType = ExportFormatType.Text
Case eReportOutputtype.rptOutputType_XML
l_strOutputFile = l_strOutputFile & ".xml"
' ReportOutputFile = ReportOutputFile & ".xml"
l_ExportFormatType = ExportFormatType.Xml
End Select
.ExportToDisk(l_ExportFormatType, l_strReportOutputPath & "\" & l_strOutputFile)
It crashes on the last line .ExportToDisk ...
I solved this problem, It was the hint from heringer that gave me the clue. I am passing 6 parameters to the main report but two of them are only used by the a sub-report not the main reports itself. I was defining these without the leading "#". I figured this out by display the parameters as I passed them in my code.
I was also able to look at an old report that was working and saw that I needed the at signs.
Bob

Poll a directory looking for files with a certain extension

I'm writing a script to look in a directory, read the file name and use a part of the file name to run a SQL query to amend a DB, then copy the files to a new location and delete the original.
Once this is done it sends an email confirmation to a predefined email address.
I have the majority in place but am not able to Poll a Dir and process all files that may be there. Im new to this VB.net stuff and to get the other stuff working iv just named it at the beginning.
Any help would be greatly appreciated.
Dim fileName As String = "C:\temp\Input\VBTEST1.success"
Dim pathname As String = "C:\temp\Input\"
Dim result As String
Dim sourceDir As String = "C:\temp\Input\"
Dim processedDir As String = "C:\temp\Input\Processed\"
Dim fList As String() = Directory.GetFiles(sourceDir, "*.success")
Dim sqlCommand As SqlCommand
Public Sub Main()
result = Path.GetFileName(fileName)
Console.WriteLine("GetFileName('{0}') returns '{1}'", fileName, result)
Dim betacell As String = result
betacell = (result.Remove(7, 8))
Dim connection As New SqlConnection(My.Settings.connectionString)
connection.Open()
Dim updateTransaction As SqlTransaction = connection.BeginTransaction()
Dim sqlQ As String = "UPDATE " & My.Settings.JobTb & " SET Status = '10' WHERE JobNumber ='" & betacell & "'"
sqlCommand = New SqlCommand(sqlQ, connection, updateTransaction)
sqlCommand.ExecuteNonQuery()
updateTransaction.Commit()
connection.Close()
SendEmail(My.Settings.emailUsers, "EMAIL TEXT")
Call MoveFiles()
End Sub
I'm all chuffed now as iv also managed to make it look for all files with a .success extension. Now it processes all files and not the one named in the code.
Module Module1
Dim sourceDir As String = My.Settings.watchPath
Dim processedDir As String = My.Settings.processedPath
Private loggerName As String = "EmailReleases"
Public Sub log(ex As Exception)
Console.WriteLine("Error: " & ex.ToString)
End Sub
Public Sub log(ByVal s As String)
Console.WriteLine(DateTime.Now.ToString & " [" & loggerName & "] " & s)
End Sub
Public Sub Main()
Dim inputFiles As String() = Directory.GetFiles(sourceDir, "*.success")
log("Starting processing of .success files in '" & sourceDir & "' ... ")
If (inputFiles.Length > 0) Then
Dim connection As New SqlConnection(My.Settings.connectionString)
connection.Open()
For Each fileName As String In inputFiles
Dim sqlCommand As SqlCommand
Dim fFile As New FileInfo(fileName)
log(" Processing " & fFile.Name)
Dim betacell As String = fFile.Name.Substring(0, fFile.Name.Length - 8)
'Update Status on Database with the use of the Betacell
Dim updateTransaction As SqlTransaction = connection.BeginTransaction()
Dim sqlQ As String = "UPDATE " & My.Settings.JobTb & " SET Status = '10' WHERE JobNumber ='" & betacell & "'"
sqlCommand = New SqlCommand(sqlQ, connection, updateTransaction)
Dim result = sqlCommand.ExecuteNonQuery()
'Email COnfirmation
SendEmail(My.Settings.emailUsers, "EMAIL TEXT")
If (result > 0) Then
'Move the file
fFile.MoveTo(processedDir & fFile.Name)
updateTransaction.Commit() ' make sure to commit only in case moving the file is OK
Else
log("ERROR - Betacell '" & betacell & "' not found in database!")
updateTransaction.Rollback()
End If
Rather than polling a folder (i.e. checking every n seconds whether it has new files) it's much more efficient to have the operating system notify you of changes in that folder. You can do this by creating a FileSystemWatcher. There is an example on MSDN.
However, if you did want to poll a folder, it's actually nice and easy - just wrap the following code in a Timer. Please note I normally code in C#, so apologies if the syntax is not 100%...
Imports System.IO
....
For Each file as String in Directory.GetFiles("C:\SomeFolder")
DoSomethingWithFile (file)
Next

Visual basic and modules

Im writing a application in visual basic to tell the user about their pc.
All this is in a module
Imports Microsoft.VisualBasic.Devices
Imports System.Management
Imports System.Net
Imports System.IO
Imports System.Windows.Forms
Imports System.Deployment.Application
Module ComputerSpecModule
Public Enum infotypes
ProcesserName
VideocardName
VideocardMem
End Enum
Public Function getinfo(ByVal infotype As infotypes) As String
Dim info As New ComputerInfo : Dim value, vganame, vgamem, proc As String
Dim searcher As New Management.ManagementObjectSearcher( _
"root\CIMV2", "Select * FROM Win32_VideoController")
Dim searcher1 As New Management.ManagementObjectSearcher( _
"Select * FROM Win32_Processor")
If infotype = infotypes.ProcesserName Then
For Each queryObject As ManagementObject In searcher1.Get
proc = queryObject.GetPropertyValue("Name").ToString
Next
value = proc
ElseIf infotype = infotypes.VideocardName Then
For Each queryObject As ManagementObject In searcher.Get
vganame = queryObject.GetPropertyValue("Name").ToString
Next
value = vganame
ElseIf infotype = infotypes.VideocardMem Then
For Each queryObject As ManagementObject In searcher.Get
vgamem = queryObject.GetPropertyValue("AdapterRAM").ToString
Next
value = Math.Round((((CDbl(Convert.ToDouble(Val(vgamem))) / 1024)) / 1024), 2) & " MB"
End If
Return value
End Function
Public oAddr As System.Net.IPAddress 'gets the ipv4 add
Public sAddr As String
Public EmailStarterMessage As String = "This message was sent by SpecMee. SpecMee is a light weight application designed to allow the users to find out the specifications of their machines. Please download this application free at http://www.wilson18.com/projects/SpecMee/" + _
Environment.NewLine + _
"" + _
Environment.NewLine + _
"" + _
Environment.NewLine + _
""
'PC SPEC CONTENT
Public ComputerName As String = (My.Computer.Name.ToString)
Public myOS As String = (My.Computer.Info.OSFullName)
Public Processor As String = (getinfo(infotypes.ProcesserName))
Public HDD As String = (Format((My.Computer.FileSystem.Drives.Item(0).TotalSize.ToString / 1024) / 1024 / 1024, "###,###,##0 GB"))
Public RAM As String = (Format((My.Computer.Info.TotalPhysicalMemory / 1024) / 1024 / 1024, "###,###,##0 GB"))
Public VideoCard As String = (getinfo(infotypes.VideocardName))
Public VideoCardMemory As String = (getinfo(infotypes.VideocardMem))
Public Function Resolution() As String
Dim intx As Integer = Screen.PrimaryScreen.Bounds.Width
Dim inty As Integer = Screen.PrimaryScreen.Bounds.Height
Return intx & " x " & inty
End Function
Public Function InternalIPAddress()
With System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName())
oAddr = New System.Net.IPAddress(.AddressList(0).Address)
InternalIPAddress = oAddr.ToString
End With
End Function
Public Function ExternalIPAddress() As String
Dim uri_val As New Uri("http://www.wilson18.com/projects/SpecMee/curip.php")
Dim request As HttpWebRequest = HttpWebRequest.Create(uri_val)
request.Method = WebRequestMethods.Http.Get
Dim response As HttpWebResponse = request.GetResponse()
Dim reader As New StreamReader(response.GetResponseStream())
Dim myip As String = reader.ReadToEnd()
response.Close()
Return myip
End Function
Public EmailContent As String = ("Computer Name: " & ComputerName & Environment.NewLine & "Operating System: " & myOS & Environment.NewLine & "Processor: " & Processor & Environment.NewLine & "Hard Drive Size : " & HDD & Environment.NewLine & "RAM: " & RAM & Environment.NewLine & "Graphics Card: " & VideoCard & Environment.NewLine & "Graphics Onboard Memory: " & VideoCardMemory & Environment.NewLine & "Resolution: " & Resolution() & Environment.NewLine & "Internal IP Address: " & InternalIPAddress() & Environment.NewLine & "External IP Address: " & ExternalIPAddress() & Environment.NewLine)
End Module
The problem I am having is that if one of the things in the module fails such as if the users graphics card does not have any onboard memory then it will fail.This is causing everything else to fail aswell...
I am very new to visual basic so ifyou could please excuse me if I have made any stupidly obvious errors and any suggestions are welcome
Thanks in advance.
Place the parts that can fail in a Try-Catch-statement
Public VideoCardMemory As String = getinfo(infotypes.VideocardMem)
Public Function getinfo(ByVal infotype As infotypes) As String
Try
...
value = ...
...
Catch
value = "Cannot be accessed!"
End Try
Return value
End Function