Exemplo n.º 1
0
        /// <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);
            }
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
        /// <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);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Add an item, the default key is ComponentName
        /// </summary>
        public void Add(CapeOpenBaseObject item)
        {
            string autokey = item.ComponentName;

            Add(autokey, item);
        }