Example #1
0
        public static void Bind(TypeRegister register)
        {
            var ns_jsb = register.CreateNamespace("jsb");

            ns_jsb.AddFunction("DoFile", _DoFile, 1);
            ns_jsb.AddFunction("AddSearchPath", _AddSearchPath, 1);
            ns_jsb.AddFunction("Yield", yield_func, 1);
            ns_jsb.AddFunction("ToArray", to_js_array, 1);
            ns_jsb.AddFunction("ToArrayBuffer", to_js_array_buffer, 1);
            ns_jsb.AddFunction("ToBytes", to_cs_bytes, 1);
            ns_jsb.AddFunction("ToFunction", to_js_function, 1);
            ns_jsb.AddFunction("ToDelegate", to_cs_delegate, 1);
            ns_jsb.AddFunction("Import", js_import_type, 2);
            ns_jsb.AddFunction("GC", _gc, 0);
            ns_jsb.AddFunction("AddCacheString", _add_cache_string, 1);
            ns_jsb.AddFunction("RemoveCacheString", _remove_cache_string, 1);
            ns_jsb.AddFunction("Sleep", _sleep, 1);
            {
                var ns_jsb_hotfix = ns_jsb.CreateNamespace("hotfix");
                ns_jsb_hotfix.AddFunction("replace_single", hotfix_replace_single, 2);
                ns_jsb_hotfix.AddFunction("before_single", hotfix_before_single, 2);
                // ns_jsb_hotfix.AddFunction("replace", hotfix_replace, 2);
                // ns_jsb_hotfix.AddFunction("before", hotfix_before);
                // ns_jsb_hotfix.AddFunction("after", hotfix_after);
                ns_jsb_hotfix.Close();
            }
            ns_jsb.Close();
        }
Example #2
0
        public static ClassDecl Bind(TypeRegister register)
        {
            var ns_jsb = register.CreateClass("JSBObject");

            ns_jsb.AddFunction("DoFile", _DoFile, 1);
            ns_jsb.AddFunction("AddSearchPath", _AddSearchPath, 1);
            ns_jsb.AddFunction("Yield", yield_func, 1);
            ns_jsb.AddFunction("ToArray", to_js_array, 1);
            ns_jsb.AddFunction("ToArrayBuffer", to_js_array_buffer, 1);
            ns_jsb.AddFunction("ToBytes", to_cs_bytes, 1);
            ns_jsb.AddFunction("ToFunction", to_js_function, 1);
            ns_jsb.AddFunction("ToDelegate", to_cs_delegate, 1);
            ns_jsb.AddFunction("Import", js_import_type, 2);
            ns_jsb.AddFunction("GC", _gc, 0);
            ns_jsb.AddFunction("SetDisposable", _set_disposable, 2);
            ns_jsb.AddFunction("AddCacheString", _add_cache_string, 1);
            ns_jsb.AddFunction("RemoveCacheString", _remove_cache_string, 1);
            ns_jsb.AddFunction("Sleep", _sleep, 1);
            ns_jsb.AddFunction("AddModule", _add_module, 2);
            ns_jsb.AddFunction("Now", _now, 0);
            ns_jsb.AddFunction("IsReflectBind", _is_reflect_bind, 0);
            {
                var ns_hotfix = register.CreateClass("JSBHotfix");
                ns_hotfix.AddFunction("replace_single", hotfix_replace_single, 2);
                ns_hotfix.AddFunction("before_single", hotfix_before_single, 2);
                // ns_hotfix.AddFunction("replace", hotfix_replace, 2);
                // ns_hotfix.AddFunction("before", hotfix_before);
                // ns_hotfix.AddFunction("after", hotfix_after);

                ns_jsb.AddValue("hotfix", ns_hotfix.GetConstructor());
            }
            return(ns_jsb);
        }
Example #3
0
        public static void Bind(TypeRegister register)
        {
            var cls = register.CreateGlobalClass("Worker", typeof(JSWorker), _js_worker_ctor);

            cls.AddMethod(false, "postMessage", _js_worker_postMessage, 1);
            cls.AddMethod(false, "terminate", _js_worker_terminate);
        }
        public IEnumerable <TypeRegister> GetServices()
        {
            var types = TypeRegister.ScanAssemblyTypes(Assembly.GetExecutingAssembly());

            types.Add(new TypeRegister(typeof(IRepository), typeof(Repository <ErpMembershipDBContext>), TypeLifetime.Scoped));
            return(types.Concat(new DataAccess.LayerServicesTypes().GetServices()));
        }
Example #5
0
        public void Load(ScriptContext context, JSValue module_obj, JSValue exports_obj)
        {
            var register = new TypeRegister(context);
            var clazz    = _bind(register);

            JSApi.JS_SetProperty(context, module_obj, register.GetAtom("exports"), clazz.GetConstructor());
            register.Finish();
        }
Example #6
0
        public void Load(ScriptContext context, JSValue module_obj, JSValue exports_obj)
        {
            var register = new TypeRegister(context);

            LoadTypes(register);
            JSApi.JS_SetProperty(context, module_obj, context.GetAtom("exports"), JSApi.JS_DupValue(context, _exports));
            register.Finish();
        }
        public static void Bind(TypeRegister register)
        {
            var       context      = register.GetContext();
            JSContext ctx          = context;
            var       globalObject = context.GetGlobalObject();

            JSApi.JS_SetProperty(ctx, globalObject, register.GetAtom("global"), JSApi.JS_DupValue(ctx, globalObject));
            JSApi.JS_FreeValue(ctx, globalObject);
        }
Example #8
0
 public static void Bind(TypeRegister register)
 {
     var ns = register.CreateNamespace();
     var cls = ns.CreateClass("Worker", typeof(JSWorker), _js_worker_ctor);
     cls.AddMethod(false, "postMessage", _js_worker_postMessage, 1);
     cls.AddMethod(false, "terminate", _js_worker_terminate);
     cls.Close();
     ns.Close();
 }
Example #9
0
        public static IServiceCollection AddApplicationLayer(this IServiceCollection services)
        {
            var resultServices = TypeRegister.ScanAssemblyTypes(Assembly.GetExecutingAssembly())
                                 .ToList();

            resultServices.RegisterServicesByLifeTime(services);

            return(services);
        }
Example #10
0
        public static void Bind(TypeRegister register)
        {
            var cls = register.CreateClass("WebSocket", typeof(WebSocket), _js_constructor);

            cls.AddMethod(false, "close", _js_close);
            cls.AddMethod(false, "send", _js_send);
            cls.AddProperty(false, "readyState", _js_readyState, null);
            cls.AddProperty(false, "bufferedAmount", _js_bufferedAmount, null);
        }
Example #11
0
 public void OnBind(ScriptRuntime runtime, TypeRegister register)
 {
     // QuickJS.Extra.WebSocket.Bind(register);
     // QuickJS.Extra.XMLHttpRequest.Bind(register);
     // if (!runtime.isWorker)
     // {
     //     QuickJS.Extra.DOMCompatibleLayer.Bind(register);
     //     QuickJS.Extra.NodeCompatibleLayer.Bind(register);
     // }
 }
Example #12
0
        public static void Bind(TypeRegister register)
        {
            var context = register.GetContext();

            context.AddFunction("setImmediate", js_set_immediate, 2);
            context.AddFunction("setInterval", js_set_interval, 3);
            context.AddFunction("setTimeout", js_set_timeout, 3);
            context.AddFunction("clearImmediate", js_clear_timer, 1);
            context.AddFunction("clearInterval", js_clear_timer, 1);
            context.AddFunction("clearTimeout", js_clear_timer, 1);
        }
Example #13
0
        public static void Bind(TypeRegister register)
        {
            var ns = register.CreateNamespace();

            ns.AddFunction("setInterval", js_set_interval, 3);
            ns.AddFunction("setTimeout", js_set_timeout, 3);
            ns.AddFunction("clearInterval", js_clear_timer, 1);
            ns.AddFunction("clearTimeout", js_clear_timer, 1);

            ns.Close();
        }
Example #14
0
        public void Initialize(IFileSystem fileSystem, IFileResolver resolver, IScriptRuntimeListener listener, IScriptLogger logger, IO.IByteBufferAllocator byteBufferAllocator)
        {
            if (logger == null)
            {
                throw new NullReferenceException(nameof(logger));
            }

            if (fileSystem == null)
            {
                throw new NullReferenceException(nameof(fileSystem));
            }

            MethodInfo bindAll = null;

            if (!isWorker)
            {
                if (listener == null)
                {
                    throw new NullReferenceException(nameof(listener));
                }

                bindAll = typeof(Values).GetMethod("BindAll", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
                if (bindAll == null)
                {
                    throw new Exception("Generate binding code before run");
                }
            }
            _listener            = listener;
            _fileResolver        = resolver;
            _byteBufferAllocator = byteBufferAllocator;
            _autorelease         = new Utils.AutoReleasePool();
            _fileSystem          = fileSystem;
            _logger       = logger;
            _timerManager = new TimerManager(_logger);
            _typeDB       = new TypeDB(this, _mainContext);

            var register = new TypeRegister(this, _mainContext);

            register.RegisterType(typeof(ScriptBridge));
            // await Task.Run(() => runner.OnBind(this, register));
            if (bindAll != null)
            {
                bindAll.Invoke(null, new object[] { register });
            }
            listener.OnBind(this, register);
            if (!_isWorker)
            {
                JSWorker.Bind(register);
            }
            TimerManager.Bind(register);
            ScriptContext.Bind(register);
            register.Finish();
            listener.OnComplete(this);
        }
        public static void RegisterContextTypes(IServiceCollection services, TypeRegister typeRegister)
        {
            typeRegister.Objects.DoForEach(o =>
            {
                if (o == null)
                {
                    return;
                }

                var objType = o.GetType();
                services.AddScoped(objType, _ => o);
                foreach (var @interface in objType.GetInterfaces())
                {
                    services.AddScoped(@interface, _ => o);
                }
            });
            typeRegister.Types.DoForEach(t =>
            {
                if (t == null)
                {
                    return;
                }

                services.AddScoped(t, t);
                foreach (var @interface in t.GetInterfaces())
                {
                    services.AddScoped(@interface, t);
                }
            });
            typeRegister.ObjAsTypes.DoForEach(kvp =>
            {
                if (kvp.Key == null)
                {
                    return;
                }

                foreach (var item in kvp.Value)
                {
                    services.AddScoped(item, _ => kvp.Key);
                }
            });
            typeRegister.TypeAsTypes.DoForEach(kvp =>
            {
                if (kvp.Key == null)
                {
                    return;
                }

                foreach (var item in kvp.Value)
                {
                    services.AddScoped(item, _ => kvp.Key);
                }
            });
        }
Example #16
0
        public static IServiceCollection AddPersistenceLayer(this IServiceCollection services,
                                                             IConfiguration configuration)
        {
            services.AddDbContext <AppDbContext>(options =>
                                                 options.UseSqlServer(configuration.GetConnectionString("Default")));

            var resultServices = TypeRegister.ScanAssemblyTypes(Assembly.GetExecutingAssembly())
                                 .ToList();

            resultServices.RegisterServicesByLifeTime(services);

            return(services);
        }
Example #17
0
        public IScope CreateChildScope(Action <ITypeRegister> typeRegisterAction = null)
        {
            var childrenCollection = _services.Clone();

            if (typeRegisterAction != null)
            {
                var typeRegister = new TypeRegister();
                typeRegisterAction(typeRegister);
                MicrosoftRegistrationHelper.RegisterContextTypes(childrenCollection, typeRegister);
            }

            return(new MicrosoftScope(childrenCollection));
        }
Example #18
0
        public static void Bind(TypeRegister register)
        {
            var cls = register.CreateGlobalClass("FSWatcher", typeof(FSWatcher), js_constructor);

            cls.AddProperty(false, "path", js_get_path, js_set_path);
            cls.AddProperty(false, "filter", js_get_filter, js_set_filter);
            cls.AddProperty(false, "enableRaisingEvents", js_get_enableRaisingEvents, js_set_enableRaisingEvents);
            cls.AddProperty(false, "includeSubdirectories", js_get_includeSubdirectories, js_set_includeSubdirectories);
            cls.AddProperty(false, "oncreate", js_get_oncreate, js_set_oncreate);
            cls.AddProperty(false, "ondelete", js_get_ondelete, js_set_ondelete);
            cls.AddProperty(false, "onchange", js_get_onchange, js_set_onchange);
            cls.AddMethod(false, "dispose", js_dispose, 0);
        }
Example #19
0
        public static void Bind(TypeRegister register)
        {
            var cls = register.CreateGlobalClass("XMLHttpRequest", typeof(XMLHttpRequest), js_constructor);

            cls.AddMethod(false, "open", js_open, 2);
            cls.AddMethod(false, "send", js_send, 0);
            cls.AddProperty(false, "readyState", js_get_readyState, null);
            cls.AddProperty(false, "status", js_get_status, null);
            cls.AddProperty(false, "responseText", js_get_responseText, null);
            cls.AddProperty(false, "timeout", js_get_timeout, js_set_timeout);
            cls.AddProperty(false, "onreadystatechange", js_get_onreadystatechange, js_set_onreadystatechange);
            cls.AddProperty(false, "onerror", js_get_onerror, js_set_onerror);
        }
Example #20
0
        public TypeRegister CreateTypeRegister()
        {
            if (_currentTypeRegister == null)
            {
                _currentTypeRegister = new TypeRegister(this);
            }
            else
            {
                _currentTypeRegister.AddRef();
            }

            return(_currentTypeRegister);
        }
Example #21
0
 public void OnBind(ScriptRuntime runtime, TypeRegister register)
 {
     _mConsole.Write(LogLevel.Info, "Bind");
     QuickJS.Extra.WebSocket.Bind(register);
     QuickJS.Extra.XMLHttpRequest.Bind(register);
     if (!runtime.isWorker)
     {
         var uri = new Uri(baseUrl);
         QuickJS.Extra.DOMCompatibleLayer.Bind(register, uri);
         QuickJS.Extra.NodeCompatibleLayer.Bind(register);
     }
     _mConsole.Write(LogLevel.Info, "Bind Finish");
 }
Example #22
0
        //TODO: 用于在动态类型注册过程中产生的关联类型注册
        public DynamicType RegisterDynamicType(TypeRegister register, Type type)
        {
            DynamicType dynamicType;

            if (_dynamicTypes.TryGetValue(type, out dynamicType))
            {
                return(dynamicType);
            }

            dynamicType = new DynamicType(type, false);
            dynamicType.Bind(register);
            _dynamicTypes[type] = dynamicType;
            return(dynamicType);
        }
        public void LoadTypes(TypeRegister register)
        {
            if (_exports.IsUndefined())
            {
                _exports = JSApi.JS_NewObject(register);
                for (int i = 0, count = _types.Count; i < count; i++)
                {
                    var reg   = _types[i];
                    var clazz = reg.bind(register);

                    SetExports(register, _exports, clazz.GetConstructor(), reg.ns, 0);
                }
            }
        }
        protected override void OnCreate(Bundle bundle)
        {
            StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
            StrictMode.SetVmPolicy(builder.Build());

            base.OnCreate(bundle);
            Forms.Init(this, bundle);

            this.SetTheme(Resource.Style.Theme_Design_Light);

            PermissionsHelper.Activity = this;

            TypeRegister.Register(typeof(List <string>), typeof(Android.Runtime.JavaList), new JavaToCSharpListConverter());
            this.LoadApplication(new App());
        }
Example #25
0
        public void OnBind(ScriptRuntime runtime, TypeRegister register)
        {
            runtime.AddStaticModule("static_test1", context => QuickJS.Native.JSApi.JS_NewInt32(context, 123));
            runtime.AddStaticModule("static_test2", context => QuickJS.Native.JSApi.JS_NewInt32(context, 456));

            FSWatcher.Bind(register);
            QuickJS.Extra.WebSocket.Bind(register);
            QuickJS.Extra.XMLHttpRequest.Bind(register);
            if (!runtime.isWorker)
            {
                var uri = new Uri(baseUrl);
                QuickJS.Extra.DOMCompatibleLayer.Bind(register, uri);
                QuickJS.Extra.NodeCompatibleLayer.Bind(register);
            }
        }
Example #26
0
        public static IServiceCollection AddApiLayer(this IServiceCollection services, IConfiguration configuration)
        {
            var coreResultServices = new AspNetCore.Lib.Configurations.DependencyInjection()
                                     .AddAspNetCoreLayer(services);

            coreResultServices.RegisterServicesByLifeTime(services);


            var resultServices = TypeRegister.ScanAssemblyTypes(Assembly.GetExecutingAssembly())
                                 .ToList();

            resultServices.RegisterServicesByLifeTime(services);


            return(services);
        }
Example #27
0
        /// <summary>
        /// Create a whole new scope with all current's scope registration.
        /// </summary>
        /// <param name="typeRegisterAction">Specific child registration..</param>
        /// <returns>Child scope.</returns>
        public IScope CreateChildScope(Action <ITypeRegister> typeRegisterAction = null)
        {
            Action <ContainerBuilder> act = null;

            if (typeRegisterAction != null)
            {
                var typeRegister = new TypeRegister();
                typeRegisterAction.Invoke(typeRegister);
                act += b => AutofacTools.RegisterContextTypes(b, typeRegister);
            }
            if (act != null)
            {
                return(new AutofacScope(scope.BeginLifetimeScope(act)));
            }
            return(new AutofacScope(scope.BeginLifetimeScope()));
        }
Example #28
0
        public static void Bind(TypeRegister register)
        {
            var ns_jsb = register.CreateNamespace("jsb");

            ns_jsb.AddFunction("Yield", yield_func, 1);
            ns_jsb.AddFunction("ToJSArray", to_js_array, 1);
            {
                var ns_jsb_hotfix = ns_jsb.CreateNamespace("hotfix");
                ns_jsb_hotfix.AddFunction("replace_single", hotfix_replace_single, 2);
                // ns_jsb_hotfix.AddFunction("replace", hotfix_replace, 2);
                // ns_jsb_hotfix.AddFunction("before", hotfix_before);
                // ns_jsb_hotfix.AddFunction("after", hotfix_after);
                ns_jsb_hotfix.Close();
            }
            ns_jsb.Close();
        }
Example #29
0
        static void InitService()
        {
            AutoInit.Init();
            TypeRegister.Init();

            RoutingRule.DistrictsName = ConfigManager.DistrictsName();

            zkAdaptor = new ZkAdaptor();
            //amqpAdaptor = new AmqpAdaptor(ConfigManager.MQIP(), ConfigManager.AMQPPort(),
            //    ConfigManager.MQUser(), ConfigManager.MQPass());

            //ServiceImplementStub.Bind<LogicClientServiceImpl, ILogicClientImpl>(amqpAdaptor, new LogicClientServiceImpl());
            ServiceImplementStub.Bind <IDbClientNotifyImpl>(zkAdaptor, new NotifyServiceImpl());

            //Logic2CliService = new ClientLogicServiceDelegate(amqpAdaptor);
            //loginNotifyDelegate = new LoginNotifyDelegate(amqpAdaptor);
            //SchedulerLogicService = new SchedulerLogicServiceDelegate(amqpAdaptor);

            dbClientNotifyDelegate = new DbClientNotifyDelegate(zkAdaptor);

            //ConfigManager.RegisterParser(new ConfigManager.ConfigParserDelegate<EndPoint>(s =>
            //{
            //    var rets = s.Split(':');
            //    var host = rets[0];
            //    var port = 0;

            //    int.TryParse(rets[1], out port);

            //    IPAddress ip;
            //    if (IPAddress.TryParse(host, out ip))
            //    {
            //        return new IPEndPoint(ip, port);
            //    }

            //    return new DnsEndPoint(host, port);
            //}));

            CacheService = new RedisDataServiceDelegate(new RedisAdaptor(ConfigManager.Instance.Read <List <EndPoint> >("DataService", "CacheConn")));
            //DbService = new MysqlDataServiceDelegate(new MysqlAdaptor(ConfigManager.DbIP(), ConfigManager.DbName(), ConfigManager.DbUser(), ConfigManager.DbPass()));

            zkAdaptor.BeginReceive();
            //amqpAdaptor.BeginReceive();

            zkAdaptor.Identity("Logic");

            //Heartbeat();
        }
Example #30
0
        public DynamicType GetDynamicType(Type type)
        {
            DynamicType dynamicType;

            if (_dynamicTypes.TryGetValue(type, out dynamicType))
            {
                return(dynamicType);
            }

            var register = new TypeRegister(_runtime, _context);

            dynamicType = new DynamicType(type);
            dynamicType.Bind(register);
            register.Finish();
            _dynamicTypes[type] = dynamicType;
            return(dynamicType);
        }
Example #31
0
 public VarDefine(TypeRegister typeRegister)
 {
     TypeRegister = typeRegister;
 }