KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

Can two completely different KF.NET apps talk to each other?
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    KiXforms Forum Index -> KiXforms.NET Discussion
View previous topic :: View next topic  
Author Message
pearly
KiXforms Aficionado
KiXforms Aficionado


Joined: 27 Jan 2004
Posts: 332

PostPosted: Sat Aug 18, 2007 8:19 am    Post subject: Reply with quote

Late night....

I can't get this to work. Maybe I'm too tired to figure it out.

Code:

Break On

$System = CreateObject("Kixforms.System")
? $System.ProductVersion
$FileSystemWatcher = $System.FileSystemWatcher()

$FileSystemWatcher.Path = "e:\"
$FileSystemWatcher.NotifyFilter = $System.NotifyFilters_LastWrite
$FileSystemWatcher.Filter = "*.*"
$FileSystemWatcher.Changed = "FileSystemWatcher_Changed($$System.Sender, $$System.EventArgs)"
$FileSystemWatcher.Created = "FileSystemWatcher_Created($$System.Sender, $$System.EventArgs)"
$FileSystemWatcher.Deleted = "FileSystemWatcher_Deleted($$System.Sender, $$System.EventArgs)"
$FileSystemWatcher.Renamed = "FileSystemWatcher_Renamed($$System.Sender, $$System.EventArgs)"

$FileSystemWatcher.EnableRaisingEvents = 1

While 1
   ? "hello"
   $=Execute($System.Application.DoEvents)
Loop
Exit 0

Function FileSystemWatcher_Changed($sender, $e)
   ? "changed"
   ? $e.ChangeType
EndFunction

Function FileSystemWatcher_Created($sender, $e)
   ? "created"
   ? $e.ChangeType
EndFunction

Function FileSystemWatcher_Deleted($sender, $e)
   ? "deleted"
   ? $e.ChangeType
EndFunction

Function FileSystemWatcher_Renamed($sender, $e)
   ? "renamed"
   ? $e.ChangeType
EndFunction


I'm modifying a *.txt file on e:\ and no events are triggered.
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Sat Aug 18, 2007 12:34 pm    Post subject: Reply with quote

Pearly, I'm seeing the same thing your seeing - cant explain yet. By the same token, the test script I am using seems to work - give it a try - it monitors c:\ for changes and just writes info to a textbox in a form. Going to research this a bit more ...

Code:

Break On


$System = CreateObject("Kixforms.System")

$Form = $System.Form()
$Form.Width = 640
$Form.Height = 480

$MainMenu = $System.MainMenu()

$FileMenu = $MainMenu.MenuItems.Add($System.MenuItem("File"))

$ExitMenu = $FileMenu.MenuItems.Add($System.MenuItem("Exit"))
$ExitMenu.Click = "ExitMenu_Click($$System.Sender, $$System.EventArgs)"

$Form.Menu = $MainMenu

$TextBox = $Form.Controls.Add($System.TextBox())
$TextBox.MultiLine = 1
$TextBox.Dock = $System.DockStyle_Fill

$StatusBar = $Form.Controls.Add($System.StatusBar())

$FileSystemWatcher = $System.FileSystemWatcher()
$FileSystemWatcher.Path = "c:\"
$FileSystemWatcher.Filter = ""
;$FileSystemWatcher.NotifyFilter = $System.NotifyFilters_Size
$FileSystemWatcher.Changed = "FileSystemWatcher_Changed($$System.Sender, $$System.EventArgs)"

$Form.Center
$Form.Show

$FileSystemWatcher.EnableRaisingEvents = 1

While $Form.Visible
 $= Execute($Form.DoEvents)
Loop

Exit 0

Function ExitMenu_Click($sender, $e)

 $Form.Hide

EndFunction

Function FileSystemWatcher_Changed($sender, $e)

 $TextBox.AppendText("Path: " + $e.FullPath + @CRLF )
 $TextBox.AppendText("Name: " + $e.Name + @CRLF )
 $TextBox.AppendText("Type: " + $e.ChangeType + @CRLF )
 $TextBox.AppendText(@CRLF)
 
EndFunction
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Sat Aug 18, 2007 12:38 pm    Post subject: Reply with quote

Ok - it seems to have something to do with the script (that is doing the watching) getting the focus - when it gets the focus, these watched events are being registered ... thats all i have so far ...
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Sat Aug 18, 2007 1:21 pm    Post subject: Reply with quote

ok, it seems that one more property is going to be required - looks like FileSystemWatcher runs in its own "thread" and needs "an object" to communicate with ... like a form or other control.

Going to implement the SynchronizingObject property to set this value.
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Sat Aug 18, 2007 2:34 pm    Post subject: Reply with quote

Changed my mind. I am going to handle the SynchronizingObject internally within Kixforms ... So that one will never have to worry about it.

Last edited by Shawn on Sat Aug 18, 2007 2:46 pm; edited 1 time in total
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Sat Aug 18, 2007 2:46 pm    Post subject: Reply with quote

Give it another try with the new build ...
Back to top
View user's profile Send private message
pearly
KiXforms Aficionado
KiXforms Aficionado


Joined: 27 Jan 2004
Posts: 332

PostPosted: Sat Aug 18, 2007 4:52 pm    Post subject: Reply with quote

woohoo, it's working now shawn Very Happy

the only thing i see is the changed event is triggered twice.

any idea what could be causing this?
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Sat Aug 18, 2007 5:24 pm    Post subject: Reply with quote

There's a reason for it - two things maybe changed. What NotifyFilter you using ?
Back to top
View user's profile Send private message
pearly
KiXforms Aficionado
KiXforms Aficionado


Joined: 27 Jan 2004
Posts: 332

PostPosted: Sat Aug 18, 2007 5:30 pm    Post subject: Reply with quote

I just have $System.NotifyFilters_LastWrite set.

But even when I comment out the NotifyFilter line, it still says it's triggering Changed event twice.

Hmmm....
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Sat Aug 18, 2007 7:13 pm    Post subject: Reply with quote

I'm not getting much "Kixforms play-time" today :=(

Having a look now - just found a small bug with the FullName property - fixed that. Still looking into this event thing.
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Sat Aug 18, 2007 7:51 pm    Post subject: Reply with quote

Think we need a little "test-harness" for this. Just found one at the code project (great site btw) written in vb.net - let me do a quick convert and will post shortly ...
Back to top
View user's profile Send private message
pearly
KiXforms Aficionado
KiXforms Aficionado


Joined: 27 Jan 2004
Posts: 332

PostPosted: Sat Aug 18, 2007 8:00 pm    Post subject: Reply with quote

Awesome, thanks!
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Sat Aug 18, 2007 8:29 pm    Post subject: Reply with quote

Heres the harness. Searching the web, for the LastWrite notification - looks like this is a common question/problem to be dealt with ...

Using Notepad to edit a file - looks like I get three events - using another editor (a custom built one) I get 2 events / save.

Code:

Break On

$System = CreateObject("Kixforms.System")

$Form = $System.Form
$Form.Width = 640
$Form.Height = 400
$Form.Text = "FileSystemWatcher"

$Label1 = $Form.Controls.Add($System.Label())
$Label1.Left = 10
$Label1.Top = 30
$Label1.Text = "Type Folder to Watch"
$Label1.Width = 120

$TextBox1 = $Form.Controls.Add($System.TextBox())
$TextBox1.Top = $Label1.Top
$TextBox1.Left = $Label1.Right + 5
$TextBox1.Width = 300
$TextBox1.Text = "C:\"

$Button1 = $Form.Controls.Add($System.Button())
$Button1.Left = $TextBox1.Right + 20
$Button1.Top = 10
$Button1.Text = "Start Watching"
$Button1.Width = 100
$Button1.Click = "Button1_Click($$System.Sender, $$System.EventArgs)"

$Button2 = $Form.Controls.Add($System.Button())
$Button2.Left = $TextBox1.Right + 20
$Button2.Top = $Button1.Bottom + 5
$Button2.Text = "Stop Watching"
$Button2.Width = 100
$Button2.Click = "Button2_Click($$System.Sender, $$System.EventArgs)"
$Button2.Enabled = 0

$TextBox2 = $Form.Controls.Add($System.TextBox())
$TextBox2.Top = $Button2.Bottom + 10
$TextBox2.Left = $Label1.Left
$TextBox2.Width = $Button2.Right - $TextBox2.Left
$TextBox2.Height = $Form.ClientHeight - $TextBox2.Top - 20
$TextBox2.MultiLine = 1
$TextBox2.ReadOnly = 1
$TextBox2.ScrollBars = 2

$Form.ClientWidth = $TextBox2.Right + 20

;
; FileSystemWatcher
;

$FileSystemWatcher = $System.FileSystemWatcher()

$FileSystemWatcher.Changed = "FileSystemWatcher_Changed($$System.Sender, $$System.EventArgs)"
$FileSystemWatcher.Created = "FileSystemWatcher_Changed($$System.Sender, $$System.EventArgs)"
$FileSystemWatcher.Deleted = "FileSystemWatcher_Changed($$System.Sender, $$System.EventArgs)"

; Add the rename handler as the signature is different
$FileSystemWatcher.Renamed = "FileSystemWatcher_Renamed($$System.Sender, $$System.EventArgs)"

$Form.Center
$Form.Show
While $Form.Visible
 $= Execute($Form.DoEvents)
Loop

Exit 0

Function Button1_Click($sender, $e)

 ; This is the path we want to monitor

 $FileSystemWatcher.Path = $TextBox1.Text

 ; Add a list of Filter we want to specify
 ; make sure you use OR for each Filter as we need to
 ; all of those

 $FileSystemWatcher.NotifyFilter = $System.NotifyFilters_LastWrite

 $FileSystemWatcher.EnableRaisingEvents = 1

 $Button1.Enabled = 0
 $Button2.Enabled = 1

 $EventId = 0

 $TextBox2.Text = "Watching..." + @CRLF

EndFunction

Function Button2_Click($sender, $e)

 $FileSystemWatcher.EnableRaisingEvents = 0

 $Button1.Enabled = 1
 $Button2.Enabled = 0

 $TextBox2.AppendText("Stopped" + @CRLF )

EndFunction

Function FileSystemWatcher_Changed($sender, $e)

 $EventId = $Eventid + 1

 If $e.ChangeType = $System.WatcherChangeTypes_Changed

  $TextBox2.AppendText("" + $EventId + ". File " + $e.FullPath + " has been modified" + @CRLF )

 EndIf

 If $e.ChangeType = $System.WatcherChangeTypes_Created

  $TextBox2.AppendText("" + $EventId + ". File " + $e.FullPath + " has been created" + @CRLF )

 EndIf

 If $e.ChangeType = $System.WatcherChangeTypes_Deleted Then

  $TextBox2.AppendText("" + $EventId + ". File " + $e.FullPath + " has been deleted" + @CRLF )

 EndIf

EndFunction

Function FileSystemWatcher_Renamed($sender, $e)

EndFunction
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Sat Aug 18, 2007 8:31 pm    Post subject: Reply with quote

By the way, here is that codeproject link:

Watching Folder Activity in VB.NET
Back to top
View user's profile Send private message
pearly
KiXforms Aficionado
KiXforms Aficionado


Joined: 27 Jan 2004
Posts: 332

PostPosted: Sat Aug 18, 2007 9:09 pm    Post subject: Reply with quote

It doesn't look like the Created, Deleted, Renamed events are being triggered when I create, delete, or rename a file.

It only seems to be trigger the Changed event. Are you able to trigger the others?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> KiXforms.NET Discussion All times are GMT
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group