示例#1
0
 /// <summary>
 /// Split an input line on the delimeter
 /// </summary>
 /// <remarks>
 /// Input line can have quoted, or non-quoted fields. Both are handled. MUST be delimiter-separated though.
 /// </remarks>
 /// <param name="InputLine"></param>
 /// <param name="Delimiter"></param>
 /// <returns></returns>
 ///
 public static List <string> SplitInputLine(string InputLine)
 {
     if (Cfg.Fixed.IsNullOrEmpty())
     {
         DelimitedLineParser Parser = new DelimitedLineParser(Cfg.Delimiter, Cfg.SimpleParse);
         return(Parser.SplitLine(InputLine, true));
     }
     else
     {
         FixedWidthReader Rdr = new FixedWidthReader();
         return(Rdr.ParseLine(InputLine));
     }
 }
示例#2
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);
        }
示例#3
0
        /// <summary>
        /// Constructs an instance with the specified configuration parameters
        /// </summary>
        /// <param name="SrcFile">The source file to read</param>
        /// <param name="RemoveEmbeddedTabs">True to replace tabs embedded in fields with four spaces</param>

        public CSVReader(string SrcFile, bool RemoveEmbeddedTabs) : base()
        {
            Rdr    = new StreamReader(SrcFile);
            Parser = new DelimitedLineParser(Cfg.Delimiter, Cfg.SimpleParse);
            this.RemoveEmbeddedTabs = RemoveEmbeddedTabs;
        }