Exemple #1
0
 public RecordKey(RecipeRecord record)
 {
     this.table    = record.Table;
     this.getValue = delegate(NrdoField field)
     {
         RecipeValueField rfield = record.GetField(field.Name) as RecipeValueField;
         return(rfield == null?Recipe.defaultValue(field.Type, field.IsNullable) : rfield.Value);
     };
 }
Exemple #2
0
        internal XmlElement ToXmlElement(XmlDocument doc)
        {
            XmlElement element = doc.CreateElement(TableName.Replace(':', '.'));

            if (NrdoId != null)
            {
                element.SetAttribute("nrdo.id", NrdoId);
            }
            foreach (RecipeField field in fields.Values)
            {
                RecipeValueField valueField = field as RecipeValueField;
                string           value;
                string           type = null;
                if (valueField != null)
                {
                    if (valueField.Value == null)
                    {
                        value = "null";
                    }
                    else
                    {
                        type = valueField.Value.GetType().FullName;
                        if (valueField.Value is DateTime)
                        {
                            value = ((DateTime)valueField.Value).ToBinary().ToString();
                        }
                        else
                        {
                            value = valueField.Value.ToString();
                        }
                    }
                }
                else
                {
                    value = "undefined";
                }
                element.SetAttribute(field.Name, type + ":" + value);
            }
            return(element);
        }
Exemple #3
0
        internal static RecipeRecord FromXmlElement(RecipeContext context, XmlElement element)
        {
            var origTableName = element.LocalName.Replace('.', ':');
            var tableName     = context.GetRenameMappedTableName(origTableName);

            if (tableName == null)
            {
                return(null);
            }

            RecipeRecord result = new RecipeRecord(context, tableName, origTableName, XmlUtil.GetAttr(element, "nrdo.id"));

            foreach (XmlAttribute attr in element.Attributes)
            {
                if (attr.LocalName == "nrdo.id")
                {
                    continue;
                }

                RecipeField field;
                string[]    parts = attr.Value.Split(new char[] { ':' }, 2);
                if (parts.Length != 2)
                {
                    throw new ArgumentException("attribute value " + attr.Name + "='" + attr.Value + "' does not contain a ':'");
                }
                string type  = parts[0];
                string value = parts[1];

                if (type == "")
                {
                    switch (value)
                    {
                    case "undefined":
                        field = new RecipeField(result, attr.LocalName);
                        break;

                    case "null":
                        field = new RecipeValueField(result, attr.LocalName, null);
                        break;

                    default:
                        throw new ArgumentException("attribute value " + attr.Name + "='" + attr.Value + "' starts with : but is neither :null nor :undefined");
                    }
                }
                else
                {
                    if (!type.StartsWith("System."))
                    {
                        throw new ArgumentException("Illegal context value type " + type);
                    }
                    object valueObject;
                    if (type == "System.DateTime")
                    {
                        valueObject = DateTime.FromBinary(long.Parse(value));
                    }
                    else
                    {
                        Type valueType = Type.GetType(type);
                        valueObject = TypeDescriptor.GetConverter(valueType).ConvertFromString(value);
                    }
                    field = new RecipeValueField(result, attr.LocalName, valueObject);
                }
                result.PutField(field);
            }
            return(result);
        }