Beispiel #1
0
        private void SetClassProperty()
        {
            if (!string.IsNullOrEmpty(this.Pattern))
            {
                Match           match  = Regex.Match(this.Pattern, dayPatternPattern, RegexOptions.Compiled | RegexOptions.Singleline);
                GroupCollection groups = match.Groups;

                if (groups == null)
                {
                    throw new ApplicationException(CommonStrings.RegexGroupsMustNotBeNull);
                }

                this.MonthValidity = CDateTime.ToValidityKind(groups["month"].Value);
                this.DayValidity   = CDateTime.ToValidityKind(groups["day"].Value);
            }
        }
Beispiel #2
0
        private bool IsMatchPattern(Iso8601Time isoTime)
        {
            DesignByContract.Check.Require(isoTime != null, string.Format(CommonStrings.XMustNotBeNull, "isoTime"));
            DesignByContract.Check.Require(this.Pattern != null, string.Format(CommonStrings.XMustNotBeNull, "Pattern"));

            if (!CDateTime.IsMatchValidityKind(this.MinuteValidity, isoTime.MinuteUnknown))
            {
                return(false);
            }

            if (!CDateTime.IsMatchValidityKind(this.SecondValidity, isoTime.SecondUnknown))
            {
                return(false);
            }

            return(true);
        }
Beispiel #3
0
        private bool IsMatchPattern(Iso8601Date isoDate)
        {
            DesignByContract.Check.Require(isoDate != null,
                                           string.Format(CommonStrings.XMustNotBeNull, "isoDate"));
            DesignByContract.Check.Require(this.Pattern != null,
                                           string.Format(CommonStrings.XMustNotBeNull, "Pattern"));

            if (!CDateTime.IsMatchValidityKind(this.MonthValidity, isoDate.MonthUnknown))
            {
                return(false);
            }

            if (!CDateTime.IsMatchValidityKind(this.DayValidity, isoDate.DayUnknown))
            {
                return(false);
            }

            return(true);
        }
Beispiel #4
0
        protected void Validate(CDateTime cDateTime)
        {
            this.ValidateBase((CPrimitive)cDateTime);

            if (cDateTime.MonthValidity != null)
            {
                this.Validate(cDateTime.MonthValidity);
                Invariant(cDateTime.MonthValidity.value != 1002 || (cDateTime.DayValidity.value == 1002 || cDateTime.DayValidity.value == 1003),
                    "cDateTime.MonthValidity is optional, means DayValidity must be either optional or disallowed.");

                Invariant(cDateTime.MonthValidity.value != 1003 || cDateTime.DayValidity.value == 1003,
                    "cDateTime.MonthValidity is disallowed, implies DayValidity must be disallowed.");
            }

            if (cDateTime.DayValidity != null)
            {
                this.Validate(cDateTime.DayValidity);

                Invariant(cDateTime.DayValidity.value != 1002 || (cDateTime.HourValidity.value == 1002 || cDateTime.HourValidity.value == 1003),
                    "cDateTime.DayValidity is optional, means HourValidity must be either optional or disallowed.");

                Invariant(cDateTime.MonthValidity.value != 1003 || cDateTime.DayValidity.value == 1003,
                    "cDateTime.DayValidity is disallowed, implies HourValidity must be disallowed.");
            }

            if (cDateTime.HourValidity != null)
            {
                this.Validate(cDateTime.HourValidity);

                Invariant(cDateTime.HourValidity.value != 1002 || (cDateTime.MinuteValidity.value == 1002 || cDateTime.MinuteValidity.value == 1003),
                    "cDateTime.HourValidity is optional, means MinuteValidity must be either optional or disallowed.");

                Invariant(cDateTime.HourValidity.value != 1003 || cDateTime.MinuteValidity.value == 1003,
                    "cDateTime.HourValidity is disallowed, implies MinuteValidity must be disallowed.");
            }

            if (cDateTime.MinuteValidity != null)
            {
                this.Validate(cDateTime.MinuteValidity);
                Invariant(cDateTime.MinuteValidity.value != 1002 || (cDateTime.SecondValidity.value == 1002 || cDateTime.SecondValidity.value == 1003),
                    "cDateTime.MinuteValidity.valueis optional, means DayValidity must be either optional or disallowed.");

                Invariant(cDateTime.MinuteValidity.value != 1003 || cDateTime.SecondValidity.value == 1003,
                    "cDateTime.MinuteValidity is disallowed, implies cDateTime.SecondValidity must be disallowed.");
            }

            if (cDateTime.SecondValidity != null)
            {
                this.Validate(cDateTime.SecondValidity);
                Invariant(cDateTime.SecondValidity.value != 1002 || (cDateTime.MillisecondValidity.value == 1002 || cDateTime.MillisecondValidity.value == 1003),
                    "cDate.SecondValidity is optional, means SecondValidity must be either optional or disallowed.");

                Invariant(cDateTime.SecondValidity.value != 1003 || cDateTime.MillisecondValidity.value == 1003,
                  "cDate.SecondValidity is disallowed, implies cDate.MillisecondValidity must be disallowed.");
            }
        }
Beispiel #5
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;
        }
Beispiel #6
0
        private void WriteXml(CDateTime cPrimitive)
        {
            if (!string.IsNullOrEmpty(cPrimitive.Pattern))
                writer.WriteElementString("pattern", OpenEhrNamespace, cPrimitive.Pattern);

            if (cPrimitive.TimezoneValidity != null)
                writer.WriteElementString("timezone_validity", OpenEhrNamespace, cPrimitive.TimezoneValidity.Value.ToString());

            if (cPrimitive.Range != null)
            {
                writer.WriteStartElement("range");
                this.WriteXml(cPrimitive.Range);
                writer.WriteEndElement();
            }

            if (cPrimitive.AssumedValue != null)
            {
                writer.WriteStartElement(UseOpenEhrPrefix(writer), "assumed_value", OpenEhrNamespace);
                writer.WriteString(cPrimitive.AssumedValue.ToString());
                writer.WriteEndElement();
            }
        }
Beispiel #7
0
        private void ReadXml(CDateTime cDateTime)
        {
            reader.ReadStartElement();
            reader.MoveToContent();

            if (reader.LocalName == "pattern")
            {
                cDateTime.Pattern = reader.ReadElementContentAsString("pattern", OpenEhrNamespace);
                reader.MoveToContent();
            }

            if (reader.LocalName == "timezone_validity")
            {
                cDateTime.TimezoneValidity = new ValidityKind(reader.ReadElementContentAsInt("timezone_validity", OpenEhrNamespace));
                reader.MoveToContent();
            }

            if (reader.LocalName == "range")
            {
                cDateTime.Range = new Interval<Iso8601DateTime>();
                this.ReadXml(cDateTime.Range);
            }

            if (reader.LocalName == "assumed_value")
            {
                cDateTime.AssumedValue = new AssumedTypes.Iso8601DateTime(reader.ReadElementContentAsString("assumed_value", OpenEhrNamespace));
                reader.MoveToContent();
            }

            reader.ReadEndElement();
            reader.MoveToContent();
        }