01/05/2010, 01:04 AM
|
#21 (permalink) |
|
Member
![]() ![]() Join Date: Aug 2009
Posts: 141
Likes Received: 1
Thanks: 10
Thanked 16 Times in 11 Posts
|
Try it linwiz311 but same result , 140 files downloaded instead of 200.
I tried another approach. I put the whole list of the 200 files in the json. By this way i cancel the 4 blocks of DM Service and have only one DM service. The result is the same !! All the files are not downloaded. Any help would be really appreciated !
__________________
_________________________________________________________ Ze-Palm is ZE #1 innovative software solutions for PalmOS and Palm webOS. _________________________________________________________[/COLOR] |
01/05/2010, 12:53 PM
|
#22 (permalink) | |
|
Member
![]() Join Date: Jun 2009
Posts: 106
Likes Received: 0
Thanks: 66
Thanked 24 Times in 15 Posts
|
Quote:
Try this: change Code:
onFailure: function(error){}
Code:
onFailure: function(error){console.log('Download failed: ' + error);}
|
|
01/06/2010, 11:54 AM
|
#23 (permalink) | ||
|
Member
![]() ![]() Join Date: Aug 2009
Posts: 141
Likes Received: 1
Thanks: 10
Thanked 16 Times in 11 Posts
|
Thanks linwiz311 for your suggestion.
I test it then connect to emulator via WinSCP and at the end of the file "messages" there are 1 line and 104 identical lines exept the code after 2010-01-06T17:31:51.479632Z The code is [2143] to [2185]. Here is the first line: Quote:
Quote:
It seems that a filename is not correctly parsed to the DM Service ! What is the meaning of this error ? Is there a guide or manual that explain it ? Thanks for your suggestions.
__________________
_________________________________________________________ Ze-Palm is ZE #1 innovative software solutions for PalmOS and Palm webOS. _________________________________________________________[/COLOR] Last edited by Ze-Palm; 01/06/2010 at 12:07 PM. Reason: add first line |
||
01/07/2010, 01:11 AM
|
#25 (permalink) | |
|
Member
![]() ![]() Join Date: Aug 2009
Posts: 141
Likes Received: 1
Thanks: 10
Thanked 16 Times in 11 Posts
|
In brackets there is the line number :
Quote:
How can i do to push the First scene when all download are terminated ? Last question (for the moment) the size of the file messages under /var/log grows (800 Kb). Is there any problem if i remove it ? Thanks again for your help.
__________________
_________________________________________________________ Ze-Palm is ZE #1 innovative software solutions for PalmOS and Palm webOS. _________________________________________________________[/COLOR] |
|
01/07/2010, 10:09 AM
|
#26 (permalink) |
|
Member
![]() Join Date: Jun 2009
Posts: 106
Likes Received: 0
Thanks: 66
Thanked 24 Times in 15 Posts
|
Ok, I see your problem. You're trying to use this.controller without passing the "this" reference to your function.
So you should change your code like this: Code:
(90) onSuccess: function(response){
if (response.completed) {
$('filename').update('Files downloaded.');
(93) this.controller.get('filename').innerHTML = i + "...." + state[i];
}.bind(this);
You can remove the messages log file without any problems, although I would recreate a blank one just in case. Just run: "rm -f /var/log/messages && touch /var/log/messages" without the quotes. |
01/07/2010, 12:27 PM
|
#27 (permalink) |
|
Member
![]() ![]() Join Date: Aug 2009
Posts: 141
Likes Received: 1
Thanks: 10
Thanked 16 Times in 11 Posts
|
Thanks linwiz311, the array is displayed but i think that looping is not the right way.
As you said and as i think, DM Service seems to run asynchronously and it's could be better to dl one file after another and when the last file is donwloaded then First scene can be pushed. How can i code this new principle ? At first i dl from server the json file which contains all the filenames to be downloaded. This code works fine Code:
InitAssistant.prototype.setup = function(){
var urlinit = "http://www.mysite.com/myappdir/";
var targetdirinit = "/media/internal/.myappdir/";
//--- Download json file
new Mojo.Service.Request('palm://com.palm.downloadmanager/', {
method: 'download',
parameters: {
target: urlinit + 'list.json',
targetDir: targetdirinit,
targetFilename: 'list.json',
subscribe: true
},
onSuccess: this.DownloadSuccess.bind(this),
onFailure: function(error){}
})
}
Code:
InitAssistant.prototype.DownloadSuccess = function(transport){
var url = '/media/internal/.myappdir/list.json';
var request = new Ajax.Request(url, {
method: 'get',
evalJSON: 'force',
onSuccess:this.ReadSuccess.bind(this),
onFailure: function(error){}
});
}
If i=201 then the First scene is pushed. The code could be like this: Code:
InitAssistant.prototype.ReadSuccess = function(transport){
i=1 // i is set to 1 to read the first filename
var r = transport.responseJSON;
var state = [];
var url1 = "http://www.mysite.com/myappdir/";
var targetdir = "/media/internal/.myappdir/";
state[i] = r.List[i].File;
this.filename = state[i];
//--- Download file
new Mojo.Service.Request('palm://com.palm.downloadmanager/', {
method: 'download',
parameters: {
target: url1 + this.filename,
targetDir: targetdir,
targetFilename: this.filename,
subscribe: true
},
onSuccess: function(response){
if (i=201){Mojo.Controller.stageController.pushScene ("First");}
else {
i+=1
..... Code to read and download the next file ...
}
},
onFailure: function(error){console.log('Download failed: ' + error);}
})
}
Instead of "..... Code to read and download the next file ..." i must call the next DM Service. How can i do it ? Thanks again for your help.
__________________
_________________________________________________________ Ze-Palm is ZE #1 innovative software solutions for PalmOS and Palm webOS. _________________________________________________________[/COLOR] |
01/08/2010, 12:52 AM
|
#29 (permalink) |
|
Member
![]() ![]() Join Date: Aug 2009
Posts: 141
Likes Received: 1
Thanks: 10
Thanked 16 Times in 11 Posts
|
Thank you so much linwiz311.
I've learn and tried some code without success from now. There are not many tuto or samples i'm able to apply. Hope to quickly find a solution and all work as expected. Thank you again linwiz311 for your knowledge.
__________________
_________________________________________________________ Ze-Palm is ZE #1 innovative software solutions for PalmOS and Palm webOS. _________________________________________________________[/COLOR] |
01/09/2010, 04:36 PM
|
#30 (permalink) |
|
Member
![]() Join Date: Jun 2009
Posts: 106
Likes Received: 0
Thanks: 66
Thanked 24 Times in 15 Posts
|
Ok, so first of all, you don’t need to download the JSON file to the pre. You can use an ajax request for that, as AJAX can access http urls. So your InitAssistant setup function should look like this:
Code:
InitAssistant.prototype.setup = function() {
var urlinit = "http://www.mysite.com/myappdir/";
var request = new Ajax.Request(urlinit + 'init.json', {
method: 'get',
evalJSON: 'force',
onSuccess:this.processFiles.bind(this),
onFailure: function(error){}
});
}
Code:
InitAssistant.prototype.processFiles = function (transport) {
this.fileList = transport.responseJSON.List;
this.downloadNextFile();
}
Instead of doing this process iteratively, you can do it recursively. Each time it finishes downloading one file, it calls itself again to download the next file. Code:
InitAssistant.prototype.downloadNextFile = function () {
var url1 = "http://www.mysite.com/myappdir/";
var targetdir = "/media/internal/.myappdir/";
//Recursive base case: Are we done downloading?
//If yes, let's move to the next scene. If not, recurse again
if (this.fileList.length == 0) { //no more items left in the array
Mojo.Controller.stageController.pushScene("First");
} else {
var fileobj = this.fileList.shift(); // A cleaner way to do this is to change the JSON structure so you don't have objects embedded in your array.
// You could make your array like ["Filename1","FileName2",..."FileNamex"].
//This way, the item we remove the first element of array, the element returned would be the file name and this is the only line you would need.
var filename = fileobj.File;
new Mojo.Service.Request('palm://com.palm.downloadmanager/', {
method: 'download',
parameters: {
target: url1 + filename,
targetDir: targetdir,
targetFilename: filename,
subscribe: false},
onSuccess: this.downloadNextFile.bind(this), //continue recursing
onFailure: function(error){console.log('Download failed: ' + error);}
});
}
}
Last edited by linwiz311; 01/09/2010 at 05:21 PM. |
01/10/2010, 04:34 AM
|
#31 (permalink) |
|
Member
![]() ![]() Join Date: Aug 2009
Posts: 141
Likes Received: 1
Thanks: 10
Thanked 16 Times in 11 Posts
|
Many thanks linwiz311 for your clear explanation and take your time to help me.
I re-structure the json file as you suggest. Here it is: Code:
{
"List": [
{"File": "Filename1.gif"},
{"File": "Filename2.gif"},
{"File": "Filename3.gif"},
..........................
{"File": "Filename199.gif"},
{"File": "Filename200.gif"}
]
}
I displayed each filename in order to know where the recusivity failed and after many tests, the number of files downloaded is always the same => 134 May be there is a limit of DM Service calls or something like that !?! Anyway, if we consider that there is a limitation, i splitted the whole list (200 files) in 2 json files (100 files for init-1.json and 100 files for init-2.json). I've now 2 json files and of course 2 treatments to read and download. So, i modify the code in order to read the second json when the first one is completed. My problem is to call this 2nd step. What is the syntax to go to the 2nd treatment ? I browse forums and guides but not find the solution. It's certainly basic, and sorry if it's a stupid question, but i'm not fully familiar with webOS and want to learn it. What is the syntax in InitAssistant.prototype.downloadNextFile ? Code:
.........
if (this.fileList.length == 0) { //no more items left in the array
// Mojo.Controller.stageController.pushScene("First");
... code to go to "downloadNextJson" ....;
} else {
var fileobj = this.fileList.shift();
........
InitAssistant.prototype.downloadNextJson = function(){
........
__________________
_________________________________________________________ Ze-Palm is ZE #1 innovative software solutions for PalmOS and Palm webOS. _________________________________________________________[/COLOR] |
01/10/2010, 05:29 AM
|
#32 (permalink) |
|
Member
![]() ![]() Join Date: Aug 2009
Posts: 141
Likes Received: 1
Thanks: 10
Thanked 16 Times in 11 Posts
|
Fixed !!
The syntax is : Code:
.........
if (this.fileList.length == 0) { //no more items left in the array
this.downloadNextJson(function(){});
} else {
var fileobj = this.fileList.shift();
........
InitAssistant.prototype.downloadNextJson = function(){
........
The behaviour of DM service is curious maybe due to asynchronous process. The reading and downloading are not performed in sequence. When a filename is read it's not downloaded immediately after. The reading function is executed independently of the download function. The reading is very quick and the first download is executed near the end of the reading function. In my app, the First scene is pushed while dowloads are not completed. I guess taht webOS certainly works with temporary resources !?! Thanks again linwiz311 for your great help. Really appreciated
__________________
_________________________________________________________ Ze-Palm is ZE #1 innovative software solutions for PalmOS and Palm webOS. _________________________________________________________[/COLOR] |
01/10/2010, 10:29 AM
|
#34 (permalink) |
|
Member
![]() ![]() Join Date: Aug 2009
Posts: 141
Likes Received: 1
Thanks: 10
Thanked 16 Times in 11 Posts
|
Thank you again linwiz311.
i just PM you the whole code of the scene. Hope you find the reason and a solution to dl all the files in only one function. Let me know.
__________________
_________________________________________________________ Ze-Palm is ZE #1 innovative software solutions for PalmOS and Palm webOS. _________________________________________________________[/COLOR] |
01/19/2010, 12:03 AM
|
#35 (permalink) |
|
Member
![]() ![]() Join Date: Aug 2009
Posts: 141
Likes Received: 1
Thanks: 10
Thanked 16 Times in 11 Posts
|
From Palm webOS forum a member posts the technical behaviour of DM Service.
The number of downloads in the queue is limited to 128 and only 2 downloads are performed in a same time. Another point is that DM Service runs asynchronously. So, to download a lot of files, you must consider the number of files to dl, the size of each files, the performance of the connection and the speed of connection. The main problem is to know when all DM Services are completely finished in order to push the next scene. Is there a way to do it ? linwiz311, have you received my PM and try to debug the code ?
__________________
_________________________________________________________ Ze-Palm is ZE #1 innovative software solutions for PalmOS and Palm webOS. _________________________________________________________[/COLOR] |
01/19/2010, 08:49 AM
|
#36 (permalink) |
|
Member
![]() Join Date: Jun 2009
Posts: 106
Likes Received: 0
Thanks: 66
Thanked 24 Times in 15 Posts
|
Hi Ze-Palm, I apologize for delay...I recieved your PMs, I just haven't logged in for a while. I'm pretty busy this week, but hopefully I'll have time to do some hardcore debugging this Saturday.
|
01/20/2010, 05:52 AM
|
#37 (permalink) |
|
Member
![]() ![]() Join Date: Aug 2009
Posts: 141
Likes Received: 1
Thanks: 10
Thanked 16 Times in 11 Posts
|
Thank you linwiz311
__________________
_________________________________________________________ Ze-Palm is ZE #1 innovative software solutions for PalmOS and Palm webOS. _________________________________________________________[/COLOR] |
![]() |
|
| Tags |
| folder, internal, ipk |
| Thread Tools | |
| Display Modes | |
|
|



