예제 #1
0
        private Maps GetMapForTable(string mappingsSection, string tabelName)
        {
            List <Maps> map = new List <Maps>();

            MessageParser.NET.Tools.XmlParser xml = new MessageParser.NET.Tools.XmlParser();

            var temp = xml.GetSubTreeByParent(mappingsSection, "EntitySetMapping");

            for (int i = 0; i < temp.Length; i++)
            {
                var temp2 = xml.GetSubTreeByParent(mappingsSection, "MappingFragment");

                var Name = xml.GetAttributeValue(temp[i].OuterXml, "EntitySetMapping", "Name");

                var StoreEntitySet = xml.GetAttributeValue(temp[i].OuterXml, "MappingFragment", "StoreEntitySet");

                if (StoreEntitySet == tabelName)
                {
                    return new Maps {
                               StoreEntitySet = StoreEntitySet, Name = Name
                    }
                }
                ;



                //map.Add(
                //    new Maps
                //    {
                //        Name = (!string.IsNullOrEmpty(Name) ? Name : "UnKnow")
                //    ,
                //        StoreEntitySet = (!string.IsNullOrEmpty(StoreEntitySet) ? StoreEntitySet : "UnKnow")
                //    });
            }

            return(null);
        }
예제 #2
0
        // private Dictionary<string, string> GetProperty(string data)
        private List <Property> GetProperty(string data)
        {
            List <Property> property = new List <Property>();

            MessageParser.NET.Tools.XmlParser xml = new MessageParser.NET.Tools.XmlParser();
            var temp = xml.GetSubTreeByParent(data, "Property");

            for (int i = 0; i < temp.Length; i++)
            {
                var Name = xml.GetAttributeValue(temp[i].OuterXml, "Property", "Name");

                var Type = xml.GetAttributeValue(temp[i].OuterXml, "Property", "Type");

                var FixedLength = (xml.GetAttributeValue(temp[i].OuterXml, "Property", "FixedLength"));

                var MaxLength = (xml.GetAttributeValue(temp[i].OuterXml, "Property", "MaxLength"));

                var Nullable = (xml.GetAttributeValue(temp[i].OuterXml, "Property", "Nullable"));

                var Unicode = (xml.GetAttributeValue(temp[i].OuterXml, "Property", "Unicode"));

                var StoreGeneratedPattern = xml.GetAttributeValue(temp[i].OuterXml, "Property", "annotation:StoreGeneratedPattern");

                property.Add(
                    new Property
                {
                    Name = (!string.IsNullOrEmpty(Name) ? Name : "UnKnow")
                    ,
                    Type = (!string.IsNullOrEmpty(Type) ? Type : "UnKnow")
                    ,
                    FixedLength = (!string.IsNullOrEmpty(FixedLength) ? bool.Parse(FixedLength) : false)
                    ,
                    MaxLength = (!string.IsNullOrEmpty(MaxLength) ? int.Parse(MaxLength) : -1)
                    ,
                    Nullable = (!string.IsNullOrEmpty(Nullable) ? bool.Parse(Nullable) : true)
                    ,
                    Unicode = (!string.IsNullOrEmpty(Unicode) ? bool.Parse(Unicode) : true)
                    ,
                    StoreGeneratedPattern = xml.GetAttributeValue(temp[i].OuterXml, "Property", "StoreGeneratedPattern")
                });
            }

            return(property);
        }
예제 #3
0
        public bool Pars(string modelPath)
        {
            StreamReader sr   = new StreamReader(modelPath);
            string       data = sr.ReadToEnd();

            sr.Close();

            MessageParser.NET.Tools.XmlParser xml = new MessageParser.NET.Tools.XmlParser();

            string ConceptualSection = xml.GetSubTreeByParent(data, "edmx:StorageModels")[0].InnerXml;
            var    dic = GetsRoles(ConceptualSection);

            var matchesEntityType = xml.GetSubTreeByParent(ConceptualSection, "EntityType");

            var entityTypeList  = xml.GetSubTreeByParent(ConceptualSection, "EntityType");
            var associationList = xml.GetSubTreeByParent(ConceptualSection, "Association");

            Queue <struc>             result            = new Queue <struc>();
            Queue <AssociationStruct> associationResult = new Queue <AssociationStruct>();

            for (int k = 0; k < associationList.Length; k++)
            {
                associationResult.Enqueue(GetAssociation(associationList[k].OuterXml));
            }

            for (int k = 0; k < entityTypeList.Length; k++)
            {
                {
                    struc te = new struc();
                    te.Fname = Filter(xml.GetAttributeValue(entityTypeList[k].OuterXml, "EntityType", "Name"));

                    te.Props = GetProperty(entityTypeList[k].OuterXml);

                    te.Map = GetMapForTable(xml.GetSubTreeByParent(data, "edmx:Mappings")[0].InnerXml, te.Fname);

                    if (result.Where(p => p.Fname == te.Fname).FirstOrDefault() != null)
                    {
                        continue;
                    }

                    if (!string.IsNullOrEmpty(NameSpace))
                    {
                        te.NameSpace = NameSpace;
                    }

                    te.ModelName = te.Map.Name;
                    te.TableName = te.Map.StoreEntitySet;
                    te.Fname     = "frm" + te.Map.Name;

                    result.Enqueue(te);
                }
            }

            var filter = Distinct(result.ToArray());

            ParsedData = filter;
            ProcessAssociation(filter, associationResult.ToArray());

            Translate(filter, dic);

            FormGenerator generate   = new FormGenerator();
            var           designFile = generate.GenerateFormDesign(filter);

            foreach (struc t in designFile)
            {
                if (File.Exists(OutPutAddress + "\\" + t.Fname + ".Designer.cs"))
                {
                    File.Delete(OutPutAddress + "\\" + t.Fname + ".Designer.cs");
                }

                StreamWriter sw = new StreamWriter(OutPutAddress + "\\" + t.Fname + ".Designer.cs", true);
                sw.Write(t.Design);
                sw.Close();
            }

            var efName = regexPatterns.GetMatches(regexPatterns.GetMatch(data, regexPatterns.EntitiyName).Value, regexPatterns.GetValue)[0].Value.Replace('"', ' ').Trim();

            CodeGenerator code     = new CodeGenerator();
            var           codeFile = code.GenerateClass(filter, efName);

            foreach (struc t in codeFile)
            {
                if (File.Exists(OutPutAddress + "\\" + t.Fname + ".cs"))
                {
                    File.Delete(OutPutAddress + "\\" + t.Fname + ".cs");
                }

                StreamWriter sw = new StreamWriter(OutPutAddress + "\\" + t.Fname + ".cs", true);
                sw.Write(t.Code);
                sw.Close();
            }

            for (int i = 0; i < result.Count; i++)
            {
                if (File.Exists(OutPutAddress + "\\" + result.ElementAt(i).Fname + ".resx"))
                {
                    File.Delete(OutPutAddress + "\\" + result.ElementAt(i).Fname + ".resx");
                }

                File.Copy(Environment.CurrentDirectory + "\\RFile.resx", OutPutAddress + "\\" + result.ElementAt(i).Fname + ".resx");
            }

            return(true);
        }
        public bool Pars(string modelPath)
        {
            StreamReader sr = new StreamReader(modelPath);
            string data = sr.ReadToEnd();
            sr.Close();

            MessageParser.NET.Tools.XmlParser xml = new MessageParser.NET.Tools.XmlParser();

            string ConceptualSection = xml.GetSubTreeByParent(data, "edmx:StorageModels")[0].InnerXml;
            var dic = GetsRoles(ConceptualSection);

            var matchesEntityType = xml.GetSubTreeByParent(ConceptualSection, "EntityType");

            var entityTypeList = xml.GetSubTreeByParent(ConceptualSection, "EntityType");
            var associationList = xml.GetSubTreeByParent(ConceptualSection, "Association");

            Queue<struc> result = new Queue<struc>();
            Queue<AssociationStruct> associationResult = new Queue<AssociationStruct>();

            for (int k = 0; k < associationList.Length; k++)
            {
                associationResult.Enqueue(GetAssociation(associationList[k].OuterXml));
            }

            for (int k = 0; k < entityTypeList.Length; k++)
            {
                {
                    struc te = new struc();
                    te.Fname = Filter(xml.GetAttributeValue(entityTypeList[k].OuterXml, "EntityType", "Name"));

                    te.Props = GetProperty(entityTypeList[k].OuterXml);

                    te.Map = GetMapForTable(xml.GetSubTreeByParent(data, "edmx:Mappings")[0].InnerXml,te.Fname);

                    if (result.Where(p => p.Fname == te.Fname).FirstOrDefault() != null)
                        continue;

                    if (!string.IsNullOrEmpty(NameSpace))
                        te.NameSpace = NameSpace;

                    te.ModelName = te.Map.Name;
                    te.TableName = te.Map.StoreEntitySet;
                    te.Fname = "frm" + te.Map.Name;

                    result.Enqueue(te);
                }
            }

            var filter = Distinct(result.ToArray());
            ParsedData = filter;
            ProcessAssociation(filter, associationResult.ToArray());

            Translate(filter, dic);

            FormGenerator generate = new FormGenerator();
            var designFile = generate.GenerateFormDesign(filter);

            foreach (struc t in designFile)
            {
                if (File.Exists(OutPutAddress + "\\" + t.Fname + ".Designer.cs"))
                    File.Delete(OutPutAddress + "\\" + t.Fname + ".Designer.cs");

                StreamWriter sw = new StreamWriter(OutPutAddress + "\\" + t.Fname + ".Designer.cs", true);
                sw.Write(t.Design);
                sw.Close();

            }

            var efName = regexPatterns.GetMatches(regexPatterns.GetMatch(data, regexPatterns.EntitiyName).Value, regexPatterns.GetValue)[0].Value.Replace('"', ' ').Trim();

            CodeGenerator code = new CodeGenerator();
            var codeFile = code.GenerateClass(filter, efName);

            foreach (struc t in codeFile)
            {
                if (File.Exists(OutPutAddress + "\\" + t.Fname + ".cs"))
                    File.Delete(OutPutAddress + "\\" + t.Fname + ".cs");

                StreamWriter sw = new StreamWriter(OutPutAddress + "\\" + t.Fname + ".cs", true);
                sw.Write(t.Code);
                sw.Close();

            }

            for (int i = 0; i < result.Count; i++)
            {
                if (File.Exists(OutPutAddress + "\\" + result.ElementAt(i).Fname + ".resx"))
                    File.Delete(OutPutAddress + "\\" + result.ElementAt(i).Fname + ".resx");

                File.Copy(Environment.CurrentDirectory + "\\RFile.resx", OutPutAddress + "\\" + result.ElementAt(i).Fname + ".resx");
            }

            return true;
        }
        private Maps GetMapForTable(string mappingsSection,string tabelName)
        {
            List<Maps> map = new List<Maps>();

            MessageParser.NET.Tools.XmlParser xml = new MessageParser.NET.Tools.XmlParser();

            var temp = xml.GetSubTreeByParent(mappingsSection, "EntitySetMapping");

            for (int i = 0; i < temp.Length; i++)
            {
                var temp2 = xml.GetSubTreeByParent(mappingsSection, "MappingFragment");

                var Name = xml.GetAttributeValue(temp[i].OuterXml, "EntitySetMapping", "Name");

                var StoreEntitySet = xml.GetAttributeValue(temp[i].OuterXml, "MappingFragment", "StoreEntitySet");

                if (StoreEntitySet == tabelName)
                    return new Maps { StoreEntitySet = StoreEntitySet, Name = Name };

   

                //map.Add(
                //    new Maps
                //    {
                //        Name = (!string.IsNullOrEmpty(Name) ? Name : "UnKnow")
                //    ,
                //        StoreEntitySet = (!string.IsNullOrEmpty(StoreEntitySet) ? StoreEntitySet : "UnKnow")
                //    });
            }

            return null;
        }
        // private Dictionary<string, string> GetProperty(string data)
        private List<Property> GetProperty(string data)
        {
            List<Property> property = new List<Property>();

            MessageParser.NET.Tools.XmlParser xml = new MessageParser.NET.Tools.XmlParser();
            var temp = xml.GetSubTreeByParent(data, "Property");

            for (int i = 0; i < temp.Length; i++)
            {
                var Name = xml.GetAttributeValue(temp[i].OuterXml, "Property", "Name");

                var Type = xml.GetAttributeValue(temp[i].OuterXml, "Property", "Type");

                var FixedLength = (xml.GetAttributeValue(temp[i].OuterXml, "Property", "FixedLength"));

                var MaxLength = (xml.GetAttributeValue(temp[i].OuterXml, "Property", "MaxLength"));

                var Nullable = (xml.GetAttributeValue(temp[i].OuterXml, "Property", "Nullable"));

                var Unicode = (xml.GetAttributeValue(temp[i].OuterXml, "Property", "Unicode"));

                var StoreGeneratedPattern = xml.GetAttributeValue(temp[i].OuterXml, "Property", "annotation:StoreGeneratedPattern");

                property.Add(
                    new Property
                    {
                        Name = (!string.IsNullOrEmpty(Name) ? Name : "UnKnow")
                    ,
                        Type = (!string.IsNullOrEmpty(Type) ? Type : "UnKnow")
                    ,
                        FixedLength = (!string.IsNullOrEmpty(FixedLength) ? bool.Parse(FixedLength) : false)
                    ,
                        MaxLength = (!string.IsNullOrEmpty(MaxLength) ? int.Parse(MaxLength) : -1)
                    ,
                        Nullable = (!string.IsNullOrEmpty(Nullable) ? bool.Parse(Nullable) : true)
                    ,
                        Unicode = (!string.IsNullOrEmpty(Unicode) ? bool.Parse(Unicode) : true)
                    ,
                        StoreGeneratedPattern = xml.GetAttributeValue(temp[i].OuterXml, "Property", "StoreGeneratedPattern")
                    });
            }

            return property;
        }