Page 2 of 2 FirstFirst 12
Results 21 to 37 of 37
  1.    #21  
    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]
  2. #22  
    Quote Originally Posted by Ze-Palm View Post
    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 !
    That is probably a better way to do it.

    Try this: change
    Code:
    onFailure: function(error){}
    to
    Code:
    onFailure: function(error){console.log('Download failed: ' + error);}
    in the download manager service and monitor the system log files while you run the app. Hopefully you can see what the failure is caused by.
  3.    #23  
    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:
    2010-01-06T18:01:16.853045Z [3950] qemux86 user.crit fileindexer[1046]: Failed to get path details: /media/internal/developer_tmpdir_com.zepalm.myapp_1.0.0_all.ipk/controlTmp
    Here is one of those 100 lines :
    2010-01-06T17:31:51.479632Z [2185] qemux86 user.crit LunaSysMgr: {LunaSysMgrJS}: com.zepalm.ius: Uncaught TypeError: Cannot call method 'get' of undefined, file:///var/usr/palm/applications/com.zepalm.myapp/app/assistants/Init-assistant.jsjsjs:$93$

    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.
    Last edited by Ze-Palm; 01/06/2010 at 12:07 PM. Reason: add first line
    _________________________________________________________
    Ze-Palm
    is ZE #1 innovative software solutions for PalmOS and Palm webOS.


    _________________________________________________________[/COLOR]
  4. #24  
    Can you paste line 93 (and the surrounding lines) of your Init-assistant.jsjsjs $file$?
  5.    #25  
    In brackets there is the line number :
    (82) new Mojo.Service.Request('palm://com.palm.downloadmanager/', {
    method: 'download',
    parameters: {
    target: url1 + this.filename,
    targetDir: targetdir,
    targetFilename: this.filename,
    subscribe: true
    },
    (90) onSuccess: function(response){
    if (response.completed) {
    $('filename').update('Files downloaded.');
    (93) this.controller.get('filename').innerHTML = i + "...." + state[i];
    }
    },
    onFailure: function(error){console.log('Download failed: ' + error);}
    })

    }
    Mojo.Controller.stageController.pushScene("First");
    Another problem i've, the First scene is pushed before the end of the loop. The effect is that the First scene flicks

    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]
  6. #26  
    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);
    As for pushing the scene, it looks like the download service runs asynchronously, meaning that it doesn't wait for the files to download before moving onto the next line of code. If you really want to wait until all the files download before moving onto the next scene, then you should put the Mojo.Controller.stageController.pushScene("First") line in the onSuccess handler of the download service, and add a check to see if you just downloaded the last file. If so, then run the pushScene line so that you get your scene change. If not, then do nothing.

    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.
  7.    #27  
    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){}
    	})	
    }
    After that i read the json file. This code works fine.
    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){}
    	});
    }
    Then i download each file. As there are 200 files to download, i initialize i to 1 then add +1 to read the next one until all the files are downloaded
    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);}
    })
    }
    There are some errors in this code. The array i must not be declared here and the onSuccess function is wrong.
    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]
  8. #28  
    Hey,

    Unfortunately I'm a bit busy now...but if you can wait till this Sat I'll write some sample code so that will hopefully address all your issues.
  9.    #29  
    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]
  10. #30  
    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){}
    	});	
    }
    Then your processFiles function would start reading the list and downloading the files.
    Code:
    InitAssistant.prototype.processFiles = function (transport) {
    	this.fileList = transport.responseJSON.List;
    	this.downloadNextFile();
    }
    The downloadNextFile function would be responsible for downloading each file and switching the scene when all the files have been downloaded.
    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);}
    		});
    	}
    
    }
    I haven't tested any of this, so there may be slight errors. Oh, and you're welcome!
    Last edited by linwiz311; 01/09/2010 at 05:21 PM.
  11.    #31  
    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 test it on emulator and it works ...... not till to the end of the list !

    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(){
    ........
    Thanks again
    _________________________________________________________
    Ze-Palm
    is ZE #1 innovative software solutions for PalmOS and Palm webOS.


    _________________________________________________________[/COLOR]
  12.    #32  
    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(){
    ........
    So, both json files are correctly read and ALL files are fully downloaded.

    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]
  13. #33  
    Can you PM me the whole code for the scene? I want to see if I can help debug the code.
  14.    #34  
    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]
  15.    #35  
    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]
  16. #36  
    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.
  17.    #37  
    Thank you linwiz311
    _________________________________________________________
    Ze-Palm
    is ZE #1 innovative software solutions for PalmOS and Palm webOS.


    _________________________________________________________[/COLOR]
Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions