コード例 #1
0
        /// <summary>
        /// Pre-processes the file (includes profiling). Gets required config info from the global Cfg instance
        /// </summary>
        /// <param name="SplitCols">A Dictionary in which each key is the name of a column and each value is the
        /// character to split that column on</param>
        /// <param name="PrepFileFqpn">The path spec of the generated prepped file</param>
        /// <returns>A List of ProfileColumn instances with data type and potentially frequency information
        /// generated from the incoming file</returns>

        static List <ProfileColumn> Preprocess(Dictionary <string, string> SplitCols, out string PrepFileFqpn)
        {
            List <ProfileColumn> Cols = null;

            Log.InformationMessage("Begin pre-process");

            Cols = FileProcessor.Process(out PrepFileFqpn, SplitCols);

            Log.InformationMessage("Finish pre-process");
            return(Cols);
        }
コード例 #2
0
 /// <summary>
 /// Displays a user-specified number of lines to the console
 /// </summary>
 /// <param name="SplitCols">A Dictionary in which each key is the name of a column and each value is the
 /// character to split that column on</param>
 static void Preview(Dictionary <string, string> SplitCols)
 {
     FileProcessor.Preview(SplitCols);
 }
コード例 #3
0
        /// <summary>
        /// Executes a number of start-up validations and initializations. Emanates the appropriate error message
        /// and sets the ExitCode if unable to proceed
        /// </summary>
        /// <returns>true if the utility can proceed, else false: the utility is unable to proceed</returns>

        static bool DoValidations()
        {
            if (Cfg.NoLoad && !Cfg.Profile && !Cfg.ShowDDL && Cfg.Preview <= 0)
            {
                Log.ErrorMessage("The -noload arg was specified, the -profile arg was not specified, -preview was not specified, and -showddl was not specified. Nothing to do.");
                Environment.ExitCode = (int)ExitCode.InvalidParameters;
                return(false);
            }

            if (!Cfg.Profile && Cfg.ShowDDL)
            {
                Log.InformationMessage("The -profile arg was not specified, but -showddl was specified. Profiling is being enabled anyway for DDL generation.");
                Cfg.Profile = true;
            }

            if (Cfg.Preview > 0)
            {
                Log.InformationMessage("The -preview was specified. All other processing options will be ignored.");
            }

            if (Cfg.Drop && !Cfg.Profile)
            {
                Log.InformationMessage("The -drop arg was specified, but -profile was not specified. Enabling profiling anyway for DDL generation.");
                Cfg.Profile = true; // if we're dropping the table, we have to profile the data to create the table
            }

            if (!File.Exists(Cfg.File))
            {
                Log.ErrorMessage("Specified file to load does not exist: {0}", Cfg.File);
                Environment.ExitCode = (int)ExitCode.SrcFileDoesNotExist;
                return(false);
            }
            else if (!FileProcessor.IsTextFile(Cfg.File))
            {
                Log.ErrorMessage("Specified file to load does not appear to be a text file: {0}", Cfg.File);
                Environment.ExitCode = (int)ExitCode.SrcFileIsNotText;
                return(false);
            }

            if (AppSettingsImpl.Delimiter.Value.ToLower() == "auto")
            {
                char c = DelimitedLineParser.CalcDelimiter(Cfg.File);
                if (c == (char)0)
                {
                    Log.ErrorMessage("'auto' was specified as the delimiter, but the utility was unable to determine the delimiter from the data file.");
                    Environment.ExitCode = (int)ExitCode.CouldNotDetermineDelimiter;
                    return(false);
                }
                Cfg.Delimiter = c;
                Log.InformationMessage("Obtained delimiter from file: {0}", c.Xlat(new char[] { '\t', '|', ',' }, new string[] { "tab", "pipe", "comma" }));
            }

            if (Cfg.ColFile != null && !File.Exists(Cfg.ColFile))
            {
                Log.ErrorMessage("Specified column header file not exist: {0}", Cfg.ColFile);
                Environment.ExitCode = (int)ExitCode.ColFileDoesNotExist;
                return(false);
            }
            if (Cfg.ColFile != null && !FileProcessor.IsTextFile(Cfg.ColFile))
            {
                Log.ErrorMessage("Specified column names file does not appear to be a text file: {0}", Cfg.ColFile);
                Environment.ExitCode = (int)ExitCode.ColFileIsNotText;
                return(false);
            }
            if (Cfg.Split != null && !File.Exists(Cfg.Split))
            {
                Log.ErrorMessage("File specified for column splitting not exist: {0}", Cfg.Split);
                Environment.ExitCode = (int)ExitCode.SplitFileDoesNotExist;
                return(false);
            }
            if (ShouldLoadTable())
            {
                // only perform server-related validations if the user wants to load the server table
                if (!ServerUtils.CanConnect(Cfg.Server))
                {
                    Log.ErrorMessage("Unable to connect to the specified SQL Server: {0}", Cfg.Server);
                    Environment.ExitCode = (int)ExitCode.DBConnectFailed;
                    return(false);
                }

                if (!ServerUtils.IsValidDatabaseName(Cfg.Server, Cfg.Db))
                {
                    Log.ErrorMessage("Specified database does not exist on the server: {0}", Cfg.Db);
                    Environment.ExitCode = (int)ExitCode.InvalidDatabaseName;
                    return(false);
                }

                if (!ServerUtils.IsValidSchemaName(Cfg.Server, Cfg.Db, Cfg.Schema))
                {
                    Log.ErrorMessage("Specified schema {0} is invalid in database {1}", Cfg.Schema, Cfg.Db);
                    Environment.ExitCode = (int)ExitCode.InvalidSchemaName;
                    return(false);
                }
            }
            return(true);
        }