private static void Widget_Click(object sender, EventArgs e) { Control widget = sender as Control; if (widget == null) { return; } string funcName; if (!s_actionHandlers.TryGetValue(widget.Name, out funcName)) { return; } Variable result = null; if (widget is CheckBox) { result = new Variable(((CheckBox)widget).Checked); } else { result = new Variable(widget.Text); } CustomFunction.Run(funcName, new Variable(widget.Name), result); }
public static void RunOnMainThread(CustomFunction callbackFunction, string arg1 = null, string arg2 = null, string arg3 = null) { List<Variable> args = new List<Variable>(); if (arg1 != null) { args.Add(new Variable(arg1)); } if (arg2 != null) { args.Add(new Variable(arg2)); } if (arg3 != null) { args.Add(new Variable(arg3)); } #if __ANDROID__ scripting.Droid.MainActivity.TheView.RunOnUiThread(() => { #elif __IOS__ scripting.iOS.AppDelegate.GetCurrentController().InvokeOnMainThread(() => { #endif callbackFunction.Run(args); #if __ANDROID__ || __IOS__ }); #endif }
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs args) { Exception exc = (Exception)args.ExceptionObject; CustomFunction.Run("OnException", new Variable("Unhandled"), new Variable(exc.Message), new Variable(exc.StackTrace)); System.Threading.Thread.Sleep(2000); }
public string SendData(string data) { if (!string.IsNullOrWhiteSpace(s_method)) { CustomFunction.Run(s_method, new Variable(s_tracking), new Variable(data)); return(""); } return(data); }
private static void Widget_TextChanged(object sender, EventArgs e) { Control widget = sender as Control; if (widget == null) { return; } string funcName; if (s_textChangedHandlers.TryGetValue(widget.Name, out funcName)) { CustomFunction.Run(funcName, new Variable(widget.Name), new Variable(widget.Text)); } }
private static void Widget_KeyPress(object sender, KeyPressEventArgs e) { Control widget = sender as Control; if (widget == null) { return; } string funcName; if (s_keyPressHandlers.TryGetValue(widget.Name, out funcName)) { CustomFunction.Run(funcName, new Variable(widget.Name), new Variable(e.KeyChar.ToString())); } }
private static void Widget_DoubleClick(object sender, EventArgs e) { Control widget = sender as Control; if (widget == null) { return; } string funcName; if (s_doubleClickHandlers.TryGetValue(widget.Name, out funcName)) { CustomFunction.Run(funcName, new Variable(widget.Name), new Variable(e.ToString())); } }
private static void Widget_PreClick(object sender, MouseEventArgs e) { Control widget = sender as Control; if (widget == null || e.Button != MouseButtons.Left) { return; } string funcName; if (s_preActionHandlers.TryGetValue(widget.Name, out funcName)) { CustomFunction.Run(funcName, new Variable(widget.Name), new Variable(e.ToString())); } }
static void ProcessWebRequest(string uri, string method, string load, string onSuccess, string onFailure, string tracking, string contentType, Variable headers) { try { WebRequest request = WebRequest.CreateHttp(uri); request.Method = method; request.ContentType = contentType; if (!string.IsNullOrWhiteSpace(load)) { var bytes = Encoding.UTF8.GetBytes(load); request.ContentLength = bytes.Length; using (var requestStream = request.GetRequestStream()) { requestStream.Write(bytes, 0, bytes.Length); } } if (headers != null && headers.Tuple != null) { var keys = headers.GetKeys(); foreach (var header in keys) { var headerValue = headers.GetVariable(header).AsString(); request.Headers.Add(header, headerValue); } } HttpWebResponse resp = request.GetResponse() as HttpWebResponse; string result; using (StreamReader sr = new StreamReader(resp.GetResponseStream())) { result = sr.ReadToEnd(); } string responseCode = resp == null ? "" : resp.StatusCode.ToString(); CustomFunction.Run(onSuccess, new Variable(tracking), new Variable(responseCode), new Variable(result)); } catch (Exception exc) { CustomFunction.Run(onFailure, new Variable(tracking), new Variable(""), new Variable(exc.Message)); } }