/// <summary>
 /// UnRegister a component with its name
 /// </summary>
 public static void UnRegister(string name)
 {
     CasterLogger.Debug($"UnRegister component {name}.");
     //if (!_components.ContainsKey(name))
     //    throw new ECapeUnknownException(
     //        $"UnRegister Failed : Key \"{name}\" is not registered.");
     //else
     _components.Remove(name);
 }
Exemple #2
0
 /// <summary>
 /// Same usage as Console.Write(). COSE should be log the message.
 /// To be usable without simulation context, will log in Debug.
 /// </summary>
 public static void LogMessage(string msg, params object[] args)
 {
     if (_diagnostic != null)
     {
         _diagnostic.LogMessage(string.Format(msg, args));
     }
     CasterLogger.DebugFormatted(msg, args);
     Debug.WriteLine(string.Format(msg, args));
 }
        /// <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>
        /// 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>
 /// delete all registered blocks
 /// </summary>
 public static void Clear()
 {
     CasterLogger.Debug("CasterLocator clear");
     _components.Clear();
 }