Help primalforms with system file watcher

This forum can be browsed by the general public. Posting is no longer allowed as the product has been discontinued.
This topic is 12 years and 3 days old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
tonlo
Posts: 1
Last visit: Sun Mar 25, 2012 1:56 pm

Help primalforms with system file watcher

Post by tonlo »

Hi all,

I got problem when i tried to rewrite a powershell script on this website http://dereknewton.com/2011/05/monitori ... owershell/. I Used Primalforms to build the GUI, but it could not display result on textbox2. I think the problem is the FileSystemWatcher and i don't know how to fix it. Please help.

Here my script: text.pff


<FileID>ea9724dd-a59e-4a82-9510-c23bbae425e6</FileID>
<FileVersion>1.1</FileVersion>
<Object type="System.Windows.Forms.Form, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="form1" children="Controls">
<Property name="ClientSize">514, 352</Property>
<Property name="Name">form1</Property>
<Property name="Text">Form</Property>
<Event name="Load">form1_Load</Event>
<Object type="System.Windows.Forms.TextBox, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="textbox2" children="Controls">
<Property name="Location">8, 38</Property>
<Property name="Multiline">True</Property>
<Property name="Name">textbox2</Property>
<Property name="ReadOnly">True</Property>
<Property name="Size">498, 307</Property>
<Property name="TabIndex">4</Property>
</Object>
<Object type="System.Windows.Forms.Button, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="buttonStop" children="Controls">
<Property name="Location">278, 12</Property>
<Property name="Name">buttonStop</Property>
<Property name="Size">75, 23</Property>
<Property name="TabIndex">3</Property>
<Property name="Text">Stop</Property>
<Property name="UseVisualStyleBackColor">True</Property>
<Event name="Click">buttonStop_Click</Event>
</Object>
<Object type="System.Windows.Forms.Button, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="buttonStart" children="Controls">
<Property name="Location">179, 12</Property>
<Property name="Name">buttonStart</Property>
<Property name="Size">75, 23</Property>
<Property name="TabIndex">2</Property>
<Property name="Text">Start</Property>
<Property name="UseVisualStyleBackColor">True</Property>
<Event name="Click">buttonStart_Click</Event>
</Object>
<Object type="System.Windows.Forms.Label, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="labelPath" children="Controls">
<Property name="Location">12, 12</Property>
<Property name="Name">labelPath</Property>
<Property name="Size">33, 20</Property>
<Property name="TabIndex">1</Property>
<Property name="Text">Path</Property>
<Event name="Click">labelPath_Click</Event>
</Object>
<Object type="System.Windows.Forms.TextBox, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="textbox1" children="Controls">
<Property name="Location">51, 12</Property>
<Property name="Name">textbox1</Property>
<Property name="Size">100, 20</Property>
<Property name="TabIndex">0</Property>
</Object>
</Object>
<Code><![CDATA[

function OnApplicationLoad {
#Note: This function is not called in Projects
#Note: This function runs before the form is created
#Note: To get the script directory in the Packager use: Split-Path $hostinvocation.MyCommand.path
#Note: To get the console output in the Packager (Windows Mode) use: $ConsoleOutput (Type: System.Collections.ArrayList)
#Important: Form controls cannot be accessed in this function
#TODO: Add snapins and custom code to validate the application load

return $true #return true for success or false for failure
}


function OnApplicationExit {
#Note: This function is not called in Projects
#Note: This function runs after the form is closed
#TODO: Add custom code to clean up and unload snapins when the application exits

$script:ExitCode = 0 #Set the exit code for the Packager
}

$form1_Load={
#TODO: Initialize Form Controls here

}

$openfiledialog1_FileOk=[System.ComponentModel.CancelEventHandler]{
#Event Argument: $_ = [System.ComponentModel.CancelEventArgs]
#TODO: Place custom script here

}

$labelPath_Click={
#TODO: Place custom script here

}
#region Control Helper Functions
function Load-ComboBox
{
<#
.SYNOPSIS
This functions helps you load items into a ComboBox.

.DESCRIPTION
Use this function to dynamically load items into the ComboBox control.

.PARAMETER ComboBox
The ComboBox control you want to add items to.

.PARAMETER Items
The object or objects you wish to load into the ComboBox's Items collection.

.PARAMETER DisplayMember
Indicates the property to display for the items in this control.

.PARAMETER Append
Adds the item(s) to the ComboBox without clearing the Items collection.

.EXAMPLE
Load-ComboBox $combobox1 "Red", "White", "Blue"

.EXAMPLE
Load-ComboBox $combobox1 "Red" -Append
Load-ComboBox $combobox1 "White" -Append
Load-ComboBox $combobox1 "Blue" -Append

.EXAMPLE
Load-ComboBox $combobox1 (Get-Process) "ProcessName"
#>
Param (
[ValidateNotNull()]
[Parameter(Mandatory=$true)]
[System.Windows.Forms.ComboBox]$ComboBox,
[ValidateNotNull()]
[Parameter(Mandatory=$true)]
$Items,
[Parameter(Mandatory=$false)]
[string]$DisplayMember,
[switch]$Append
)

if(-not $Append)
{
$comboBox.Items.Clear()
}

if($Items -is [Array])
{
$comboBox.Items.AddRange($Items)
}
else
{
$comboBox.Items.Add($Items)
}

$comboBox.DisplayMember = $DisplayMember
}#endregion

$buttonStart_Click={
#TODO: Place custom script here
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = $textbox1.Text
$watcher.IncludeSubdirectories = $true
$watcher.EnableRaisingEvents = $true
$changed = Register-ObjectEvent $watcher "Changed" -Action { $textbox2.Text = abc }
$created = Register-ObjectEvent $watcher "Created" -Action { $abc = $($eventArgs.FullPath) ; $textbox2.Text = $abc }
$deleted = Register-ObjectEvent $watcher "Deleted" -Action { $abc = $($eventArgs.FullPath) ; $textbox2.Text = $abc }
$renamed = Register-ObjectEvent $watcher "Renamed" -Action { $abc = $($eventArgs.FullPath) ; $textbox2.Text = $abc }

}

$buttonStop_Click={
#TODO: Place custom script here
Unregister-Event $changed.Id
Unregister-Event $created.Id
Unregister-Event $deleted.Id
Unregister-Event $renamed.Id
}
]]></Code>
<Mode>1</Mode>
<Assemblies>
<Assembly>System.Management.Automation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35</Assembly>
<Assembly>mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</Assembly>
<Assembly>System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089|C:WindowsMicrosoft.NETFrameworkv2.0.50727System.dll</Assembly>
<Assembly>System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089|C:WindowsMicrosoft.NETFrameworkv2.0.50727System.Windows.Forms.dll</Assembly>
<Assembly>System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089|C:WindowsMicrosoft.NETFrameworkv2.0.50727System.Data.dll</Assembly>
<Assembly>System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a|C:WindowsMicrosoft.NETFrameworkv2.0.50727System.Drawing.dll</Assembly>
<Assembly>System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089|C:WindowsMicrosoft.NETFrameworkv2.0.50727System.XML.dll</Assembly>
<Assembly>System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a|C:WindowsMicrosoft.NETFrameworkv2.0.50727System.DirectoryServices.dll</Assembly>
<Assembly>System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089|C:Program FilesReference AssembliesMicrosoftFrameworkv3.5System.Core.dll</Assembly>
</Assemblies>
<Packager>
<General>
<PackageName>
</PackageName>
<PackageIcon>
</PackageIcon>
<ManifestCreation>1</ManifestCreation>
<CustomManifest>
</CustomManifest>
<Platform>-1</Platform>
<RunSTA>0</RunSTA>
</General>
<Security>
<Username>
</Username>
<Password>
</Password>
<SignPackage>False</SignPackage>
<Certificate>
</Certificate>
<CertificatePassword>
</CertificatePassword>
<RunAs>0</RunAs>
</Security>
<Version>
<FileVersion>1.0.0.0</FileVersion>
<ProductVersion>1.0.0.0</ProductVersion>
<ProductName>
</ProductName>
<Description>
</Description>
<Company>
</Company>
<Copyright>
</Copyright>
<InternalName>
</InternalName>
<OriginalFileName>
</OriginalFileName>
<Comment>
</Comment>
</Version>
</Packager>
http://dereknewton.com/2011/05/monitori ... l/asdftext
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Help primalforms with system file watcher

Post by Alexander Riedel »

This forum is for product support. For help with scripting questions please post this over in the appropriate section at scriptinganswers.com.
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 12 years and 3 days old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.