public void greet(string args) { string name = JsonHelper.Deserialize<string>(args); string message = "Hello, " + name; PluginResult result = new PluginResult(PluginResult.Status.OK, message); DispatchCommandResult(result); }
public void getAppId(string args) { // string name = JsonHelper.Deserialize<string>(args); string message = "REPLACE_WITH_APPID"; PluginResult result = new PluginResult(PluginResult.Status.OK, message); DispatchCommandResult(result); }
public void close(string options="") { if (browser != null) { Deployment.Current.Dispatcher.BeginInvoke(() => { PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame; if (frame != null) { PhoneApplicationPage page = frame.Content as PhoneApplicationPage; if (page != null) { Grid grid = page.FindName("LayoutRoot") as Grid; if (grid != null) { grid.Children.Remove(browser); } page.ApplicationBar = null; } } browser = null; string message = JSON.JsonHelper.Serialize("{\"type\":\"close\"}"); PluginResult result = new PluginResult(PluginResult.Status.OK, message); result.KeepCallback = true; this.DispatchCommandResult(result); }); } }
private void GetWebResource(String url) { Console.Write("GET "+url); HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url); httpWebRequest.Method = "GET"; try{ httpWebRequest.BeginGetResponse(Response_Completed, httpWebRequest); } catch (Exception e) { Console.WriteLine(e.ToString()); PluginResult pr = new PluginResult(PluginResult.Status.ERROR); this.DispatchCommandResult(pr); } }
public void getJSON(string options) { Console.WriteLine("getJSON:"+options); String url = ""; try { Options opts = WP7CordovaClassLib.Cordova.JSON.JsonHelper.Deserialize<Options[]>(options)[0]; url=opts.url; GetWebResource(url); } catch (Exception e) { Console.WriteLine(e.Message); PluginResult pr = new PluginResult(PluginResult.Status.ERROR,e.Message); this.DispatchCommandResult(pr); } }
void Response_Completed(IAsyncResult aResult) { Console.WriteLine("URL Retrieved"); PluginResult pr = new PluginResult(PluginResult.Status.ERROR); /** * * The result will be parsed from string to JSON by cordova.<br> * So the javascript callback will get a JSON object. * */ String result = null; try { result = ""; // HttpWebRequest request = (HttpWebRequest)aResult.AsyncState; HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(aResult); using (StreamReader streamReader = new StreamReader(response.GetResponseStream())) { result = streamReader.ReadToEnd(); Console.WriteLine("result:\n"+result); } if (null == result || "" == result) { pr = new PluginResult(PluginResult.Status.NO_RESULT); } else { pr = new PluginResult(PluginResult.Status.OK,result); } } catch (Exception e) { Console.WriteLine(e.ToString()); pr = new PluginResult(PluginResult.Status.ERROR); } Console.Write("Success:"+pr.IsSuccess); this.DispatchCommandResult(pr); }
/// <summary> /// Handles command execution result. /// </summary> /// <param name="callbackId">Command callback identifier on client side</param> /// <param name="result">Execution result</param> private void OnCommandResult(string callbackId, PluginResult result) { #region args checking if (result == null) { Debug.WriteLine("OnCommandResult missing result argument"); return; } if (String.IsNullOrEmpty(callbackId)) { Debug.WriteLine("OnCommandResult missing callbackId argument"); return; } #endregion string status = ((int)result.Result).ToString(); string jsonResult = result.ToJSONString(); ScriptCallback scriptCallback = null; if (String.IsNullOrEmpty(result.Cast)) { scriptCallback = new ScriptCallback("CordovaCommandResult", new string[] { status, callbackId, jsonResult }); } else { scriptCallback = new ScriptCallback("CordovaCommandResult", new string[] { status, callbackId, jsonResult, result.Cast }); } this.InvokeScriptCallback(scriptCallback); }
void browser_NavigationFailed(object sender, System.Windows.Navigation.NavigationFailedEventArgs e) { string message = "{\"type\":\"navigationError\",\"location\":\"" + e.Uri.AbsoluteUri + "\"}"; PluginResult result = new PluginResult(PluginResult.Status.ERROR, message); result.KeepCallback = true; this.DispatchCommandResult(result); }
void browser_Navigating(object sender, NavigatingEventArgs e) { string message = "{\"type\":\"locationAboutToChange\",\"location\":\"" + e.Uri.AbsoluteUri + "\"}"; PluginResult result = new PluginResult(PluginResult.Status.OK, message); result.KeepCallback = true; this.DispatchCommandResult(result); }
void browser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e) { string message = JSON.JsonHelper.Serialize("{\"type\":\"locationChanged\", \"location\":\"" + e.Uri.AbsoluteUri + "\"}"); PluginResult result = new PluginResult(PluginResult.Status.OK, message); result.KeepCallback = true; this.DispatchCommandResult(result); }