Пример #1
0
        /// <summary>
        /// Depends on ManufacturesList
        /// </summary>
        /// <returns></returns>
        public static List <Shipment> GenerateDefault()
        {
            List <Shipment> resultList = new List <Shipment>();

            if (ManufacturerList._lastList.Count <= 0)
            {
                return(resultList);
            }

            // ShipmentList (whole tab) generated shipment by shipment
            for (int i = 0; i < RandomNumberGenerator.GetInt32(1, 15); i++)
            {
                List <BoxedProduct> productsToShip = new List <BoxedProduct>();
                DateTime            beginTime = DateTime.Now, endTime = DateTime.Now;

                // productsToShip list fill
                for (int j = 0; j < RandomNumberGenerator.GetInt32(1, 10); j++)
                {
                    productsToShip.Add(new BoxedProduct(
                                           new Product("Product #" + j.ToString()),
                                           RandomNumberGenerator.GetInt32(1, 1000)));
                }

                DateGenerator.GenerateDatePeriod(beginTime, endTime);

                resultList.Add(new Shipment(
                                   ManufacturerList._lastList[RandomNumberGenerator.GetInt32(1, ManufacturerList._lastListCounter)],
                                   productsToShip, beginTime, endTime));
            }

            return(resultList);
        }
Пример #2
0
        public void GetDirectlyLicd()
        {
            var licdUrls = new string[7];

            licdUrls [0] = "http://cdn.leasticoulddo.com/comics/20100309.gif";
            licdUrls [1] = "http://cdn.leasticoulddo.com/comics/20100310.gif";
            licdUrls [2] = "http://cdn.leasticoulddo.com/comics/20100311.gif";
            licdUrls [3] = "http://cdn.leasticoulddo.com/comics/20100312.gif";
            licdUrls [4] = "http://cdn.leasticoulddo.com/comics/20100313.gif";
            licdUrls [5] = "http://cdn.leasticoulddo.com/comics/20100314.gif";
            licdUrls [6] = "http://cdn.leasticoulddo.com/comics/20100315.gif";

            var dateCount = new DateGenerator(new ComicUri(licdUrls [2]));

            dateCount.Start = "20100309";
            dateCount.Days  = DateGenerator.EveryDay;
            Assert.AreEqual(licdUrls, dateCount.Get(0, 7).ToArray());

            licdUrls [0] = "http://cdn.leasticoulddo.com/comics/20100309.gif";
            licdUrls [1] = "http://cdn.leasticoulddo.com/comics/20100310.gif";
            licdUrls [2] = "http://cdn.leasticoulddo.com/comics/20100311.gif";
            licdUrls [3] = "http://cdn.leasticoulddo.com/comics/20100316.gif";
            licdUrls [4] = "http://cdn.leasticoulddo.com/comics/20100317.gif";
            licdUrls [5] = "http://cdn.leasticoulddo.com/comics/20100318.gif";
            licdUrls [6] = "http://cdn.leasticoulddo.com/comics/20100323.gif";


            dateCount       = new DateGenerator(new ComicUri(licdUrls [0]));
            dateCount.Start = "20100309";
            var days = new string[] { DayOfWeek.Tuesday.ToString(), DayOfWeek.Wednesday.ToString(), DayOfWeek.Thursday.ToString() };

            dateCount.Days = new List <string> (days);
            Assert.AreEqual(licdUrls, dateCount.Get(0, 7));
        }
Пример #3
0
        public void GenerateSome()
        {
            var smbcUrls = new string[7];

            smbcUrls [0] = "http://www.smbc-comics.com/comics/20061011.gif";
            smbcUrls [1] = "http://www.smbc-comics.com/comics/20061012.gif";
            smbcUrls [2] = "http://www.smbc-comics.com/comics/20061013.gif";
            smbcUrls [3] = "http://www.smbc-comics.com/comics/20061014.gif";
            smbcUrls [4] = "http://www.smbc-comics.com/comics/20061015.gif";
            smbcUrls [5] = "http://www.smbc-comics.com/comics/20061016.gif";
            smbcUrls [6] = "http://www.smbc-comics.com/comics/20061017.gif";

            var dateCount = new DateGenerator(new ComicUri(smbcUrls [0]));

            dateCount.Days = DateGenerator.EveryDay;
            Assert.AreEqual(smbcUrls, dateCount.GenerateSome().ToArray());

            smbcUrls [0] = "http://www.smbc-comics.com/comics/20061011.gif";
            smbcUrls [1] = "http://www.smbc-comics.com/comics/20061012.gif";
            smbcUrls [2] = "http://www.smbc-comics.com/comics/20061013.gif";
            smbcUrls [3] = "http://www.smbc-comics.com/comics/20061018.gif";
            smbcUrls [4] = "http://www.smbc-comics.com/comics/20061019.gif";
            smbcUrls [5] = "http://www.smbc-comics.com/comics/20061020.gif";
            smbcUrls [6] = "http://www.smbc-comics.com/comics/20061025.gif";

            var days = new string[] { DayOfWeek.Wednesday.ToString(), DayOfWeek.Thursday.ToString(), DayOfWeek.Friday.ToString() };

            dateCount      = new DateGenerator(new ComicUri(smbcUrls [0]));
            dateCount.Days = new List <string> (days);
            Assert.AreEqual(smbcUrls, dateCount.GenerateSome());
        }
Пример #4
0
        public void FindFormat()
        {
            var isoDate      = "http://comic.com/19871024";
            var ukDate       = "http://comic.com/24101987";
            var usDate       = "http://comic.com/10241987";
            var isoDateShort = "http://comic.com/871024";
            var ukDateShort  = "http://comic.com/241087";
            var usDateShort  = "http://comic.com/102487";
            var fakeDate     = "http://comic.com/99999999";

            // implicitly tests FindFormat by calling the property BlockDateCount.Format
            var dateCount = new DateGenerator(new ComicUri(isoDate));

            Assert.AreEqual(DateType.Iso, dateCount.Format);

            dateCount = new DateGenerator(new ComicUri(ukDate));
            Assert.AreEqual(DateType.Uk, dateCount.Format);

            dateCount = new DateGenerator(new ComicUri(usDate));
            Assert.AreEqual(DateType.Us, dateCount.Format);

            dateCount = new DateGenerator(new ComicUri(isoDateShort));
            Assert.AreEqual(DateType.IsoShort, dateCount.Format);

            dateCount = new DateGenerator(new ComicUri(ukDateShort));
            Assert.AreEqual(DateType.UkShort, dateCount.Format);

            dateCount = new DateGenerator(new ComicUri(usDateShort));
            Assert.AreEqual(DateType.UsShort, dateCount.Format);

            dateCount = new DateGenerator(new ComicUri(fakeDate));
            Assert.AreEqual(DateType.NotRecognized, dateCount.Format);
        }
Пример #5
0
        public void DateGenerator()
        {
            IDateGenerator dategenerator = new DateGenerator();
            DateTime       testdatetime  = dategenerator.Generate(random, DateTime.MinValue, DateTime.MaxValue);

            Assert.IsNotNull(testdatetime);
        }
Пример #6
0
        public void GetUrlGeneratorSmbc()
        {
            var smbcUrl    = "http://www.smbc-comics.com/index.php?db=comics&id=614";
            var smbcUrl0   = "http://www.smbc-comics.com/comics/20061010.gif";
            var smbcUrl1   = "http://www.smbc-comics.com/comics/20061011.gif";
            var smbcUrl2   = "http://www.smbc-comics.com/comics/20061012.gif";
            var smbcParser = new ComicParser(smbcUrl);

            // get the generator object
            DateGenerator urlGen = (DateGenerator)smbcParser.GetUrlGenerator();

            urlGen.Days = DateGenerator.EveryDay;

            // generate 10 urls, going backwards, including the original (and starting from the original)
            List <string> backUrls = urlGen.Get(-1, 10);
            // generate 10 urls, going forwards, excluding the original (and starting from the original)
            List <string> forwardUrls = urlGen.Get(0, 10);

            // each url should be the comic, directly
            // urls are sorted
            Assert.AreEqual(smbcUrl0, backUrls [0]);
            Assert.AreEqual(smbcUrl1, backUrls [1]);
            Assert.AreEqual(10, backUrls.Count());
            Assert.AreEqual(smbcUrl1, forwardUrls [0]);
            Assert.AreEqual(smbcUrl2, forwardUrls [1]);
            Assert.AreEqual(10, forwardUrls.Count());
        }
Пример #7
0
        public void DateGeneratorTestWithStringOverride()
        {
            IDateGenerator dategenerator = new DateGenerator();
            DateTime       testdatetime  = dategenerator.Generate(random, "1/2/2009");

            Assert.IsNotNull(testdatetime);
            Assert.AreEqual(Convert.ToDateTime("1/2/2009"), testdatetime);
        }
Пример #8
0
 public VisitorSegment(string name)
 {
     Name             = name;
     VisitorVariables = new List <IVisitorVariables>();
     VisitVariables   = new List <IVisitorVariables>();
     RequestVariables = new List <IVisitorVariables>();
     DateGenerator    = new DateGenerator();
 }
        internal static void Seed(BillsPaymentSystemContext context, int count, List <User> users)
        {
            for (int i = 0; i < count; i++)
            {
                var payment = new PaymentMethod()
                {
                    User        = users[IntGenerator.GenerateInt(0, users.Count - 1)],
                    Type        = PaymentType.BankAccount,
                    BankAccount = new BankAccount()
                    {
                        BankAccountId = i,
                        //Balance = PriceGenerator.GeneratePrice(),
                        BankName  = TextGenerator.FirstName() + "\'s Bank",
                        SwiftCode = TextGenerator.Password(10)
                    },
                    BankAccountId = i
                };
                payment.BankAccount.Deposit(PriceGenerator.GeneratePrice());

                var result = new List <ValidationResult>();
                if (AttributeValidator.IsValid(payment, result))
                {
                    context.PaymentMethods.Add(payment);
                }
                else
                {
                    Console.WriteLine(string.Join(Environment.NewLine, result));
                }

                payment = new PaymentMethod()
                {
                    User       = users[IntGenerator.GenerateInt(0, users.Count - 1)],
                    Type       = PaymentType.CreditCard,
                    CreditCard = new CreditCard()
                    {
                        CreditCardId   = i,
                        ExpirationDate = DateGenerator.FutureDate(),
                        Limit          = PriceGenerator.GeneratePrice(),
                        //MoneyOwed = PriceGenerator.GeneratePrice()
                    },
                    CreditCardId = i
                };
                payment.CreditCard.Withdraw(PriceGenerator.GeneratePrice());

                result = new List <ValidationResult>();
                if (AttributeValidator.IsValid(payment, result))
                {
                    context.PaymentMethods.Add(payment);
                }
                else
                {
                    Console.WriteLine(string.Join(Environment.NewLine, result));
                }
            }

            context.SaveChanges();
        }
 public LogRecordTemplate()
 {
     _ipAddressGenerator = new IpAddressGenerator(_random, _data.UniqueIpCount);
     _hyphenGenerator = new HyphenGenerator();
     _userIdGenerator = new UserIdGenerator(_random);
     _dateGenerator = new DateGenerator(_random);
     _requestLineGenerator = new RequestLineGenerator(_random, _data.RequestLineParameters);
     _codeDefinitionGenerator = new CodeDefinitionGenerator(_random, _data.Codes);
     _fileSizeGenerator = new FileSizeGenerator(_random);
 }
Пример #11
0
 public LogRecordTemplate()
 {
     _ipAddressGenerator      = new IpAddressGenerator(_random, _data.UniqueIpCount);
     _hyphenGenerator         = new HyphenGenerator();
     _userIdGenerator         = new UserIdGenerator(_random);
     _dateGenerator           = new DateGenerator(_random);
     _requestLineGenerator    = new RequestLineGenerator(_random, _data.RequestLineParameters);
     _codeDefinitionGenerator = new CodeDefinitionGenerator(_random, _data.Codes);
     _fileSizeGenerator       = new FileSizeGenerator(_random);
 }
Пример #12
0
        private static CreditCard NewCreditCard()
        {
            CreditCard creditCard = new CreditCard()
            {
                Limit          = Limit(),
                MoneyOwed      = MoneyOwed(),
                ExpirationDate = DateGenerator.GenerateDate()
            };

            return(creditCard);
        }
Пример #13
0
        public void DateGeneratorTestWithAttributeRangeMap()
        {
            IDateGenerator dategenerator = new DateGenerator();
            AttributeMap   attmap        = new AttributeMap {
                MinDate = "1/1/2009", maxDate = "4/1/2009"
            };
            DateTime testdatetime = dategenerator.Generate(random, attmap);

            Assert.IsNotNull(testdatetime);
            Assert.Between(testdatetime, Convert.ToDateTime("1/1/2009"), Convert.ToDateTime("4/1/2009"));
        }
Пример #14
0
        public void DateGeneratorTestWithAttributeOverrideMap()
        {
            IDateGenerator dategenerator = new DateGenerator();
            AttributeMap   attmap        = new AttributeMap {
                DefaultDate = Convert.ToDateTime("1/1/2009")
            };
            DateTime testdatetime = dategenerator.Generate(random, attmap);

            Assert.IsNotNull(testdatetime);
            Assert.AreEqual(Convert.ToDateTime("1/1/2009"), testdatetime);
        }
        internal static Homework GenerateHomework(List <Course> courses, List <Student> students)
        {
            var homework = new Homework()
            {
                Content        = TextGenerator.Text("Lab", "Exercise", "Exam", "Other stuff"),
                SubmissionTime = DateGenerator.RandomDate(),
                ContentType    = (ContentType)IntGenerator.GenerateInt(1, 3),
                Course         = courses[IntGenerator.GenerateInt(0, courses.Count - 1)],
                Student        = students[IntGenerator.GenerateInt(0, students.Count - 1)]
            };

            return(homework);
        }
Пример #16
0
        public void FindDays()
        {
            var comic     = new ComicUri("http://www.smbc-comics.com/comics/20061011.gif");
            var dateCount = new DateGenerator(comic);

//			// by chance, two consecutive Thursdays were missed here
//			Assert.AreEqual (6, dateCount.Days.Count);
//			Assert.IsFalse (dateCount.Days.Contains ("Thursday"));

            // Behaviour changed:
            // FindDays is no longer called to calculate what days the comic runs
            // Every day is assumed
            // This is quicker and simpler: if URL not found, download quietly fails
            Assert.AreEqual(7, dateCount.Days.Count);
        }
        internal static void InitialStudentSeed(StudentSystemContext context, int count)
        {
            for (int i = 0; i < count; i++)
            {
                var student = new Student()
                {
                    Name         = TextGenerator.FirstName() + " " + TextGenerator.LastName(),
                    RegisteredOn = DateGenerator.PastDate()
                };

                context.Students.Add(student);
            }

            context.SaveChanges();
        }
Пример #18
0
        internal static void InitialCourseSeed(StudentSystemContext context, int count)
        {
            for (int i = 0; i < count; i++)
            {
                var date   = DateGenerator.RandomDate();
                var course = new Course()
                {
                    Name      = TextGenerator.FirstName(),
                    StartDate = date,
                    EndDate   = DateGenerator.DateAfter(date),
                    Price     = PriceGenerator.GeneratePrice()
                };

                context.Courses.Add(course);
            }

            context.SaveChanges();
        }
Пример #19
0
        public void DaysNotAssignedExplicitly()
        {
            var smbc = "http://www.smbc-comics.com/comics/20061017.gif";

            var smbcUrls = new string[7];

            smbcUrls [0] = "http://www.smbc-comics.com/comics/20061011.gif";
            smbcUrls [1] = "http://www.smbc-comics.com/comics/20061012.gif";
            smbcUrls [2] = "http://www.smbc-comics.com/comics/20061013.gif";
            smbcUrls [3] = "http://www.smbc-comics.com/comics/20061014.gif";
            smbcUrls [4] = "http://www.smbc-comics.com/comics/20061015.gif";
            smbcUrls [5] = "http://www.smbc-comics.com/comics/20061016.gif";
            smbcUrls [6] = "http://www.smbc-comics.com/comics/20061017.gif";

            var dateCount = new DateGenerator(new ComicUri(smbc));

            dateCount.Start = "20061011";
            Assert.AreEqual(smbcUrls, dateCount.Get(0, 7).ToArray());
        }
Пример #20
0
        public static void SetAuthorizationCookie(this HttpContextBase httpContext, string username)
        {
            string          key      = Settings.InitSetting.Instance.AuthCookieName;
            DateTime        utcNow   = DateTime.UtcNow;
            PayloadIdentity identity = new PayloadIdentity()
            {
                IssuedAt = DateGenerator.ToUnixTimeStamp(utcNow),
                ExpireAt = DateGenerator.ToUnixTimeStamp(utcNow) + Settings.InitSetting.Instance.AuthorizationTokenLifeSpanInSecond,
                Username = username
            };
            JwtUtility <JwtHeader, PayloadIdentity> jwtUtil = new JwtUtility <JwtHeader, PayloadIdentity>(new JwtHeader(), identity);
            string     token  = jwtUtil.ToString();
            HttpCookie cookie = new HttpCookie(key);

            cookie.HttpOnly = false;
            cookie.Value    = token;
            cookie.Expires  = DateTime.Now.AddSeconds(Settings.InitSetting.Instance.AuthorizationTokenLifeSpanInSecond);
            httpContext.Response.Cookies.Add(cookie);
            AddTokenIssued(username, token, DateGenerator.ZeroUnixTimestamp.AddSeconds(identity.IssuedAt), DateGenerator.ZeroUnixTimestamp.AddSeconds(identity.ExpireAt));
        }
Пример #21
0
        public void Start()
        {
            // default
            var url    = "http://www.smbc-comics.com/comics/20061011.gif";
            var dateCo = new DateGenerator(url);

            Assert.AreEqual("20061011", dateCo.Start);
            Assert.AreEqual(10, dateCo.Date.Month);

            // setting value
            var newStart = "19871024";

            dateCo.Start = newStart;
            Assert.AreEqual(newStart, dateCo.Start);

            // setting value in wrong format
            newStart     = "31121999";
            dateCo.Start = newStart;
            Assert.AreEqual("19991231", dateCo.Start);
        }
Пример #22
0
        public Product(string title)
        {
            Id      = NextProductId++;
            Title   = title;
            Barcode = new int[13];
            Type    = new List <string>();

            for (int i = 0; i < 13; i++)
            {
                Barcode[i] = RandomNumberGenerator.GetInt32(0, 10);
            }

            for (int i = 0; i < RandomNumberGenerator.GetInt32(0, 5); i++)
            {
                Type.Add("Type #" + Barcode[i].ToString());
            }

            ManufacturingDate = DateGenerator.GenerateWideDateTime();
            ExpirationDate    = DateGenerator.GenerateDateTime();
            Description       = "Description #" + Id.ToString();
        }
Пример #23
0
        public void _display(int mode = 0)
        {
            string divider = mode == 0 ? "\t" : "\n";

            Console.Write("[Title]" + Manufacturer.Title + divider);

            int sum = 0;

            foreach (var box in ContentToShip)
            {
                Console.Write("[" + box.Quantity.ToString() + "]" + box.ProductInStack.Title + " ");
                sum += box.Quantity;
            }

            Console.Write("[sum]" + sum + divider);

            Console.Write("[PD]" + DateGenerator.DateToShortString(PurchaseDate) + divider);
            Console.Write("[ShB]" + DateGenerator.DateToShortString(ShipmentDateBegin) + divider);
            Console.Write("[ShE]" + DateGenerator.DateToShortString(ShipmentDateEnd) + divider);
            Console.Write("\n");
        }
Пример #24
0
 //Checks initilization of UI elements
 void nullCheck()
 {
     //print("Nullcheck");
     if (player == null)
     {
         player    = GameObject.FindGameObjectWithTag("Player");
         pl        = player.GetComponent <PlayerLogic>();
         sl        = player.GetComponentInChildren <SplashLogic>();
         playerMat = player.GetComponentInChildren <Renderer>();
     }
     if (camera == null)
     {
         camera        = GameObject.FindGameObjectWithTag("MainCamera");
         cameraRespawn = camera.transform.position;
     }
     if (countdownObj == null)
     {
         countdownObj = GameObject.Find("Canvas/Countdown");
     }
     if (respawn == null)
     {
         respawn = GameObject.FindGameObjectWithTag("Respawn");
     }
     if (gameoverPanel == null)
     {
         gameoverPanel = GameObject.Find("Canvas/GameOverPanel");
         punTime       = gameoverPanel.GetComponentInChildren <PunGenerator>();
         dateGen       = gameoverPanel.GetComponentInChildren <DateGenerator>();
     }
     if (finalText == null)
     {
         finalText = GameObject.Find("Canvas/GameOverPanel/FinalText").GetComponent <Text>();
     }
     if (bestDistanceText == null)
     {
         bestDistanceText = GameObject.Find("Canvas/GameOverPanel/BestDistanceText").GetComponent <Text>();
     }
     if (meltAgainButton == null)
     {
         meltAgainButton = GameObject.Find("Canvas/GameOverPanel/MeltAgainButton").GetComponent <Button>();
     }
     if (gameUi == null)
     {
         gameUi = GameObject.Find("Canvas/GameUI");
     }
     if (distanceText == null)
     {
         distanceText = GameObject.Find("Canvas/GameUI/DistanceText").GetComponent <Text>();
     }
     if (playerSizeText == null)
     {
         playerSizeText = GameObject.Find("Canvas/GameUI/PlayerSizeText").GetComponent <Text>();
     }
     if (sunIcon == null)
     {
         sunIcon = GameObject.Find("Canvas/GameUI/SunImage").GetComponent <Image>();
     }
     if (tempIcon == null)
     {
         tempIcon    = GameObject.Find("Canvas/GameUI/TemperatureImage/Temperature").GetComponent <RectTransform>();
         tempRespawn = tempIcon.sizeDelta;
     }
 }
Пример #25
0
 /// <summary>
 /// Create a DateGenerator based on the list of DateGenerators.
 /// </summary>
 /// <param name="array"></param>
 public MultiplexGenerator(DateGenerator[] array)
 {
     _generators = array;
     _enumerators = new IEnumerator<DateTime>[array.Length];
     _hasMore = new bool[array.Length];
 }
Пример #26
0
 /// <summary>
 /// Check whether the token expires yet. Timezone: UTC
 /// </summary>
 /// <returns></returns>
 public bool isTokenExpired()
 {
     return(ExpireAt <= DateGenerator.ToUnixTimeStamp(DateTime.UtcNow));
 }
Пример #27
0
 private static void ApplyShiftPattern(DateGenerator gen, GroupCollection groups)
 {
     Group gShift = groups["shift"];
     Group gReq = groups["req"];
     if (gShift.Success && gReq.Success)
     {
         ShiftMode mode = ShiftMode.None;
         switch (gShift.Value)
         {
             case "<=":
                 mode = ShiftMode.OnOrBefore;
                 break;
             case "<":
                 mode = ShiftMode.Before;
                 break;
             case "<>":
                 mode = ShiftMode.Nearest;
                 break;
             case ">":
                 mode = ShiftMode.After;
                 break;
             case "=>":
                 mode = ShiftMode.OnOrAfter;
                 break;
         }
         WDay wday = GetWDayFromAbbrev(gReq.Value);
         gen.Mode = mode;
         gen.RequiredDay = wday;
     }
 }
Пример #28
0
 public void DateGeneratorTestWithStringOverride()
 {
     IDateGenerator dategenerator = new DateGenerator();
     DateTime testdatetime = dategenerator.Generate(random, "1/2/2009");
     Assert.IsNotNull(testdatetime);
     Assert.AreEqual(Convert.ToDateTime("1/2/2009"), testdatetime);
 }
Пример #29
0
 public void DateGenerator()
 {
     IDateGenerator dategenerator = new DateGenerator();
     DateTime testdatetime = dategenerator.Generate(random, DateTime.MinValue, DateTime.MaxValue);
     Assert.IsNotNull(testdatetime);
 }
Пример #30
0
 public void DateGeneratorTestWithAttributeOverrideMap()
 {
     IDateGenerator dategenerator = new DateGenerator();
     AttributeMap attmap = new AttributeMap { DefaultDate = Convert.ToDateTime("1/1/2009") };
     DateTime testdatetime = dategenerator.Generate(random, attmap);
     Assert.IsNotNull(testdatetime);
     Assert.AreEqual(Convert.ToDateTime("1/1/2009"), testdatetime);
 }
Пример #31
0
        /// <summary>
        /// Create a string representation of the date generator.
        /// </summary>
        public static string GetString(DateGenerator gen)
        {
            string s = null;
            if (gen is FixedIntervalGenerator)
            {
                s = "D" + ((FixedIntervalGenerator) gen).Cycle;
            }
            else if (gen is WeekDaysGenerator)
            {
                s = "Wmf,1";
            }
            else if (gen is WeeklyGenerator)
            {
                var weekly = (WeeklyGenerator) gen;
                var sb = new StringBuilder();
                bool[] days = weekly.Days;
                for (int i = 1; i < 7; i++)
                {
                    if (days[i]) sb.Append("sumotuwethfrsa", i << 1, 2);
                }
                if (days[0]) sb.Append("su");
                string sDays = sb.ToString();
                switch (sDays)
                {
                    case "motuwethfr":
                        sDays = "mf";
                        break;
                    case "sasu":
                        sDays = "ss";
                        break;
                    case "motuwethfrsasu":
                        sDays = "ad";
                        break;
                }
                s = "W" + sDays + "," + weekly.Cycle;
            }
            else if (gen is MonthlyAbsoluteGenerator)
            {
                var monthly = (MonthlyAbsoluteGenerator) gen;
                s = "M" + monthly.DayOfMonth + "," + monthly.Cycle;
            }
            else if (gen is MonthlyRelativeGenerator)
            {
                var monthly = (MonthlyRelativeGenerator) gen;
                string day = "admfssmotuwethfrsasu".Substring((int) monthly.DayId << 1, 2);
                if (gen is YearlyRelativeGenerator)
                {
                    var yr = (YearlyRelativeGenerator) gen;
                    s = "Y" + yr.MonthNumber + "," + yr.WeekInMonth + day;
                }
                else
                {
                    s = "M" + monthly.WeekInMonth + day + "," + monthly.Cycle;
                }
            }
            else if (gen is AnniversaryGenerator)
            {
                var anniv = (AnniversaryGenerator) gen;
                s = "Y" + anniv.Month + "," + anniv.Day;
            }
            else if (gen is EnumDateGenerator)
            {
                var genEnum = (EnumDateGenerator) gen;
                s = "E" + string.Join(",", genEnum.Dates.Select(dt => dt.ToString(DateFmt)).ToArray());
            }
            else if (gen is MultiplexGenerator)
            {
                var genMerge = (MultiplexGenerator) gen;
                s = string.Join("|", genMerge.Generators.Select(g => GetString(g)).ToArray());
            }

            if (gen.HasRange)
            {
                s = string.Format("{0};{1};{2}",
                                  gen.Start.ToString(DateFmt),
                                  (gen.End == DateTime.MaxValue ? gen.Occurrences.ToString() : gen.End.ToString(DateFmt)),
                                  s);
            }

            if (gen.Mode != ShiftMode.None)
            {
                var symbols = new[] {"", "<>", "<=", "=>", "<", ">"};
                s += symbols[(int) gen.Mode] + "admfssmotuwethfrsasu".Substring((int) gen.RequiredDay << 1, 2);
            }
            return s;
        }
Пример #32
0
        public Faker(string dirPath)
        {
            List <Assembly> allAssemblies = new List <Assembly>();


            foreach (string dll in Directory.GetFiles(dirPath, "*.dll"))
            {
                allAssemblies.Add(Assembly.LoadFile(dll));
            }

            collectionTypeGenerator = new Dictionary <string, ICollectionGenerator>();

            basicTypeGenerator = new Dictionary <Type, IGenerator>();

            var doubleGenerator = new DoubleGenerator();

            basicTypeGenerator.Add(doubleGenerator.GetGeneratorType(), doubleGenerator);

            var uintGenerator = new UIntGenerator();

            basicTypeGenerator.Add(uintGenerator.GetGeneratorType(), uintGenerator);

            var floatGenerator = new FloatGenerator();

            basicTypeGenerator.Add(floatGenerator.GetGeneratorType(), floatGenerator);

            var charGenerator = new CharGenerator();

            basicTypeGenerator.Add(charGenerator.GetGeneratorType(), charGenerator);

            var stringGenerator = new StringGenerator();

            basicTypeGenerator.Add(stringGenerator.GetGeneratorType(), stringGenerator);

            var longGenerator = new LongGenerator();

            basicTypeGenerator.Add(longGenerator.GetGeneratorType(), longGenerator);

            var datetimeGenerator = new DateGenerator();

            basicTypeGenerator.Add(datetimeGenerator.GetGeneratorType(), datetimeGenerator);

            foreach (var asm in allAssemblies)
            {
                Console.WriteLine(asm.FullName);
                var types = asm.GetTypes().Where(t => t.GetInterfaces().Where(i => i.Equals(typeof(IGenerator))).Any());

                foreach (var type in types)
                {
                    var  plugin = asm.CreateInstance(type.FullName) as IGenerator;
                    Type t      = plugin.GetGeneratorType();
                    if (!basicTypeGenerator.ContainsKey(t))
                    {
                        basicTypeGenerator.Add(plugin.GetGeneratorType(), plugin);
                    }
                }
            }

            var listGenerator = new ListGenerator();

            collectionTypeGenerator.Add(listGenerator.GetGeneratorType().Name, listGenerator);

            recursionList = new List <Type>();
        }
Пример #33
0
 public void SetPattern(DateGenerator gen)
 {
     Recurrence = DateGeneratorFactory.GetString(gen);
 }
Пример #34
0
 public void DateGeneratorTestWithAttributeRangeMap()
 {
     IDateGenerator dategenerator = new DateGenerator();
     AttributeMap attmap = new AttributeMap { MinDate = "1/1/2009", maxDate = "4/1/2009" };
     DateTime testdatetime = dategenerator.Generate(random, attmap);
     Assert.IsNotNull(testdatetime);
     Assert.Between(testdatetime, Convert.ToDateTime("1/1/2009"), Convert.ToDateTime("4/1/2009"));
 }