Exemple #1
0
        internal static OpenEhr.AM.Archetype.ConstraintModel.Primitive.CPrimitive CPrimitive(string typeName)
        {
            DesignByContract.Check.Require(!string.IsNullOrEmpty(typeName), string.Format(CommonStrings.XMustNotBeNullOrEmpty, "typeName"));

            OpenEhr.AM.Archetype.ConstraintModel.Primitive.CPrimitive cPrimitive = null;
            switch (typeName)
            {
            case "C_BOOLEAN":
                cPrimitive = new CBoolean();
                break;

            case "C_DATE":
                cPrimitive = new CDate();
                break;

            case "C_DATE_TIME":
                cPrimitive = new CDateTime();
                break;

            case "C_DURATION":
                cPrimitive = new CDuration();
                break;

            case "C_TIME":
                cPrimitive = new CTime();
                break;

            case "C_INTEGER":
                cPrimitive = new CInteger();
                break;

            case "C_REAL":
                cPrimitive = new CReal();
                break;

            case "C_STRING":
                cPrimitive = new CString();
                break;

            default:
                throw new NotSupportedException("type not supported: " + typeName);
            }

            DesignByContract.Check.Ensure(cPrimitive != null, "cObject must not be null.");

            return(cPrimitive);
        }
Exemple #2
0
 internal override bool IsSubsetOf(CPrimitive other)
 {
     throw new NotImplementedException(
               string.Format(AmValidationStrings.IsSubsetNotImplementedInX, "CString"));
 }
Exemple #3
0
 internal override bool IsSubsetOf(CPrimitive other)
 {
     throw new NotImplementedException(
         string.Format(AmValidationStrings.IsSubsetNotImplementedInX, "CInteger"));
 }
Exemple #4
0
 protected void ValidateBase(CPrimitive cPrimitive)
 {
     Invariant(!cPrimitive.HasAssumedValue() ||
         string.IsNullOrEmpty(cPrimitive.ValidValue(cPrimitive.AssumedValue)),
         AmValidationStrings.AssumedValueInvalid);
 }
Exemple #5
0
        protected void Validate(CPrimitive cPrimitive)
        {
            if (cPrimitive == null) throw new ArgumentNullException(string.Format(
                CommonStrings.XMustNotBeNull, "cPrimitive"));

            const string methodName = "Validate";

            try
            {
                System.Reflection.MethodInfo method = this.GetType().GetMethod(methodName,
                    System.Reflection.BindingFlags.ExactBinding | System.Reflection.BindingFlags.NonPublic
                    | System.Reflection.BindingFlags.Instance, Type.DefaultBinder,
                               new Type[] { cPrimitive.GetType() },
                               new System.Reflection.ParameterModifier[0]);

                if (method != null)
                {
                    if (method != lastCPrimitiveMethod || cPrimitive != lastCPrimitive)
                    {
                        lastCPrimitiveMethod = method;
                        lastCPrimitive = cPrimitive;

                        method.Invoke(this, new Object[] { cPrimitive });

                    }
                    else
                    {
                        string message = string.Format(CommonStrings.LoopingMethodTerminated,
                            methodName, cPrimitive.GetType().ToString());
                        System.Diagnostics.Debug.WriteLine(message);
                        throw new ApplicationException(message);
                    }
                }
                else
                {
                    string message = string.Format(CommonStrings.MethodXNotImplementedForParamTypeY,
                        methodName, cPrimitive.GetType().ToString());
                    System.Diagnostics.Debug.WriteLine(message);
                    throw new ApplicationException(message);
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                    if (ex.InnerException is ApplicationException && ex.InnerException.InnerException != null
                            && ex.InnerException.Message == ex.InnerException.InnerException.Message)
                        throw new ApplicationException(ex.InnerException.Message, ex.InnerException.InnerException);
                    else
                        throw new ApplicationException(ex.InnerException.Message, ex.InnerException);
                else
                    throw new ApplicationException(ex.Message, ex);
            }
        }
Exemple #6
0
 /// <summary>
 /// True if the current node constraints is narrower than other
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 internal abstract bool IsSubsetOf(CPrimitive other);
Exemple #7
0
        private void WriteXml(CPrimitive cPrimitiveObj)
        {
            if (cPrimitiveObj == null) throw new ArgumentNullException(string.Format(CommonStrings.XIsNull, "cPrimitiveObj"));

            const string methodName = "WriteXml";

            try
            {
                System.Reflection.MethodInfo method = this.GetType().GetMethod(methodName,
                    System.Reflection.BindingFlags.ExactBinding | System.Reflection.BindingFlags.NonPublic
                    | System.Reflection.BindingFlags.Instance, Type.DefaultBinder,
                               new Type[] { cPrimitiveObj.GetType() },
                               new System.Reflection.ParameterModifier[0]);

                if (method != null)
                {
                    // Avoid StackOverflow exceptions by executing only if the method and visitable
                    // are different from the last parameters used.
                    if (method != lastMethodWriteXmlCPrimitive || cPrimitiveObj != lastCPrimitiveWrite)
                    {
                        lastMethodWriteXmlCPrimitive = method;
                        lastCPrimitiveWrite = cPrimitiveObj;

                        method.Invoke(this, new Object[] { cPrimitiveObj });

                    }
                    else
                    {
                        string message = string.Format(CommonStrings.LoopingMethodTerminated,
                            methodName, cPrimitiveObj.GetType().ToString());
                        System.Diagnostics.Debug.WriteLine(message);
                        throw new ApplicationException(message);
                    }
                }
                else
                {
                    string message = string.Format(CommonStrings.MethodXNotImplementedForParamTypeY,
                        methodName, cPrimitiveObj.GetType().ToString());
                    System.Diagnostics.Debug.WriteLine(message);
                    throw new ApplicationException(message);
                }
            }
            catch (System.Reflection.TargetInvocationException ex)
            {
                if (ex.InnerException != null)
                    throw new ApplicationException(ex.InnerException.Message, ex.InnerException);
                else
                    throw new ApplicationException(ex.Message, ex);
            }
        }
Exemple #8
0
 /// <summary>
 /// True if the current node constraints is narrower than other
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 internal abstract bool IsSubsetOf(CPrimitive other);