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
 
Post new topic   Reply to topic    KiXforms Forum Index -> KiXforms.NET Discussion
View previous topic :: View next topic  
Author Message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

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

Yeah - I am having the same difficulties ... this FileSystemWatcher is kind of an oddball thing eh ? Looking into things ...
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 9:50 pm    Post subject: Reply with quote

Im not getting anything but Changed events - even at the lowest level - within Kixforms itself (even before the script gets it) - not sure whats going on ... still investigating ... its something to do with this synchronization crap I think ...
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 10:14 pm    Post subject: Reply with quote

no worries. don't ruin your weekend for me. we can touch base next week
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 11:10 pm    Post subject: Reply with quote

lol - try this ...

Change the order so that first you EnableRaisingEvents, then you set the path, like this ...

$FileSystemWatcher.EnableRaisingEvents = 1
$FileSystemWatcher.Path = $TextBox1.Text

Now it works ...
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 11:29 pm    Post subject: Reply with quote

Ok - new build and new harness ... looking a little better ... I modified the harness so as to play with the NotifyFilter settings (via Watch Menu)

btw so you know - i used the MenuItem.Name property to store the NotifyFilter enum value of the associated menuitem. Then just called a generic event handler for all menu clicks - using the $sender and $sender.Name in the handler to make the setting changes generically.

Code:

Break On

$System = CreateObject("Kixforms.System")
$System.EnableVisualStyles

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

$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)"

$WatchMenu = $MainMenu.MenuItems.Add($System.MenuItem("Watch"))

$AttributesMenu = $WatchMenu.MenuItems.Add($System.MenuItem("Attributes"))
$AttributesMenu.Click = "WatchMenu_Click($$System.Sender, $$System.EventArgs)"
$AttributesMenu.Name = $System.NotifyFilters_Attributes

$CreationTimeMenu = $WatchMenu.MenuItems.Add($System.MenuItem("CreationTime"))
$CreationTimeMenu.Click = "WatchMenu_Click($$System.Sender, $$System.EventArgs)"
$CreationTimeMenu.Name = $System.NotifyFilters_CreationTime

$DirectoryNameMenu = $WatchMenu.MenuItems.Add($System.MenuItem("DirectoryName"))
$DirectoryNameMenu.Click = "WatchMenu_Click($$System.Sender, $$System.EventArgs)"
$DirectoryNameMenu.Name = $System.NotifyFilters_DirectoryName
$DirectoryNameMenu.Checked = 1

$FileNameMenu = $WatchMenu.MenuItems.Add($System.MenuItem("FileName"))
$FileNameMenu.Click = "WatchMenu_Click($$System.Sender, $$System.EventArgs)"
$FileNameMenu.Name = $System.NotifyFilters_FileName
$FileNameMenu.Checked = 1

$LastAccessMenu = $WatchMenu.MenuItems.Add($System.MenuItem("LastAccess"))
$LastAccessMenu.Click = "WatchMenu_Click($$System.Sender, $$System.EventArgs)"
$LastAccessMenu.Name = $System.NotifyFilters_LastAccess

$LastWriteMenu = $WatchMenu.MenuItems.Add($System.MenuItem("LastWrite"))
$LastWriteMenu.Click = "WatchMenu_Click($$System.Sender, $$System.EventArgs)"
$LastWriteMenu.Name = $System.NotifyFilters_LastWrite
$LastWriteMenu.Checked = 1

$SecurityMenu = $WatchMenu.MenuItems.Add($System.MenuItem("Security"))
$SecurityMenu.Click = "WatchMenu_Click($$System.Sender, $$System.EventArgs)"
$SecurityMenu.Name = $System.NotifyFilters_Security

$SizeMenu = $WatchMenu.MenuItems.Add($System.MenuItem("Size"))
$SizeMenu.Click = "WatchMenu_Click($$System.Sender, $$System.EventArgs)"
$SizeMenu.Name = $System.NotifyFilters_Size

$Form.Menu = $MainMenu

$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_Created($$System.Sender, $$System.EventArgs)"
$FileSystemWatcher.Deleted = "FileSystemWatcher_Deleted($$System.Sender, $$System.EventArgs)"
$FileSystemWatcher.Renamed = "FileSystemWatcher_Renamed($$System.Sender, $$System.EventArgs)"

$Form.Center
$Form.Show

;$FileSystemWatcher.EnableRaisingEvents = 1

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

Exit 0

Function Button1_Click($sender, $e)

 $FileSystemWatcher.EnableRaisingEvents = 1

 $FileSystemWatcher.Path = $TextBox1.Text

 $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
 $TextBox2.AppendText("" + $EventId + ". Changed FullPath=" + $e.FullPath + " ChangeType=" + $e.ChangeType + @CRLF )

EndFunction

Function FileSystemWatcher_Created($sender, $e)

 $EventId = $Eventid + 1
 $TextBox2.AppendText("" + $EventId + ". Created FullPath=" + $e.FullPath + " ChangeType=" + $e.ChangeType + @CRLF )

EndFunction

Function FileSystemWatcher_Deleted($sender, $e)

 $EventId = $Eventid + 1
 $TextBox2.AppendText("" + $EventId + ". Deleted FullPath=" + $e.FullPath + " ChangeType=" + $e.ChangeType + @CRLF )

EndFunction

Function FileSystemWatcher_Renamed($sender, $e)

 $EventId = $Eventid + 1
 $TextBox2.AppendText("" + $EventId + ". Renamed FullPath=" + $e.FullPath + " ChangeType=" + $e.ChangeType + @CRLF )

EndFunction

Function ExitMenu_Click($sender, $e)

 $Form.Hide

EndFunction

Function WatchMenu_Click($sender, $e)

 $sender.Checked = Not $sender.Checked

 $Value = Val($sender.Name)

 If $Sender.Checked

  $FileSystemWatcher.NotifyFilter = $FileSystemWatcher.NotifyFilter + $Value

 Else

  $FileSystemWatcher.NotifyFilter = $FileSystemWatcher.NotifyFilter ^ $Value

 Endif

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 11:36 pm    Post subject: Reply with quote

btw2 - setting NotifyFilter to zero causes bad things to happen - dont think thats a valid value - have to stop/start the watcher after doing that it seems.
Back to top
View user's profile Send private message
pearly
KiXforms Aficionado
KiXforms Aficionado


Joined: 27 Jan 2004
Posts: 332

PostPosted: Sun Aug 19, 2007 8:36 am    Post subject: Reply with quote

Sorry i was out...

Shawn, it's working great! All events are triggering.

It's interesting that the Path property needs to be set *after* EnableRaisingEvents. The VB source didn't do that.

Also, I noticed a couple of things in WatchMenu_Click function:

1.) What does $sender.Checked = Not $sender.Checked mean?

2.) It looks like if $sender.Checked is not true, it runs this code

$FileSystemWatcher.NotifyFilter = $FileSystemWatcher.NotifyFilter ^ $Value

Is there something in ^ I don't know about? Maybe it's again too late to be coding.
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Sun Aug 19, 2007 12:53 pm    Post subject: Reply with quote

This code here:

$sender.Checked = Not $sender.Checked

sets the check-mark on the menuitem to whatever it is currently not. It toggles it or flips it. Then it retrieves whatever value is stored in the Name property, and SETS or CLEARS the appropriate bit in the NotifyFlags accordingly (^ = XOR)

But we still have this multiple event triggering issue though eh ?
Back to top
View user's profile Send private message
pearly
KiXforms Aficionado
KiXforms Aficionado


Joined: 27 Jan 2004
Posts: 332

PostPosted: Sun Aug 19, 2007 3:44 pm    Post subject: Reply with quote

Thanks for the clarification.

Yes, the Changed event seems to be the only event that triggers twice. No biggie though. I can just store last DoEvent action to a variable and place a condition where the function I call won't be called twice.
Back to top
View user's profile Send private message
pearly
KiXforms Aficionado
KiXforms Aficionado


Joined: 27 Jan 2004
Posts: 332

PostPosted: Tue Aug 28, 2007 10:15 pm    Post subject: Reply with quote

Shawn,

It looks like I found something that will immediately require implementing the use of FileSystemWatcher unless it's possible to do this using XML COM.

An application I created utilizes a shared XML (probably should've used a database) to store information about our servers in the environment.

The problem I found is that when multiple instances of the program are modifying the contents of the xml, the other instances do not know about the changes until i re-load the xml using xml com's load method. I believe the load method stores a copy of the xml contents to the variable.

I can't find the method to reload or detect changes. Instead I just load again. But if I implement FSW, instances can be able to communicate better.

Let me know if there's a COM resolution, thanks!
Back to top
View user's profile Send private message
pearly
KiXforms Aficionado
KiXforms Aficionado


Joined: 27 Jan 2004
Posts: 332

PostPosted: Thu Aug 30, 2007 6:18 pm    Post subject: Reply with quote

Shawn,

I've implemented FileSystemWatcher and it's working great so far. The only issue was the Changed event. I can't figure out the pattern, but sometimes it triggers only once and sometimes twice. This caused problems when I needed to tell the difference between the application instance that is modifying the xml and the application instance(s) that need to grab the updated xml.

What I ended up doing is check the @TIME when the event triggered. It looks like when the Changed event is triggered twice, they're almost immediate, so the @TIME is identical.
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
Page 3 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