public Actor_SansType _CreateInstanceActorForScene_(Type typeToCreate, Actor_SansType parent) { ActinInstantiator inst; ActinInstantiator parentInst; bool needParentInstantiator = parent != null; bool successChild; bool successParent; lock (lockInstantiators) { successChild = this.instantiators.TryGetValue(typeToCreate, out inst); if (!needParentInstantiator) { successParent = true; parentInst = null; } else { successParent = this.instantiators.TryGetValue(parent.GetType(), out parentInst); } } if (!successChild) { throw new ApplicationException($"Actin could not create an instance of {typeToCreate?.Name ?? "null"} for parent {parent?.ActorName ?? "null"}. Ensure that this type was marked with the 'Instance' attribute, or that a type alias has been specified."); } if (!successParent) { throw new ApplicationException($"Actin could not create an instance of {typeToCreate?.Name ?? "null"} for parent {parent?.ActorName ?? "null"}. Ensure that the parent was marked with the 'Instance' or 'Singleton' attribute."); } return((Actor_SansType)inst.GetInstance(this, parent, parentInst)); }
public async Task DisposeActor(Actor_SansType actor, DateTimeOffset?time = null, bool throwErrors = true) { if (time != null) { this.Clock.Simulate(time, null); } await actor.ActuallyDispose(() => new ActorUtilNS.DispatchData { MainLog = new EmptyLog(), }, throwErrors); }
public ActorUtil(Actor_SansType _actor, ActinClock clock) { if (clock == null) { throw new ArgumentNullException("clock may not be null"); } this.clock = clock; this.actor = _actor; this.Log = new LogDispatcherForActor(new LogDispatcher(clock), _actor); if (_actor != null) { this.Log.AddDestination(_actor.ActorLog); } }
private async Task <object> GetActorInternal(Type t, bool initialize, Actor_SansType parentScene) { var isSingleton = t.HasAttribute <SingletonAttribute>(); if (isSingleton) { lock (lockSingletons) { if (singletons.TryGetValue(t, out var singletonInstance)) { return(singletonInstance); } } } var constructor = RicochetUtil.GetConstructor(t); var instance = constructor.New(); var actorInstance = instance as Actor_SansType; if (actorInstance != null) { actorInstance.Util = new ActorUtil(actorInstance, this.Clock) { _IsTest_ = true, }; } if (isSingleton) { lock (lockSingletons) { singletons[t] = instance; } } var props = RicochetUtil.GetPropsAndFields(t); foreach (var prop in props) { if (prop.Markers.Contains(nameof(ParentAttribute)) || prop.Markers.Contains(nameof(SiblingAttribute)) || prop.Markers.Contains(nameof(FlexibleParentAttribute)) || prop.Markers.Contains(nameof(FlexibleSiblingAttribute))) { //Create an instance: if (parentScene != null) { if (prop.Markers.Contains(nameof(FlexibleParentAttribute))) { prop.SetVal(instance, parentScene); } else if (prop.Markers.Contains(nameof(ParentAttribute))) { throw new ApplicationException($"In class {t.Name}, field {prop.Name} must use the FlexibleParent attribute instead of the Parent attribute, as its parent is a Scene."); } else { var relative = this.GetDependencyInternal(prop.Type, parentScene); prop.SetVal(instance, relative); } } else { var relative = RicochetUtil.GetConstructor(prop.Type).New(); var relativeActor = relative as Actor_SansType; if (relativeActor != null) { relativeActor.Util = new ActorUtil(relativeActor, this.Clock) { _IsTest_ = true, }; } prop.SetVal(instance, relative); } } else if (prop.Markers.Contains(nameof(SingletonAttribute))) { lock (lockSingletons) { if (!singletons.TryGetValue(prop.Type, out var singleton)) { singleton = RicochetUtil.GetConstructor(prop.Type).New(); var singletonActor = singleton as Actor_SansType; if (singletonActor != null) { singletonActor.Util = new ActorUtil(singletonActor, this.Clock) { _IsTest_ = true }; } singletons[prop.Type] = singleton; } prop.SetVal(instance, singleton); } } else if (prop.Markers.Contains(nameof(InstanceAttribute))) { var child = RicochetUtil.GetConstructor(prop.Type).New(); var childActor = child as Actor_SansType; if (childActor != null) { childActor.Util = new ActorUtil(childActor, this.Clock) { _IsTest_ = true }; } prop.SetVal(instance, child); } } if (initialize && actorInstance != null) { await this.InitActor(actorInstance); } return(instance); }
public Actor_SansType _CreateInstanceActorForScene_(Type typeToCreate, Actor_SansType parent) { return((Actor_SansType)GetActorInternal(typeToCreate, false, parent).Result); }
private Actor_SansType process; //This is really just here for debugging. It's not used for anything. public ActorDisposeHandle(Func <Func <DispatchData>, bool, Task> _actuallyDisposeProcess, Actor_SansType _process) { this.actuallyDisposeProcess = _actuallyDisposeProcess; this.process = _process; }