Exemple #1
0
        /// <summary>
        /// Generate instances for the specified component
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event parameters</param>
        protected void btnTest_Click(object sender, EventArgs e)
        {
            RecurringObject            ro = null;
            DateTimeInstanceCollection instances;
            string   calendar;
            int      start;
            double   elapsed;
            DateTime startDate, endDate;

            try
            {
                lblCount.Text = String.Empty;

                if (!DateTime.TryParse(txtStartDate.Text, CultureInfo.CurrentCulture, DateTimeStyles.None,
                                       out startDate) || !DateTime.TryParse(txtEndDate.Text, CultureInfo.CurrentCulture,
                                                                            DateTimeStyles.None, out endDate))
                {
                    lblCount.Text = "Invalid start or end date/time format";
                    return;
                }

                // Wrap it in VCALENDAR tags and parse it
                calendar = String.Format("BEGIN:VCALENDAR\nVERSION:2.0\n{0}\nEND:VCALENDAR", txtCalendar.Text);

                VCalendar cal = VCalendarParser.ParseFromString(calendar);

                // Get the first event, to-do, or journal item
                if (cal.Events.Count > 0)
                {
                    ro = cal.Events[0];
                }
                else
                if (cal.ToDos.Count > 0)
                {
                    ro = cal.ToDos[0];
                }
                else
                if (cal.Journals.Count > 0)
                {
                    ro = cal.Journals[0];
                }

                if (ro == null)
                {
                    lblCount.Text = "No event, to-do, or journal item found";
                    return;
                }

                // Apply the time zone to the calendar.  If "None" is selected, the time zone will be cleared on
                // all items.
                if (cboTimeZone.SelectedIndex < 1)
                {
                    cal.ApplyTimeZone(null);
                }
                else
                {
                    cal.ApplyTimeZone(VCalendar.TimeZones[cboTimeZone.SelectedIndex - 1]);
                }

                foreach (RRuleProperty rrule in ro.RecurrenceRules)
                {
                    ApplyLimits(ro, rrule.Recurrence);
                }

                foreach (ExRuleProperty exrule in ro.ExceptionRules)
                {
                    ApplyLimits(ro, exrule.Recurrence);
                }

                txtCalendar.Text = ro.ToString();

                start     = System.Environment.TickCount;
                instances = ro.InstancesBetween(startDate, endDate, chkInLocalTime.Checked);
                elapsed   = (System.Environment.TickCount - start) / 1000.0;

                cal.Dispose();

                // The date instance contains the start and end date/times, the duration, and time zone
                // information.  The duration is based on the duration of the calendar component.  The time zone
                // information is based on the "In Local Time" parameter of the InstancesBetween() method and
                // whether or not the component has a Time Zone ID specified.
                dlDates.DataSource = instances;
                dlDates.DataBind();

                // If nothing was found remind the user that they may need to adjust the start and end date range
                // to find stuff within the item.
                if (instances.Count == 0)
                {
                    lblCount.Text = "Nothing found.  If this was unexpected, check the limiting date range " +
                                    "in the two date/time text boxes at the top of the form and the calendar item date/time " +
                                    "properties to make sure that they do overlap<br/><br/>";
                }

                lblCount.Text += String.Format("Found {0:N0} instances in {1:N2} seconds ({2:N2} instances/second)",
                                               instances.Count, elapsed, instances.Count / elapsed);
            }
            catch (Exception ex)
            {
                lblCount.Text = ex.Message;
            }
        }
Exemple #2
0
        /// <summary>
        /// Test the recurrence within the specified iCalendar component
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void btnTest_Click(object sender, EventArgs e)
        {
            RecurringObject            ro = null;
            DateTimeInstanceCollection instances;
            string calendar;
            int    start;
            double elapsed;

            try
            {
                lblCount.Text = null;

                // Wrap it in VCALENDAR tags and parse it
                calendar = String.Format("BEGIN:VCALENDAR\nVERSION:2.0\n{0}\nEND:VCALENDAR", txtCalendar.Text);

                VCalendar cal = VCalendarParser.ParseFromString(calendar);

                // Get the first event, to-do, or journal item
                if (cal.Events.Count > 0)
                {
                    ro = cal.Events[0];
                }
                else
                if (cal.ToDos.Count > 0)
                {
                    ro = cal.ToDos[0];
                }
                else
                if (cal.Journals.Count > 0)
                {
                    ro = cal.Journals[0];
                }

                if (ro == null)
                {
                    lblCount.Text = "No event, to-do, or journal item found";
                    return;
                }

                // Apply the time zone to the calendar.  If "None" is selected, the time zone will be cleared on
                // all items.
                if (cboTimeZone.SelectedIndex < 1)
                {
                    cal.ApplyTimeZone(null);
                }
                else
                {
                    cal.ApplyTimeZone(VCalendar.TimeZones[cboTimeZone.SelectedIndex - 1]);
                }

                txtCalendar.Text = ro.ToString();

                lbDates.Items.Clear();
                this.Cursor = Cursors.WaitCursor;

                start     = System.Environment.TickCount;
                instances = ro.InstancesBetween(dtpStartDate.Value, dtpEndDate.Value, chkInLocalTime.Checked);
                elapsed   = (System.Environment.TickCount - start) / 1000.0;

                cal.Dispose();

                // The date instance contains the start and end date/times, the duration, and time zone
                // information.  The duration is based on the duration of the calendar component.  The time
                // zone information is based on the "In Local Time" parameter of the InstancesBetween() method
                // and whether or not the component has a Time Zone ID specified.
                foreach (DateTimeInstance dti in instances)
                {
                    lbDates.Items.Add(String.Format("{0:G} {1} to {2:G} {3} ({4})", dti.StartDateTime,
                                                    dti.AbbreviatedStartTimeZoneName, dti.EndDateTime, dti.AbbreviatedEndTimeZoneName,
                                                    dti.Duration.ToDescription()));

                    if (lbDates.Items.Count > 5000)
                    {
                        lblCount.Text += "A large number of instances were returned.  Only the first 5000 " +
                                         "have been loaded into the list box.\r\n";
                        break;
                    }
                }

                // If nothing was found remind the user that they may need to adjust the start and end date range
                // to find stuff within the item.
                if (instances.Count == 0)
                {
                    MessageBox.Show("Nothing found.  If this was unexpected, check the limiting date range in " +
                                    "the two date/time text boxes at the top of the form and the calendar item date/time " +
                                    "properties to make sure that they do overlap");
                }

                lblCount.Text += String.Format("Found {0:N0} instances in {1:N2} seconds ({2:N2} instances/second)",
                                               instances.Count, elapsed, instances.Count / elapsed);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }