Beispiel #1
0
        public static void Main(string[] args)
        {
            ExtendedCSV jamf = new ExtendedCSV(new FileStream("Z:\\Jason\\iPads\\jamf.csv", FileMode.Open), new List <string> {
                "Serial Number"
            })
            {
                ConflictRule = new PickTheFirstConflictRule()
            };
            CSV wasp = new CSV(new FileStream("Z:\\Jason\\iPads\\wasp.csv", FileMode.Open));

            jamf.Merge(wasp);
            jamf.Save("Z:\\Jason\\iPads\\jamfExtended.csv");

            CSV misingFromJamf = new CSV();

            foreach (string serial in wasp["Serial Number"])
            {
                if (!String.IsNullOrWhiteSpace(serial) && !jamf["Serial Number"].Contains(serial))
                {
                    Console.WriteLine("Jamf does not contain {0}.", serial);
                    misingFromJamf.Add(wasp["Serial Number", serial]);
                }
            }

            misingFromJamf.Save("Z:\\Jason\\iPads\\missingFromJamf.csv");

            Console.WriteLine("Done!");
            Console.ReadKey();
        }
Beispiel #2
0
        public static void Combine()
        {
            List <String> files =
                Directory.EnumerateFiles("/Users/jcox/Documents/toCombine/").Where(
                    fn => fn.EndsWith(".csv", StringComparison.InvariantCultureIgnoreCase)).ToList();

            CSV output = new CSV();

            foreach (string fileName in files)
            {
                CSV toAdd = new CSV(new FileStream(fileName, FileMode.Open));
                output.Add(toAdd);
            }

            output.Save("/Users/jcox/Documents/combined.csv");
        }
Beispiel #3
0
        public static void Flatten()
        {
            List <String> files = Directory.EnumerateFiles(String.Format("/Users/{0}/Documents/toFlatten/", Environment.UserName)).ToList();

            if (!Directory.Exists(String.Format("/Users/{0}/Documents/flattened", Environment.UserName)))
            {
                Directory.CreateDirectory(String.Format("/Users/{0}/Documents/flattened", Environment.UserName));
            }

            List <String> uniqueFields = new List <string>();

            if (File.Exists(String.Format("/Users/{0}/Documents/toFlatten/.flatten.conf", Environment.UserName)))
            {
                StreamReader reader =
                    new StreamReader(
                        new FileStream(
                            String.Format("/Users/{0}/Documents/toFlatten/.flatten.conf", Environment.UserName),
                            FileMode.Open));

                String fields = reader.ReadLine();
                uniqueFields.AddRange(fields.Split('\t'));
            }
            else
            {
                // ask the user.
                Console.WriteLine("What are the unique fields?  [Enter one at a time.  '*' to End.");
                String field = "";
                while (true)
                {
                    Console.Write(">> ");
                    field = Console.ReadLine();
                    if (field.Equals("*"))
                    {
                        break;
                    }
                    else
                    {
                        uniqueFields.Add(field);
                    }
                }
            }

            foreach (string fileName in files)
            {
                if (!fileName.EndsWith(".csv", StringComparison.CurrentCultureIgnoreCase))
                {
                    continue;
                }
                Console.WriteLine(fileName);
                FileStream fileStream = new FileStream(fileName, FileMode.Open);

                ExtendedCSV extendedCSV = new ExtendedCSV(fileStream, uniqueFields)
                {
                    ConflictRule = new YesBeatsNoConflictRule()
                    {
                        NextRule = new UserResolveConflictRule()
                    }
                };

                CSV    output      = extendedCSV.FlattenRows();
                string outfilename = fileName.Replace("toFlatten", "flattened");
                output.Save(outfilename);
                Console.WriteLine("Flattened: {0}", outfilename);
            }

            Console.WriteLine("Done!");
            Console.ReadKey();
        }