Exemplo n.º 1
0
 public static void notifyBrowser()
 {
     App.main.Dispatcher.Invoke(() =>
     {
         if (callbackarg)
         {
             Awesomium.Core.JSObject status = new Awesomium.Core.JSObject();
             status["running"]     = running;
             status["paused"]      = paused;
             status["done"]        = done;
             status["currentLoop"] = currentLoop;
             status["loopAmount"]  = loopAmount;
             callbackarg?.Invoke("call", callbackarg, status);
         }
     });
 }
Exemplo n.º 2
0
        void InitWizForm_DocumentReady(object sender, Awesomium.Core.UrlEventArgs e)
        {
            webControl1.DocumentReady -= new Awesomium.Core.UrlEventHandler(InitWizForm_DocumentReady);

            // Make sure the view is alive.
            if (!webControl1.IsLive)
            {
                return;
            }

            //Awesomium.Core.JSObject window = webControl1.ExecuteJavascriptWithResult("window");

            //string play = " if ($('.playing').length === 0) { $('.play_pause').click(); }";
            //Awesomium.Core.JSObject window = webControl1.ExecuteJavascriptWithResult(play);
            //Awesomium.Core.Error err = webControl1.GetLastError();


            // NOTE: Below code (and comments) are modified Awesomium sample code
            //
            // This sample demonstrates creating and acquiring a Global Javascript object.
            // These object persist for the lifetime of the web-view.
            using (Awesomium.Core.JSObject myGlobalObject = webControl1.CreateGlobalJavascriptObject("mutefm"))
            {
                // 'Bind' is the method of the regular API, that needs to be used to create
                // a custom method on our global object and bind it to a handler.
                // The handler is of type JavascriptMethodEventHandler. Here we define it
                // using a lambda expression.
                myGlobalObject.Bind("launchWebSite", false, (s, e2) =>
                {
                    // We need to call this asynchronously because the code of 'ChangeHTML'
                    // includes synchronous calls. In this case, 'ExecuteJavascriptWithResult'.
                    // Synchronous Javascript interoperation API calls, cannot be made from
                    // inside Javascript method handlers.
                    BeginInvoke((Action <String>)LaunchWebSite, (string)e2.Arguments[0]);
                });
                myGlobalObject.Bind("closebrowser", false, (s, e2) =>
                {
                    BeginInvoke((Action)CloseBrowser, null);
                });
            }
        }
Exemplo n.º 3
0
 public static void updateCallback(Awesomium.Core.JSObject cb)
 {
     callbackarg = cb;
     notifyBrowser();
 }
Exemplo n.º 4
0
        public static async Task <bool> login(string username, string password, string hwid, Awesomium.Core.JSObject callbackarg)
        {
            var values = new Dictionary <string, string>();

            values.Add("username", username);
            values.Add("password", password);
            values.Add("hwid", hwid);
            var content = new FormUrlEncodedContent(values);

            using (var client = new HttpClient())
            {
                try
                {
                    client.DefaultRequestHeaders.TryAddWithoutValidation("Accept", "text/html,application/xhtml+xml,application/xml");
                    client.DefaultRequestHeaders.TryAddWithoutValidation("Accept-Encoding", "gzip, deflate");
                    client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0");
                    client.DefaultRequestHeaders.TryAddWithoutValidation("Accept-Charset", "ISO-8859-1");
                    var httpResponseMessage = await client.PostAsync("http://handsfreeleveler.com:4446/api/remotelogin", content);

                    if (httpResponseMessage.StatusCode == HttpStatusCode.OK)
                    {
                        string data = await httpResponseMessage.Content.ReadAsStringAsync();

                        var res = JSONSerializer <serviceRes> .DeSerialize(data);

                        if (res.err != null && res.userData == null)
                        {
                            callbackarg?.Invoke("call", callbackarg, false);
                            MessageBox.Show(res.err);
                            return(false);
                        }
                        else
                        {
                            if (res.userData != null)
                            {
                                App.Client = JSONSerializer <User> .DeSerialize(data);

                                callbackarg?.Invoke("call", callbackarg, data);
                                LoginContract loginDetails = new LoginContract();
                                loginDetails.username = username;
                                loginDetails.password = password;
                                Storage.SerializeObject(loginDetails, "loginDetails.xml");
                                return(true);
                            }
                            else
                            {
                                callbackarg?.Invoke("call", callbackarg, false);
                                return(false);
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Server not responding to your request.");
                        callbackarg?.Invoke("call", callbackarg, false);
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    callbackarg?.Invoke("call", callbackarg, false);
                    return(false);
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Process a display request.  For example the calling JS would look like: Authority.request(handlername, somedata).
        /// </summary>
        /// <param name="pDisplay">The display which called this api function.</param>
        /// <param name="pSurface">The surface which this display is hosted on.</param>
        /// <param name="sRequestHandler">The name of the request handler.</param>
        /// <param name="dArguments">The table of arguments which were given in the data parameter.</param>
        /// <returns>True if the request was sucessfully handled.  False if not.</returns>
        public static bool ProcessRequest(Display pDisplay, Surface pSurface, String sRequestHandler, Awesomium.Core.JSObject dArguments)
        {
            // Check the display and surface are valid.
            if (pDisplay == null)
            {
                throw new ArgumentNullException("Cannot process a display API request without a display.");
            }
            if (pSurface == null)
            {
                throw new ArgumentNullException("Cannot process a display API request without a surface.");
            }

            // Check we have a valid request handler.
            if (sRequestHandler == null || sRequestHandler.Length == 0)
            {
                Log.Write("Cannot process a display API request without a handler name.", pDisplay.ToString(), Log.Type.DisplayWarning);
                return(false);
            }

            // Make the request handler lower case.
            sRequestHandler = sRequestHandler.ToLower();

            // Search the bound request handlers.
            DisplayAPI.IRequest pHandler = null;
            if (dRequestHandlers.TryGetValue(sRequestHandler, out pHandler))
            {
                // If one is found, process the request and return the success condition.
                return(pHandler.ProcessRequest(pDisplay, pSurface, dArguments));
            }

            // No handler for request.
            Log.Write("Authority could not find handler for request '" + sRequestHandler + "'.", pDisplay.ToString(), Log.Type.DisplayWarning);
            return(false);
        }