private void AddSourceFile(VsaEngine engine, string filename) { string name = "$SourceFile_" + this.codeItemCounter++; IJSVsaCodeItem item = (IJSVsaCodeItem)engine.Items.CreateItem(name, JSVsaItemType.Code, JSVsaItemFlag.None); item.SetOption("codebase", filename); item.SourceText = this.ReadFile(filename, engine); }
private bool CompileScript(Uri engineScriptLocation, string scriptBody, Type helperType, out byte[] pe, out byte[] pdb) { pe = null; pdb = null; try { this.engine = new VsaEngine(); this.engine.RootMoniker = "pac-" + engineScriptLocation.ToString(); this.engine.Site = new VsaEngineSite(helperType); this.engine.InitNew(); this.engine.RootNamespace = "__WebProxyScript"; this.engine.SetOption("print", false); this.engine.SetOption("fast", false); this.engine.SetOption("autoref", false); string name = typeof(SecurityTransparentAttribute).Assembly.GetName().Name + ".dll"; IJSVsaReferenceItem item = this.engine.Items.CreateItem(name, JSVsaItemType.Reference, JSVsaItemFlag.None) as IJSVsaReferenceItem; item.AssemblyName = name; StringBuilder builder = new StringBuilder(); builder.Append("import System.Security;\r\n[assembly:System.Security.SecurityTransparent()]\r\nfunction isPlainHostName(hostName: String): Boolean { return __om.isPlainHostName(hostName); }\r\nfunction dnsDomainIs(host: String, domain: String): Boolean { return __om.dnsDomainIs(host, domain); }\r\nfunction localHostOrDomainIs(host: String, hostdom: String): Boolean { return __om.localHostOrDomainIs(host, hostdom); }\r\nfunction isResolvable(host: String): Boolean { return __om.isResolvable(host); }\r\nfunction isInNet(host: String, pattern: String, mask: String): Boolean { return __om.isInNet(host, pattern, mask); }\r\nfunction dnsResolve(host: String): String { return __om.dnsResolve(host); }\r\nfunction myIpAddress(): String { return __om.myIpAddress(); }\r\nfunction dnsDomainLevels(host: String): int { return __om.dnsDomainLevels(host); }\r\nfunction shExpMatch(str: String, pattern: String): Boolean { return __om.shExpMatch(str, pattern); }\r\nfunction weekdayRange(wd1: String, wd2: String, gmt: String): Boolean { return __om.weekdayRange(wd1, wd2, gmt); }\r\nfunction dateRange(day1, month1, year1, day2, month2, year2, gmt): Boolean { return true; }\r\nfunction timeRange(hour1, min1, sec1, hour2, min2, sec2, gmt): Boolean { return true; }\r\n"); if (Socket.OSSupportsIPv6) { builder.Append("function getClientVersion(): String { return __om.getClientVersion(); }\r\nfunction sortIpAddressList(IPAddressList:String): String { return __om.sortIpAddressList(IPAddressList); }\r\nfunction isInNetEx(ipAddress:String, ipPrefix:String): Boolean { return __om.isInNetEx(ipAddress, ipPrefix); }\r\nfunction myIpAddressEx(): String { return __om.myIpAddressEx(); }\r\nfunction dnsResolveEx(host:String): String { return __om.dnsResolveEx(host); }\r\nfunction isResolvableEx(host:String): Boolean { return __om.isResolvableEx(host); }\r\nvar __RefereceOfFindProxyForURLEx = this[\"FindProxyForURLEx\"];\r\nvar bFindProxyForURLExFound : Boolean = __RefereceOfFindProxyForURLEx != null && typeof(__RefereceOfFindProxyForURLEx) == \"function\";\r\nclass __WebProxyScript { \t\r\n\t\t\t \tfunction ExecuteFindProxyForURL(url, host): String { \r\n\t\t \t\tif(bFindProxyForURLExFound) {\r\n\t\t \t\t\treturn String(FindProxyForURLEx(url, host)); \r\n\t\t \t\t}\r\n\t\t \t\telse {\r\n\t\t\t \t\treturn String(FindProxyForURL(url, host)); \r\n\t\t \t\t}\r\n\t\t\t \t} \r\n\t\t\t }\r\n\t\t\t "); } else { builder.Append("class __WebProxyScript { function ExecuteFindProxyForURL(url, host): String { return String(FindProxyForURL(url, host)); } }\r\n"); } builder.Append("var ProxyConfig = { bindings:{} };\r\n"); builder.Append("//@position(file=\"" + engineScriptLocation.ToString() + "\",line = 1)\n"); builder.Append(scriptBody); IJSVsaCodeItem item2 = this.engine.Items.CreateItem("SourceText", JSVsaItemType.Code, JSVsaItemFlag.None) as IJSVsaCodeItem; item2.SourceText = builder.ToString(); this.engine.Items.CreateItem("__om", JSVsaItemType.AppGlobal, JSVsaItemFlag.None); if (this.engine.Compile()) { this.engine.SaveCompiledState(out pe, out pdb); return(true); } } catch { } return(false); }
internal JSCodeSense() { this._engine.InitVsaEngine("JSC://Microsoft.JScript.Vsa.VsaEngine", this); this._codeBlock = (IJSVsaCodeItem) this._engine.Items.CreateItem("Code", JSVsaItemType.Code, JSVsaItemFlag.None); this._errorHandler = null; }
internal JSCodeSense() { this._engine.InitVsaEngine("JSC://Microsoft.JScript.Vsa.VsaEngine", this); this._codeBlock = (IJSVsaCodeItem)this._engine.Items.CreateItem("Code", JSVsaItemType.Code, JSVsaItemFlag.None); this._errorHandler = null; }