Exemplo n.º 1
0
        /// <summary>
        /// This method will call ParameterValidate and PortValidate, in most case, no need to override this, just override ParameterValidate and PortValidate
        /// </summary>
        /// <paramCollection name="message">return the combined error message</paramCollection>
        public virtual bool Validate(ref string message)
        {
            CasterLogger.Debug("Validate");

            string parameterMessage = null;
            string portMessage      = null;

            Status = CapeValidationStatus.CAPE_VALID;

            if (!ParamtersValidate(out parameterMessage))
            {
                Status = CapeValidationStatus.CAPE_INVALID;
            }

            if (!PortsValidate(out portMessage))
            {
                Status = CapeValidationStatus.CAPE_INVALID;
            }

            message = "" + parameterMessage + '\n' + portMessage;
            if (Status == CapeValidationStatus.CAPE_VALID)
            {
                CasterLogger.Debug("Validate success.");
                return(true);
            }
            else
            {
                CasterLogger.DebugFormatted("Validate fails. {0}", message);
                Debug.WriteLine("Validate fails. {0}", message);
                return(false);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Search possible propertyName in Available Prop List, find the first one start will the possible name, if not found, return defaultName
        /// </summary>
        /// <paramCollection name="category">category of property</paramCollection>
        /// <paramCollection name="possibleName">possible name of the property, like "gibbs" for "gibbsEnergy" or "gibbsFreeEnergy"</paramCollection>
        /// <paramCollection name="defaultName">if not found, return defaultName, default defaultName is possibleName</paramCollection>
        /// <returns></returns>
        public string SearchPropName(PropertyCategory category, string possibleName, string defaultName = null)
        {
            CasterLogger.Debug($"SearchPropName for {possibleName}");
            string propName = null;

            try
            {
                if (category == PropertyCategory.SinglePhaseProp)
                {
                    propName = AvailableSinglePhaseProp.FirstOrDefault(x => x.ToLower().Contains(possibleName));
                }
                else if (category == PropertyCategory.TwoPhaseProp)
                {
                    propName = AvailableTwoPhaseProp.FirstOrDefault(x => x.ToLower().Contains(possibleName));
                }
                else if (category == PropertyCategory.ConstantProp)
                {
                    propName = AvailableConstProp.FirstOrDefault(x => x.ToLower().Contains(possibleName));
                }
                else if (category == PropertyCategory.TDependentProp)
                {
                    propName = AvailableTDependentProp.FirstOrDefault(x => x.ToLower().Contains(possibleName));
                }
                else if (category == PropertyCategory.PDependentProp)
                {
                    propName = AvailablePDependentProp.FirstOrDefault(x => x.ToLower().Contains(possibleName));
                }
                else if (category == PropertyCategory.UniversalConstantProp)
                {
                    propName = AvailableUniversalConstProp.FirstOrDefault(x => x.ToLower().Contains(possibleName));
                }
            }
            catch (Exception)
            {
                CasterLogger.DebugFormatted("Property {0} not found, use {1}", possibleName, defaultName);
                Debug.WriteLine("Property {0} not found, use {1}", possibleName, defaultName);
            }
            if (propName == null)
            {
                propName = defaultName ?? possibleName;
                CasterLogger.DebugFormatted("Property {0} not found, use {1}", possibleName, defaultName);
                Debug.WriteLine("Property {0} not found, use {1}", possibleName, propName);
            }
            return(propName);
        }