private static void Run(List<string> ldifs, string colConfig, string fileOut) { System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer( typeof(List<PivotColumn>)); LdifCsvPivot pivot = new LdifCsvPivot(); if (string.IsNullOrEmpty(colConfig)) { pivot.AddColumn("dn", "dn", null); pivot.AddColumn("rdn", "rdn", null); pivot.AddColumn("parent", "parent", null); pivot.AddColumn("samaccountname", "uid", null); pivot.AddColumn("objectclass", "objectclass", PivotColumn.LAST_INDEX); pivot.AddColumn("sn", "sn", null); pivot.AddColumn("givenName", "givenName", null); pivot.AddColumn("mail", "mail", null); EmitSampleXml(pivot, ser); } else { using (System.IO.FileStream fs = new System.IO.FileStream(colConfig, System.IO.FileMode.Open, System.IO.FileAccess.Read)) { pivot.Columns = (List<PivotColumn>)ser.Deserialize(fs); } } if (!string.IsNullOrEmpty(fileOut)) pivot.Output = new System.IO.StreamWriter(fileOut, false, new System.Text.UTF8Encoding(false, true)); try { int i = 0; foreach (string s in ldifs) { try { pivot.Process(s, i++ == 0); } catch (Exception) { Console.Error.WriteLine("Failed on file {0}", s); throw; } } } finally { if (!string.IsNullOrEmpty(fileOut)) pivot.Output.Dispose(); } }
private static void EmitSampleXml(LdifCsvPivot pivot, System.Xml.Serialization.XmlSerializer ser) { try { string temp = System.Environment.GetEnvironmentVariable("TEMP"); string opath = SamplePath.Replace("%TEMP%", temp ?? @"c:\temp"); if (!System.IO.File.Exists(opath)) { using (System.IO.FileStream fs = new System.IO.FileStream(opath, System.IO.FileMode.Create)) { ser.Serialize(fs, pivot.Columns); } } } catch (Exception x) { Console.Error.WriteLine("Couldn't generate sample config at {0}: {1}", SamplePath, x.Message); } }