public RRuleTextBuilderTestHelper(string rRuleString, string readableString, string culture)
            {
                RRuleString    = rRuleString;
                ReadableString = readableString;
                string rRuleStringC = RRuleTextBuilder.GetRRuleStringCorrection(rRuleString);

                recurrencePattern    = new RecurrencePattern(rRuleStringC);
                RecreatedRRuleString = recurrencePattern.ToString();
                ReadableResult       = recurrencePattern.ToText(new CultureInfo(culture));
            }
Exemplo n.º 2
0
        private string GetRecurringRuleText()
        {
            if (String.IsNullOrWhiteSpace(Rule))
            {
                return("");
            }
            var recurrencePattern = new RecurrencePattern(Rule);

            return(recurrencePattern.ToText());
        }
Exemplo n.º 3
0
        public IActionResult CreateRRule([FromBody] RRuleWrapper RRuleWrapper)
        {
            if (RRuleWrapper == null)
            {
                var rRuleResultE = new RRuleResult()
                {
                    ErrorText = "invalid data"
                };
                return(new JsonResult(rRuleResultE));
            }
            ;

            var recurrencePattern = new RecurrencePattern(RRuleWrapper.GetFrequencyType(), RRuleWrapper.Interval);

            switch (recurrencePattern.Frequency)
            {
            case FrequencyType.None:
            case FrequencyType.Secondly:
            case FrequencyType.Minutely:
            case FrequencyType.Hourly:
            case FrequencyType.Daily:
                break;

            case FrequencyType.Weekly:
                recurrencePattern.ByDay = RRuleWrapper.GetByDayList();
                break;

            case FrequencyType.Monthly:
                recurrencePattern.ByDay         = RRuleWrapper.GetByDayList();
                recurrencePattern.ByMonthDay    = RRuleWrapper.ByMonthDay;
                recurrencePattern.BySetPosition = RRuleWrapper.BySetPosition;
                break;

            case FrequencyType.Yearly:
                recurrencePattern.ByDay         = RRuleWrapper.GetByDayList();
                recurrencePattern.ByMonth       = RRuleWrapper.ByMonth;
                recurrencePattern.ByMonthDay    = RRuleWrapper.ByMonthDay;
                recurrencePattern.BySetPosition = RRuleWrapper.BySetPosition;
                break;

            default:
                break;
            }
            if (RRuleWrapper.Count > 0)
            {
                recurrencePattern.Count = RRuleWrapper.Count;
            }
            if (RRuleWrapper.Until.HasValue)
            {
                recurrencePattern.Until = RRuleWrapper.Until.Value;
            }

            //var rRuleResult = new RRuleResult() { RecurrencePatternString = recurrencePattern.ToString(), RecurrencePatternText = recurrencePattern.ToText() };
            var browserLang = Request.Headers["Accept-Language"].ToString().Split(";").FirstOrDefault()?.Split(",").FirstOrDefault();
            var rRuleResult = new RRuleResult()
            {
                RecurrencePatternString = recurrencePattern.ToString(), RecurrencePatternText = recurrencePattern.ToText(new CultureInfo(browserLang))
            };
            var startTime = RRuleWrapper.StartDate != null ? RRuleWrapper.StartDate : DateTime.Now;

            rRuleResult.RecurrencePatternList = RecurringRuleProcessor.GetAppointments(startTime, startTime.AddYears(maxYears), recurrencePattern.ToString()).Take(maxOccurences + 1).ToList();
            if (rRuleResult.RecurrencePatternList.Count > maxOccurences)
            {
                rRuleResult.RecurrencePatternList.RemoveAt(maxOccurences);
                rRuleResult.HintText = $"there are more occurences, only first {maxOccurences} occurences in the next {maxYears} years at most are listed";
            }

            return(new JsonResult(rRuleResult));
        }
Exemplo n.º 4
0
        public IActionResult Index()
        {
            List <RRuleHumanReadableSample> list = new List <RRuleHumanReadableSample>();
            List <string> samples = new List <string>()
            {
                "FREQ=WEEKLY;INTERVAL=1;BYDAY=MO,TU",
                "FREQ=YEARLY;BYDAY=WE;BYSETPOS=-1;BYMONTH=4",
                "FREQ=WEEKLY;BYDAY=MO,WE"
            };

            foreach (var sample in samples)
            {
                var recurrencePattern = new RecurrencePattern(sample);
                list.Add(new RRuleHumanReadableSample()
                {
                    Language = RRuleTextBuilder.GetDefaultCulture().EnglishName, RRule = sample, HumanReadable = recurrencePattern.ToText()
                });
            }

            var defaultCulture = RRuleTextBuilder.GetDefaultCulture();

            foreach (var cultureInfo in RRuleTextBuilder.GetAvailableCultures())
            {
                if (cultureInfo.TwoLetterISOLanguageName == defaultCulture.TwoLetterISOLanguageName)
                {
                    continue;
                }
                foreach (var sample in samples)
                {
                    var recurrencePattern = new RecurrencePattern(sample);
                    list.Add(new RRuleHumanReadableSample()
                    {
                        Language = cultureInfo.EnglishName, RRule = sample, HumanReadable = recurrencePattern.ToText(cultureInfo)
                    });
                }
            }

            return(View(list));
        }