Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
 public string SendData(string data)
 {
     if (!string.IsNullOrWhiteSpace(s_method))
     {
         CustomFunction.Run(s_method, new Variable(s_tracking),
                            new Variable(data));
         return("");
     }
     return(data);
 }
Exemplo n.º 5
0
        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));
            }
        }
Exemplo n.º 6
0
        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()));
            }
        }
Exemplo n.º 7
0
        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()));
            }
        }
Exemplo n.º 8
0
        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()));
            }
        }
Exemplo n.º 9
0
        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));
            }
        }