Example #1
0
 public void Reject(string error)
 {
     using (var cefV8Value = CefV8Value.CreateString(error))
     {
         reject.ExecuteFunction(null, new[] { cefV8Value });
     }
 }
Example #2
0
        // Execute the onFailure JavaScript callback.
        void ExecuteFailureCallback(int browserId, int contextId, int requestId,
                                    int errorCode, string errorMessage)
        {
            Helpers.RequireRendererThread();

            bool removed = false;
            var  info    = GetRequestInfo(browserId, contextId, requestId, true, ref removed);

            if (info == null)
            {
                return;
            }

            var context = GetContextByID(contextId);

            if (context != null && info.FailureCallback != null)
            {
                var args = new[] {
                    CefV8Value.CreateInt(errorCode),
                    CefV8Value.CreateString(errorMessage)
                };
                info.FailureCallback.ExecuteFunctionWithContext(context, null, args);
            }

            Debug.Assert(removed);
            info.Dispose();
        }
Example #3
0
        protected override bool Execute(string name, CefV8Value obj,
                                        CefV8Value[] arguments, out CefV8Value returnValue,
                                        out string exception)
        {
            string result = string.Empty;

            switch (name)
            {
            case "MyFunction":
                MyFunction();
                break;

            case "GetMyParam":
                result = GetMyParam();
                break;

            case "SetMyParam":
                result = SetMyParam(arguments[0].GetStringValue());
                break;

            default:
                MessageBox.Show(string.Format("JS调用C# >> {0} >> {1} 返回值",
                                              name, obj.GetType()), "系统提示", MessageBoxButtons.OK);
                break;
            }
            returnValue = CefV8Value.CreateString(result);
            exception   = null;
            return(true);
        }
Example #4
0
        /// <summary>
        /// Register custom variables and functions as the object 'reko' in the global context
        /// </summary>
        public void RegisterGlobals()
        {
            context.Acquire(() => {
                var global  = context.GetGlobal();
                var rekoObj = CefV8Value.CreateObject();

                var dumpBytesFn      = new Proto_DumpBytes(decompiler);
                var procListRenderer = new ProcedureListRenderer(decompiler);

                global.SetValue("reko", rekoObj);
                RegisterAsyncFunction(rekoObj, "OpenFile", new OpenFileHandler(promiseFactory, pendingPromises));
                RegisterAsyncFunction(rekoObj, "Proto_DisassembleRandomBytes", new Func <string, string, string>(Proto_DisassembleRandomBytes.Execute));
                RegisterAsyncFunction(rekoObj, "Proto_GeneratePng", new Func <int, byte[]>(Proto_GeneratePng.Execute));
                RegisterAsyncFunction(rekoObj, "LoadFile", new Func <string, string?, Address?, bool>(decompiler.Load));
                RegisterAsyncFunction(rekoObj, "Scan", new Action(decompiler.ScanPrograms));
                RegisterAsyncFunction(rekoObj, "DumpBytes", new Func <string, string, long, string>(dumpBytesFn.Execute));
                RegisterAsyncFunction(rekoObj, "GetProcedureList", new Func <string, string>(procListRenderer.Render));
                RegisterFunction(rekoObj, "TestListener", new Action(() =>
                {
                    var listener = services.RequireService <DecompilerEventListener>();
                    listener.Info(new NullCodeLocation("web"), "Hello World");
                }));
                RegisterFunction(rekoObj, "RegisterEventListener", new Proto_RegisterEventListener(eventListeners));
                RegisterFunction(rekoObj, "RenderProjectView", new Func <string>(() => ProjectViewRenderer.RenderToHtml(decompiler)));
                RegisterFunction(rekoObj, "RenderProcedure", new Func <CefV8Value, CefV8Value>((CefV8Value key) =>
                {
                    var iKey = key.GetIntValue();
                    var proc = new ProcedureViewModel(iKey);
                    var obj  = CefV8Value.CreateObject();
                    obj.SetValue("name", CefV8Value.CreateString(proc.Name));
                    obj.SetValue("body", CefV8Value.CreateString(proc.Body));
                    return(obj);
                }));
            });
        }
Example #5
0
        public static CefV8Value ToCefV8Value(this JavaScriptValue source)
        {
            switch (source.ValueType)
            {
            case JavaScriptValueType.Null:
                return(CefV8Value.CreateNull());

            case JavaScriptValueType.Bool:
                return(CefV8Value.CreateBool(source.GetBool()));

            case JavaScriptValueType.Int:
                return(CefV8Value.CreateInt(source.GetInt()));

            case JavaScriptValueType.Double:
                return(CefV8Value.CreateDouble(source.GetDouble()));

            case JavaScriptValueType.String:
                return(CefV8Value.CreateString(source.GetString()));

            case JavaScriptValueType.DateTime:
                return(CefV8Value.CreateDate(source.GetDateTime()));

            case JavaScriptValueType.Property:
                break;

            case JavaScriptValueType.Function:
                break;

            case JavaScriptValueType.Object:
                var obj = CefV8Value.CreateObject();
                foreach (var key in source.Keys)
                {
                    var retval = source.GetValue(key)?.ToCefV8Value();
                    if (retval != null)
                    {
                        obj.SetValue(key, retval);
                    }
                }
                return(obj);

            case JavaScriptValueType.Array:
                var result = new List <CefV8Value>();
                for (int i = 0; i < source.ArrayLength; i++)
                {
                    var retval = source.GetValue(i)?.ToCefV8Value();
                    if (retval != null)
                    {
                        result.Add(retval);
                    }
                }
                var array = CefV8Value.CreateArray(result.Count);
                for (int i = 0; i < result.Count; i++)
                {
                    array.SetValue(i, result[i]);
                }
                return(array);
            }

            return(null);
        }
Example #6
0
        protected override bool Execute(string name, CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue, out string exception)
        {
            string result = string.Empty;

            switch (name)
            {
            case "MyFunction":
                MyFunction();
                break;

            case "GetEmail":
                result = GetEmail();
                break;

            case "SetEmail":
                SetEmail(arguments[0].GetStringValue());
                break;

            default:
                break;
            }

            returnValue = CefV8Value.CreateString(result);
            exception   = null;
            return(true);
        }
Example #7
0
        // Execute the onSuccess JavaScript callback.
        private void ExecuteSuccessCallback(int browserId, int contextId, int requestId, string response)
        {
            Helpers.RequireRendererThread();

            bool removed = false;
            var  info    = GetRequestInfo(browserId, contextId, requestId, false, ref removed);

            if (info == null)
            {
                return;
            }

            var context = GetContextByID(contextId);

            if (context != null && info.SuccessCallback != null)
            {
                var args = new[] { CefV8Value.CreateString(response) };
                info.SuccessCallback.ExecuteFunctionWithContext(context, null, args);
            }

            if (removed)
            {
                info.Dispose();
            }
        }
Example #8
0
        protected override void OnContextCreated(CefBrowser browser, CefFrame frame, CefV8Context context)
        {
            CefV8Value cefV8Value = context.GetGlobal();

            cefV8Value.SetValue("appName", CefV8Value.CreateString("CMCS.Monitor.Win"), CefV8PropertyAttribute.ReadOnly);

            base.OnContextCreated(browser, frame, context);
        }
        protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message)
        {
            if (message.Name == "SetOverlayAPI")
            {
                // 対象のフレームを取得
                var frameName      = message.Arguments.GetString(0);
                var frame          = GetFrameByName(browser, frameName);
                var overlayName    = message.Arguments.GetString(1);
                var overlayVersion = message.Arguments.GetString(2);

                // API を設定
                if (frame != null && frame.V8Context.Enter())
                {
                    var apiObject = CefV8Value.CreateObject(null);

                    var broadcastMessageFunction = CefV8Value.CreateFunction(
                        BuiltinFunctionHandler.BroadcastMessageFunctionName,
                        builtinFunctionHandler);
                    var sendMessageFunction = CefV8Value.CreateFunction(
                        BuiltinFunctionHandler.SendMessageFunctionName,
                        builtinFunctionHandler);
                    var overlayMessageFunction = CefV8Value.CreateFunction(
                        BuiltinFunctionHandler.OverlayMessageFunctionName,
                        builtinFunctionHandler);
                    var endEncounterFunction = CefV8Value.CreateFunction(
                        BuiltinFunctionHandler.EndEncounterFunctionName,
                        builtinFunctionHandler);

                    apiObject.SetValue("version", CefV8Value.CreateString(overlayVersion), CefV8PropertyAttribute.ReadOnly);
                    apiObject.SetValue("overlayName", CefV8Value.CreateString(overlayName), CefV8PropertyAttribute.ReadOnly);

                    apiObject.SetValue(
                        BuiltinFunctionHandler.BroadcastMessageFunctionName,
                        broadcastMessageFunction,
                        CefV8PropertyAttribute.ReadOnly);
                    apiObject.SetValue(
                        BuiltinFunctionHandler.SendMessageFunctionName,
                        sendMessageFunction,
                        CefV8PropertyAttribute.ReadOnly);
                    apiObject.SetValue(
                        BuiltinFunctionHandler.OverlayMessageFunctionName,
                        overlayMessageFunction,
                        CefV8PropertyAttribute.ReadOnly);
                    apiObject.SetValue(
                        BuiltinFunctionHandler.EndEncounterFunctionName,
                        endEncounterFunction,
                        CefV8PropertyAttribute.ReadOnly);

                    frame.V8Context.GetGlobal().SetValue("OverlayPluginApi", apiObject, CefV8PropertyAttribute.ReadOnly);

                    frame.V8Context.Exit();
                }
                return(true);
            }

            return(base.OnProcessMessageReceived(browser, sourceProcess, message));
        }
Example #10
0
 protected override void Execute()
 {
     ctx.Acquire(() =>
     {
         eventListeners.Invoke(sinkName, new CefV8Value[]
         {
             CefV8Value.CreateString(message)
         });
     });
 }
 public void Test_GetSimpleValue_String()
 {
     Test(() =>
     {
         object res = null;
         bool ok    = _CefV8_Converter.GetSimpleValue(CefV8Value.CreateString("titi").Convert(), out res);
         ok.Should().BeTrue();
         res.Should().Be("titi");
     });
 }
        public virtual void Invoke(IV8PluginRouter router, CefV8Context context, object result, int errorCode, string error)
        {
            if (CallbackFunction == null)
            {
                throw new ObjectDisposedException("_callback");
            }

            // Have to enter the context in order to be able to create object/array/function/date V8 instances
            context.Enter();
            try
            {
                var args = new List <CefV8Value>();
                switch (_callbackType)
                {
                case V8CallbackType.ParameterCallback:
                case V8CallbackType.EventListener:
                {
                    var remoteResult = result as ResultData;
                    var localArray   = result as object[];

                    if (remoteResult != null)
                    {
                        if (remoteResult.Items != null)
                        {
                            args.AddRange(remoteResult.Items.Select(item => ToCefV8Value(router, item)));
                        }
                    }
                    else if (localArray != null)
                    {
                        args.AddRange(localArray.Select(item => ToCefV8Value(router, item)));
                    }

                    break;
                }

                case V8CallbackType.FunctionCallback:
                {
                    args.Add(ToCefV8Value(router, result));
                    args.Add(CefV8Value.CreateInt(errorCode));
                    args.Add(CefV8Value.CreateString(error));
                    break;
                }
                }
                var functionResult = CallbackFunction.ExecuteFunction(null, args.ToArray());
                if (functionResult == null && CallbackFunction.HasException)
                {
                    var exception = CallbackFunction.GetException();
                    Logger.Error("Error executing callback: ", exception.Message);
                }
            }
            finally
            {
                context.Exit();
            }
        }
 protected override bool Execute(
     string name,
     CefV8Value obj,
     CefV8Value[] arguments,
     out CefV8Value returnValue,
     out string exception)
 {
     returnValue = CefV8Value.CreateString("");
     this.ReceiveJsFunctionCall(arguments, ref returnValue);
     exception = (string)null;
     return(true);
 }
Example #14
0
 public static CefV8Value ConvertToV8Value(object o)
 {
     if (o == null)
     {
         return(CefV8Value.CreateUndefined());
     }
     if (o is bool)
     {
         return(CefV8Value.CreateBool((bool)o));
     }
     if (o is DateTime)
     {
         return(CefV8Value.CreateDate((DateTime)o));
     }
     if (o is double)
     {
         return(CefV8Value.CreateDouble((double)o));
     }
     if (o is int)
     {
         return(CefV8Value.CreateInt((int)o));
     }
     if (o is string)
     {
         return(CefV8Value.CreateString((string)o));
     }
     if (o is uint)
     {
         return(CefV8Value.CreateUInt((uint)o));
     }
     if (o is Array)
     {
         var a   = (Array)o;
         var rtn = CefV8Value.CreateArray(a.Length);
         for (int i = 0; i < a.Length; i++)
         {
             rtn.SetValue(i, ConvertToV8Value(a.GetValue(i)));
         }
         return(rtn);
     }
     if (o is System.Collections.IList)
     {
         var a   = (System.Collections.IList)o;
         var rtn = CefV8Value.CreateArray(a.Count);
         for (int i = 0; i < a.Count; i++)
         {
             rtn.SetValue(i, ConvertToV8Value(a[i]));
         }
         return(rtn);
     }
     throw new NotSupportedException("??");
 }
Example #15
0
        /// <summary>
        /// 执行JS方法
        /// </summary>
        /// <param name="name">方法名</param>
        /// <param name="obj"></param>
        /// <param name="arguments"></param>
        /// <param name="returnValue"></param>
        /// <param name="exception"></param>
        /// <returns></returns>
        protected override bool Execute(string name, CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue, out string exception)
        {
            exception = null;
            try
            {
                List <object> paras  = V8ValueClrMap.ConvertToClrParameters(arguments);
                var           clrObj = V8ValueClrMap.GetClrValue(obj);
                Type          t      = null;
                if (obj.IsObject)
                {
                    t = clrObj.GetType();
                }

                var function = t.GetMethod(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.IgnoreCase | BindingFlags.DeclaredOnly);
                if (function != null)
                {
                    var objRst = function.Invoke(clrObj, paras.Count == 0 ? null : paras.ToArray());
                    if (objRst is CefV8Handler)
                    {
                        returnValue = CefV8Value.CreateObject(null);
                        Bind(name, objRst as CefV8Handler, returnValue);
                    }
                    else
                    {
                        returnValue = V8ValueClrMap.ConvertToV8Value(objRst);
                    }
                }
                else
                {
                    exception   = "方法没有找到:" + name;
                    returnValue = CefV8Value.CreateString("");
                    var message3 = CefProcessMessage.Create("Exception");
                    message3.Arguments.SetString(0, exception);
                    //var success2 = Browser.SendProcessMessage(CefProcessId.Browser, message3);

                    return(true);
                }
                return(true);
            }
            catch (Exception ee)
            {
                returnValue = CefV8Value.CreateString("");
                exception   = ee.Message;

                returnValue = CefV8Value.CreateString("");
                var message3 = CefProcessMessage.Create("Exception");
                message3.Arguments.SetString(0, ee.ToString());
                //var success2 = Browser.SendProcessMessage(CefProcessId.Browser, message3);

                return(true);
            }
        }
Example #16
0
 public static CefV8Value ConvertToV8Value(dynamic result)
 {
     if (result != null)
     {
         if (result is bool)
         {
             return(CefV8Value.CreateBool(result));
         }
         else if (result is DateTime)
         {
             return(CefV8Value.CreateDate(result));
         }
         else if (result is double)
         {
             return(CefV8Value.CreateDouble(result));
         }
         else if (result is int)
         {
             return(CefV8Value.CreateInt(result));
         }
         else if (result is string)
         {
             return(CefV8Value.CreateString(result));
         }
         else if (result is uint)
         {
             return(CefV8Value.CreateUInt(result));
         }
         else if (result is Array)
         {
             var source      = (Array)result;
             var destination = CefV8Value.CreateArray(source.Length);
             for (int x = 0; x < source.Length; x++)
             {
                 destination.SetValue(x, ConvertToV8Value(source.GetValue(x)));
             }
             return(destination);
         }
         else if (result is System.Collections.IList)
         {
             var source      = (System.Collections.IList)result;
             var destination = CefV8Value.CreateArray(source.Count);
             for (int x = 0; x < source.Count; x++)
             {
                 destination.SetValue(x, ConvertToV8Value(source[x]));
             }
             return(destination);
         }
         //else throw new NotSupportedException("V8 Value");
     }
     return(CefV8Value.CreateNull());
 }
Example #17
0
 public static CefV8Value ConvertToJsValue(object?value)
 {
     if (value is null)
     {
         return(CefV8Value.CreateNull());
     }
     return(value switch
     {
         CefV8Value v => v,
         string s => CefV8Value.CreateString(s),
         bool b => CefV8Value.CreateBool(b),
         Exception ex => MakeJsRejection(ex),
         _ => throw new NotImplementedException()
     });
        protected override void OnContextCreated(CefBrowser browser, CefFrame frame, CefV8Context context)
        {
            base.OnContextCreated(browser, frame, context);

            context.Enter();

            //可在這裡面改V8引擎載入的js物件
            var window       = context.GetGlobal();
            var computerName = CefV8Value.CreateString(Environment.MachineName);

            window.SetValue("computer_name", computerName, CefV8PropertyAttribute.DontDelete | CefV8PropertyAttribute.ReadOnly);

            context.Exit();
        }
Example #19
0
        public static CefV8Value CreateValue(object value)
        {
            if (value == null)
            {
                return(CefV8Value.CreateNull());
            }
            if (value is bool)
            {
                return(CefV8Value.CreateBool((bool)value));
            }
            if (value is double)
            {
                return(CefV8Value.CreateDouble((double)value));
            }
            if (value is float)
            {
                return(CefV8Value.CreateDouble((double)(float)value));
            }
            if (value is int)
            {
                return(CefV8Value.CreateInt((int)value));
            }
            var s = value as string;

            if (s != null)
            {
                return(CefV8Value.CreateString(s));
            }
            if (value is uint)
            {
                return(CefV8Value.CreateUInt((uint)value));
            }
            var list = value as IList;

            if (list == null)
            {
                return(CefV8Value.CreateUndefined());
            }
            var val = list;

            var arr = CefV8Value.CreateArray(val.Count);

            for (var i = 0; i < val.Count; i++)
            {
                arr.SetValue(i, CreateValue(val[i]));
            }

            return(arr);
        }
Example #20
0
        private void CefWebBrowserMainView_CreateJSObject(object sender, Xilium.CefGlue.WindowsForms.CefWebBrowser.CefWebCreateJSObjectEventArgs e)
        {
            // Retrieve the context's window object.
            CefV8Value window = e.Context.GetGlobal();

            // window.pos
            CefV8Value pos = CefV8Value.CreateObject(null);

            window.SetValue("pos", pos, CefV8PropertyAttribute.DontDelete | CefV8PropertyAttribute.ReadOnly);

            // window.pos.Message
            CefV8Value pos_Message = CefV8Value.CreateString("Hello Vue.js 讀書會");

            pos.SetValue("Message", pos_Message, CefV8PropertyAttribute.DontDelete | CefV8PropertyAttribute.ReadOnly);
        }
Example #21
0
        protected override bool Execute(string name, CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue, out string exception)
        {
            exception = null;
            switch (name)
            {
            case "CallCSharpMethod":
                string methodName = arguments[0].GetStringValue();
                string values     = arguments[1].GetStringValue();
                string res        = Global.CallMethod(activeBrowser, methodName, values);
                returnValue = CefV8Value.CreateString(res);
                return(true);
            }

            returnValue = null;
            return(false);
        }
Example #22
0
        protected override bool Execute(string name, CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue, out string exception)
        {
            exception   = null;
            returnValue = null;
            string paramSampler1 = "", paramSampler2 = "";

            if (arguments.Length > 0)
            {
                paramSampler1 = arguments[0].GetStringValue();
            }
            if (arguments.Length > 1)
            {
                paramSampler2 = arguments[1].GetStringValue();
            }

            switch (name)
            {
            // 设置
            case "SubmitSet":
                bool res = SetConfig(paramSampler1, paramSampler2);
                returnValue = CefV8Value.CreateString(res.ToString());
                break;

            //获取异常信息
            case "GetHitchs":
                //异常信息
                string machineCode = string.Empty;
                if (paramSampler1 == "#1")
                {
                    machineCode = GlobalVars.MachineCode_InPDCYJ_1;
                }
                else if (paramSampler1 == "#2")
                {
                    machineCode = GlobalVars.MachineCode_InPDCYJ_2;
                }
                equInfHitchs = CommonDAO.GetInstance().GetEquInfHitchsByTime(machineCode, DateTime.Now);
                returnValue  = CefV8Value.CreateString(Newtonsoft.Json.JsonConvert.SerializeObject(equInfHitchs.Select(a => new { MachineCode = a.MachineCode, HitchTime = a.HitchTime.ToString("yyyy-MM-dd HH:mm"), HitchDescribe = a.HitchDescribe })));
                break;

            default:
                returnValue = null;
                break;
            }

            return(true);
        }
Example #23
0
        public static CefV8Value CreateValue(object value)
        {
            if (value == null)
            {
                return(CefV8Value.CreateNull());
            }
            if (value is bool)
            {
                return(CefV8Value.CreateBool((bool)value));
            }
            if (value is double)
            {
                return(CefV8Value.CreateDouble((double)value));
            }
            if (value is float)
            {
                return(CefV8Value.CreateDouble((double)(float)value));
            }
            if (value is int)
            {
                return(CefV8Value.CreateInt((int)value));
            }
            if (value is string)
            {
                return(CefV8Value.CreateString((string)value));
            }
            if (value is uint)
            {
                return(CefV8Value.CreateUInt((uint)value));
            }
            if (value is IList)
            {
                IList val = (IList)value;

                var arr = CefV8Value.CreateArray(val.Count);

                for (int i = 0; i < val.Count; i++)
                {
                    arr.SetValue(i, CreateValue(val[i]));
                }

                return(arr);
            }
            return(CefV8Value.CreateUndefined());
        }
Example #24
0
        protected override bool Execute(string name, CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue, out string exception)
        {
            exception   = null;
            returnValue = null;
            string paramSampler = arguments[0].GetStringValue();

            switch (name)
            {
            //获取异常信息
            case "GetHitchs":
                //异常信息
                string machineCode = string.Empty;
                if (paramSampler == "#1")
                {
                    machineCode = GlobalVars.MachineCode_QZDZYJ_1;
                }
                else if (paramSampler == "#2")
                {
                    machineCode = GlobalVars.MachineCode_QZDZYJ_2;
                }
                equInfHitchs = CommonDAO.GetInstance().GetEquInfHitchsByTime(machineCode, DateTime.Now);
                returnValue  = CefV8Value.CreateString(Newtonsoft.Json.JsonConvert.SerializeObject(equInfHitchs.Select(a => new { MachineCode = a.MachineCode, HitchTime = a.HitchTime.ToString("yyyy-MM-dd HH:mm"), HitchDescribe = a.HitchDescribe })));
                break;

            case "OpenAutoMaker":
                CefProcessMessage OpenAutoMaker = CefProcessMessage.Create("OpenAutoMaker");
                int f = 0;
                foreach (CefV8Value item in arguments)
                {
                    CefValue model = CefValue.Create();
                    model.SetString(item.GetStringValue());
                    OpenAutoMaker.Arguments.SetValue(f, model);
                    f++;
                }

                CefV8Context.GetCurrentContext().GetBrowser().SendProcessMessage(CefProcessId.Browser, OpenAutoMaker);
                break;

            default:
                returnValue = null;
                break;
            }

            return(true);
        }
Example #25
0
        public void Then(CefV8Value promise, CefV8Context context, Action <PromiseResult> continuation)
        {
            var id = pendingPromises.Save(context.GetFrame().Identifier, new PendingPromise
            {
                Continuation = continuation
            });

            using (new ContextHelper(context))
                using (var global = context.GetGlobal())
                    using (var s = global.GetValue(HelperObjectName))
                    {
                        var userData       = s.GetUserData() as PromiseUserData;
                        var waitForPromise = userData.WaitForPromise;
                        using (var idValue = CefV8Value.CreateString(id.ToString()))
                        {
                            waitForPromise.ExecuteFunctionWithContext(context, null, new[] { promise, idValue }).Dispose();
                        }
                    }
        }
        private CefV8Value DontMeetRequirements(CefV8Context context, CefV8Value callback)
        {
            var msg = JsonMapper.ToJson(new StatusHelper("Error", "Arguments do not meet function requirement"));

            if (callback != null)
            {
                var runner = CefTaskRunner.GetForCurrentThread();
                new Task(() =>
                {
                    context.Enter();
                    runner.PostTask(new CallbackTask(context, callback, msg));
                    context.Exit();
                }).Start();
                return(CefV8Value.CreateNull());
            }
            else
            {
                return(CefV8Value.CreateString(msg));
            }
        }
Example #27
0
 private CefV8Value InvokeContructor(ConstructorInfo constructor, List <object> args, Type type)
 {
     if (constructor != null)
     {
         if (type == typeof(bool))
         {
             return(CefV8Value.CreateBool((bool)constructor.Invoke(args.ToArray())));
         }
         else if (type == typeof(DateTime))
         {
             return(CefV8Value.CreateDate((DateTime)constructor.Invoke(args.ToArray())));
         }
         else if (type == typeof(double))
         {
             return(CefV8Value.CreateDouble((double)constructor.Invoke(args.ToArray())));
         }
         else if (type == typeof(int))
         {
             return(CefV8Value.CreateInt((int)constructor.Invoke(args.ToArray())));
         }
         else if (type == typeof(string))
         {
             return(CefV8Value.CreateString((string)constructor.Invoke(args.ToArray())));
         }
         else if (type == typeof(uint))
         {
             return(CefV8Value.CreateUInt((uint)constructor.Invoke(args.ToArray())));
         }
         else if (type == typeof(string[]) ||
                  type == typeof(int[]) ||
                  type == typeof(double[]) ||
                  type == typeof(DateTime[]) ||
                  type == typeof(bool[]) ||
                  type == typeof(uint[]) ||
                  type == typeof(Enum[]))
         {
             return(Extension.ConvertToV8Value(constructor.Invoke(args.ToArray())));
         }
     }
     return(null);
 }
Example #28
0
 private CefV8Value InvokeMethod(MethodInfo method, List <object> args, Type type)
 {
     if (method != null)
     {
         if (type == typeof(bool))
         {
             return(CefV8Value.CreateBool((bool)method.Invoke(this, args.ToArray())));
         }
         else if (type == typeof(DateTime))
         {
             return(CefV8Value.CreateDate((DateTime)method.Invoke(this, args.ToArray())));
         }
         else if (type == typeof(double))
         {
             return(CefV8Value.CreateDouble((double)method.Invoke(this, args.ToArray())));
         }
         else if (type == typeof(int))
         {
             return(CefV8Value.CreateInt((int)method.Invoke(this, args.ToArray())));
         }
         else if (type == typeof(string))
         {
             return(CefV8Value.CreateString((string)method.Invoke(this, args.ToArray())));
         }
         else if (type == typeof(uint))
         {
             return(CefV8Value.CreateUInt((uint)method.Invoke(this, args.ToArray())));
         }
         else if (type == typeof(string[]) ||
                  type == typeof(int[]) ||
                  type == typeof(double[]) ||
                  type == typeof(DateTime[]) ||
                  type == typeof(bool[]) ||
                  type == typeof(uint[]) ||
                  type == typeof(Enum[]))
         {
             return(Extension.ConvertToV8Value(method.Invoke(this, args.ToArray())));
         }
     }
     return(null);
 }
Example #29
0
        static CefV8_Factory()
        {
            Register <string>(CefV8Value.CreateString);

            Register <Int64>((source) => CefV8Value.CreateDouble((double)source));
            Register <UInt64>((source) => CefV8Value.CreateDouble((double)source));
            Register <float>((source) => CefV8Value.CreateDouble((double)source));

            Register <Int32>(CefV8Value.CreateInt);
            Register <Int16>((source) => CefV8Value.CreateInt((int)source));

            Register <UInt32>(CefV8Value.CreateUInt);
            Register <UInt16>((source) => CefV8Value.CreateUInt((UInt32)source));

            //check two way and convertion back
            Register <char>((source) => CefV8Value.CreateString(new StringBuilder().Append(source).ToString()));
            Register <double>(CefV8Value.CreateDouble);
            Register <decimal>((source) => CefV8Value.CreateDouble((double)source));
            Register <bool>(CefV8Value.CreateBool);
            Register <DateTime>(CefV8Value.CreateDate);
        }
Example #30
0
        protected override bool Execute(string name, CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue, out string exception)
        {
            exception   = null;
            returnValue = null;
            string paramSampler = arguments[0].GetStringValue();

            switch (name)
            {
            //获取异常信息
            case "GetHitchs":
                //异常信息
                string machineCode = string.Empty;
                if (paramSampler == "#1CYG")
                {
                    machineCode = GlobalVars.MachineCode_CYG1;
                }
                else if (paramSampler == "#2CYG")
                {
                    machineCode = GlobalVars.MachineCode_CYG2;
                }
                else if (paramSampler == "#1QD")
                {
                    machineCode = GlobalVars.MachineCode_QD;
                }

                equInfHitchs = CommonDAO.GetInstance().GetEquInfHitchsByTime(machineCode, DateTime.Now);
                returnValue  = CefV8Value.CreateString(Newtonsoft.Json.JsonConvert.SerializeObject(equInfHitchs.Select(a => new { MachineCode = a.MachineCode, HitchTime = a.HitchTime.ToString("yyyy-MM-dd HH:mm"), HitchDescribe = a.HitchDescribe })));
                break;

            default:
                returnValue = null;
                break;
            }

            return(true);
        }