Ejemplo n.º 1
0
 private static bool IsChar(string item, ItemDefintion definition)
 {
     if (!string.IsNullOrWhiteSpace(item))
     {
         return(!(item.Length > 1));
     }
     return(true);
 }
Ejemplo n.º 2
0
        public static void run()
        {
            Validator     v  = new Validator();
            ItemDefintion id = new ItemDefintion()
            {
                Type = "int", Precision = "4"
            };

            Console.WriteLine("validation answer is {0}", v.IsValid("3", id));
        }
Ejemplo n.º 3
0
        private static void ValidateFile(string[] args)
        {
            Validator v = new Validator(); System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
            var       options = new Options();
            var       isValid = CommandLine.Parser.Default.ParseArgumentsStrict(args, options);

            timer.Start();
            Console.WriteLine("definition file {0} delimiting by {1}", options.DefinitionFilePath, Char.Parse(options.Delimiter));
            Console.WriteLine("reading file {0} delimiting by {1}", options.InputFile, Char.Parse(options.Delimiter));
            Console.WriteLine();
            string line; string[] items; Int64 lineCount = 0; Int64 itemCount = 0; ItemDefintion def = new ItemDefintion();
            int    trues = 0; int falses = 0; bool result; TimeSpan ts = new TimeSpan();

            StreamReader r2    = new StreamReader(options.DefinitionFilePath);
            string       line2 = r2.ReadLine();

            r2.Close();
            List <ItemDefintion> types = line2.Split(new char[] { Char.Parse(options.Delimiter) }).Select(type => new ItemDefintion(type)).ToList();
            int          numTypes      = types.Count();
            StreamReader r             = new StreamReader(options.InputFile);

            int iStartRow;

            if (Int32.TryParse(options.StartRow, out iStartRow))
            {
                while (iStartRow > 0)
                {
                    r.ReadLine();
                    iStartRow--;
                }
            }

            Console.WriteLine("processor count {0}:", Environment.ProcessorCount);
            TimeSpan ets = new TimeSpan(0, 0, 0, 0, 1);

            Console.WriteLine("there are {0} ticks per millisection", ets.Ticks);
            int proc = Environment.ProcessorCount;

            while ((line = r.ReadLine()) != null)
            {
                lineCount++;
                items = line.Split(new char[] { Char.Parse(options.Delimiter) });
                if (items.Count() != numTypes)
                {
                    Console.WriteLine("ERROR:  expected more or less items in line # {0}", lineCount);
                }

                for (int i = 0; i < numTypes; i++)
                {
                    //def.Type = types[i];
                    result = v.IsValid(items[i], types[i]); // takes about 150 ticks to do this.  threading overhead will not speed ths up
                    //result = true;
                    if (result)
                    {
                        trues++;
                    }
                    else
                    {
                        Console.WriteLine("failure:  row #{0}  item#{1} value: {2}  not a {3}", lineCount, i, items[i], types[i].originalType);
                        Console.WriteLine("the line is");
                        Console.WriteLine(line);//r.Close();
                        //break;
                        falses++;
                    }
                    //Console.WriteLine("Item: {0} validation test is: {1} for type {2}", items[i], v.IsValid(items[i], def), types[i]);
                    itemCount++;
                }

                if (lineCount % 1000000 == 0)
                {
                    ts = timer.Elapsed;
                    Console.Write("\rLine Count {0}:  Item Count {1}: Passes: {2} Failes: {3}  Run time {4} Avg/line {5}", lineCount, itemCount, trues.ToString(), falses.ToString(),
                                  String.Format("{0:00}:{1:00}:{2:00}", ts.Hours, ts.Minutes, ts.Seconds), ts.Ticks / lineCount);
                }
            }
            timer.Stop();
            r.Close();
            Console.WriteLine();
            Console.Write("Validation completed:");
            Console.WriteLine("Line Count {0}:  Item Count {1}: Passes: {2} Failes: {3}  Run time {4}", lineCount, itemCount, trues.ToString(), falses.ToString(),
                              String.Format("{0:00}:{1:00}:{2:00}", ts.Hours, ts.Minutes, ts.Seconds));
            //}
            //else
            //{
            //	Console.WriteLine("you are missing required arguments");
            //}
            //run();
            Console.ReadLine();
        }
Ejemplo n.º 4
0
        private static bool IsDate(string item, ItemDefintion definition)
        {
            DateTime result;

            return(DateTime.TryParse(item, out result));
        }
Ejemplo n.º 5
0
 private static bool IsTimeStamp(string item, ItemDefintion definition)
 {
     return(IsDate(item, definition));
 }
Ejemplo n.º 6
0
 private static bool IsVarchar(string item, ItemDefintion definition)
 {
     return(!definition.Length.HasValue || item.Length <= definition.Length);
 }
Ejemplo n.º 7
0
        private static bool IsDecimal(string item, ItemDefintion definition)
        {
            Decimal result;

            return(Decimal.TryParse(item, out result));
        }
Ejemplo n.º 8
0
        private static bool IsBigInt(string item, ItemDefintion definition)
        {
            Int64 result;

            return(Int64.TryParse(item, out result));
        }
Ejemplo n.º 9
0
        private static bool IsInt(string item, ItemDefintion definition)
        {
            int result;

            return(int.TryParse(item, out result));
        }
Ejemplo n.º 10
0
        public bool IsValid(string item, ItemDefintion definition)
        {
            bool result = ValidationStrategy[definition.Type.ToLower()](item, definition);

            return(result);
        }