public static void LifeCycleShutdown(this ILifeCycle instance)
 {
     if (instance != null)
     {
         instance.ExecuteLifeCycleShutdown();
     }
 }
Esempio n. 2
0
    /// <summary>
    /// 更新模块生命周期
    /// </summary>
    public static void UpdateLifeCycle()
    {
        int count = _moduleList.Count;

        for (int i = 0; i < count; i++)
        {
            ILifeCycle view = _moduleList[i];
            if (!_moduleLifeCycle.ContainsKey(view))
            {
                continue;
            }
            //时间减1秒
            _moduleLifeCycle[view]--;
            if (_moduleLifeCycle[view] <= 0 && !_willRemoveList.Contains(view))
            {//如果=0,Dispose
                _willRemoveList.Add(view);
            }
        }

        //卸载后消耗
        count = _willRemoveList.Count;
        for (int i = 0; i < count; i++)
        {
            Log.info("生命周期结束,自动销毁::viewName:" + _willRemoveList[i].GetName());
            _willRemoveList[i].Dispose();

            _moduleLifeCycle.Remove(_willRemoveList[i]);
            _moduleList.Remove(_willRemoveList[i]);
            RemoveFromCacheList(_willRemoveList[i]);//从缓存队列里移除
        }
        _willRemoveList.Clear();
    }
Esempio n. 3
0
 private static void RemoveFromCacheList(ILifeCycle view)
 {
     if (_cacheList.Contains(view))
     {
         _cacheList.Remove(view);
     }
 }
Esempio n. 4
0
 public void AddLifeCycle(IPreloadOperation operation, ILifeCycle cycle, AssetData data)
 {
     operation.OnCompleted += () =>
     {
         cycle.Begin(null, data);
     };
     m_runList.Add(cycle);
 }
Esempio n. 5
0
 /// <summary>
 /// 解除注册
 /// </summary>
 /// <param name="viewName"></param>
 public static void UnRegLifeCycle(ILifeCycle view)
 {
     if (_moduleLifeCycle.ContainsKey(view))
     {
         _moduleLifeCycle.Remove(view);
         _moduleList.Remove(view);
     }
 }
Esempio n. 6
0
    /// <summary>
    /// 注册生命周期管理
    /// </summary>
    /// <param name="view"></param>
    /// <param name="type"></param>
    public static void RegLifeCycle(ILifeCycle view, ModuleLifeType type)
    {
        if (type == ModuleLifeType.Cache_None || type == ModuleLifeType.Cache_Always)
        {
            return;
        }

        if (!_moduleLifeCycle.ContainsKey(view))
        {
            _moduleList.Add(view);
        }
        AddCacheList(view);
        _moduleLifeCycle[view] = (int)type;
    }
Esempio n. 7
0
        public void LifeCycleStopping(ILifeCycle e)
        {
            stopping     = true;
            stoppingTime = (DateTime.UtcNow.Ticks / 1000);

            // need to sleep to make sure the stopping and stopped times are not
            // the same
            try
            {
                System.Threading.Thread.Sleep(1);
            }
            catch (Exception err)
            {
                Console.WriteLine(err.StackTrace);
            }
        }
Esempio n. 8
0
        public static Universe Create(ILifeCycle lifeCycle, ISimulationTime simulationTime, IEnumerable<IModule> modules = null, Random random = null)
        {
            var universe = new Universe(lifeCycle, simulationTime) { RandomGenerator = random ?? new Random() };

            // TODO: Manage CurrentUniverses.
            CurrentUniverse = universe;

            if (modules != null)
            {
                foreach (var module in modules)
                {
                    universe._modules.Add(module);
                }
            }

            return universe;
        }
Esempio n. 9
0
 private static void AddCacheList(ILifeCycle view)
 {
     if (!_cacheList.Contains(view))
     {//如果不存在
         if (_cacheList.Count < _cacheNumMax)
         {
             _cacheList.Add(view);
         }
         else
         {//超出缓存个数,添加到待销毁列表
             _willRemoveList.Add(_cacheList[0]);
             _cacheList.RemoveAt(0);
             _cacheList.Add(view);
         }
     }
     else  //如果存在
     {
         _cacheList.Remove(view);
         _cacheList.Add(view);//放到最后面
     }
 }
        /// <summary>
        /// Registers a given type
        /// </summary>
        /// <typeparam name="I">The type being registered</typeparam>
        /// <typeparam name="T">The implementation of type I</typeparam>
        /// <param name="lifeCycle">The desired <see cref="ILifeCycle"/> handler</param>
        /// <exception cref="InvalidOperationException">Exception for duplicate registrants</exception>
        public void Register <I, T>(ILifeCycle lifeCycle)
            where I : class
            where T : I
        {
            Type baseType  = typeof(I);
            Type classType = typeof(T);

            // check if the type has already been registered
            if (Registrants.ContainsKey(baseType))
            {
                throw new InvalidOperationException(string.Format("'{0}' has already been registered.", baseType.Name));
            }

            lifeCycle.ItemType = classType;

            if (lifeCycle.BuildUp == null)
            {
                // use the default buildup
                lifeCycle.BuildUp = new DependencyInjectionBuildUp(this);
            }

            Registrants.Add(baseType, lifeCycle);
        }
Esempio n. 11
0
 public static void BindLifeCycle(this Page page, ILifeCycle viewModel)
 {
     page.BindingContext = viewModel;
     page.Appearing     += viewModel.Appearing;
     page.Disappearing  += viewModel.Disappearing;
 }
Esempio n. 12
0
 public IPreloadOperation AddLifeCycle(IRuntimeBundleData data, ILifeCycle cycle)
 {
     return(AssetProvider.Preload(SkipLoadProcess.Create(data.Identifier)));
 }
Esempio n. 13
0
 protected Entity()
 {
     LifeCycle = new LifeCycle(this);
 }
Esempio n. 14
0
 protected Entity()
 {
     LifeCycle = new LifeCycle(this);
     Data      = new TData();
 }
Esempio n. 15
0
        public void LifeCycleStopping(ILifeCycle e)
        {
            stopping = true;
            stoppingTime = (DateTime.UtcNow.Ticks/1000);

            // need to sleep to make sure the stopping and stopped times are not
            // the same
            try
            {
                System.Threading.Thread.Sleep(1);
            }
            catch (Exception err)
            {
                Console.WriteLine(err.StackTrace);
            }
        }
 /// <summary>
 /// Adds a lifecycle to this lifecycle.
 /// The lifecycle implementing this interface will be responsible for handling these
 /// additional lifecycles.
 /// </summary>
 /// <param name="lifeCycle">The life cycle.</param>
 public void AddLifeCycle(ILifeCycle lifeCycle)
 {
     _lifeCycles.Add(lifeCycle);
 }
Esempio n. 17
0
 public IPreloadOperation AddLifeCycle(string assetPath, ILifeCycle cycle)
 {
     return(new PreloadOperation(SkipLoadProcess.Create(assetPath)));
 }
Esempio n. 18
0
 public void LifeCycleFailure(ILifeCycle e, Exception cause)
 {
     failure    = true;
     this.cause = cause;
 }
Esempio n. 19
0
 public void LifeCycleFailure(ILifeCycle e, Exception cause)
 {
     failure = true;
     this.cause = cause;
 }
Esempio n. 20
0
 public void LifeCycleStopped(ILifeCycle e)
 {
     stopped     = true;
     stoppedTime = (DateTime.UtcNow.Ticks / 1000);
 }
Esempio n. 21
0
 public void LifeCycleStopped(ILifeCycle e)
 {
     stopped = true;
     stoppedTime = (DateTime.UtcNow.Ticks/1000);
 }
Esempio n. 22
0
 public IPreloadOperation AddLifeCycle(IRuntimeBundleData data, ILifeCycle cycle)
 {
     return(new PreloadOperation(SkipLoadProcess.Create(data)));
 }
Esempio n. 23
0
 protected Universe(ILifeCycle universeLifeCycle, ISimulationTime simulationTime)
 {
     _universeLifeCycle = universeLifeCycle;
     _simulationTime = simulationTime;
 }