Esempio n. 1
0
        void ValidateComponent(Component component, Dictionary<string, object> record, Dictionary<string, string> values, List<Error> errors, string componentName)
        {
            string name = component.Concept.Id;
            object obj = null;
            bool optionalAttribute = component is Attribute && ((Attribute)component).AssignmentStatus == AssignmentStatus.Conditional;
            if (!record.TryGetValue(name, out obj))
            {   
                if (!optionalAttribute)
                {
                    errors.Add(new MandatoryComponentMissing(name, string.Format("{0} '{1}' is missing from record ({2}).", componentName, name, RecordToString(record))));
                }

                values.Add(name, null);
            }
            else
            {
                if (obj == null || obj is DBNull)
                {
                    if (!optionalAttribute)
                    {
                        errors.Add(new MandatoryComponentMissing(name, string.Format("Null value for {0}: Name:'{1}' Value:'null' Record ({2}).", componentName, name, RecordToString(record))));
                    }

                    values.Add(name, null);
                }
                else
                {
                    string value = null;
                    string startTime = null;
                    if (!component.TrySerialize(obj, out value, out startTime))
                    {
                        errors.Add(new SerializationError(name, obj, string.Format("Cannot serialize {0}: Name:'{1}' Value:'{2}' Type:'{4}' Record ({3}).", componentName, name, obj, RecordToString(record), obj.GetType())));
                    }
                    else
                    {
                        values.Add(name, value);
                    }
                }
            }
        }
Esempio n. 2
0
        private bool TryParse(List<Error> errorList, string name, string value, Component comp, out object obj)
        {
            obj = null;
            if (comp == null)
            {
                AddValidationError(errorList, "Invalid tag '{0}'.", name);
                return false;
            }

            string startTime = null;
            if (!comp.TryParse(value, startTime, out obj))
            {
                AddParseError(string.Format("Cannot parse value '{1}' for '{0}'.", name, value), errorList, name, value);
                return false;
            }

            return true ;
        }