Example #1
0
        private bool DoGetStubInfoMessage(long messageID, ExecCallback callback, Dictionary <string, object> jsonData)
        {
            if (!jsonData.ContainsKey("reference"))
            {
                callback(FormatError(messageID, -1001, "errUnknownObject", "object reference missing"));
                return(false);
            }
            string reference         = (string)jsonData["reference"];
            object destinationObject = this.GetDestinationObject(reference);

            if (destinationObject == null)
            {
                callback(FormatError(messageID, -1001, "errUnknownObject", "cannot find object with reference <" + reference + ">"));
                return(false);
            }
            List <MethodInfo> list = destinationObject.GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance).ToList <MethodInfo>();

            list.AddRange(destinationObject.GetType().GetMethods(BindingFlags.Public | BindingFlags.Static).ToList <MethodInfo>());
            ArrayList list2 = new ArrayList();

            foreach (MethodInfo info in list)
            {
                if ((Array.IndexOf <string>(s_IgnoredMethods, info.Name) < 0) && (!info.IsSpecialName || (!info.Name.StartsWith("set_") && !info.Name.StartsWith("get_"))))
                {
                    System.Reflection.ParameterInfo[] parameters = info.GetParameters();
                    ArrayList list3 = new ArrayList();
                    foreach (System.Reflection.ParameterInfo info2 in parameters)
                    {
                        list3.Add(info2.Name);
                    }
                    JspmMethodInfo info3 = new JspmMethodInfo(info.Name, (string[])list3.ToArray(typeof(string)));
                    list2.Add(info3);
                }
            }
            List <PropertyInfo> list4 = destinationObject.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).ToList <PropertyInfo>();
            ArrayList           list5 = new ArrayList();

            foreach (PropertyInfo info4 in list4)
            {
                list5.Add(new JspmPropertyInfo(info4.Name, info4.GetValue(destinationObject, null)));
            }
            List <System.Reflection.FieldInfo> list6 = destinationObject.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance).ToList <System.Reflection.FieldInfo>();

            foreach (System.Reflection.FieldInfo info5 in list6)
            {
                list5.Add(new JspmPropertyInfo(info5.Name, info5.GetValue(destinationObject)));
            }
            List <EventInfo> list7 = destinationObject.GetType().GetEvents(BindingFlags.Public | BindingFlags.Instance).ToList <EventInfo>();
            ArrayList        list8 = new ArrayList();

            foreach (EventInfo info6 in list7)
            {
                list8.Add(info6.Name);
            }
            callback(new JspmStubInfoSuccess(messageID, reference, (JspmPropertyInfo[])list5.ToArray(typeof(JspmPropertyInfo)), (JspmMethodInfo[])list2.ToArray(typeof(JspmMethodInfo)), (string[])list8.ToArray(typeof(string))));
            return(true);
        }
        public InstanceExecResponse(ClientWebSocket websocket, string uri, ExecCallback callback)
        {
            this.Data    = new InstancesResponseData();
            this.Headers = new Dictionary <string, object> {
            };

            this.websocket = websocket;
            this.callback  = callback;
            this.uri       = new Uri(uri);
        }
Example #3
0
        public bool DoMessage(string jsonRequest, ExecCallback callback, WebView webView)
        {
            long messageID = kInvalidMessageID;

            try
            {
                var jsonData = Json.Deserialize(jsonRequest) as Dictionary <string, object>;
                if (jsonData == null || !jsonData.ContainsKey("messageID") || !jsonData.ContainsKey("version") || !jsonData.ContainsKey("type"))
                {
                    callback(FormatError(messageID, kErrInvalidMessageFormat, "errInvalidMessageFormat", jsonRequest));
                    return(false);
                }

                messageID = (long)jsonData["messageID"];
                double versionNumber = double.Parse((string)jsonData["version"], System.Globalization.CultureInfo.InvariantCulture);
                string type          = (string)jsonData["type"];

                if (versionNumber > kProtocolVersion)
                {
                    callback(FormatError(messageID, kErrUnsupportedProtocol, "errUnsupportedProtocol", "The protocol version <" + versionNumber + "> is not supported by this verison of the code"));
                    return(false);
                }

                if (type == kTypeInvoke)
                {
                    return(DoInvokeMessage(messageID, callback, jsonData));
                }

                if (type == kTypeGetStubInfo)
                {
                    return(DoGetStubInfoMessage(messageID, callback, jsonData));
                }

                if (type == kTypeOnEvent)
                {
                    return(DoOnEventMessage(messageID, callback, jsonData, webView));
                }
            }
            catch (Exception ex)
            {
                callback(FormatError(messageID, kErrInvalidMessageFormat, "errInvalidMessageFormat", ex.Message));
            }

            return(false);
        }
        int ISQLiteProvider.sqlite3_exec(IntPtr db, string sql, ExecCallback callback, object userData, out string errMsg)
        {
            if (callback != null)
            {
                throw new NotSupportedException();
            }

            var result = sqlite3_exec(db, sql.ToUTF8Bytes(), null, IntPtr.Zero, out var _errMsg);

            if (_errMsg != IntPtr.Zero)
            {
                errMsg = _errMsg.ToUTF8String();
                sqlite3_free(_errMsg);
            }
            else
            {
                errMsg = null;
            }
            return(result);
        }
Example #5
0
 public static extern void BizSetExecCallback(ExecCallback cb);
Example #6
0
        private bool DoInvokeMessage(long messageID, ExecCallback callback, Dictionary <string, object> jsonData)
        {
            if (!jsonData.ContainsKey("destination") || !jsonData.ContainsKey("method") || !jsonData.ContainsKey("params"))
            {
                callback(FormatError(messageID, kErrUnknownObject, "errUnknownObject", "object reference, method name or parameters missing"));
                return(false);
            }

            string        destination = (string)jsonData["destination"];
            string        methodName  = (string)jsonData["method"];
            List <object> paramList   = (List <object>)jsonData["params"];

            object destObject = GetDestinationObject(destination);

            if (destObject == null)
            {
                callback(FormatError(messageID, kErrUnknownObject, "errUnknownObject", "cannot find object with reference <" + destination + ">"));
                return(false);
            }

            Type type = destObject.GetType();

            MethodInfo[] methods     = type.GetMethods();
            MethodInfo   foundMethod = null;

            object[] parameters = null;
            string   err        = "";

            foreach (MethodInfo method in methods)
            {
                if (method.Name != methodName)
                {
                    continue;
                }

                try
                {
                    parameters  = ParseParams(method, paramList);
                    foundMethod = method;
                    break;
                }
                catch (Exception e)
                {
                    err = e.Message;
                }
            }

            if (foundMethod == null)
            {
                callback(FormatError(messageID, kErrUnknownMethod, "errUnknownMethod", "cannot find method <" + methodName + "> for object <" + destination + ">, reason:" + err));
                return(false);
            }

            AddTask(() =>
            {
                try
                {
                    object res = foundMethod.Invoke(destObject, parameters);
                    callback(FormatSuccess(messageID, res));
                }
                catch (TargetInvocationException tiex)
                {
                    if (tiex.InnerException != null)
                    {
                        callback(FormatError(messageID, kErrInvocationFailed, tiex.InnerException.GetType().Name, tiex.InnerException.Message));
                    }
                    else
                    {
                        callback(FormatError(messageID, kErrInvocationFailed, tiex.GetType().Name, tiex.Message));
                    }
                }
                catch (Exception ex)
                {
                    callback(FormatError(messageID, kErrInvocationFailed, ex.GetType().Name, ex.Message));
                }
            });

            return(true);
        }
Example #7
0
 private bool DoOnEventMessage(long messageID, ExecCallback callback, Dictionary <string, object> jsonData, WebView webView)
 {
     callback(FormatError(messageID, kErrUnknownMethod, "errUnknownMethod", "method DoOnEventMessage is deprecated"));
     return(false);
 }
Example #8
0
        private bool DoGetStubInfoMessage(long messageID, ExecCallback callback, Dictionary <string, object> jsonData)
        {
            if (!jsonData.ContainsKey("reference"))
            {
                callback(FormatError(messageID, kErrUnknownObject, "errUnknownObject", "object reference missing"));
                return(false);
            }

            string reference  = (string)jsonData["reference"];
            object destObject = GetDestinationObject(reference);

            if (destObject == null)
            {
                callback(FormatError(messageID, kErrUnknownObject, "errUnknownObject", "cannot find object with reference <" + reference + ">"));
                return(false);
            }

            //Add the public functions and static methods
            List <MethodInfo> methods = (destObject.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public)).ToList();

            methods.AddRange((destObject.GetType().GetMethods(BindingFlags.Public | BindingFlags.Static)).ToList());

            ArrayList methodList = new ArrayList();

            foreach (MethodInfo method in methods)
            {
                if (Array.IndexOf(s_IgnoredMethods, method.Name) >= 0)
                {
                    continue;
                }

                if (method.IsSpecialName && (method.Name.StartsWith("set_") || method.Name.StartsWith("get_")))
                {
                    continue;
                }

                ParameterInfo[] parameters    = method.GetParameters();
                ArrayList       parameterList = new ArrayList();
                foreach (ParameterInfo parameter in parameters)
                {
                    parameterList.Add(parameter.Name);
                }

                JspmMethodInfo info = new JspmMethodInfo(method.Name, (string[])parameterList.ToArray(typeof(string)));
                methodList.Add(info);
            }

            List <PropertyInfo> properties   = destObject.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly).ToList();
            ArrayList           propertyList = new ArrayList();

            foreach (PropertyInfo property in properties)
            {
                propertyList.Add(new JspmPropertyInfo(property.Name, property.GetValue(destObject, null)));
            }

            List <FieldInfo> fields = destObject.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public).ToList();

            foreach (FieldInfo field in fields)
            {
                propertyList.Add(new JspmPropertyInfo(field.Name, field.GetValue(destObject)));
            }

            List <EventInfo> events    = destObject.GetType().GetEvents(BindingFlags.Instance | BindingFlags.Public).ToList();
            ArrayList        eventList = new ArrayList();

            foreach (EventInfo evt in events)
            {
                eventList.Add(evt.Name);
            }

            callback(new JspmStubInfoSuccess(messageID, reference,
                                             (JspmPropertyInfo[])propertyList.ToArray(typeof(JspmPropertyInfo)),
                                             (JspmMethodInfo[])methodList.ToArray(typeof(JspmMethodInfo)),
                                             (string[])eventList.ToArray(typeof(string))));

            return(true);
        }
Example #9
0
 private bool DoInvokeMessage(long messageID, ExecCallback callback, Dictionary <string, object> jsonData)
 {
Example #10
0
 public abstract void BizSetExecCallback(IntPtr ctx, ExecCallback cb);
Example #11
0
        /// <summary>
        /// Lists the instances.
        /// </summary>
        /// <returns>The instances.</returns>
        /// <param name="listFunctionsRequest">List instances request.</param>
        public InstanceExecResponse InstanceExec(InstanceExecRequest instanceExecRequest, ExecCallback callback)
        {
            var webPath = Config.Endpoint + instanceExecRequest.GetPath() + "?" + instanceExecRequest.GetQueries();

            webPath = webPath.Replace("http", "ws");

            ClientWebSocket ws = new ClientWebSocket();

            Dictionary <string, string> headers = new Dictionary <string, string> {
                // { "host", this.Config.Host},
                { "date", DateTime.Now.ToUniversalTime().ToString("r") },
                { "user-agent", this.Config.UserAgent },
            };

            if (this.Config.SecurityToken != "")
            {
                headers.Add("x-fc-security-token", this.Config.SecurityToken);
            }
            headers.Add("authorization", instanceExecRequest.GetSign(headers));

            foreach (var header in headers)
            {
                ws.Options.SetRequestHeader(header.Key, header.Value);
            }

            return(new InstanceExecResponse(ws, webPath, callback));
        }