Beispiel #1
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;
        }