Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            OpenFileDialog ofdxml = new OpenFileDialog();

            ofdxml.Filter = "*.xml|*.xml";
            SaveFileDialog sfdxml = new SaveFileDialog();

            sfdxml.Filter = "*.xml|*.xml";

            SaveFileDialog sfdcsv = new SaveFileDialog();

            sfdcsv.Filter = "*.csv|*.csv";

            if (args.Length == 1 && String.Compare(args[0], "/format", true) == 0)
            {
                if (ofdxml.ShowDialog() == DialogResult.OK)
                {
                    XDocument xo = XDocument.Load(ofdxml.FileName);
                    sfdxml.FileName = ofdxml.FileName;
                    if (sfdxml.ShowDialog() == DialogResult.OK)
                    {
                        xo.Save(sfdxml.FileName);
                    }
                }
            }
            bool conv = false, convf = false;

            if (args.Length == 1 && ((convf = String.Compare(args[0], "/convf", true) == 0) || (conv = String.Compare(args[0], "/conv", true) == 0)))
            {
                if (ofdxml.ShowDialog() == DialogResult.OK)
                {
                    XDocument xo = XDocument.Load(ofdxml.FileName);
                    if (sfdcsv.ShowDialog() == DialogResult.OK)
                    {
                        using (var wr = new StreamWriter(sfdcsv.FileName, false, Encoding.UTF8)) {
                            Csvw w    = new Csvw(wr, ',', '"');
                            var  evs  = EVUt.Events(xo).ToArray();
                            var  keys = evs.SelectMany(q => q.Keys).Distinct().ToArray();
                            foreach (var k in keys)
                            {
                                w.Write(k);
                            }
                            w.NextRow();
                            String v;
                            foreach (var ev in evs.Where(q => conv || VUt.Gets(q, "EventID").Equals("4659")))
                            {
                                foreach (var k in keys)
                                {
                                    w.Write(ev.TryGetValue(k, out v) ? v : "");
                                }
                                w.NextRow();
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
 public static void SaveCsv(String fpcsv, DataTable dt, Encoding enc) {
     Csvw wr = new Csvw();
     foreach (DataColumn dc in dt.Columns)
         wr.AddCol(dc.ColumnName);
     wr.NewRow();
     foreach (DataRow dr in dt.Rows) {
         foreach (DataColumn dc in dt.Columns) {
             wr.AddCol(Convert.ToString(dr[dc]));
         }
         wr.NewRow();
     }
     File.WriteAllText(fpcsv, wr.ToString(), enc);
 }