/// <summary> /// UnRegister a component /// </summary> public static void UnRegister(CapeOpenBaseObject component) { string name = component.ComponentName; CasterLogger.Debug($"UnRegister component {name}."); if (!_components.ContainsKey(name)) { return; } //throw new ECapeUnknownException( // $"UnRegister Failed : Key \"{name}\" is not registered."); else { _components.Remove(name); } }
/// <summary> /// create an cape unknown exception, obj should be the unit which throw the exception, in most case, it's UnitOp /// </summary> public ECapeUnknownException(CapeOpenBaseObject obj, string message, Exception inner = null, string interfaceName = null) : base(message) { ErrorObject = obj; this.InnerException = inner; this.HResult = (int)ECapeErrorHResult.ECapeUnknownHR; this.name = message ?? inner.Message; this.interfaceName = interfaceName; string errorMessage = $"CapeUnknownException : {message}"; if (inner != null) { errorMessage += $"\n InnerMessage : {inner.Message}"; } CapeDiagnostic.LogMessage(errorMessage); ErrorObject.SetError(message, interfaceName, scope); }
/// <summary> /// Register a component, the id is ComponentName of the component, should be unique /// </summary> /// <param name="component">component to be added, normally a unit operation component or a property package</param> public static void Register(CapeOpenBaseObject component) { string name = component.ComponentName; CasterLogger.Debug($"Register component {name}."); if (_components.ContainsKey(name)) { if (_components[name] == component) { return; } //else // cofe will load component in calculation, that leads to multiple instance with same name // throw new ECapeUnknownException( // $"Register Failed : Already create a different component with a same id : {name}."); } else { _components.Add(name, component); } }
/// <summary> /// Add an item, the default key is ComponentName /// </summary> public void Add(CapeOpenBaseObject item) { string autokey = item.ComponentName; Add(autokey, item); }