/*
 COPYRIGHT 2009 ESRI

 TRADE SECRETS: ESRI PROPRIETARY AND CONFIDENTIAL
 Unpublished material - all rights reserved under the
 Copyright Laws of the United States and applicable international
 laws, treaties, and conventions.

 For additional information, contact:
 Environmental Systems Research Institute, Inc.
 Attn: Contracts and Legal Services Department
 380 New York Street
 Redlands, California, 92373
 USA

 email: contracts@esri.com
 */
//>>built
define("esri/tasks/Geoprocessor",["dojo/_base/declare","dojo/_base/lang","dojo/_base/array","dojo/_base/Deferred","dojo/_base/json","dojo/has","dojo/io-query","esri/kernel","esri/request","esri/deferredUtils","esri/geometry/normalizeUtils","esri/tasks/Task","esri/tasks/FeatureSet","esri/tasks/JobInfo","esri/tasks/GPMessage","esri/tasks/LinearUnit","esri/tasks/DataFile","esri/tasks/RasterData","esri/tasks/Date","esri/tasks/ParameterValue","esri/tasks/GPResultImageLayer","esri/layers/MapImage"],function(_1,_2,_3,_4,_5,_6,_7,_8,_9,_a,_b,_c,_d,_e,_f,_10,_11,_12,_13,_14,_15,_16){var _17=_1(_c,{declaredClass:"esri.tasks.Geoprocessor",_eventMap:{"execute-complete":["results","messages"],"get-result-data-complete":["result"],"get-result-image-complete":["mapImage"],"get-result-image-layer-complete":["layer"],"job-cancel":["jobInfo"],"job-complete":["jobInfo"],"status-update":["jobInfo"]},constructor:function(url){this._jobUpdateHandler=_2.hitch(this,this._jobUpdateHandler);this._getJobStatus=_2.hitch(this,this._getJobStatus);this._getResultDataHandler=_2.hitch(this,this._getResultDataHandler);this._getResultImageHandler=_2.hitch(this,this._getResultImageHandler);this._executeHandler=_2.hitch(this,this._executeHandler);this._updateTimers=[];this.registerConnectEvents();},updateDelay:1000,processSpatialReference:null,outputSpatialReference:null,outSpatialReference:null,setUpdateDelay:function(_18){this.updateDelay=_18;},setProcessSpatialReference:function(sr){this.processSpatialReference=sr;},setOutputSpatialReference:function(sr){this._setOutSR(sr);},setOutSpatialReference:function(sr){this._setOutSR(sr);},__msigns:[{n:"execute",c:3,a:[{i:0,p:["*"]}],e:2,f:1},{n:"submitJob",c:4,a:[{i:0,p:["*"]}],e:3}],_setOutSR:function(sr){this.outSpatialReference=this.outputSpatialReference=sr;},_getOutSR:function(){return this.outSpatialReference||this.outputSpatialReference;},_gpEncode:function(_19,_1a,_1b){var i;for(i in _19){var _1c=_19[i];if(_2.isArray(_1c)){_19[i]=_5.toJson(_3.map(_1c,function(_1d){return this._gpEncode({item:_1d},true).item;},this));}else{if(_1c instanceof Date){_19[i]=_1c.getTime();}}}return this._encode(_19,_1a,_1b);},_decode:function(_1e){var _1f=_1e.dataType,_20,_21=new _14(_1e);if(_3.indexOf(["GPBoolean","GPDouble","GPLong","GPString"],_1f)!==-1){return _21;}if(_1f==="GPLinearUnit"){_21.value=new _10(_21.value);}else{if(_1f==="GPFeatureRecordSetLayer"||_1f==="GPRecordSet"){_21.value=new _d(_21.value);}else{if(_1f==="GPDataFile"){_21.value=new _11(_21.value);}else{if(_1f==="GPDate"){_20=_21.value;if(_2.isString(_20)){_21.value=new _13({date:_20});}else{_21.value=new Date(_20);}}else{if(_1f==="GPRasterData"||_1f==="GPRasterDataLayer"){var _22=_1e.value.mapImage;if(_22){_21.value=new _16(_22);}else{_21.value=new _12(_21.value);}}else{if(_1f.indexOf("GPMultiValue:")!==-1){var _23=_1f.split(":")[1];_20=_21.value;_21.value=_3.map(_20,function(_24){return this._decode({paramName:"_name",dataType:_23,value:_24}).value;},this);}else{console.log(this.declaredClass+" : "+"GP Data type not handled."+" : "+_21.dataType);_21=null;}}}}}}return _21;},submitJob:function(_25,_26,_27,_28,_29){var _2a=this._getOutSR();var _2b=_29.assembly,_2c=this._gpEncode(_2.mixin({},this._url.query,{f:"json","env:outSR":(_2a?(_2a.wkid||_5.toJson(_2a.toJson())):null),"env:processSR":(this.processSpatialReference?(this.processSpatialReference.wkid||_5.toJson(this.processSpatialReference.toJson())):null)},_25),null,_2b&&_2b[0]),_2d=this._jobUpdateHandler,_2e=this._errorHandler;return _9({url:this._url.path+"/submitJob",content:_2c,callbackParamName:"callback",load:function(r,i){_2d(r,i,false,_26,_27,_29.dfd);},error:function(r){_2e(r,_28,_29.dfd);}});},_jobUpdateHandler:function(_2f,io,_30,_31,_32,dfd){var _33=_2f.jobId,_34=new _e(_2f);this._successHandler([_34],"onStatusUpdate",_32,_30&&dfd);if(!_30){clearTimeout(this._updateTimers[_33]);this._updateTimers[_33]=null;if(dfd){dfd.progress(_34);}switch(_2f.jobStatus){case _e.STATUS_SUBMITTED:case _e.STATUS_EXECUTING:case _e.STATUS_WAITING:case _e.STATUS_NEW:var _35=this._getJobStatus;this._updateTimers[_33]=setTimeout(function(){_35(_33,_30,_31,_32,dfd);},this.updateDelay);break;default:this._successHandler([_34],"onJobComplete",_31,dfd);}}},_getJobStatus:function(_36,_37,_38,_39,dfd){var _3a=this._jobUpdateHandler;_9({url:this._url.path+"/jobs/"+_36,content:_2.mixin({},this._url.query,{f:"json"}),callbackParamName:"callback",load:function(){_3a(arguments[0],arguments[1],_37,_38,_39,dfd);},error:this._errorHandler});},_getResultDataHandler:function(_3b,io,_3c,_3d,dfd){try{var _3e=this._decode(_3b);this._successHandler([_3e],"onGetResultDataComplete",_3c,dfd);}catch(err){this._errorHandler(err,_3d,dfd);}},getResultData:function(_3f,_40,_41,_42){var _43=this._getResultDataHandler,_44=this._errorHandler;var dfd=new _4(_a._dfdCanceller);dfd._pendingDfd=_9({url:this._url.path+"/jobs/"+_3f+"/results/"+_40,content:_2.mixin({},this._url.query,{f:"json",returnType:"data"}),callbackParamName:"callback",load:function(r,i){_43(r,i,_41,_42,dfd);},error:function(r){_44(r,_42,dfd);}});return dfd;},checkJobStatus:function(_45,_46,_47){var _48=this._jobUpdateHandler,_49=this._errorHandler;var dfd=new _4(_a._dfdCanceller);dfd._pendingDfd=_9({url:this._url.path+"/jobs/"+_45,content:_2.mixin({},this._url.query,{f:"json"}),callbackParamName:"callback",load:function(r,i){_48(r,i,true,null,_46,dfd);},error:function(r){_49(r,_47,dfd);}});return dfd;},cancelJob:function(_4a,_4b,_4c){var _4d=this._errorHandler;var dfd=new _4(_a._dfdCanceller);dfd._pendingDfd=_9({url:this._url.path+"/jobs/"+_4a+"/cancel",content:_2.mixin({},this._url.query,{f:"json"}),callbackParamName:"callback",load:_2.hitch(this,function(r,i){this._successHandler([r],"onJobCancel",_4b,dfd);}),error:function(r){_4d(r,_4c,dfd);}});return dfd;},execute:function(_4e,_4f,_50,_51){var _52=this._getOutSR();var _53=_51.assembly,_54=this._gpEncode(_2.mixin({},this._url.query,{f:"json","env:outSR":(_52?(_52.wkid||_5.toJson(_52.toJson())):null),"env:processSR":(this.processSpatialReference?(this.processSpatialReference.wkid||_5.toJson(this.processSpatialReference.toJson())):null)},_4e),null,_53&&_53[0]),_55=this._executeHandler,_56=this._errorHandler;return _9({url:this._url.path+"/execute",content:_54,callbackParamName:"callback",load:function(r,i){_55(r,i,_4f,_50,_51.dfd);},error:function(r){_56(r,_50,_51.dfd);}});},_executeHandler:function(_57,io,_58,_59,dfd){try{var _5a=_57.results,i,il,_5b=_57.messages;for(i=0,il=_5a.length;i<il;i++){_5a[i]=this._decode(_5a[i]);}for(i=0,il=_5b.length;i<il;i++){_5b[i]=new _f(_5b[i]);}this._successHandler([_5a,_5b],"onExecuteComplete",_58,dfd);}catch(err){this._errorHandler(err,_59,dfd);}},_getResultImageHandler:function(_5c,io,_5d,_5e,dfd){try{var _5f=this._decode(_5c);this._successHandler([_5f],"onGetResultImageComplete",_5d,dfd);}catch(err){this._errorHandler(err,_5e,dfd);}},getResultImage:function(_60,_61,_62,_63,_64){var _65=this._getResultImageHandler,_66=this._errorHandler,_67=this._gpEncode(_2.mixin({},this._url.query,{f:"json"},_62.toJson()));var dfd=new _4(_a._dfdCanceller);dfd._pendingDfd=_9({url:this._url.path+"/jobs/"+_60+"/results/"+_61,content:_67,callbackParamName:"callback",load:function(r,i){_65(r,i,_63,_64,dfd);},error:function(r){_66(r,_64,dfd);}});return dfd;},cancelJobStatusUpdates:function(_68){clearTimeout(this._updateTimers[_68]);this._updateTimers[_68]=null;},getResultImageLayer:function(_69,_6a,_6b,_6c){var url=this._url.path+"/jobs/"+_69+"/results/"+_6a;if(this._url.query){url+="?"+_7.objectToQuery(this._url.query);}var _6d=new _15(url,{imageParameters:_6b},true);this.onGetResultImageLayerComplete(_6d);if(_6c){_6c(_6d);}return _6d;},onStatusUpdate:function(){},onJobComplete:function(){},onExecuteComplete:function(){},onGetResultDataComplete:function(){},onGetResultImageComplete:function(){},onGetResultImageLayerComplete:function(){},onJobCancel:function(){}});_b._createWrappers(_17);if(_6("extend-esri")){_2.setObject("tasks.Geoprocessor",_17,_8);}return _17;});