Ejemplo n.º 1
0
        /// <summary>
        /// Create a valid siren ('approximately' unique)
        /// </summary>
        public static string Siren()
        {
            // Some protections... (really ???) the two first digits will be the same within a week
            // Get week number and add 10
            DateTime           time = DateTime.Now;
            DateTimeFormatInfo dfi  = DateTimeFormatInfo.CurrentInfo;
            Calendar           cal  = dfi.Calendar;
            int week = cal.GetWeekOfYear(time, dfi.CalendarWeekRule,
                                         dfi.FirstDayOfWeek);

            week += 10;
            // --

            string num = week + MTools.RandNUM(6);

            // Luhn algo : 8 + 1
            var    sum    = 0;
            var    alt    = true;
            var    digits = num.ToCharArray();
            string numCtrl;

            for (int i = digits.Length - 1; i >= 0; i--)
            {
                var curDigit = (digits[i] - 48);
                if (alt)
                {
                    curDigit *= 2;
                    if (curDigit > 9)
                    {
                        curDigit -= 9;
                    }
                }
                sum += curDigit;
                alt  = !alt;
            }
            if ((sum % 10) == 0)
            {
                numCtrl = "0";
            }
            else
            {
                numCtrl = (10 - (sum % 10)).ToString();
            }

            return(num + numCtrl);
        }
Ejemplo n.º 2
0
        static private string GetResultFunc(string func)
        {
            // Could be {ddj}
            // Could be {ddj(-1)}

            var    pattern   = @"{(.*?)(\((.*?)\))?}";
            var    match     = Regex.Match(func, pattern);
            string nameFunc  = match.Groups[1].Value;
            string paramFunc = null;

            if (!string.IsNullOrEmpty(match.Groups[3].Value))
            {
                paramFunc = match.Groups[3].Value;
            }

            // Case sensitive
            switch (nameFunc.ToLower().Trim())
            {
            case "ddj":
            case "today":
                if (paramFunc != null)
                {
                    string[] arr = paramFunc.Split(',');
                    if (arr.Length > 1)
                    {
                        return(MTools.Today(Int32.Parse(arr[0]), arr[1]));
                    }
                    else
                    {
                        return(MTools.Today(Int32.Parse(paramFunc)));
                    }
                }
                return(MTools.Today());

            case "randdate":
            case "randDate":
                return(MTools.RandDate(Int32.Parse(paramFunc)));

            case "randan":
            case "randAn":
            case "randAN":
            case "randAlphaNum":
                return(MTools.RandAlphaNum(Int32.Parse(paramFunc)));

            case "randnum":
            case "randNum":
            case "randNUM":
                return(MTools.RandNUM(Int32.Parse(paramFunc)));

            case "randstr":
            case "randStr":
            case "randSTR":
                return(MTools.RandSTR(Int32.Parse(paramFunc)));

            case "randu1str":
            case "randU1Str":
                return(MTools.FirstCharToUpper(MTools.RandSTR(Int32.Parse(paramFunc))));

            case "siren":
                return(MTools.Siren());

            case "randcountry":
            case "randCountry":
                return(MTools.RandCountry());

            default:
                match = Regex.Match(func, "^[a-zA-Z]+");
                if (!match.Success)
                {
                    return(func);       // Les cas ne commançant pas par une lettre tel que {3} ou {,3} sont ignorés
                }
                throw new Exception("Unknow function " + func + ". Check syntax. Currently List is: today, ddj (same as today), randan, randnum, randstr, randu1str, siren, randcountry");
            }
        }
Ejemplo n.º 3
0
        public void Run()
        {
            // Example of each tools
            Console.WriteLine("Today(): " + MTools.Today());
            Console.WriteLine("Today(): " + MTools.Today(0, "dddd, dd MMMM yyyy HH:mm:ss"));
            
            Console.WriteLine("Today(-7): " + MTools.Today(-7));
            Console.WriteLine("Today(7): " + MTools.Today(7));

            Console.WriteLine("MTools.FrDateAdd(\"21/06/2004\", 15): " + MTools.FrDateAdd("21/06/2004", 15));

            Console.WriteLine("MTools.IsPastFrDate(\"21/06/2004\"): " + MTools.IsPastFrDate("21/06/2004"));

            Console.WriteLine("MTools.DateNumToFrDate(\"20191115\"): " + MTools.DateNumToFrDate("20191115"));

            Console.WriteLine("MTools.CompareFrDate(\"21/06/2004\", \"21/07/2004\"): " + MTools.CompareFrDate("21/06/2004","21/07/2004"));

            Console.WriteLine("MTools.FrDateToYMDDate(\"21/06/2004\"): " + MTools.FrDateToYMDDate("21/06/2004"));

            Console.WriteLine("MTools.FrDateToDateNum(\"21/06/2004\"): " + MTools.FrDateToDateNum("21/06/2004"));

            Console.WriteLine("RandDate(2020): " + MTools.RandDate(2020));            
            
            Console.WriteLine("RandNum(3): " + MTools.RandNum(3));
            
            Console.WriteLine("RandAlphaNum(10): " + MTools.RandAlphaNum(10));
            
            Console.WriteLine("RandStr(10): " + MTools.RandStr(10));

            Console.WriteLine("FirstCharToUpper(\"john\"): " + MTools.FirstCharToUpper("john"));

            Console.WriteLine("Siren(): " + MTools.Siren());
            
            Console.WriteLine("RandCountry(): " + MTools.RandCountry());
            Console.WriteLine("RandCountry(\"FRANCE\"): " + MTools.RandCountry("FRANCE"));
            
            Console.WriteLine(System.Environment.NewLine);

            // Demo on csv string
            string s = "{};COM;{}  etc...
            string s = DatasetTools.ProcessData("{today};{today(5)};CHATEAUROUX;Jean-{randu1str(12)};{randstr(12)};{randnum(5)}; {randcountry}")
            Console.WriteLine("ProcessData: " + s);

            Dictionary<string, string> replacementDico = new Dictionary<string, string>();
            replacementDico.Add("author", "Antoine De Saint-Exupéry")
            s = DatasetTools.ProcessData("{today};{today(5)};CHATEAUROUX;Jean-{randu1str(12)};{randstr(12)};{randnum(5)}; {randcountry};{#author}");

            Console.WriteLine(System.Environment.NewLine);

            // Demo on csv file
            CsvInfo csvInfo = new CsvInfo();
            csvInfo.fullFilename = "demo.csv";

            var resList = CSVLoader.LoadAndProcessData(csvInfo);
            foreach(var line in resList)
            {
               Console.WriteLine(line);
            }
        }