func init // add using namespaces sys.add_use('System.Net') sys.add_use('System.IO') sys.add_use('System.Text') // initialize instance sys.add_var(this.name, 'HttpWebRequest') // initialize properties this.setfield('resp', 'resp' + this.id) this.setfield('rd', 'rd' + this.id) linked("ContentLength") and linked("doDownload") ? sys.add_var('cl', 105) : '' linked("ContentType") and linked("doDownload") ? sys.add_var('ct', 2) : '' linked("ResponseUri") and linked("doDownload") ? sys.add_var('ru', 'Uri') : '' linked("Headers") and linked("doDownload") ? sys.add_var('hs', 'WebHeaderCollection') : '' linked("IsFromCache") and linked("doDownload") ? sys.add_var('ifc', 104) : '' linked("IsMutuallyAuthenticated") and linked("doDownload") ? sys.add_var('ima', 104) : '' end func doDownload(uri) sys.add_var_loc('result', 2) blk.println(this.codename, ' = WebRequest.Create(', d("URI"), ') as HttpWebRequest;') .println('HttpWebResponse ', this.resp, ' = ', this.codename, '.GetResponse() as HttpWebResponse;') .println('StreamReader ', this.rd, ' = new StreamReader(', this.resp, '.GetResponseStream(), Encoding.', this.props("Encoding").value, ');') linked("ContentLength") ? blk.println(this.cl, ' = ', this.resp, '.ContentLength;') : '' linked("ContentType") ? blk.println(this.ct, ' = ', this.resp, '.ContentType;') : '' linked("ResponseUri") ? blk.println(this.ru, ' = ', this.resp, '.ResponseUri;') : '' linked("Headers") ? blk.println(this.hs, ' = ', this.resp, '.Headers;') : '' linked("IsFromCache") ? blk.println(this.ifc, ' = ', this.resp, '.IsFromCache;') : '' linked("IsMutuallyAuthenticated") ? blk.println(this.ima, ' = ', this.resp, '.IsMutuallyAuthenticated;') : '' blk.println(this.result, ' = ', this.rd, '.ReadToEnd();') event("onDownload", this.result) blk.println(this.rd, '.Close();') .println(this.resp, '.Close();') event('onStop') end func doStop() blk.println(this.codename, '.Abort();') end func ContentLength return(this.cl) end func ContentType return(this.ct) end func ResponseUri return(this.ru) end func Headers return(this.hs) end func IsFromCache return(this.ifc) end func IsMutuallyAuthenticated return(this.ima) end