private void AddComponentLazy(ModSessionComponent component, Ob_ModSessionComponent config) { foreach (var dep in component.Dependencies) { if (m_dependencySatisfyingComponents.ContainsKey(dep)) { continue; } ModSessionComponentRegistry.CreateComponent factory; if (!_factories.TryGetValue(dep, out factory)) { throw new ArgumentException("Can't add " + component.GetType() + " since we don't have dependency " + dep + " loaded or a factory for it"); } AddComponentLazy(factory(), null); } // Safe to add to the end of the ordered list. var item = new RuntimeSessionComponent(component, config); foreach (var dep in component.Dependencies) { var depRes = m_dependencySatisfyingComponents[dep]; depRes.Dependents.Add(item); item.Dependencies.Add(item); item.Component.SatisfyDependency(depRes.Component); } Insert(item); m_orderedComponentList.Add(item); if (item.Config != null) { item.Component.LoadConfiguration(item.Config); } item.Component.Attached(this); ComponentAttached?.Invoke(item.Component); }
private void Insert(RuntimeSessionComponent rsc) { rsc.SetProfilingAverageLength(ProfilingAverageLength); var myType = rsc.Component.GetType(); List <RuntimeSessionComponent> list; if (!m_componentDictionary.TryGetValue(myType, out list)) { m_componentDictionary[myType] = list = new List <RuntimeSessionComponent>(); } list.Add(rsc); foreach (var dep in rsc.Component.SuppliedComponents) { m_dependencySatisfyingComponents.Add(dep, rsc); } }
public void Register(ModSessionComponent component, Ob_ModSessionComponent config = null) { foreach (var sat in component.SuppliedComponents) { if (m_dependencySatisfyingComponents.ContainsKey(sat)) { throw new ArgumentException("We already have a component satisfying the " + sat + " dependency; we can't have two."); } } if (!m_attached) { var rsc = new RuntimeSessionComponent(component, config); Insert(rsc); return; } m_componentsToModify.Enqueue(new RemoveOrAdd(component, false, config)); }