示例#1
0
        private bool _validateDouble(urakawa.metadata.Metadata metadata, MetadataDefinition definition)
        {
            try
            {
                double x = Convert.ToDouble(metadata.NameContentAttribute.Value);
            }
            catch (Exception)
            {
                MetadataFormatValidationError err =
                    new MetadataFormatValidationError(metadata, definition, m_EventAggregator);
                err.Hint = m_NumericHint;

                m_ParentValidator.ReportError(err);
                return(false);
            }
            return(true);
        }
示例#2
0
        private bool _validateLanguageCode(urakawa.metadata.Metadata metadata, MetadataDefinition definition)
        {
            string lang  = metadata.NameContentAttribute.Value;
            bool   valid = true;

            if (m_InvalidLanguageCodes.Contains(lang))
            {
                valid = false;
            }
            else
            {
                try
                {
                    CultureInfo info = CultureInfo.GetCultureInfo(lang);
                    if (info != null)
                    {
                        return(true);
                    }
                }
                catch
                {
                    valid = false;

                    if (!m_InvalidLanguageCodes.Contains(lang))
                    {
                        m_InvalidLanguageCodes.Add(lang);
                    }
                }
            }
            if (valid)
            {
                return(true);
            }
            MetadataFormatValidationError err =
                new MetadataFormatValidationError(metadata, definition, m_EventAggregator);

            err.Hint = m_LanguageHint;

            m_ParentValidator.ReportError(err);

            return(false);
        }
示例#3
0
        public bool Validate(urakawa.metadata.Metadata metadata, MetadataDefinition definition)
        {
            //neither required nor optional fields may be empty
            //check both an empty string and our "magic" string value that is
            //used upon creation of a new metadata item
            if (!string.IsNullOrEmpty(metadata.NameContentAttribute.Value) &&
                metadata.NameContentAttribute.Value != SupportedMetadata_Z39862005.MagicStringEmpty)
            {
                return(true);
            }
            else
            {
                MetadataFormatValidationError err =
                    new MetadataFormatValidationError(metadata, definition, m_EventAggregator);
                err.Hint = m_NonEmptyHint;

                m_ParentValidator.ReportError(err);
                return(false);
            }
        }
示例#4
0
        private bool _validateDate(urakawa.metadata.Metadata metadata, MetadataDefinition definition)
        {
            MetadataFormatValidationError err =
                new MetadataFormatValidationError(metadata, definition, m_EventAggregator);

            err.Hint = m_DateHint;

            string date = metadata.NameContentAttribute.Value;

            //Require at least the year field
            //The max length of the entire datestring is 10
            if (date.Length < 4 || date.Length > 10)
            {
                m_ParentValidator.ReportError(err);
                return(false);
            }

            string[] dateArray = date.Split('-');

            //the year has to be 4 digits
            if (dateArray[0].Length != 4)
            {
                m_ParentValidator.ReportError(err);
                return(false);
            }


            //the year has to be digits
            try
            {
                int year = Convert.ToInt32(dateArray[0]);
            }
            catch
            {
                m_ParentValidator.ReportError(err);
                return(false);
            }

            //check for a month value (it's optional)
            if (dateArray.Length >= 2)
            {
                //the month has to be numeric
                int month = 0;
                try
                {
                    month = Convert.ToInt32(dateArray[1]);
                }
                catch
                {
                    m_ParentValidator.ReportError(err);
                    return(false);
                }
                //the month has to be in this range
                if (month < 1 || month > 12)
                {
                    m_ParentValidator.ReportError(err);
                    return(false);
                }
            }
            //check for a day value (it's optional but only if a month is specified)
            if (dateArray.Length == 3)
            {
                //the day has to be a number
                int day = 0;
                try
                {
                    day = Convert.ToInt32(dateArray[2]);
                }
                catch
                {
                    m_ParentValidator.ReportError(err);
                    return(false);
                }
                //it has to be in this range
                if (day < 1 || day > 31)
                {
                    m_ParentValidator.ReportError(err);
                    return(false);
                }
            }

            return(true);
        }