public void ProcessScriptBase(IScriptBase scriptBase, XmlNode scriptBaseNode)
        {
            /*
             *      <Name>Table1</Name>
             *      <Description />
             *      <Enabled>False</Enabled>
             *      <IsUserDefined>False</IsUserDefined>
             *      <UID>00000000-0000-0000-0000-000000000000</UID>
             */

            NodeProcessor proc = new NodeProcessor(scriptBaseNode);

            scriptBase.Name          = proc.GetString("Name");
            scriptBase.Schema        = proc.GetString("Schema");
            scriptBase.Description   = proc.GetString("Description");
            scriptBase.Enabled       = proc.GetBool("Enabled");
            scriptBase.IsUserDefined = proc.GetBool("IsUserDefined");

            if (proc.Exists(VirtualPropertyDeserialiser.VirtualPropertiesNodeName))
            {
                var deserialiser = new VirtualPropertyDeserialiser();
                scriptBase.Ex =
                    deserialiser.DeserialiseVirtualProperties(
                        scriptBaseNode.SelectSingleNode(VirtualPropertyDeserialiser.VirtualPropertiesNodeName));
            }
        }
        protected virtual void ProcessConfig(XmlNode node, IDesignerProject project, string projectFilename)
        {
            NodeProcessor proc = new NodeProcessor(node);

            string relativeCompilePath = proc.GetString("RelativeCompilePath");

            project.CompileFolderName = controller.ToAbsolutePath(relativeCompilePath, projectFilename);

            project.Version  = proc.GetString("Version");
            project.ProjType = proc.GetEnum <ProjectTypes>("ProjectType");

            string relativeDebugProjectFile = proc.GetString("DebugProjectFile");

            project.DebugProjectFile = controller.ToAbsolutePath(relativeDebugProjectFile, projectFilename);

            var relativeTestGenerateDirectory = proc.GetString("TestGenerateDirectory");

            project.TestGenerateDirectory = controller.ToAbsolutePath(relativeTestGenerateDirectory, projectFilename);

            var namespaceNodes = node.SelectNodes("IncludedNamespaces/Namespace");

            if (namespaceNodes != null)
            {
                foreach (XmlNode namespaceNode in namespaceNodes)
                {
                    project.AddNamespace(namespaceNode.InnerText);
                }
            }

            var refereceNodes = node.SelectNodes("References/Reference");

            ProcessProjectReferences(refereceNodes, project, projectFilename);
        }
        public void ProcessReferencedKey(IKey key, XmlNode keyNode, IDatabase db)
        {
            var referencedKeyNode = keyNode.SelectSingleNode("ReferencedKey");

            if (referencedKeyNode != null)
            {
                NodeProcessor proc      = new NodeProcessor(referencedKeyNode);
                string        tableName = proc.GetString("TableName");
                string        schema    = proc.GetString("Schema");
                string        keyName   = proc.GetString("KeyName");
                key.ReferencedKey = db.GetKey(tableName, schema, keyName);
            }
        }
        public virtual void ReadProject(XmlNode projectElement, IDesignerProject project, string projectFilename)
        {
            if (projectElement == null)
            {
                throw new DeserialisationException("Could not find Project node");
            }

            NodeProcessor proc = new NodeProcessor(projectElement);

            project.ProjectName        = proc.GetString("Name");
            project.ProjectDescription = proc.GetString("Description");

            ProcessConfig(projectElement.SelectSingleNode("Config"), project, projectFilename);
        }
Exemple #5
0
        public Discriminator DeserialiseDiscriminator(XmlNode discriminatorNode)
        {
            NodeProcessor processor = new NodeProcessor(discriminatorNode);

            Discriminator discriminator = new Discriminator();

            discriminator.AllowNull         = processor.GetBool("AllowNull");
            discriminator.ColumnName        = processor.GetString("ColumnName");
            discriminator.DiscriminatorType = (Enums.DiscriminatorTypes)Enum.Parse(typeof(Enums.DiscriminatorTypes), processor.GetString("DiscriminatorType"), true);
            discriminator.Force             = processor.GetBool("Force");
            discriminator.Formula           = processor.GetString("Formula");
            discriminator.Insert            = processor.GetBool("Insert");
            return(discriminator);
        }
        public ComponentMapping DeserialiseComponentMapping(XmlNode mappingNode, IDatabase database, EntitySet set)
        {
            NodeProcessor proc = new NodeProcessor(mappingNode);
            ComponentMapping mapping = new ComponentMappingImpl();

            mapping.FromTable = database.GetTable(proc.GetString("FromTable"), proc.GetString("FromSchema"));

            NodeProcessor specProcessor = new NodeProcessor(mappingNode.SelectSingleNode("ToComponent"));

            var specification = set.GetComponentSpecification(specProcessor.Attributes.GetString("specification"));
            var parentEntity = set.GetEntity(specProcessor.Attributes.GetString("parent-entity"));
            string name = specProcessor.Attributes.GetString("name");

            if (parentEntity == null)
                throw new DeserialisationException(string.Format("Could not find the Entity named {0}", name));
            if (specification == null)
                throw new DeserialisationException(string.Format("Could not find the Component Specification named {0}", name));

            var component = specification.ImplementedComponents.FirstOrDefault(c => ReferenceEquals(c.ParentEntity, parentEntity) && c.Name == name);
            if (component == null)
                throw new DeserialisationException(string.Format("Could not find the component named {0}", name));

            mapping.ToComponent = component;
            var columnNodes = mappingNode.SelectNodes("FromColumns/Column");
            var propNodes = mappingNode.SelectNodes("ToProperties/Property");
            if (columnNodes == null) throw new DeserialisationException("There were no columns in this Mapping xml");
            if (propNodes == null) throw new DeserialisationException("There were no properties in this Mapping xml");

            List<IColumn> columns = new List<IColumn>();
            foreach (XmlNode columnNode in columnNodes)
            {
                columns.Add(mapping.FromTable.GetColumn(columnNode.InnerText));
            }

            List<ComponentPropertyMarker> properties = new List<ComponentPropertyMarker>();
            foreach (XmlNode propNode in propNodes)
            {
                properties.Add(mapping.ToComponent.GetProperty(propNode.InnerText));
            }

            if (columns.Count != properties.Count) throw new DeserialisationException("Mapping contains different numbers of columns and properties");

            for (int i = 0; i < columns.Count; i++)
            {
                mapping.AddPropertyAndColumn(properties[i], columns[i]);
            }

            ProcessScriptBase(mapping, mappingNode);
            return mapping;
        }
        public TableReferenceMapping DeserialiseReferenceMapping(XmlNode referenceMappingNode, IDatabase database, EntitySet set)
        {
            NodeProcessor         proc    = new NodeProcessor(referenceMappingNode);
            TableReferenceMapping mapping = new TableReferenceMappingImpl();
            string fromTableName          = proc.GetString("FromTable");
            string fromSchema             = proc.GetString("FromSchema");
            Guid   toReferenceIdentifier  = proc.GetGuid("ToReference");
            var    reference = set.References.FirstOrDefault(r => r.Identifier == toReferenceIdentifier);

            mapping.FromTable   = database.GetTable(fromTableName, fromSchema);
            mapping.ToReference = reference;
            ProcessScriptBase(mapping, referenceMappingNode);
            return(mapping);
        }
        public IUserOption DeserialiseVirtualProperty(XmlNode virtualPropertyNode)
        {
            NodeProcessor proc = new NodeProcessor(virtualPropertyNode);
            string        name = proc.Attributes.GetString("name");

            string typeName = proc.Attributes.GetString("type");

            Type type = GetTypeNamed(typeName);

            if (type == null)
            {
                throw new Exception(string.Format("Could not find type named \"{0}\" for virtual property {1}", typeName, name));
            }

            string valueString = proc.GetString("Value");

            IUserOption option = new UserOption();

            option.Name     = name;
            option.DataType = type;

            if (type == TypePropertiesForThisEntity)
            {
                option.Value = valueString;
            }
            else
            {
                option.Value = valueString.As(option.DataType);
            }

            return(option);
        }
        public IUserOption DeserialiseVirtualProperty(XmlNode virtualPropertyNode)
        {
            NodeProcessor proc = new NodeProcessor(virtualPropertyNode);
            string name = proc.Attributes.GetString("name");

            string typeName = proc.Attributes.GetString("type");

            Type type = GetTypeNamed(typeName);

            if (type == null)
                throw new Exception(string.Format("Could not find type named \"{0}\" for virtual property {1}", typeName, name));

            string valueString = proc.GetString("Value");

            IUserOption option = new UserOption();
            option.Name = name;
            option.DataType = type;

            if (type == TypePropertiesForThisEntity)
                option.Value = valueString;
            else
                option.Value = valueString.As(option.DataType);

            return option;
        }
Exemple #10
0
        public Property DeserialiseProperty(XmlNode propertyNode, EntityImpl parentEntity)
        {
            Property property = new PropertyImpl();

            property.Entity = parentEntity;

            NodeProcessor processor = new NodeProcessor(propertyNode);

            if (processor.Exists("IsKey"))
            {
                property.IsKeyProperty = processor.GetBool("IsKey");
            }

            property.Name     = processor.GetString("Name");
            property.ReadOnly = processor.GetBool("ReadOnly");
            property.Type     = processor.GetString("Type");

            if (processor.Exists("NHibernateType"))
            {
                property.NHibernateType = processor.GetString("NHibernateType");
            }

            if (processor.Exists("Validation"))
            {
                property.ValidationOptions = DeserialiseValidationOptions(propertyNode.SelectSingleNode("Validation"));
            }
            else
            {
                property.ValidationOptions = new ValidationOptions();
            }

            if (processor.Exists("IsHiddenByAbstractParent"))
            {
                property.IsHiddenByAbstractParent = processor.GetBool("IsHiddenByAbstractParent");
            }

            if (processor.Exists("IsPartOfHiddenKey"))
            {
                property.IsPartOfHiddenKey = processor.GetBool("IsPartOfHiddenKey");
            }

            ProcessScriptBase(property, propertyNode);

            return(property);
        }
        /// <summary>
        /// Creates a FunctionInfo object from the given XML. Because it
        /// has to resolve Type objects, this should only be done after
        /// all referenced assemblies are loaded into the current AppDomain.
        /// </summary>
        /// <param name="rootElement"></param>
        /// <returns></returns>
        public virtual FunctionInfo ReadFunction(XmlNode rootElement)
        {
            if (rootElement == null)
            {
                throw new DeserialisationException("Could not find Function node");
            }

            CheckVersion(rootElement);

            NodeProcessor proc = new NodeProcessor(rootElement);

            var  name               = proc.GetString("Name");
            bool isTemplateFunc     = proc.GetBool("IsTemplateFunction");
            bool isExtMethod        = proc.GetBool("IsExtensionMethod");
            var  extendedType       = proc.GetString("ExtendedType");
            var  scriptLang         = proc.GetEnum <SyntaxEditorHelper.ScriptLanguageTypes>("ScriptLanguage");
            var  description        = proc.GetString("Description");
            var  category           = proc.GetString("Category");
            var  bodyText           = proc.GetString("Body");
            var  returnType         = GetTypeNamed(proc.GetString("ReturnType"));
            var  templateReturnLang = proc.GetString("TemplateReturnLanguage");

            FunctionInfo fi = new FunctionInfo(name, returnType, bodyText, isTemplateFunc, scriptLang, description, templateReturnLang, category, isExtMethod, extendedType);

            ProcessFunctionParameters(fi, rootElement);

            return(fi);
        }
        protected virtual ApiExtensionMethod ReadApiExtension(XmlNode extensionNode, Type extendedType)
        {
            NodeProcessor proc       = new NodeProcessor(extensionNode);
            var           methodName = proc.GetString("MethodName");
            MethodInfo    method     = extendedType.GetMethod(methodName);

            if (method == null)
            {
                throw new DeserialisationException(string.Format("Cannot find method named {0} on type {1}", methodName, extendedType.FullName));
            }

            string overrideText = proc.GetString("OverrideFunctionText");

            ApiExtensionMethod extMethod = new ApiExtensionMethod(method);

            extMethod.OverridingFunctionBody = overrideText;
            return(extMethod);
        }
Exemple #13
0
        public Reference DeserialiseReference(XmlNode refNode, EntitySet set)
        {
            Reference reference = new ReferenceImpl();

            NodeProcessor processor = new NodeProcessor(refNode);

            reference.Identifier  = processor.Attributes.GetGuid("identifier");
            reference.End1Name    = processor.GetString("End1Name");
            reference.End2Name    = processor.GetString("End2Name");
            reference.End1Enabled = processor.GetBool("End1Enabled");
            reference.End2Enabled = processor.GetBool("End2Enabled");

            reference.Entity1 = set.GetEntity(processor.GetString("Entity1"));
            reference.Entity2 = set.GetEntity(processor.GetString("Entity2"));

            reference.Cardinality1 = DeserialiseCardinality(refNode.SelectSingleNode("Cardinality1"));
            reference.Cardinality2 = DeserialiseCardinality(refNode.SelectSingleNode("Cardinality2"));

            if (Version >= 2)
            {
                reference.IncludeForeignKey = processor.GetBool("IncludeForeignKey");
            }

            ProcessScriptBase(reference, refNode);

            // Fixup virtual properties of type PropertiesForThisEntity
            foreach (var uo in reference.Ex.Where(v => v.DataType == TypePropertiesForThisEntity))
            {
                object obj = null;

                if (reference.Entity1 != null)
                {
                    obj = reference.Entity1.Properties.SingleOrDefault(p => p.Name.Equals(uo.Value.ToString(), StringComparison.InvariantCultureIgnoreCase));
                }

                if (obj == null && reference.Entity2 != null)
                {
                    obj = reference.Entity2.Properties.SingleOrDefault(p => p.Name.Equals(uo.Value.ToString(), StringComparison.InvariantCultureIgnoreCase));
                }

                uo.Value = obj;
            }
            return(reference);
        }
        public Mapping DeserialiseMapping(XmlNode node, IDatabase database, EntitySet set)
        {
            NodeProcessor proc = new NodeProcessor(node);
            Mapping mapping = new MappingImpl();

            mapping.FromTable = database.GetTable(proc.GetString("FromTable"), proc.GetString("FromSchema"));

            if (mapping.FromTable == null)
                mapping.FromTable = database.GetView(proc.GetString("FromTable"), proc.GetString("FromSchema"));

            mapping.ToEntity = set.GetEntity(proc.GetString("ToEntity"));

            if (mapping.FromTable == null || mapping.ToEntity == null)
                return null;

            var columnNodes = node.SelectNodes("FromColumns/Column");
            var propNodes = node.SelectNodes("ToProperties/Property");
            if (columnNodes == null) throw new DeserialisationException("There were no columns in this Mapping xml");
            if (propNodes == null) throw new DeserialisationException("There were no properties in this Mapping xml");

            List<IColumn> columns = new List<IColumn>();
            foreach (XmlNode columnNode in columnNodes)
                columns.Add(mapping.FromTable.GetColumn(columnNode.InnerText));

            List<Property> properties = new List<Property>();
            foreach (XmlNode propNode in propNodes)
                properties.Add(mapping.ToEntity.GetProperty(propNode.InnerText));

            if (columns.Count != properties.Count) throw new DeserialisationException("Mapping contains different numbers of columns and properties");

            for (int i = 0; i < columns.Count; i++)
            {
                if (properties[i] != null && columns[i] != null)
                    mapping.AddPropertyAndColumn(properties[i], columns[i]);
            }

            ProcessScriptBase(mapping, node);

            return mapping;
        }
        public IColumn ProcessColumnNode(XmlNode node)
        {
            IColumn column = new Column();

            ProcessScriptBase(column, node);

            /*
             *      <Datatype>int</Datatype>
             *      <Default />
             *      <InPrimaryKey>True</InPrimaryKey>
             *      <IsCalculated>False</IsCalculated>
             *      <IsComputed>False</IsComputed>
             *      <IsIdentity>False</IsIdentity>
             *      <IsNullable>False</IsNullable>
             *      <IsReadOnly>False</IsReadOnly>
             *      <IsUnique>True</IsUnique>
             *      <OrdinalPosition>1</OrdinalPosition>
             *      <Precision>10</Precision>
             *      <Scale>0</Scale>
             *      <Size>0</Size>
             */
            NodeProcessor proc = new NodeProcessor(node);

            column.OriginalDataType = proc.GetString("Datatype");
            column.Default          = proc.GetString("Default");
            column.InPrimaryKey     = proc.GetBool("InPrimaryKey");
            column.IsCalculated     = proc.GetBool("IsCalculated");
            column.IsComputed       = proc.GetBool("IsComputed");
            column.IsIdentity       = proc.GetBool("IsIdentity");
            column.IsNullable       = proc.GetBool("IsNullable");
            column.IsReadOnly       = proc.GetBool("IsReadOnly");
            column.IsUnique         = proc.GetBool("IsUnique");
            column.OrdinalPosition  = proc.GetInt("OrdinalPosition");
            column.Precision        = proc.GetInt("Precision");
            column.Scale            = proc.GetInt("Scale");
            column.Size             = proc.GetLong("Size");

            return(column);
        }
        public virtual void LoadDefaultApiFunctionBodies(XmlNode functionsElement, IDesignerProject project)
        {
            if (functionsElement == null)
            {
                throw new DeserialisationException("Could not find FunctionInformation element");
            }
            CheckVersion(functionsElement);

            project.ClearOverriddenFunctionInformation();

            var functionInformations = new List <OverriddenFunctionInformation>();

            var functions = functionsElement.SelectNodes("Function");

            if (functions == null)
            {
                return;
            }

            foreach (XmlNode funcNode in functions)
            {
                var proc = new NodeProcessor(funcNode);

                var parameters = proc.GetStrings("Parameter").Select(p => GetTypeNamed(p));


                string functionName = proc.Attributes.GetString("name");
                string typeName     = proc.Attributes.GetString("type");

                string xmlcomments  = proc.GetString("XmlComments");
                string functionBody = proc.GetString("BodyText");

                functionInformations.Add(
                    new OverriddenFunctionInformation(GetTypeNamed(typeName), functionName, parameters, xmlcomments, functionBody));
            }

            project.AddOverriddenFunctionInformation(functionInformations);
        }
Exemple #17
0
        public ComponentProperty DeserialiseComponentProperty(XmlNode propertyNode, ComponentSpecification spec)
        {
            NodeProcessor proc = new NodeProcessor(propertyNode);

            ComponentProperty property = new ComponentPropertyImpl();

            property.Specification = spec;
            property.Name          = proc.GetString("Name");
            property.Type          = proc.GetString("Type");

            if (proc.Exists("Validation"))
            {
                property.ValidationOptions = DeserialiseValidationOptions(propertyNode.SelectSingleNode("Validation"));
            }
            else
            {
                property.ValidationOptions = new ValidationOptions();
            }

            ProcessScriptBase(property, propertyNode);

            return(property);
        }
        public static string GetProjectFilesFolder(string projectFilename)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(projectFilename);

            string folder = GetProjectFilesDirectoryName(projectFilename);

            if (!Directory.Exists(RelativePaths.RelativeToAbsolutePath(Path.GetDirectoryName(projectFilename), folder)))

                try
                {
                    NodeProcessor proc = new NodeProcessor(doc.DocumentElement);
                    folder = proc.GetString("Folder");
                }
                catch
                {
                    throw new Exception("Files folder not found for this project.\nIf your project file is called 'xyz.wbproj' then the files folder should be called 'xyz_files'.");
                }
            return RelativePaths.RelativeToAbsolutePath(Path.GetDirectoryName(projectFilename), folder);
        }
Exemple #19
0
        public ValidationOptions DeserialiseValidationOptions(XmlNode validationNode)
        {
            var options = new ValidationOptions();

            var proc = new NodeProcessor(validationNode);

            options.NotEmpty         = proc.GetNullable <bool>("NotEmpty");
            options.Nullable         = proc.GetNullable <bool>("Nullable");
            options.MaximumValue     = proc.GetNullable <int>("MaximumValue");
            options.MinimumValue     = proc.GetNullable <int>("MinimumValue");
            options.FutureDate       = proc.GetNullable <bool>("FutureDate");
            options.PastDate         = proc.GetNullable <bool>("PastDate");
            options.FractionalDigits = proc.GetNullable <int>("FractionalDigits");
            options.IntegerDigits    = proc.GetNullable <int>("IntegerDigits");
            options.MaximumLength    = proc.GetNullable <long>("MaximumLength");
            options.MinimumLength    = proc.GetNullable <int>("MinimumLength");
            options.RegexPattern     = proc.GetString("RegexPattern", null);
            options.Validate         = proc.Exists("Validate");

            return(options);
        }
        public virtual UserOption ReadUserOption(XmlNode rootElement)
        {
            if (rootElement == null)
            {
                throw new DeserialisationException("Could not find Option element");
            }

            CheckVersion(rootElement);

            NodeProcessor proc = new NodeProcessor(rootElement);

            var  varName           = proc.GetString("VariableName");
            var  varType           = GetTypeNamed(proc.GetString("Type"));
            var  displayText       = proc.GetString("DisplayText");
            var  descr             = proc.GetString("Description");
            var  defaultValueBody  = proc.GetString("DefaultValue");
            var  iteratorType      = GetTypeNamed(proc.GetString("IteratorName"));
            var  validatorBody     = proc.GetString("ValidatorFunction");
            var  displayToUserBody = proc.GetString("DisplayToUserFunction");
            bool resetPerSesion    = proc.GetBool("ResetPerSession");

            List <string> values     = new List <string>();
            XmlNodeList   valueNodes = rootElement.SelectNodes("Values/Value");

            if (valueNodes != null)
            {
                foreach (XmlNode valueNode in valueNodes)
                {
                    values.Add(valueNode.Attributes["value"].Value);
                }
            }

            UserOption uo = new UserOption(varName, "", varType,
                                           displayText, descr, values, defaultValueBody,
                                           iteratorType, validatorBody, displayToUserBody, resetPerSesion);

            return(uo);
        }
        public static string GetProjectFilesFolder(string projectFilename)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(projectFilename);

            string folder = GetProjectFilesDirectoryName(projectFilename);

            if (!Directory.Exists(RelativePaths.RelativeToAbsolutePath(Path.GetDirectoryName(projectFilename), folder)))
            {
                try
                {
                    NodeProcessor proc = new NodeProcessor(doc.DocumentElement);
                    folder = proc.GetString("Folder");
                }
                catch
                {
                    throw new Exception("Files folder not found for this project.\nIf your project file is called 'xyz.wbproj' then the files folder should be called 'xyz_files'.");
                }
            }
            return(RelativePaths.RelativeToAbsolutePath(Path.GetDirectoryName(projectFilename), folder));
        }
        public Mapping DeserialiseMapping(XmlNode node, IDatabase database, EntitySet set)
        {
            NodeProcessor proc    = new NodeProcessor(node);
            Mapping       mapping = new MappingImpl();

            mapping.FromTable = database.GetTable(proc.GetString("FromTable"), proc.GetString("FromSchema"));

            if (mapping.FromTable == null)
            {
                mapping.FromTable = database.GetView(proc.GetString("FromTable"), proc.GetString("FromSchema"));
            }

            mapping.ToEntity = set.GetEntity(proc.GetString("ToEntity"));

            if (mapping.FromTable == null || mapping.ToEntity == null)
            {
                return(null);
            }

            var columnNodes = node.SelectNodes("FromColumns/Column");
            var propNodes   = node.SelectNodes("ToProperties/Property");

            if (columnNodes == null)
            {
                throw new DeserialisationException("There were no columns in this Mapping xml");
            }
            if (propNodes == null)
            {
                throw new DeserialisationException("There were no properties in this Mapping xml");
            }

            List <IColumn> columns = new List <IColumn>();

            foreach (XmlNode columnNode in columnNodes)
            {
                columns.Add(mapping.FromTable.GetColumn(columnNode.InnerText));
            }

            List <Property> properties = new List <Property>();

            foreach (XmlNode propNode in propNodes)
            {
                properties.Add(mapping.ToEntity.GetProperty(propNode.InnerText));
            }

            if (columns.Count != properties.Count)
            {
                throw new DeserialisationException("Mapping contains different numbers of columns and properties");
            }

            for (int i = 0; i < columns.Count; i++)
            {
                if (properties[i] != null && columns[i] != null)
                {
                    mapping.AddPropertyAndColumn(properties[i], columns[i]);
                }
            }

            ProcessScriptBase(mapping, node);

            return(mapping);
        }
        /// <summary>
        /// Creates a FunctionInfo object from the given XML. Because it
        /// has to resolve Type objects, this should only be done after
        /// all referenced assemblies are loaded into the current AppDomain.
        /// </summary>
        /// <param name="rootElement"></param>
        /// <returns></returns>
        public virtual FunctionInfo ReadFunction(XmlNode rootElement)
        {
            if (rootElement == null) throw new DeserialisationException("Could not find Function node");

            CheckVersion(rootElement);

            NodeProcessor proc = new NodeProcessor(rootElement);

            var name = proc.GetString("Name");
            bool isTemplateFunc = proc.GetBool("IsTemplateFunction");
            bool isExtMethod = proc.GetBool("IsExtensionMethod");
            var extendedType = proc.GetString("ExtendedType");
            var scriptLang = proc.GetEnum<SyntaxEditorHelper.ScriptLanguageTypes>("ScriptLanguage");
            var description = proc.GetString("Description");
            var category = proc.GetString("Category");
            var bodyText = proc.GetString("Body");
            var returnType = GetTypeNamed(proc.GetString("ReturnType"));
            var templateReturnLang = proc.GetString("TemplateReturnLanguage");

            FunctionInfo fi = new FunctionInfo(name, returnType, bodyText, isTemplateFunc, scriptLang, description, templateReturnLang, category, isExtMethod, extendedType);

            ProcessFunctionParameters(fi, rootElement);

            return fi;
        }
        public virtual void LoadDefaultApiFunctionBodies(XmlNode functionsElement, IDesignerProject project)
        {
            if (functionsElement == null)
                throw new DeserialisationException("Could not find FunctionInformation element");
            CheckVersion(functionsElement);

            project.ClearOverriddenFunctionInformation();

            var functionInformations = new List<OverriddenFunctionInformation>();

            var functions = functionsElement.SelectNodes("Function");

            if (functions == null) return;

            foreach (XmlNode funcNode in functions)
            {
                var proc = new NodeProcessor(funcNode);

                var parameters = proc.GetStrings("Parameter").Select(p => GetTypeNamed(p));

                string functionName = proc.Attributes.GetString("name");
                string typeName = proc.Attributes.GetString("type");

                string xmlcomments = proc.GetString("XmlComments");
                string functionBody = proc.GetString("BodyText");

                functionInformations.Add(
                    new OverriddenFunctionInformation(GetTypeNamed(typeName), functionName, parameters, xmlcomments, functionBody));
            }

            project.AddOverriddenFunctionInformation(functionInformations);
        }
        public virtual UserOption ReadUserOption(XmlNode rootElement)
        {
            if (rootElement == null)
                throw new DeserialisationException("Could not find Option element");

            CheckVersion(rootElement);

            NodeProcessor proc = new NodeProcessor(rootElement);

            var varName = proc.GetString("VariableName");
            var varType = GetTypeNamed(proc.GetString("Type"));
            var displayText = proc.GetString("DisplayText");
            var descr = proc.GetString("Description");
            var defaultValueBody = proc.GetString("DefaultValue");
            var iteratorType = GetTypeNamed(proc.GetString("IteratorName"));
            var validatorBody = proc.GetString("ValidatorFunction");
            var displayToUserBody = proc.GetString("DisplayToUserFunction");
            bool resetPerSesion = proc.GetBool("ResetPerSession");

            List<string> values = new List<string>();
            XmlNodeList valueNodes = rootElement.SelectNodes("Values/Value");
            if (valueNodes != null)
            {
                foreach (XmlNode valueNode in valueNodes)
                {
                    values.Add(valueNode.Attributes["value"].Value);
                }
            }

            UserOption uo = new UserOption(varName, "", varType,
                                           displayText, descr, values, defaultValueBody,
                                           iteratorType, validatorBody, displayToUserBody, resetPerSesion);

            return uo;
        }
        public virtual void ReadProject(XmlNode projectElement, IDesignerProject project, string projectFilename)
        {
            if (projectElement == null) throw new DeserialisationException("Could not find Project node");

            NodeProcessor proc = new NodeProcessor(projectElement);
            project.ProjectName = proc.GetString("Name");
            project.ProjectDescription = proc.GetString("Description");

            ProcessConfig(projectElement.SelectSingleNode("Config"), project, projectFilename);
        }
        private ConnectionStringHelper LoadGenericDatabaseData(XmlNode node, DatabaseTypes databaseType)
        {
            NodeProcessor proc = new NodeProcessor(node);

            var connectionHelper = new ConnectionStringHelper();

            if (string.IsNullOrEmpty(connectionHelper.ServerName))
            {
                switch (databaseType)
                {
                case DatabaseTypes.SQLCE:
                //case DatabaseTypes.SQLServer2000:
                case DatabaseTypes.SQLServer2005:
                    connectionHelper.ServerName = Environment.MachineName;
                    break;

                case DatabaseTypes.SQLServerExpress:
                    connectionHelper.ServerName = Environment.MachineName + "\\SQLEXPRESS";
                    break;

                case DatabaseTypes.MySQL:
                    connectionHelper.ServerName = "localhost";
                    break;

                case DatabaseTypes.Oracle:
                    connectionHelper.ServerName = "localhost";
                    break;

                case DatabaseTypes.PostgreSQL:
                    connectionHelper.ServerName = "localhost";
                    break;

                case DatabaseTypes.Firebird:
                    connectionHelper.ServerName = "localhost";
                    break;

                case DatabaseTypes.SQLite:
                    connectionHelper.ServerName = Environment.MachineName;
                    break;

                default:
                    throw new NotImplementedException("Database type not handled yet: " + databaseType.ToString());
                }
            }
            connectionHelper.CurrentDbType = databaseType;

            if (proc.Exists("ServerName"))
            {
                connectionHelper.ServerName = proc.GetString("ServerName");
            }

            if (proc.Exists("DatabaseName"))
            {
                connectionHelper.DatabaseName = proc.GetString("DatabaseName");
                connectionHelper.UseFileName  = false;
            }
            if (proc.Exists("FileName"))
            {
                connectionHelper.FileName    = proc.GetString("FileName");
                connectionHelper.UseFileName = true;
            }
            if (proc.Exists("UseIntegratedSecurity"))
            {
                connectionHelper.UseIntegratedSecurity = proc.GetBool("UseIntegratedSecurity");
            }

            if (proc.Exists("UserName"))
            {
                connectionHelper.UserName = proc.GetString("UserName");
            }

            if (proc.Exists("Password"))
            {
                string password = "";
                try
                {
                    password = proc.GetString("Password").Decrypt();
                }
                catch
                {
                    // Do nothing
                    password = "";
                }
                connectionHelper.Password = password;
            }
            if (proc.Exists("Port"))
            {
                connectionHelper.Port = proc.GetInt("Port");
            }

            if (proc.Exists("ServiceName"))
            {
                connectionHelper.ServiceName = proc.GetString("ServiceName");
            }

            if (proc.Exists("SchemaName"))
            {
                connectionHelper.ServiceName = proc.GetString("SchemaName");
            }

            if (proc.Exists("UseDirectConnection"))
            {
                connectionHelper.UseDirectConnection = proc.GetBool("UseDirectConnection");
            }
            else
            {
                connectionHelper.UseDirectConnection = false;
            }

            return(connectionHelper);
        }
        protected virtual void ProcessConfig(XmlNode node, IDesignerProject project, string projectFilename)
        {
            NodeProcessor proc = new NodeProcessor(node);

            string relativeCompilePath = proc.GetString("RelativeCompilePath");
            project.CompileFolderName = controller.ToAbsolutePath(relativeCompilePath, projectFilename);

            project.Version = proc.GetString("Version");
            project.ProjType = proc.GetEnum<ProjectTypes>("ProjectType");

            string relativeDebugProjectFile = proc.GetString("DebugProjectFile");
            project.DebugProjectFile = controller.ToAbsolutePath(relativeDebugProjectFile, projectFilename);

            var relativeTestGenerateDirectory = proc.GetString("TestGenerateDirectory");
            project.TestGenerateDirectory = controller.ToAbsolutePath(relativeTestGenerateDirectory, projectFilename);

            var namespaceNodes = node.SelectNodes("IncludedNamespaces/Namespace");
            if (namespaceNodes != null)
                foreach (XmlNode namespaceNode in namespaceNodes)
                    project.AddNamespace(namespaceNode.InnerText);

            var refereceNodes = node.SelectNodes("References/Reference");
            ProcessProjectReferences(refereceNodes, project, projectFilename);
        }
        public IColumn ProcessColumnNode(XmlNode node)
        {
            IColumn column = new Column();
            ProcessScriptBase(column, node);
            /*
                <Datatype>int</Datatype>
                <Default />
                <InPrimaryKey>True</InPrimaryKey>
                <IsCalculated>False</IsCalculated>
                <IsComputed>False</IsComputed>
                <IsIdentity>False</IsIdentity>
                <IsNullable>False</IsNullable>
                <IsReadOnly>False</IsReadOnly>
                <IsUnique>True</IsUnique>
                <OrdinalPosition>1</OrdinalPosition>
                <Precision>10</Precision>
                <Scale>0</Scale>
                <Size>0</Size>
             */
            NodeProcessor proc = new NodeProcessor(node);

            column.OriginalDataType = proc.GetString("Datatype");
            column.Default = proc.GetString("Default");
            column.InPrimaryKey = proc.GetBool("InPrimaryKey");
            column.IsCalculated = proc.GetBool("IsCalculated");
            column.IsComputed = proc.GetBool("IsComputed");
            column.IsIdentity = proc.GetBool("IsIdentity");
            column.IsNullable = proc.GetBool("IsNullable");
            column.IsReadOnly = proc.GetBool("IsReadOnly");
            column.IsUnique = proc.GetBool("IsUnique");
            column.OrdinalPosition = proc.GetInt("OrdinalPosition");
            column.Precision = proc.GetInt("Precision");
            column.Scale = proc.GetInt("Scale");
            column.Size = proc.GetLong("Size");

            return column;
        }
        public Relationship DeserialiseRelationship(XmlNode node, IDatabase database)
        {
            NodeProcessor proc = new NodeProcessor(node);

            var rel = new RelationshipImpl();

            rel.Identifier = proc.Attributes.GetGuid("identifier");
            rel.Name = proc.GetString("Name");

            ITable table1 = database.GetTable(proc.GetString("PrimaryTable"), proc.GetString("PrimarySchema"));
            ITable table2 = database.GetTable(proc.GetString("ForeignTable"), proc.GetString("ForeignSchema"));

            if (table1 == null)
                table1 = database.GetView(proc.GetString("PrimaryTable"), proc.GetString("PrimarySchema"));

            if (table2 == null)
                table2 = database.GetView(proc.GetString("ForeignTable"), proc.GetString("ForeignSchema"));

            if (table1 == null || table2 == null)
                return null;

            var key1 = table1.GetKey(proc.GetString("PrimaryKey"));
            var key2 = table2.GetKey(proc.GetString("ForeignKey"));

            if (key1 == null || key2 == null)
                return null; // The foreign key has probably been removed

            if (key1.Keytype == DatabaseKeyType.Foreign)
            {
                // The keys are around the wrong way.
                var tempKey = key2;
                key2 = key1;
                key1 = tempKey;

                var tempTable = table2;
                table2 = table1;
                table1 = tempTable;
            }

            rel.AddThisTo(table1, table2);
            rel.PrimaryKey = key1;
            rel.ForeignKey = key2;
            rel.PrimaryCardinality = rel.ForeignKey.IsUnique ? Cardinality.One : Cardinality.Many;
            rel.ForeignCardinality = rel.PrimaryKey.IsUnique ? Cardinality.One : Cardinality.Many;
            rel.Database = database;

            return rel;
        }
        public ComponentMapping DeserialiseComponentMapping(XmlNode mappingNode, IDatabase database, EntitySet set)
        {
            NodeProcessor    proc    = new NodeProcessor(mappingNode);
            ComponentMapping mapping = new ComponentMappingImpl();

            mapping.FromTable = database.GetTable(proc.GetString("FromTable"), proc.GetString("FromSchema"));

            NodeProcessor specProcessor = new NodeProcessor(mappingNode.SelectSingleNode("ToComponent"));

            var    specification = set.GetComponentSpecification(specProcessor.Attributes.GetString("specification"));
            var    parentEntity  = set.GetEntity(specProcessor.Attributes.GetString("parent-entity"));
            string name          = specProcessor.Attributes.GetString("name");

            if (parentEntity == null)
            {
                throw new DeserialisationException(string.Format("Could not find the Entity named {0}", name));
            }
            if (specification == null)
            {
                throw new DeserialisationException(string.Format("Could not find the Component Specification named {0}", name));
            }

            var component = specification.ImplementedComponents.FirstOrDefault(c => ReferenceEquals(c.ParentEntity, parentEntity) && c.Name == name);

            if (component == null)
            {
                throw new DeserialisationException(string.Format("Could not find the component named {0}", name));
            }

            mapping.ToComponent = component;
            var columnNodes = mappingNode.SelectNodes("FromColumns/Column");
            var propNodes   = mappingNode.SelectNodes("ToProperties/Property");

            if (columnNodes == null)
            {
                throw new DeserialisationException("There were no columns in this Mapping xml");
            }
            if (propNodes == null)
            {
                throw new DeserialisationException("There were no properties in this Mapping xml");
            }

            List <IColumn> columns = new List <IColumn>();

            foreach (XmlNode columnNode in columnNodes)
            {
                columns.Add(mapping.FromTable.GetColumn(columnNode.InnerText));
            }

            List <ComponentPropertyMarker> properties = new List <ComponentPropertyMarker>();

            foreach (XmlNode propNode in propNodes)
            {
                properties.Add(mapping.ToComponent.GetProperty(propNode.InnerText));
            }

            if (columns.Count != properties.Count)
            {
                throw new DeserialisationException("Mapping contains different numbers of columns and properties");
            }

            for (int i = 0; i < columns.Count; i++)
            {
                mapping.AddPropertyAndColumn(properties[i], columns[i]);
            }

            ProcessScriptBase(mapping, mappingNode);
            return(mapping);
        }
        public Relationship DeserialiseRelationship(XmlNode node, IDatabase database)
        {
            NodeProcessor proc = new NodeProcessor(node);

            var rel = new RelationshipImpl();

            rel.Identifier = proc.Attributes.GetGuid("identifier");
            rel.Name       = proc.GetString("Name");

            ITable table1 = database.GetTable(proc.GetString("PrimaryTable"), proc.GetString("PrimarySchema"));
            ITable table2 = database.GetTable(proc.GetString("ForeignTable"), proc.GetString("ForeignSchema"));

            if (table1 == null)
            {
                table1 = database.GetView(proc.GetString("PrimaryTable"), proc.GetString("PrimarySchema"));
            }

            if (table2 == null)
            {
                table2 = database.GetView(proc.GetString("ForeignTable"), proc.GetString("ForeignSchema"));
            }

            if (table1 == null || table2 == null)
            {
                return(null);
            }

            var key1 = table1.GetKey(proc.GetString("PrimaryKey"));
            var key2 = table2.GetKey(proc.GetString("ForeignKey"));

            if (key1 == null || key2 == null)
            {
                return(null);                // The foreign key has probably been removed
            }
            if (key1.Keytype == DatabaseKeyType.Foreign)
            {
                // The keys are around the wrong way.
                var tempKey = key2;
                key2 = key1;
                key1 = tempKey;

                var tempTable = table2;
                table2 = table1;
                table1 = tempTable;
            }

            rel.AddThisTo(table1, table2);
            rel.PrimaryKey         = key1;
            rel.ForeignKey         = key2;
            rel.PrimaryCardinality = rel.ForeignKey.IsUnique ? Cardinality.One : Cardinality.Many;
            rel.ForeignCardinality = rel.PrimaryKey.IsUnique ? Cardinality.One : Cardinality.Many;
            rel.Database           = database;

            return(rel);
        }
        private ConnectionStringHelper LoadGenericDatabaseData(XmlNode node, DatabaseTypes databaseType)
        {
            NodeProcessor proc = new NodeProcessor(node);

            var connectionHelper = new ConnectionStringHelper();

            if (string.IsNullOrEmpty(connectionHelper.ServerName))
            {
                switch (databaseType)
                {
                    case DatabaseTypes.SQLCE:
                    //case DatabaseTypes.SQLServer2000:
                    case DatabaseTypes.SQLServer2005:
                        connectionHelper.ServerName = Environment.MachineName;
                        break;
                    case DatabaseTypes.SQLServerExpress:
                        connectionHelper.ServerName = Environment.MachineName + "\\SQLEXPRESS";
                        break;
                    case DatabaseTypes.MySQL:
                        connectionHelper.ServerName = "localhost";
                        break;
                    case DatabaseTypes.Oracle:
                        connectionHelper.ServerName = "localhost";
                        break;
                    case DatabaseTypes.PostgreSQL:
                        connectionHelper.ServerName = "localhost";
                        break;
                    case DatabaseTypes.Firebird:
                        connectionHelper.ServerName = "localhost";
                        break;
                    case DatabaseTypes.SQLite:
                        connectionHelper.ServerName = Environment.MachineName;
                        break;
                    default:
                        throw new NotImplementedException("Database type not handled yet: " + databaseType.ToString());

                }
            }
            connectionHelper.CurrentDbType = databaseType;

            if (proc.Exists("ServerName"))
                connectionHelper.ServerName = proc.GetString("ServerName");

            if (proc.Exists("DatabaseName"))
            {
                connectionHelper.DatabaseName = proc.GetString("DatabaseName");
                connectionHelper.UseFileName = false;
            }
            if (proc.Exists("FileName"))
            {
                connectionHelper.FileName = proc.GetString("FileName");
                connectionHelper.UseFileName = true;
            }
            if (proc.Exists("UseIntegratedSecurity"))
                connectionHelper.UseIntegratedSecurity = proc.GetBool("UseIntegratedSecurity");

            if (proc.Exists("UserName"))
                connectionHelper.UserName = proc.GetString("UserName");

            if (proc.Exists("Password"))
            {
                string password = "";
                try
                {
                    password = proc.GetString("Password").Decrypt();
                }
                catch
                {
                    // Do nothing
                    password = "";
                }
                connectionHelper.Password = password;
            }
            if (proc.Exists("Port"))
                connectionHelper.Port = proc.GetInt("Port");

            if (proc.Exists("ServiceName"))
                connectionHelper.ServiceName = proc.GetString("ServiceName");

            if (proc.Exists("SchemaName"))
                connectionHelper.ServiceName = proc.GetString("SchemaName");

            if (proc.Exists("UseDirectConnection"))
                connectionHelper.UseDirectConnection = proc.GetBool("UseDirectConnection");
            else
                connectionHelper.UseDirectConnection = false;

            return connectionHelper;
        }
        public void ProcessScriptBase(IScriptBase scriptBase, XmlNode scriptBaseNode)
        {
            /*
                <Name>Table1</Name>
                <Description />
                <Enabled>False</Enabled>
                <IsUserDefined>False</IsUserDefined>
                <UID>00000000-0000-0000-0000-000000000000</UID>
             */

            NodeProcessor proc = new NodeProcessor(scriptBaseNode);

            scriptBase.Name = proc.GetString("Name");
            scriptBase.Schema = proc.GetString("Schema");
            scriptBase.Description = proc.GetString("Description");
            scriptBase.Enabled = proc.GetBool("Enabled");
            scriptBase.IsUserDefined = proc.GetBool("IsUserDefined");

            if (proc.Exists(VirtualPropertyDeserialiser.VirtualPropertiesNodeName))
            {
                var deserialiser = new VirtualPropertyDeserialiser();
                scriptBase.Ex =
                    deserialiser.DeserialiseVirtualProperties(
                        scriptBaseNode.SelectSingleNode(VirtualPropertyDeserialiser.VirtualPropertiesNodeName));
            }
        }
 public void ProcessReferencedKey(IKey key, XmlNode keyNode, IDatabase db)
 {
     var referencedKeyNode = keyNode.SelectSingleNode("ReferencedKey");
     if (referencedKeyNode != null)
     {
         NodeProcessor proc = new NodeProcessor(referencedKeyNode);
         string tableName = proc.GetString("TableName");
         string schema = proc.GetString("Schema");
         string keyName = proc.GetString("KeyName");
         key.ReferencedKey = db.GetKey(tableName, schema, keyName);
     }
 }
        protected virtual ApiExtensionMethod ReadApiExtension(XmlNode extensionNode, Type extendedType)
        {
            NodeProcessor proc = new NodeProcessor(extensionNode);
            var methodName = proc.GetString("MethodName");
            MethodInfo method = extendedType.GetMethod(methodName);
            if (method == null)
                throw new DeserialisationException(string.Format("Cannot find method named {0} on type {1}", methodName, extendedType.FullName));

            string overrideText = proc.GetString("OverrideFunctionText");

            ApiExtensionMethod extMethod = new ApiExtensionMethod(method);
            extMethod.OverridingFunctionBody = overrideText;
            return extMethod;
        }
 public TableReferenceMapping DeserialiseReferenceMapping(XmlNode referenceMappingNode, IDatabase database, EntitySet set)
 {
     NodeProcessor proc = new NodeProcessor(referenceMappingNode);
     TableReferenceMapping mapping = new TableReferenceMappingImpl();
     string fromTableName = proc.GetString("FromTable");
     string fromSchema = proc.GetString("FromSchema");
     Guid toReferenceIdentifier = proc.GetGuid("ToReference");
     var reference = set.References.FirstOrDefault(r => r.Identifier == toReferenceIdentifier);
     mapping.FromTable = database.GetTable(fromTableName, fromSchema);
     mapping.ToReference = reference;
     ProcessScriptBase(mapping, referenceMappingNode);
     return mapping;
 }