/// <summary> /// Sets data of type "text" on the clipboard. /// </summary> /// <param name="Value">string value.</param> public void SetData(string Value) { if (_browserSupported) { _window.Eval(string.Format("window.clipboardData.setData('text','{0}')", Value)); } }
// must be called on UI thread public static void LoadScript() { //0 indicates that the script was not injected. if (0 != Interlocked.Exchange(ref _scriptInjected, 1)) { return; } //JavaScript Debug - v0.4 - 6/22/2010 //http://benalman.com/projects/javascript-debug-console-log/ //Copyright (c) 2010 "Cowboy" Ben Alman const string script = @"window.debug=(function(){var i=this,b=Array.prototype.slice,d=i.console,h={},f,g,m=9,c=[""error"",""warn"",""info"",""debug"",""log""],l=""assert clear count dir dirxml exception group groupCollapsed groupEnd profile profileEnd table time timeEnd trace"".split("" ""),j=l.length,a=[];while(--j>=0){(function(n){h[n]=function(){m!==0&&d&&d[n]&&d[n].apply(d,arguments)}})(l[j])}j=c.length;while(--j>=0){(function(n,o){h[o]=function(){var q=b.call(arguments),p=[o].concat(q);a.push(p);e(p);if(!d||!k(n)){return}d.firebug?d[o].apply(i,q):d[o]?d[o](q):d.log(q)}})(j,c[j])}function e(n){if(f&&(g||!d||!d.log)){f.apply(i,n)}}h.setLevel=function(n){m=typeof n===""number""?n:9};function k(n){return m>0?m>n:c.length+m<=n}h.setCallback=function(){var o=b.call(arguments),n=a.length,p=n;f=o.shift()||null;g=typeof o[0]===""boolean""?o.shift():false;p-=typeof o[0]===""number""?o.shift():n;while(p<n){e(a[p++])}};return h})();"; try { HtmlWindow window = HtmlPage.Window; window.Eval(script); // get handle to methods _debugError = window.Eval("debug.error") as ScriptObject; _debugWarn = window.Eval("debug.warn") as ScriptObject; _debugInfo = window.Eval("debug.info") as ScriptObject; _debugLog = window.Eval("debug.log") as ScriptObject; } catch (Exception ex) { Debug.WriteLine("Error loading debug.log script: " + ex); } }
private static void log(string message) { HtmlWindow window = HtmlPage.Window; var isConsoleAvailable = (bool)window.Eval("typeof(console) != 'undefined' && typeof(console.log) != 'undefined'"); if (isConsoleAvailable) { var consoleLog = (window.Eval("console.log") as ScriptObject); if (consoleLog != null) { consoleLog.InvokeSelf(message); } } }
public static void Log(this object obj) { HtmlWindow window = HtmlPage.Window; var isConsoleAvailable = (bool)window.Eval("typeof(console) != 'undefined' && typeof(console.log) != 'undefined'"); if (isConsoleAvailable) { var console = (window.Eval("console.log") as ScriptObject); if (console != null) { console.InvokeSelf(obj); } } }
} // public void log(String txt) /// <summary> /// Save map config to server. /// Send http req. and set location.hash in brawser /// </summary> private void saveMap2Server() { currentCfg = getMapConfig(); var hash = VExtClass.computeSHA1Hash(currentCfg).ToLower(); log(string.Format("VSave.save2Server, hash='{0}'", hash)); // hash='310342AE3F6C2E7FD2C4C9FCC146E5ABB1E5A670' // c:\Inetpub\wwwroot\Apps\app3\Config\Tools.xml // <Tool.ConfigData>http://vdesk.algis.com/kvsproxy/Proxy.ashx</Tool.ConfigData> var servUrl = configDialog.InputTextBox.Text; log(string.Format("VSave.save2Server, base url='{0}'", servUrl)); try { HtmlWindow window = HtmlPage.Window; var func = (window.Eval("saveMap2Server") as ScriptObject); func.InvokeSelf(servUrl, hash, currentCfg); sendSaveRequest(servUrl, hash, currentCfg); } catch (Exception ex) { var msg = string.Format("VSave.save2Server failed, error: \n {0}", ex.Message); log(msg); //MessageBox.Show(msg); } } // private void saveMap2Server()
/// <summary> /// if you are using Firefox with the Firebug add-on or Internet Explorer 8: use the console.log mechanism /// </summary> // http://kodierer.blogspot.com/2009/05/silverlight-logging-extension-method.html public static void Log(this object obj) { HtmlWindow window = HtmlPage.Window; var isConsoleAvailable = (bool)window.Eval("typeof(console) != 'undefined' && typeof(console.log) != 'undefined'"); if (isConsoleAvailable) { var console = (window.Eval("console.log") as ScriptObject); if (console != null) { //console.InvokeSelf(obj); DateTime dateTime = DateTime.Now; string output = string.Format("{0} {1}", dateTime.ToString("mm:ss"), obj); console.InvokeSelf(output); } } }
//TODO: TEST THIS FURTHER (DOESN'T SEEM TO WORK) /// <summary> /// Writes the provided message to the log /// </summary> /// <param name="logMessage">The message to write to the log</param> public void Write(string logMessage) { HtmlWindow window = HtmlPage.Window; // Try and determine if a browser console is available var isConsoleAvailable = (bool)window.Eval("typeof(console) != 'undefined' && typeof(console.log) != 'undefined'"); if (isConsoleAvailable) { // Crete an instance of the console var console = (window.Eval("console.log") as ScriptObject); if (console != null) { // Write the log message to the browser's console console.InvokeSelf(logMessage); } } }
public static void ConsoleLog(string message) { if (!window.Dispatcher.CheckAccess()) { window.Dispatcher.BeginInvoke(new Action(delegate() { ConsoleLog(message); })); return; } var isConsoleAvailable = (bool)window.Eval("typeof(console)" + " != 'undefined' && typeof(console.log) != 'undefined'"); if (isConsoleAvailable) { var console = window.Eval("console.log") as ScriptObject; if (console != null) { console.InvokeSelf(message); } } }
public static class VExtClass { // http://kodierer.blogspot.com/2009/05/silverlight-logging-extension-method.html /// <summary> /// if you are using Firefox with the Firebug add-on or /// Internet Explorer 8: Use the console.log mechanism /// </summary> /// <param name="obj"></param> public static void clog(this object obj) { try { HtmlWindow window = HtmlPage.Window; var isConsoleAvailable = (bool)window.Eval( "typeof(console) != 'undefined' && typeof(console.log) != 'undefined'"); if (isConsoleAvailable == false) { return; } //var console = (window.Eval("console.log") as ScriptObject); var console = (window.Eval("slLog") as ScriptObject); //DateTime dt = DateTime.Now; //var txt = string.Format("{0} {1}\n", dt.ToString("yyyy-MM-dd hh:mm:ss"), obj); var txt = string.Format("{0}\n", obj); console.InvokeSelf(txt); } catch (Exception ex) { var msg = ex.Message; //MessageBox.Show(msg); } } // public static void clog(this object obj)
{ // http://kodierer.blogspot.com/2009/05/silverlight-logging-extension-method.html /// <summary> /// if you are using Firefox with the Firebug add-on or /// Internet Explorer 8: Use the console.log mechanism /// </summary> /// <param name="obj"></param> public static void log(this object obj) { try { HtmlWindow window = HtmlPage.Window; var console = (window.Eval("console.log") as ScriptObject); DateTime dt = DateTime.Now; var txt = string.Format("{0} {1}\n", dt.ToString("yyyy-MM-dd hh:mm:ss"), obj); console.InvokeSelf(txt); } catch (Exception ex) { var msg = ex.Message; //MessageBox.Show(msg); } } // public static void Log(this object obj)
public static void Write(object message, params object[] values) { HtmlWindow window = HtmlPage.Window; var isConsoleAvailable = (bool)window.Eval("typeof(console) != 'undefined' && typeof(console.log) != 'undefined'"); if (isConsoleAvailable) { var createLogFunction = (bool)window.Eval("typeof(sllog) == 'undefined'"); if (createLogFunction) { // Load the logging function into global scope: string logFunction = "function sllog(msg) { console.log(msg); }"; string code = string.Format(@"if(window.execScript) {{ window.execScript('{0}'); }} else {{ eval.call(null, '{0}'); }}", logFunction); window.Eval(code); } // Prepare the message DateTime dateTime = DateTime.Now; string output = string.Format("{0} - {1}", dateTime.ToString("u"), string.Format(message.ToString(), values)); // Invoke the logging function: var logger = window.Eval("sllog") as ScriptObject; if (logger != null) { // Workaround: Cannot call InvokeSelf outside of UI thread, without dispatcher Dispatcher d = Deployment.Current.Dispatcher; if (!d.CheckAccess()) { d.BeginInvoke((ThreadStart)(() => logger.InvokeSelf(output))); } else { logger.InvokeSelf(output); } } } }
} // public void configure() public void doRestoreMap(string baseurl) { log(string.Format("VRestoreFromServ.doRestore...")); // http://vdesk.algis.com/Apps/app3/index.htm#940213BE6D82CEC72CDA9CBC6976E534A1C232B4 HtmlWindow window = HtmlPage.Window; var func = (window.Eval("getLocationHash") as ScriptObject); var res = func.InvokeSelf() as string; log(string.Format("VRestoreFromServ.doRestore, hash='{0}'", res)); if (res == "") { log(string.Format("VRestoreFromServ.doRestore done, hash is null")); return; } else { cfgHash = res; log(string.Format("VRestoreFromServ.doRestore, proceed cfg retrieval...")); readConfig(baseurl, res); } } // public void doRestoreMap()
public void JsonSerializerTest() { ScriptObject services = (ScriptObject)content.GetProperty("services"); // the msdn docs say this is valid, but it appears it is not. ScriptObject serializer = (ScriptObject)window.Eval("serializer = " + strplugin + ".content.services.createObject ('jsonSerializer');"); Assert.IsNull(serializer); // the jsonSerialize method is, however, available List <int> l = new List <int> { 4, 5, 6 }; object o = services.Invoke("jsonSerialize", new object[] { l }); Assert.IsInstanceOfType(o, typeof(string), "serialize #1"); Assert.AreEqual("[4,5,6]", o, "serialize #2"); }