Example #1
0
        /// <summary>
        ///     create object of type "T"
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="arg"></param>
        /// <param name="start"></param>
        /// <returns></returns>
        public T Create <T>(ObjArg arg, bool start) where T : class, TValue, new()
        {
            var ret = New <T>(arg, start);

            _items.Add(ret);
            return(ret);
        }
Example #2
0
        /// <summary>
        ///    internal called when an Obj is initialized
        /// </summary>
        /// <param name="arg"></param>
        protected override void OnInit(ObjArg arg)
        {
            base.OnInit(arg);

            if (Ins != null)
            {
                throw new Exception("Launcher already instantiated!");
            }
            Ins = this;

            var more = arg.As <LauncherArg>();

            // logger
            GlobalVarPool.Ins.Set(GlobalVarPool.NameOfLogger, more.Logger ?? new DefaultLogger());

            // performance monitor
            if (more.MonitorEnabled)
            {
                var monitor = New <PerformanceMonitor>(ObjArg.Empty);
                GlobalVarPool.Ins.Set(GlobalVarPool.NameOfMonitor, monitor);
            }

            // service
            var service = New <Service>(ObjArg.Empty);

            GlobalVarPool.Ins.Set(GlobalVarPool.NameOfLogicService, service);
        }
Example #3
0
        /// <summary>
        ///    internal called when an Obj is initialized
        /// </summary>
        /// <param name="arg"></param>
        protected virtual void OnInit(ObjArg arg)
        {
            Owner = arg.Owner;

            var flushableAncestor = (this as IObj).GetAncestor <IFlushable>();

            _cheduler = flushableAncestor != null ? new BatchedScheduler(flushableAncestor) : new Scheduler();
        }
Example #4
0
        /// <summary>
        ///     Initialize
        /// </summary>
        /// <param name="arg"></param>
        public void Init(ObjArg arg)
        {
            if (Initialized)
            {
                throw new Exception("Already initialized");
            }

            // 执行初始化
            OnInit(arg);
            Initialized = true;
        }
Example #5
0
        /// <summary>
        ///     Create an obj of type 'T' with arg
        ///     If 'start' == true, Obj will be started after initialized
        /// </summary>
        /// <returns></returns>
        public static T New <T>(ObjArg arg, bool start = false) where T : IObj, new()
        {
            var ret = new T();

            ret.Init(arg);
            if (start)
            {
                ret.Start();
            }
            return(ret);
        }
Example #6
0
        /// <summary>
        ///     create object of type "type"
        /// </summary>
        /// <param name="type"></param>
        /// <param name="arg"></param>
        /// <param name="start"></param>
        /// <returns></returns>
        public static IObj Create(Type type, ObjArg arg, bool start)
        {
            var ctor = GetCtor(type);
            var obj  = ctor();

            obj.Init(arg);

            if (start)
            {
                obj.Start();
            }

            return(obj);
        }
Example #7
0
        /// <summary>
        ///     create object of type "T"
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="arg"></param>
        /// <param name="start"></param>
        /// <returns></returns>
        public static T Create <T>(ObjArg arg, bool start) where T : IObj
        {
            var obj = Create(typeof(T), arg, start);

            return((T)obj);
        }
Example #8
0
 /// <summary>
 ///     Create an obj of 'type' with arg and return 'obj as T'
 ///     If 'start' == true, Obj will be started after initialized
 /// </summary>
 /// <returns></returns>
 public static T New <T>(Type type, ObjArg arg, bool start = false) where T : class, IObj
 {
     return(New(type, arg, start) as T);
 }
Example #9
0
 /// <summary>
 ///     Create an obj of 'type' with arg
 ///     If 'start' == true, Obj will be started after initialized
 /// </summary>
 /// <returns></returns>
 public static IObj New(Type type, ObjArg arg, bool start = false)
 {
     return(ObjFactory.Create(type, arg, start));
 }
Example #10
0
 /// <summary>
 ///    internal called when an Obj is initialized
 /// </summary>
 /// <param name="arg"></param>
 protected override void OnInit(ObjArg arg)
 {
     base.OnInit(arg);
     GlobalVarPool.Ins.Service.Idle += OnIdle;
 }