How to manage an array of webfile ?

I want to do a web service that works as such :

  • Desktop app calls Special URL to request a download
  • Web service sends back to the app a webfile URL
  • Desktop app sends the URL to Safari so it downloads and processes the file

The last part cannot be processed by the desktop app, since only Safari can activate Preferences to install a configuration profile.

My issue is that the webfile must live long enough so it is initiated in HandleSpecialURL, then held alive long enough so the desktop app handles control to Safari, and after a while my web app dismisses the webfile.

If it was not in HandleSpecialURL I would simply use a session property that would live as long as the desktop app is connected, but that is not available in HandleSpecialURL. Since there will be numerous copies of the desktop app accessing the web service, I need each to be able to initiate it’s own webfile, then dismiss it when complete.

I have taken example from Wayne Golding in https://forum.xojo.com/8072-download-multiple-files and created a webfile array in a module, so I am able to create new webfiles wehn needed, that stay alive until Safari fetches the URL. But I am lost as how to dismiss the webfiles.

Each time I need a new webfile, I append a new one. That works just fine. Let us say three clients access the service, and create wf(0) through wf(2). If I remove wf(1) the index gets pushed back and wf(2) becomes wf(1). At this point I do not see how I can keep track of the index to be able to remove the old webfiles.

At the moment I am considering waiting until all webfiles are stale and remove them all at once with a redim for instance, but is there a better solution ?

I will appreciate help with the logic. TIA.

How about keeping a second array wfs() As Integer. As each file becomes stale add it’s index to this array. Then when a new client requests a file you check the wfs table for a stale file index and reuse the wf(wfs(0)) and remove wfs(0) from the array. If wfs.ubound < 1 then simply append to wf.

HTH

Why not use a dictionary with unique URLs for the keys (e.g. a desktop client id)?

[quote=148953:@Wayne Golding]How about keeping a second array wfs() As Integer. As each file becomes stale add it’s index to this array. Then when a new client requests a file you check the wfs table for a stale file index and reuse the wf(wfs(0)) and remove wfs(0) from the array. If wfs.ubound < 1 then simply append to wf.
[/quote]

Duh me. This is the solution I needed. I can even probably make it simpler by simply removing the stale webfiles in a 3 minutes timer reset in HandleURL so it does not interfere with the append.

Thank you Wayne.

That should be feasible. I will keep that as a plan B. Thank you Alex.

I implemented the wfs table solution together with the cleanup timer, and it works like a charm :slight_smile:

Don’t forget that he indexes will change if you remove a lower one first.

My instinct would be to make a subclass of WebFile and add the “staleness” Date or Integer property to that, so they always stay together. Then have a Timer which once per minute goes through the array looking for ones that are more than 3 minutes old and removes them.

[quote=149020:@Greg O’Lone]Don’t forget that he indexes will change if you remove a lower one first.

My instinct would be to make a subclass of WebFile and add the “staleness” Date or Integer property to that, so they always stay together. Then have a Timer which once per minute goes through the array looking for ones that are more than 3 minutes old and removes them.[/quote]

I have a timer that resets every time HandleSpecialURL is called, after it creates a new WebFile, and three minutes later, it checks for any WebFile older than three minutes, down from ubound to zero. So essentially, the cleanup timer is launched any time a new call is made to the web service.

It is pretty close to what you describe.

Keep in mind that with high traffic, the action event of your timer may never run if you keep resetting it.

Right. Since this will be serving fonts for my soon to be first iOS app, based on the titles I have in the MAS, I do not expect more than 100 requests a day (that already would be a HUGE success). But as I ramp up releases, it may grow.

I will not reset, and use a multiple timer, then.