public bool ShouldDie(LifeTime o, int index) { counter++; LifeTimeENUM lifeTime = o.LifeTime; switch (lifeTime) { case LifeTimeENUM.Short: if (counter % shortLifeTime == 0) return true; break; case LifeTimeENUM.Medium: if (counter % mediumLifeTime == 0) return true; break; case LifeTimeENUM.Long: return false; } return false; }
private static void Register(Type baseType, Type typeImpl, LifeTime lifeTime) { if (typeImpl != baseType && !baseType.GetTypeInfo().IsAssignableFrom(typeImpl.GetTypeInfo())) { throw new ArgumentException($"Type {typeImpl.FullName} must inherit or implement {baseType.FullName}"); } if (lifeTime == LifeTime.Global) { if (Global.ContainsKey(typeImpl)) { throw new ArgumentException($"Global instance of {typeImpl.FullName} already exists, cannot register again"); } } descriptors[baseType] = new ServiceDescriptor { BaseType = baseType, Implementor = typeImpl, LifeTime = lifeTime }; }
public static void TryToAdd(object obj, LifeTime lifeTime) { if (lifeTime == LifeTime.External) { return; } var disposable = obj as IDisposable; if (disposable == null) { return; } if (lifeTime == LifeTime.Scene) { AddSceneDisposable(disposable); } else { _global.Add(disposable); } }
public static void Main() { using (var cin = new StreamReader(Console.OpenStandardInput())) using (var cout = new StreamWriter(Console.OpenStandardOutput())) { var line = cin.ReadLine().Trim(); int n = Convert.ToInt32(line); var population = new List <LifeTime>(n); var checkPoints = new SortedSet <uint>(); for (int p = 0; p < n; p++) { line = cin.ReadLine().Trim(); var yrs = line.Split(' '); var person = new LifeTime(UInt32.Parse(yrs[0]), UInt32.Parse(yrs[1])); population.Add(person); checkPoints.Add(person.birthYear); checkPoints.Add(person.deathYear); } uint maxYear = 0; int maxPopulation = 0; foreach (uint curYear in checkPoints) { int curPopulation = population.Where(l => l.birthYear <= curYear && curYear < l.deathYear) .Count(); if (curPopulation > maxPopulation) { maxYear = curYear; maxPopulation = curPopulation; } } cout.WriteLine(maxYear + " " + maxPopulation); } }
protected sealed override void OnExecute() { if (!Application.isPlaying) { return; } _isStateActive = false; _state = new RxStateProxy <IContext>(this, this, this, this); _inputPort = GetPortValue(nameof(input)); LifeTime.AddCleanUpAction(StopState); LogNodeExecutionState(); //get all actual stat tokens and try to run state _inputPort.Receive <IStateToken>() .Where(x => !_isStateActive) .Select(x => (token: x, owned: OwnToken(x))) .Where(x => x.owned) .Do(x => OnActivateState(x.token)) .Subscribe() .AddTo(LifeTime); }
public override string Compile() { string output = ""; if (Parent is SkillInfo) { if (Amount > 0) { output += "Disables morale immunity " + Regex.Replace(GetTarget(), "of", "for"); } else { output += "Enables morale immunity " + Regex.Replace(GetTarget(), "of", "for"); } if (LifeTime > 0) { output += " for " + LifeTime.ToString() + " seconds."; } output += "<li>Restores morale " + Regex.Replace(GetTarget(), "of", "for") + "</li>"; } return(output); }
public IInstanceProvider Get <TImplementation>(LifeTime lifeTime, InstanceProtectionMode protectionMode, InjectionAlertChannel alertChannel) where TImplementation : new() { IInstanceProvider instance; switch (lifeTime) { case LifeTime.Singleton: instance = new SingletonInstanceProvider <TImplementation>(protectionMode); break; case LifeTime.Transient: instance = new TransientInstanceProvider <TImplementation>(protectionMode); break; case LifeTime.Unknown: throw new ArgumentOutOfRangeException($"You can only register {LifeTime.Unknown} instances with a {nameof(Func<IInstanceProvider>)} parameter.Please check overloaded method.s"); default: throw new ArgumentOutOfRangeException(nameof(lifeTime), lifeTime, null); } instance.AlertChannel = alertChannel; return(instance); }
protected sealed override UniTask OnExecute() { if (!Application.isPlaying) { return(UniTask.CompletedTask); } _isStateActive = false; _asyncStateProxy = new AsyncContextStateProxy(this, this, this, this); _inputPort = GetPortValue(nameof(input)); LifeTime.AddCleanUpAction(() => _asyncStateProxy.ExitAsync()); LogNodeExecutionState(); //get all actual stat tokens and try to run state _inputPort.Receive <IStateToken>(). Where(x => _isStateActive == false). Select(async x => await OwnToken(x)). Subscribe(). AddTo(LifeTime); return(UniTask.CompletedTask); }
public void Populate(IServiceCollection serviceCollection, LifeTime lifeTime, bool includeOpenGenericWireup) { foreach (var abstraction in _typeCache.GetTypes(AutoType.Abstraction)) { var types = _implementationsFinder.FindImplemenationsOf(abstraction); if (!includeOpenGenericWireup && types.All(x => x.IsGenericType)) { return; } var dependencyType = types.FirstOrDefault(type => _serviceTypeNameFilter.IsMatch(abstraction, type)); switch (lifeTime) { case LifeTime.Singleton: RegisterDependency(serviceCollection.AddSingleton, abstraction, dependencyType); break; case LifeTime.Transient: RegisterDependency(serviceCollection.AddTransient, abstraction, dependencyType); break; } } }
private V _Push <V>(String key, V value, LifeTime lifetime = LifeTime.Request, DateTime?expires = null) { var toCache = new CacheItem() { Object = value, Expires = expires }; //Remove invalidation key var wasRemoved = Context.Cache.Remove(_invalidateKey(_currentUser(), key)) != null; switch (lifetime) { case LifeTime.Session: Context.Session[key] = toCache; goto case LifeTime.Request; #pragma warning disable CS0618 // Type or member is obsolete case LifeTime.AppDomain: Context.Cache.Add(key, toCache, null, expires ?? DateTime.MaxValue, System.Web.Caching.Cache.NoSlidingExpiration, CacheItemPriority.Default, null); goto case LifeTime.Request; #pragma warning restore CS0618 // Type or member is obsolete case LifeTime.Request: Context.Items[key] = toCache; break; default: throw new ArgumentOutOfRangeException("lifetime"); } return(value); }
public NinjectProviderDependency(Type @interface, Type provider, LifeTime lifeTime) : base(@interface, null, lifeTime) { Provider = provider; }
public static void Register <T>(this IocContainer container, Func <T> factory, string name, LifeTime lifeTime) { var keyType = factory.GetType().GetGenericArguments().Last(); container.Register(keyType, () => factory(), name, lifeTime); }
public static void Register <T, TC>(this IocContainer container, string name, LifeTime lifeTime) { container.Register(typeof(T), typeof(TC), name, lifeTime); }
public void UpdateRegistration(Type abstractType, Func<object> factory, string name, LifeTime lifetime) { Validate.That(abstractType).IsNotNull(); Validate.That(factory).IsNotNull(); Validate.That(name).IsNotNullOrEmpty(); var key = GetKey(abstractType, name); Update(key, a => factory(), lifetime); }
protected void Bind <TInterface, TClass>(string dependancyName, LifeTime lifeTime = LifeTime.Transient) where TInterface : class where TClass : class { Dependencies.Add(new NinjectNamedDependency(typeof(TInterface), typeof(TClass), lifeTime, dependancyName)); }
public void Unbind(LifeTime lifeTime) { throw new NotImplementedException(); }
public MapToAttribute(Type serviceType, LifeTime lifeTime = LifeTime.Transient) { this.ServiceType = serviceType; this.LifeTime = lifeTime; }
public bool ShouldDie(LifeTime o, int index) { LifeTimeENUM lifeTime = o.LifeTime; // short objects will live for 20 seconds, long objects will live for more. switch (lifeTime) { case LifeTimeENUM.Short: if (Environment.TickCount - lastShortTickCount > 1) // this is in accureat enumber, since // we will be finsh iterating throuh the short life time object in less than 1 ms , so we need // to switch either to QueryPeroformanceCounter, or to block the loop for some time through // Thread.Sleep, the other solution is to increase the number of objects a lot. { lastShortTickCount = Environment.TickCount; lastShortIndex = index; return true; } break; case LifeTimeENUM.Medium: if (Environment.TickCount - lastMediumTickCount > 20) { lastMediumTickCount = Environment.TickCount; lastMediumIndex = index; return true; } break; case LifeTimeENUM.Long: break; } return false; }
public AutofacInstanceDependency(Type @interface, object instance, LifeTime lifeTime) : base(@interface, null, lifeTime) { Instance = instance; }
public void Register(Type abstractType, Type concreteType, LifeTime lifetime) { Register(abstractType, concreteType, defaultName, lifetime); }
private void Update(string key, Func<IocActivator, object> factory, LifeTime lifeTime) { Func<IocActivator, object> value; if (lifeTime.Equals(LifeTime.Singleton)) { var singleton = new Lazy<object>(() => factory(activator)); value = a => singleton.Value; } else { value = factory; } Update(key, value); }
public void UpdateRegistration(Type abstractType, Type concreteType, string name, LifeTime lifetime) { Validate.That(abstractType).IsNotNull(); Validate.That(concreteType).IsNotNull(); Validate.That(name).IsNotNullOrEmpty(); var key = GetKey(abstractType, name); Update(key, a => a.CreateInstance(concreteType), lifetime); }
public void UpdateRegistration(Type abstractType, Type concreteType, LifeTime lifetime) { UpdateRegistration(abstractType, concreteType, defaultName, lifetime); }
private Object CreateGenericObject(object[] constructorParams, Type implementationType, Type interfaceType, LifeTime lifetime) { //Set object type arguments to ones mentioned in container. return(CreateObjInternal(constructorParams, implementationType.MakeGenericType(interfaceType.GenericTypeArguments), interfaceType, lifetime)); }
private Object CreateObjInternal(object[] constructorParams, Type implementationType, Type interfaceType, LifeTime lifetime) { object createdObj; if (constructorParams == null) { createdObj = Activator.CreateInstance(implementationType); } else { createdObj = GetConstructor(implementationType).Invoke(constructorParams); } if (lifetime == LifeTime.Singleton) { _singletons.Add(new Singleton() { ObjType = implementationType, Interface = interfaceType, SingletonInstance = createdObj }); } return(createdObj); }
public void Register(Type abstractType, Func<object> factory, LifeTime lifetime) { Register(abstractType, factory, defaultName, lifetime); }
public IServiceBuilder LifeTime(LifeTime lifeTime) { configuration.Lifetime = lifeTime; return(this); }
public void AddObject(LifeTime o, int index) { objectContainer.AddObjectAt(o, index); //objContainer[index] = o; }
protected void BindProvider <TInterface, TProvider>(LifeTime lifeTime = LifeTime.Transient) { Dependencies.Add(new NinjectProviderDependency(typeof(TInterface), typeof(TProvider), lifeTime)); }
public SingletonProvider(Func <T> factoryMethod, ILifeTimeManager lifeTimeManager, LifeTime lifeTime) { _factoryMethod = factoryMethod; _lifeTimeManager = lifeTimeManager; LifeTime = lifeTime; }
public InjectableDependencyAttribute(LifeTime lifetime) { Lifetime = lifetime; }
public void UpdateRegistration(Type abstractType, Func<object> factory, LifeTime lifetime) { UpdateRegistration(abstractType, factory, defaultName, lifetime); }
private static void objectDied(LifeTime lifeTime, int index) { // put a new fresh object instead; LifeTimeENUM lifeTimeEnum; lifeTimeEnum = lifeTime.LifeTime; ObjectWrapper oWrapper = lifeTime as ObjectWrapper; bool weakReferenced = oWrapper.IsWeak(); bool pinned = oWrapper.IsPinned(); if (pinned) { oWrapper.CleanUp(); } oWrapper = new ObjectWrapper(runFinalizer, pinned, weakReferenced); oWrapper.LifeTime = lifeTimeEnum; oWrapper.DataSize = lifeTime.LifeTime == LifeTimeENUM.Short ? shortDataSize : mediumDataSize; lifeTimeManager.AddObject(oWrapper, index); }
public static void UpdateRegistration <T>(this IocContainer container, LifeTime lifeTime) { container.UpdateRegistration(typeof(T), lifeTime); }
protected void Bind <TInterface>(object instance, LifeTime lifeTime = LifeTime.Transient) where TInterface : class { Dependencies.Add(new AutofacInstanceDependency(typeof(TInterface), instance, lifeTime)); }
public static void UpdateRegistration <T, TC>(this IocContainer container, string name, LifeTime lifeTime) { container.UpdateRegistration(typeof(T), typeof(TC), name, lifeTime); }
public SingletonProvider(ILifeTimeManager lifeTimeManager, LifeTime lifeTime) : this(Activator.CreateInstance <T>, lifeTimeManager, lifeTime) { }
public static void UpdateRegistration <T>(this IocContainer container, Func <T> factory, LifeTime lifeTime) { var keyType = factory.GetType().GetGenericArguments().Last(); container.UpdateRegistration(keyType, () => factory(), lifeTime); }
public DependencyInjectionAttribute(Type service, LifeTime lifeTime = LifeTime.Singleton) { Service = service; LifeTime = lifeTime; }
public static void Register <T>(this IocContainer container, LifeTime lifeTime) { container.Register(typeof(T), lifeTime); }