Ejemplo n.º 1
0
        public void TestTextWriter()
        {
            CodeWriterText writer = new CodeWriterText(null);
            string         line1  = "Line 1";
            string         line2  = "Line 2";

            writer.WriteLine(line1);
            writer.WriteLine(line2);
            Assert.AreEqual(String.Format("{0}{1}{2}{1}", line1, Environment.NewLine, line2), writer.ToString());

            CodeWriterText writer2 = new CodeWriterText(null);

            writer2.WriteLine(line1);
            writer.WriteFrom(writer2);
            Assert.AreEqual(String.Format("{0}{1}{2}{1}{0}{1}", line1, Environment.NewLine, line2), writer.ToString());
        }
Ejemplo n.º 2
0
        public void TestTextWriterSeparatedString()
        {
            List <Item> list = new List <Item>();

            list.Add(new Item("Item 1"));
            list.Add(new Item("Item 2"));
            list.Add(new Item("Item 3"));
            string separator = ", ";
            string result    = list[0].Name + separator + list[1].Name + separator + list[2].Name;

            CodeWriterText writer = new CodeWriterText(null);

            Assert.AreEqual(result,
                            writer.ToSeparatedString(list, separator,
                                                     delegate(object item, int count) { return(String.Format("{0}", (item as Item).Name)); }));
        }
Ejemplo n.º 3
0
        public void Dump(string fileName)
        {
            CodeWriterText cw = new CodeWriterText(Lamp);

            cw.WriteLine("Entities:");
            cw.BeginScope();
            foreach (Entity en in Entities)
            {
                cw.WriteLine("{0} {1}", en.ToString(), en.Persistence.ToString());
                cw.BeginScope();
                cw.WriteLine("Attributes:");
                cw.BeginScope();
                foreach (Attribute a in en.Attributes)
                {
                    cw.WriteLine("{0} {1}", a.ToString(), a.Persistence.ToString());
                }
                cw.EndScope();
                if (en.Constraints.PrimaryId != null)
                {
                    cw.WriteLine("PrimaryId: {0}", en.Constraints.PrimaryId.Persistence);
                    cw.BeginScope();
                    foreach (Attribute a in en.Constraints.PrimaryId.Attributes)
                    {
                        cw.WriteLine(a.ToString());
                    }
                    cw.EndScope();
                }
                else
                {
                    cw.WriteLine("PrimaryId: not defined");
                }
                if (en.Constraints.UniqueIds.Count > 0)
                {
                    foreach (UniqueId uid in en.Constraints.UniqueIds)
                    {
                        cw.WriteLine("UniqueId: {0}", uid.Persistence);
                        cw.BeginScope();
                        foreach (Attribute a in uid.Attributes)
                        {
                            cw.WriteLine(a.ToString());
                        }
                        cw.EndScope();
                    }
                }
                cw.EndScope();
            }
            cw.EndScope();

            cw.WriteLine();
            cw.WriteLine("Relations:");
            cw.BeginScope();
            foreach (Relation r in Relations)
            {
                cw.WriteLine("{0}(Nav:{1}, Nav2:{2}) {3}", r.ToString(), r.Navigate, r.Navigate2, r.Persistence);
                cw.BeginScope();
                foreach (RelationAttributeMatch am in r.AttributesMatch)
                {
                    cw.WriteLine(am.ToString());
                }
                cw.WriteLine("Foreign key: {0}", r.ForeignKey);
                cw.BeginScope();
                foreach (Attribute a in r.ForeignKey.ChildTableColumns)
                {
                    cw.WriteLine(a.ToString());
                }
                if (r.ForeignKey.Index != null)
                {
                    cw.WriteLine("Index: {0}", r.ForeignKey.Index.ToString());
                    cw.BeginScope();
                    foreach (IndexColumn col in r.ForeignKey.Index.Columns)
                    {
                        cw.WriteLine(col.ToString());
                    }
                    cw.EndScope();
                }
                cw.EndScope();
                cw.EndScope();
            }
            cw.EndScope();

            cw.WriteLine();
            cw.WriteLine("Enumerations:");
            cw.BeginScope();
            foreach (Enumeration em in Enumerations)
            {
                cw.WriteLine("{0} {1}", em.ToString(), em.Persistence.ToString());
                cw.BeginScope();
                foreach (EnumerationItem item in em.Items)
                {
                    cw.WriteLine(item.ToString());
                }
                cw.EndScope();
            }
            cw.EndScope();

            cw.WriteLine();
            cw.WriteLine("Generators:");
            cw.BeginScope();
            foreach (Generator gen in Generators)
            {
                cw.WriteLine("{0} {1}", gen.ToString(), gen.Persistence.ToString());
            }
            cw.EndScope();

            cw.WriteLine();
            cw.WriteLine("Types:");
            cw.BeginScope();
            foreach (Type t in Types)
            {
                cw.WriteLine("{0}", t.ToString());
            }
            cw.EndScope();

            cw.WriteLine();
            cw.WriteLine("Indexes:");
            cw.BeginScope();
            foreach (Index i in this.PhysicalModel.Indexes)
            {
                cw.WriteLine("{0}", i.ToString());
                cw.BeginScope();
                foreach (IndexColumn col in i.Columns)
                {
                    cw.WriteLine("{0}", col.ToString());
                }
                cw.EndScope();
            }
            cw.EndScope();

            cw.Save(fileName);
        }