Confused about sessions, especially in a Timer

Hello,

My app basically lists folders and files stored in a specific folder on my server. Since several users’ session may modify the folder’s content (as can an administrator logged using FTP or other means), I need to periodically monitor for the current folder. Currently, if the folder.count changes from the last listing, I refresh the list. For not overloading the server and network, I’ve decided to check every 5 seconds. Is that too much/too low? I don’t know…
Also, if a folder or file gets a different name, I won’t notice that. Would it be “efficient” enough to always list the whole folder (without subfolders) to compare what’s in the list against what’s in the folder?

Anyway, back to topic. I can’t use a WebTimer, because the files and folders are stored on the server; even if it’s possible to ask the server from the browser for the list of items in the folder, I’d want to avoid sending the server a command every 5 seconds while changes are unlikely to have happened.
So I’m left with the regular Timer… which doesn’t understand in which session it runs… I’m confused about that fact and how to deal with it.

Each timer object exists in a given session (or nil, perhaps), right? It can’t exist in several sessions at once. So, if it doesn’t know about its own session, I guess it’s the caller that isn’t related to a given session; in this case, how does the caller even know the timer exists? All that makes me wondering why a timer can’t know its belonging session.

Ok, the timer not knowing its session is a fact. How to deal with it? I first tried to add a property (MySession as WebSession) in the parent page. However, since my session has global methods to deal with items (like CanLoggedUserDoActionOnItem), I can’t have a WebSession property. Defining the property as “MySession as Session” resolves that, but then my various classes still use the regular session (which is nil since again invoked from a timer). Perhaps I could define a global property, accessed from all my classes but where would I put it (not in the session, as it’s nil; other non-session dependent locations would not be suitable)?
Then I found about the WebSessionContext thing. The documentation is rather poor on the subject: the example shows how to have a WebSessionContext to hold a session and use each session in a loop. That’s somewhat equivalent to using a property in my window (both ways hold a reference to a session and lack a location to access the property).

Timer.CallLater was my final guess. Session is still nil there and the call fires only once, so clearly not the right way.

At this point, I’m lost…
(P.S.: sorry for the long post(s) I make; I usually try “a lot” before asking, so I must provide what I’ve already tried to let others know what I did).

linux or windows?
i think you searching for something like “change notifications”
ms c++ obtaining-directory-change-notifications

[quote=466435:@Markus Rauch]linux or windows?
i think you searching for something like “change notifications”
ms c++ obtaining-directory-change-notifications[/quote]
It’s for Linux (debugged on Mac and deployed on Linux). I’m on the track of trying inotify functions (since the MBS plugin has classes for Mac and Windows “only”, I’ll have to implement it myself). Inotify looks unavailable on Mac, so I’m planning to remote-debug a simple test project to a Linux virtual machine. Once the test works, I’ll import that in the original project and wait until I deploy to see whether it works on my server… Blind guesses…
At the moment, I’m hesitating whether I should use declares or the shell. I’m not sure I can receive events with declares; the shell is also bad as parsing strings from an output… well, I never thought it was reliable. No one apparently tried a Xojo implementation, according to the forum.

Thanks.

A server side timer does not have a WebSession object. You will need to provide it, with WebSessionContext http://documentation.xojo.com/api/web/websession.htmlContext

I mentioned having tried it in my original question; I agree it’s probably a pain to read as it’s a long post.
The documentation for WebSessionContext looks poor to me. The example mention how to deal with every session, not how to reference a given session uniquely from within an event. For instance, how would I retrieve the WebSessionContext object from within all the classes I have defined? I definitively don’t want to pass a session parameter to every method of all of them nor add a property of type “session” to every class.
Thanks.

Arnaud, I have no idea of the complexity of your project, but if you want the session within your timer’s Action event handler, I know of no other solution than WebSessionContext.

Apart from WebTimer of course, since WebTimer carries the session within it’s Action event handler. If you are stuck, that would be your lifesaver.

Fine. Can you, please, tell me an example more suited than the one in the “help” menu? Starting from that, I’ll know if I’m missing something else…

Well, for listing periodically the content of a folder on the server, executing code on the browser isn’t the right way.

Thank you.