Esempio n. 1
0
 public DbColumnViewModel(DbColumn model)
 {
     // TODO: Complete member initialization
     this.Model = model;
     this.DisplayName = model.DisplayName;
     this.Name = model.Name;
     this.DataType = model.DataType;
     this.AllowNull = model.AllowNull;
     this.Length = model.Length;
     this.Id = model.Id;
 }
Esempio n. 2
0
        private DbSchema LoadSchema(XmlDocument doc)
        {
            XmlNode nodeModel = doc.SelectSingleNode("/Model/RootObject/Children/Model");
            DbSchema schema = new DbSchema();
            schema.Id = nodeModel.Attributes["Id"].Value;
            schema.Name = nodeModel.SelectSingleNode("Code").InnerText;
            schema.DisplayName = nodeModel.SelectSingleNode("Name").InnerText;

            XmlNodeList nodeRules = doc.SelectNodes("/Model/RootObject/Children/Model/BusinessRules/BusinessRule");

            foreach (XmlNode nodeRule in nodeRules)
            {
                String serverExpression = nodeRule.SelectSingleNode("ServerExpression").InnerText;
                if (serverExpression.StartsWith("@PR"))
                {
                    DbRulePr rulePr = new DbRulePr();
                    rulePr.Id = nodeRule.Attributes["Id"].Value;
                    rulePr.ChausseIdColumnName = serverExpression.Replace("@PR", "").Replace("(", "").Replace(")", "");
                    schema.Rules.Add(rulePr);
                }

                if (serverExpression.StartsWith("@EMPRISE_CHAUSSEE"))
                {
                    DbRuleEmprise ruleEmprise = new DbRuleEmprise();
                    ruleEmprise.Id = nodeRule.Attributes["Id"].Value;
                    ruleEmprise.ChausseIdColumnName = serverExpression.Replace("@EMPRISE_CHAUSSEE", "").Replace("(", "").Replace(")", "");
                    schema.Rules.Add(ruleEmprise);
                }

                if (serverExpression.StartsWith("@COLOR"))
                {
                    DbRuleColor ruleColor = new DbRuleColor();
                    ruleColor.Id = nodeRule.Attributes["Id"].Value;
                    schema.Rules.Add(ruleColor);
                }
                if (serverExpression.StartsWith("@LOCATION_REF"))
                {
                    DbRuleLocationRef ruleLocation = new DbRuleLocationRef();

                    ruleLocation.Id = nodeRule.Attributes["Id"].Value;
                    schema.Rules.Add(ruleLocation);
                }
                if (serverExpression.StartsWith("@LOCATION_REF_GEOM"))
                {
                    DbRuleLocationRefGeom ruleLocation = new DbRuleLocationRefGeom();
                     ruleLocation.Id = nodeRule.Attributes["Id"].Value;
                    schema.Rules.Add(ruleLocation);
                }
                if (serverExpression.StartsWith("@LOCATION_DEB"))
                {
                    DbRuleLocationDeb ruleLocation = new DbRuleLocationDeb();
                    ruleLocation.Id = nodeRule.Attributes["Id"].Value;
                    schema.Rules.Add(ruleLocation);
                }
                if (serverExpression.StartsWith("@LOCATION_FIN"))
                {
                    DbRuleLocationFin ruleLocation = new DbRuleLocationFin();
                   ruleLocation.Id = nodeRule.Attributes["Id"].Value;
                    schema.Rules.Add(ruleLocation);
                }
            }

            XmlNodeList nodes = doc.SelectNodes("/Model/RootObject/Children/Model/Tables/Table");
            foreach (XmlNode nodeTable in nodes)
            {

                String id = nodeTable.Attributes["Id"].Value;
                DbTable table = new DbTable();
                table.Id = id;
                table.Name = nodeTable.SelectSingleNode("Code").InnerText;

                table.DisplayName = nodeTable.SelectSingleNode("Name").InnerText;

                XmlNodeList nodeTableRules = nodeTable.SelectNodes("AttachedRules/BusinessRule");
                foreach (XmlNode nodeTableRule in nodeTableRules)
                {
                    String ruleId = nodeTableRule.Attributes["Ref"].Value;
                    DbRule rule = (from s in schema.Rules where s.Id.Equals(ruleId) select s).FirstOrDefault();
                    if (rule != null)
                    {
                        table.Rules.Add(rule);
                    }
                }

                XmlNodeList nodeColumns = nodeTable.SelectNodes("Columns/Column");
                foreach (XmlNode nodeColumn in nodeColumns)
                {
                    DbColumn column = new DbColumn();
                    column.Id = nodeColumn.Attributes["Id"].Value;
                    column.Name = nodeColumn.SelectSingleNode("Code").InnerText;
                    column.DisplayName = nodeColumn.SelectSingleNode("Name").InnerText;
                    column.DataType = nodeColumn.SelectSingleNode("DataType").InnerText;
                    column.Length = null;
                    if (nodeColumn.SelectSingleNode("Length") != null)
                    { column.Length = Int32.Parse(nodeColumn.SelectSingleNode("Length").InnerText); }

                    column.AllowNull = true;
                    if (nodeColumn.SelectSingleNode("Mandatory") != null)
                    {
                        if (nodeColumn.SelectSingleNode("Mandatory").InnerText.Equals("1"))
                        { column.AllowNull = false; }

                    }
                    XmlNodeList nodeColumnRules = nodeColumn.SelectNodes("AttachedRules/BusinessRule");
                    foreach (XmlNode nodeColumnRule in nodeColumnRules)
                    {
                        String ruleId = nodeColumnRule.Attributes["Ref"].Value;
                        DbRule rule = (from s in schema.Rules where s.Id.Equals (ruleId ) select s).FirstOrDefault();
                        if (rule != null)
                        {
                             column.Rules.Add(rule);
                        }

                    }
                    table.Columns.Add(column);
                }

                schema.Tables.Add(table);

            }

            return schema;
        }