Page 2 of 2

Re: Converting from HTML output to GridView

Posted: Tue Jan 13, 2015 12:21 pm
by jvierra
You are using V2 setting. PsCustomObject will not work with V2. Switch to V3 or V4.

Re: Converting from HTML output to GridView

Posted: Tue Jan 13, 2015 12:34 pm
by cstewart28
I'm trying to change it, but the only option I have from the Platform drop down is V2 - 32 Bit and V2 - 64 Bit.

Re: Converting from HTML output to GridView

Posted: Tue Jan 13, 2015 12:39 pm
by jvierra
Don't you have V3/4 installed? Download and install it from MS.

Re: Converting from HTML output to GridView

Posted: Tue Jan 13, 2015 12:42 pm
by cstewart28
V4

Re: Converting from HTML output to GridView

Posted: Tue Jan 13, 2015 12:54 pm
by jvierra
Post in CS forum for PS 2014. There is a fix for that but I do not remember what it is.

Re: Converting from HTML output to GridView

Posted: Tue Jan 13, 2015 9:28 pm
by cstewart28
I think I have added the progressbar correctly, but now I'm trying to get the rows high lighted based on a value returned from the function and what I found does not seem to work.

Here is the function:

Code: Select all

# utility function to get camera data
function Get-CameraData
{
	Param ($csvfile)
		Import-Csv $csvfile |
		ForEach-Object{
		$progressbaroverlay1.Maximum = $csvfile.count
		$item = $_
		Try
		{
			$timetaken = (Measure-Command { $Request = Invoke-WebRequest -Uri $item.ip }).TotalMilliseconds
			$progressbaroverlay1.PerformStep()
			
		}
		Catch
		{
			$Request = [PsCustomObject]@{
				StatusDescription = $_.Exception.Response
				RawContentLength = 0
				StatusCode = -1
			}
			$timetaken = -1
		}
		[PSCustomObject]@{
			#Time = [datetime]::Now
			Name = $item.name
			Uri = $item.ip
			StatusCode = $Request.StatusCode
			StatusDescription = $Request.StatusDescription
			ResponseLength = $Request.RawContentLength
			TimeTaken = $timetaken
		}
	}
}

here is the Button:

Code: Select all

$buttonCheckCameras_Click = {
	$progressbaroverlay1.TextOverlay = 'Checking Camera...'
	$progressbaroverlay1.Value = 0
	$progressbaroverlay1.Step = 1
	$this.enabled = $false
	$cameradata = Get-CameraData $CSVFileName.Text
	$array = [System.Collections.ArrayList]$cameradata
	#$datagridview.DataSource = [System.Collections.ArrayList]$cameradata
	$dataGridView.ColumnCount = 6
	$dataGridView.ColumnHeadersVisible = $true
	$dataGridView.Columns[0].Name = "Name"
	$dataGridView.Columns[1].Name = "IP Address"
	$dataGridView.Columns[2].Name = "Status Code"
	$dataGridView.Columns[3].Name = "Description"
	$dataGridView.Columns[4].Name = "Web Response Length"
	$dataGridView.Columns[5].Name = "Time Taken(ms)"
	foreach ($item in $array)
	{
		#check if status code is not eqal to 200, which means we can't connect
		#statusCode is 3rd item in attay
		if ($item[2] -ne "200")
		{
			#write data to datagridview
			$datagridview.Rows.Add($_.name,$_.uri,$_.StatusCode,$_.StatusDescription,$_.ResponseLength,$_.TimeTaken)		
			#make the row all red
			$datagridviewResults_CellFormatting = [System.Windows.Forms.DataGridViewCellFormattingEventHandler]{
				$_.CellStyle.BackColor = 'Red'
			}
		}
		
		else
		{
			#write data to datagridview
			$datagridview.Rows.Add($_.name, $_.uri, $_.StatusCode, $_.StatusDescription, $_.ResponseLength, $_.TimeTaken)
			#make the row all green
			$datagridviewResults_CellFormatting = [System.Windows.Forms.DataGridViewCellFormattingEventHandler]{
				$_.CellStyle.BackColor = 'Green'
			}
		}
		
	}
	
	$progressbaroverlay1.Value = $progressbaroverlay1.Maximum
	$progressbaroverlay1.TextOverlay = 'Complete!'
	$this.enabled = $true
Also it takes about 30 seconds to return the data and it seems to be all at one, not per line, any ideas on how I can do that with the individually or does it make more since to do it all at once?

Thanks again this is my first attempt at this.

Re: Converting from HTML output to GridView

Posted: Tue Jan 13, 2015 11:27 pm
by jvierra
Start by loading th gris with all data from the CSV plus extra columns for status. Enumerate the grid and test, update progrss and color.

Your approach is lniear and overly complicated. If you simplify things you will find it is easir to do all of this.

I havebeen designing andbuilding Windows based applicaitons for 20+ years. Believe me it should notbethis hard.

THe grid is anexcellent place to start. It is an array of sorts and is a repository for data. Learn how to load it from an object collection or from a CSV file. Enumerate the grid to perform tasks and mark status.

Re: Converting from HTML output to GridView

Posted: Tue Jan 13, 2015 11:29 pm
by jvierra
cstewart28 wrote: Also it takes about 30 seconds to return the data and it seems to be all at one, not per line, any ideas on how I can do that with the individually or does it make more since to do it all at once?

.
In an event the system is never updated until the event is exited. THe best way to do thisis to use a background job that enumerates the grid and returns incremental results.

Look into the "Job-Tracker" Control Set to help with this.

Re: Converting from HTML output to GridView

Posted: Tue Jan 13, 2015 11:32 pm
by jvierra
cstewart28 wrote:I think I have added the progressbar correctly, but now I'm trying to get the rows high lighted based on a value returned from the function and what I found does not seem to work.
TO update teh format of a row use the row changed event to set teh color or other attirbutes when the row is changed. This allows the form to run in a pure event driven fashion.

Widows and Forms do not work well whenyou use linear programming techniques. Windows is a "state" driven systemm and works best when the state trigegrs and events are used to manage the system/form.