Exemple #1
0
        static void Main(string[] args)
        {
            try
            {
                List <string> inputFilenames = new List <string>();
                string        osFilename     = null;
                string        oiFilename     = null;
                bool          notExcel       = false;
                string        hashPassPhrase = null;
                DIDFlags      didFlags       = DIDFlags.None;
                OutputFormat  outputFormat   = OutputFormat.Dw;
                int           maxResponse    = 0;
                bool          help           = false;

                for (int i = 0; i < args.Length; ++i)
                {
                    switch (args[i])
                    {
                    case "-h":
                        help = true;
                        break;

                    case "-i":
                    {
                        ++i;
                        if (i >= args.Length)
                        {
                            throw new ArgumentException("Invalid command line. '-i' option not followed by filename.");
                        }
                        inputFilenames.Add(args[i]);
                    }
                    break;

                    case "-os":
                    {
                        ++i;
                        if (i >= args.Length)
                        {
                            throw new ArgumentException("Invalid command line. '-o' option not followed by filename.");
                        }
                        if (osFilename != null)
                        {
                            throw new ArgumentException("Only one output file may be specified.");
                        }
                        string filename = Path.GetFullPath(args[i]);
                        osFilename = filename;
                    }
                    break;

                    case "-oi":
                    {
                        ++i;
                        if (i >= args.Length)
                        {
                            throw new ArgumentException("Invalid command line. '-o' option not followed by filename.");
                        }
                        if (oiFilename != null)
                        {
                            throw new ArgumentException("Only one output file may be specified.");
                        }
                        string filename = Path.GetFullPath(args[i]);
                        oiFilename = filename;
                    }
                    break;

                    case "-notxl":
                        notExcel = true;
                        break;

                    case "-hid":
                    {
                        ++i;
                        if (i >= args.Length)
                        {
                            throw new ArgumentException("Invalid command line. '-hid' option not followed by passphrase.");
                        }
                        hashPassPhrase = args[i];
                    }
                    break;

                    case "-did":
                    {
                        ++i;
                        if (i >= args.Length)
                        {
                            throw new ArgumentException("Invalid command line. '-did' option not followed by flags.");
                        }
                        foreach (char c in args[i])
                        {
                            switch (Char.ToLowerInvariant(c))
                            {
                            case 'i':
                                didFlags |= DIDFlags.Id;
                                break;

                            case 'n':
                                didFlags |= DIDFlags.Name;
                                break;

                            case 'b':
                                didFlags |= DIDFlags.Birthdate;
                                break;

                            case 'd':
                                didFlags |= DIDFlags.Demographics;
                                break;

                            case 's':
                                didFlags |= DIDFlags.School;
                                break;

                            default:
                                throw new ArgumentException(string.Format("Invalid command line. '.did' flag '{0}' is undefined.", c));
                            }
                        }
                    }
                    break;

                    case "-fmt":
                        ++i;
                        if (i >= args.Length)
                        {
                            throw new ArgumentException("Invalid command line. '-fmt' option not followed by format type.");
                        }
                        switch (args[i])
                        {
                        case "dw":
                            outputFormat = OutputFormat.Dw;
                            break;

                        case "all":
                            outputFormat = OutputFormat.All;
                            break;

                        case "allshort":
                            outputFormat = OutputFormat.All;
                            maxResponse  = 10;
                            break;

                        default:
                            throw new ArgumentException(string.Format("Invalid command line. Output format '{0}' is unknown.", args[i]));
                        }
                        break;

                    default:
                        throw new ArgumentException(string.Format("Unknown command line option '{0}'. Use '-h' for syntax help.", args[i]));
                    }
                }

                if (help || args.Length == 0)
                {
                    Console.WriteLine(sSyntax);
                }

                else
                {
                    if (inputFilenames.Count == 0 || (osFilename == null && oiFilename == null))
                    {
                        throw new ArgumentException("Invalid command line. Use '-h' for syntax help");
                    }

                    if (osFilename != null)
                    {
                        Console.WriteLine("Writing student assessment results to: " + osFilename);
                    }
                    if (oiFilename != null)
                    {
                        Console.WriteLine("Writing item level results to: " + oiFilename);
                    }
                    using (ToCsvProcessor processor = new ToCsvProcessor(osFilename, oiFilename, outputFormat))
                    {
                        processor.HashPassPhrase = hashPassPhrase;
                        processor.DIDFlags       = didFlags;
                        processor.MaxResponse    = maxResponse;
                        processor.NotExcel       = notExcel;

                        foreach (string filename in inputFilenames)
                        {
                            ProcessInputFilename(filename, processor);
                        }
                    }
                }

                if (s_ErrorCount > 0)
                {
                    Console.Error.WriteLine("{0} total errors", s_ErrorCount);
                }
            }
            catch (Exception err)
            {
                Console.WriteLine();
#if DEBUG
                Console.WriteLine(err.ToString());
#else
                Console.WriteLine(err.Message);
#endif
            }

            if (Win32Interop.ConsoleHelper.IsSoleConsoleOwner)
            {
                Console.Write("Press any key to exit.");
                Console.ReadKey(true);
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            try
            {
                List <string> inputFilenames = new List <string>();
                string        osFilename     = null;
                string        oiFilename     = null;
                string        hashPassPhrase = null;
                string        didcsv         = null;
                DIDFlags      didFlags       = DIDFlags.None;
                OutputFormat  outputFormat   = OutputFormat.Dw;
                int           maxResponse    = 0;
                bool          help           = false;

                for (int i = 0; i < args.Length; ++i)
                {
                    switch (args[i])
                    {
                    case "-h":
                        help = true;
                        break;

                    case "-i":
                    {
                        ++i;
                        if (i >= args.Length)
                        {
                            throw new ArgumentException("Invalid command line. '-i' option not followed by filename.");
                        }
                        inputFilenames.Add(args[i]);
                    }
                    break;

                    case "-os":
                    {
                        ++i;
                        if (i >= args.Length)
                        {
                            throw new ArgumentException("Invalid command line. '-o' option not followed by filename.");
                        }
                        if (osFilename != null)
                        {
                            throw new ArgumentException("Only one output file may be specified.");
                        }
                        string filename = Path.GetFullPath(args[i]);
                        osFilename = filename;
                    }
                    break;

                    case "-d":
                    {
                        ++i;
                        if (i >= args.Length)
                        {
                            throw new ArgumentException("Invalid command line. '-d' option not followed by directory.");
                        }
                        string [] fileEntries = Directory.GetFiles(args[i]);
                        foreach (string fileName in fileEntries)
                        {
                            inputFilenames.Add(fileName);
                        }
                    }
                    break;

                    case "-oi":
                    {
                        ++i;
                        if (i >= args.Length)
                        {
                            throw new ArgumentException("Invalid command line. '-o' option not followed by filename.");
                        }
                        if (oiFilename != null)
                        {
                            throw new ArgumentException("Only one output file may be specified.");
                        }
                        string filename = Path.GetFullPath(args[i]);
                        oiFilename = filename;
                    }
                    break;

                    case "-hid":
                    {
                        ++i;
                        if (i >= args.Length)
                        {
                            throw new ArgumentException("Invalid command line. '-hid' option not followed by passphrase.");
                        }
                        hashPassPhrase = args[i];
                    }
                    break;

                    case "-didcsv":
                    {
                        ++i;
                        if (i >= args.Length)
                        {
                            throw new ArgumentException("Invalid command line. '-didcsv' needs file arg.");
                        }
                        didcsv = args[i];
                    }
                    break;

                    case "-did":
                    {
                        ++i;
                        if (i >= args.Length)
                        {
                            throw new ArgumentException("Invalid command line. '-did' option not followed by flags.");
                        }
                        foreach (char c in args[i])
                        {
                            switch (Char.ToLowerInvariant(c))
                            {
                            case 'i':
                                didFlags |= DIDFlags.Id;
                                break;

                            case 'n':
                                didFlags |= DIDFlags.Name;
                                break;

                            case 'b':
                                didFlags |= DIDFlags.Birthdate;
                                break;

                            case 'd':
                                didFlags |= DIDFlags.Demographics;
                                break;

                            case 's':
                                didFlags |= DIDFlags.School;
                                break;

                            default:
                                throw new ArgumentException(string.Format("Invalid command line. '.did' flag '{0}' is undefined.", c));
                            }
                        }
                    }
                    break;

                    case "-fmt":
                        Console.WriteLine("WTF");
                        ++i;
                        if (i >= args.Length)
                        {
                            throw new ArgumentException("Invalid command line. '-fmt' option not followed by format type.");
                        }
                        switch (args[i])
                        {
                        case "dw":
                            outputFormat = OutputFormat.Dw;
                            break;

                        case "all":
                            outputFormat = OutputFormat.All;
                            break;

                        case "allshort":
                            outputFormat = OutputFormat.All;
                            maxResponse  = 10;
                            break;

                        default:
                            throw new ArgumentException(string.Format("Invalid command line. Output format '{0}' is unknown.", args[i]));
                        }
                        break;

                    default:
                        throw new ArgumentException(string.Format("Unknown command line option '{0}'. Use '-h' for syntax help.", args[i]));
                    }
                }

                if (help || args.Length == 0)
                {
                    Console.WriteLine(sSyntax);
                }
                else if (didcsv != "")
                {
                    var reader = new StreamReader(File.OpenRead(didcsv));

                    SHA1   sha       = new SHA1CryptoServiceProvider();
                    byte[] pfb       = UTF8NoByteOrderMark.GetBytes("smarter");
                    byte[] m_hashKey = sha.ComputeHash(pfb);


                    List <string> listA = new List <string>();
                    //List<string> listB = new List<string>();
                    while (!reader.EndOfStream)
                    {
                        var line = reader.ReadLine();
                        listA.Add(line);
                        //var values = line.Split(',');

                        //listA.Add(values[0]);
                        //listB.Add(values[1]);
                    }

                    foreach (string l in listA)
                    {
                        //Console.WriteLine(l);
                        var values = l.Split(',');
                        if (values[0] == "State")
                        {
                            Console.WriteLine(l);
                            continue;
                        }
                        HMACSHA1 hmac = new HMACSHA1(m_hashKey);
                        //Console.WriteLine(values[10]);
                        byte[] bid   = UTF8NoByteOrderMark.GetBytes(values[10]);
                        byte[] hash  = hmac.ComputeHash(bid);
                        string new10 = ByteArrayToHexString(hash);
                        values[9]  = "";        //fname
                        values[8]  = "";        //mname
                        values[7]  = "";        //lname
                        values[14] = "";        //bday
                        values[10] = new10;     //ssid
                        values[11] = new10;     //altssid
                        string newline = string.Join(",", values);
                        Console.WriteLine(newline);
                    }
                }
                else
                {
                    if (inputFilenames.Count == 0 || (osFilename == null && oiFilename == null))
                    {
                        throw new ArgumentException("Invalid command line. Use '-h' for syntax help");
                    }

                    if (osFilename != null)
                    {
                        Console.WriteLine("Writing student assessment results to: " + osFilename);
                    }
                    if (oiFilename != null)
                    {
                        Console.WriteLine("Writing item level results to: " + oiFilename);
                    }
                    using (ToCsvProcessor processor = new ToCsvProcessor(osFilename, oiFilename, outputFormat))
                    {
                        processor.HashPassPhrase = hashPassPhrase;
                        processor.DIDFlags       = didFlags;
                        processor.MaxResponse    = maxResponse;

                        foreach (string filename in inputFilenames)
                        {
                            ProcessInputFilename(filename, processor);
                        }
                    }
                }

                if (s_ErrorCount > 0)
                {
                    Console.Error.WriteLine("{0} total errors", s_ErrorCount);
                }
            }
            catch (Exception err)
            {
                Console.WriteLine();
#if DEBUG
                Console.WriteLine(err.ToString());
#else
                Console.WriteLine(err.Message);
#endif
            }

            /*
             * if (Win32Interop.ConsoleHelper.IsSoleConsoleOwner)
             * {
             *  Console.Write("Press any key to exit.");
             *  Console.ReadKey(true);
             * }
             */
        }