Exemplo n.º 1
0
        static void Main(string[] args)
        {
            int                count    = Convert.ToInt32(args[0]);
            StreamWriter       writer   = new StreamWriter(args[1]);
            string             format   = args[2];
            List <ContactData> contacts = new List <ContactData>();
            List <GroupData>   groups   = new List <GroupData>();

            if (count == 2)
            {
                for (int i = 0; i < count; i++)
                {
                    contacts.Add(new ContactData(BaseTest.GeneraterandomString(10))
                    {
                        LastName   = BaseTest.GeneraterandomString(10),
                        MiddleName = BaseTest.GeneraterandomString(10)
                    });
                }
                if (format == "csv")
                {
                    writeContactToCsvFile(contacts, writer);
                }
                else if (format == "xml")
                {
                    writeContactToXmlFile(contacts, writer);
                }
                else if (format == "json")
                {
                    writeContactToJsonFile(contacts, writer);
                }
                else
                {
                    System.Console.Out.Write("Error format" + format);
                }
                writer.Close();
            }
            else
            {
                {
                    for (int i = 0; i < count; i++)
                    {
                        groups.Add(new GroupData(BaseTest.GeneraterandomString(10))
                        {
                            Header = BaseTest.GeneraterandomString(10),
                            Footer = BaseTest.GeneraterandomString(10)
                        });
                    }
                    if (format == "csv")
                    {
                        writeGroupsToCsvFile(groups, writer);
                    }
                    else if (format == "xml")
                    {
                        writeGroupsToXmlFile(groups, writer);
                    }
                    else if (format == "json")
                    {
                        writeGroupsToJsonFile(groups, writer);
                    }
                    else
                    {
                        System.Console.Out.Write("Error format" + format);
                    }
                    writer.Close();
                }
            }
        }