Beispiel #1
0
        public void ParseICS()
        {
            string contents = File.ReadAllText(@"birthday_cal.ics");
            var    calendar = (VCalendar)CalendarObject.Parse(contents);

            this.myfriends = new ArrayList();
            foreach (var item in calendar.Children)
            {
                string name = item.Properties[1].Value;
                string id   = item.Properties[4].Value;
                string date = item.Properties[0].Value;

                friend x = new friend(name, id, date);
                myfriends.Add(x);
                //Console.WriteLine("Name : " + item.Properties[1].Value);
                //Console.WriteLine("ID : " + item.Properties[4].Value);
                //Console.WriteLine("Date : " + item.Properties[0].Value);
            }

            //MessageBox.Show("Parsing Done! See Console");
        }
Beispiel #2
0
        /// <summary>
        /// This is an example of how you can sort calendar object collections
        /// </summary>
        /// <param name="x">The first calendar object</param>
        /// <param name="y">The second calendar object</param>
        /// <remarks>Due to the variety of properties in a calendar object, sorting is left up to the developer
        /// utilizing a comparison delegate.  This example sorts the collection by the start date/time property
        /// and, if they are equal, the summary description.  This is used to handle all of the collection
        /// types.</remarks>
        private static int CalendarSorter(CalendarObject x, CalendarObject y)
        {
            DateTime d1, d2;
            string   summary1, summary2;

            if (x is VEvent)
            {
                VEvent e1 = (VEvent)x, e2 = (VEvent)y;

                d1       = e1.StartDateTime.TimeZoneDateTime;
                d2       = e2.StartDateTime.TimeZoneDateTime;
                summary1 = e1.Summary.Value;
                summary2 = e2.Summary.Value;
            }
            else
            if (x is VToDo)
            {
                VToDo t1 = (VToDo)x, t2 = (VToDo)y;

                d1       = t1.StartDateTime.TimeZoneDateTime;
                d2       = t2.StartDateTime.TimeZoneDateTime;
                summary1 = t1.Summary.Value;
                summary2 = t2.Summary.Value;
            }
            else
            if (x is VJournal)
            {
                VJournal j1 = (VJournal)x, j2 = (VJournal)y;

                d1       = j1.StartDateTime.TimeZoneDateTime;
                d2       = j2.StartDateTime.TimeZoneDateTime;
                summary1 = j1.Summary.Value;
                summary2 = j2.Summary.Value;
            }
            else
            {
                VFreeBusy f1 = (VFreeBusy)x, f2 = (VFreeBusy)y;

                d1       = f1.StartDateTime.TimeZoneDateTime;
                d2       = f2.StartDateTime.TimeZoneDateTime;
                summary1 = f1.Organizer.Value;
                summary2 = f2.Organizer.Value;
            }

            if (d1.CompareTo(d2) == 0)
            {
                if (summary1 == null)
                {
                    summary1 = String.Empty;
                }

                if (summary2 == null)
                {
                    summary2 = String.Empty;
                }

                // For descending order, change this to compare summary 2 to summary 1 instead
                return(String.Compare(summary1, summary2, StringComparison.CurrentCulture));
            }

            // For descending order, change this to compare date 2 to date 1 instead
            return(d1.CompareTo(d2));
        }
 public void ParseUsHolidaysTest()
 {
     var content  = ReadResource("USHolidays.ics");
     var calendar = (VCalendar)CalendarObject.Parse(content);
 }
 public async Task ParseWPEventsCalendar()
 {
     // Modern Tribe's Demo Site (creators of popular WordPress calendar plugin)
     var calendar = await CalendarObject.LoadAsync("https://wpshindig.com/?ical=1");
 }
 public void ParseYogamTest()
 {
     var content  = ReadResource("yogam.ics");
     var calendar = (VCalendar)CalendarObject.Parse(content);
 }
Beispiel #6
0
        //=====================================================================

        /// <summary>
        /// Initialize the dialog controls using the specified object
        /// </summary>
        /// <param name="oCal">The calendar object from which to get the settings</param>
        public void SetValues(CalendarObject oCal)
        {
            string timeZoneId  = null;
            bool   isICalendar = (oCal.Version == SpecificationVersions.iCalendar20);

            // Disable controls that aren't relevant to the vCalendar spec
            txtDuration.Enabled      = txtOrganizer.Enabled = ucRequestStatus.Enabled = txtLatitude.Enabled =
                txtLongitude.Enabled = btnFind.Enabled = cboTimeZone.Enabled = btnApplyTZ.Enabled = isICalendar;

            if (oCal is VEvent e)
            {
                this.Text = "Event Properties";

                lblCompleted.Visible = dtpCompleted.Visible = lblPercent.Visible = udcPercent.Visible = false;
                lblEndDate.Text      = "End";

                // Header
                txtUniqueId.Text       = e.UniqueId.Value;
                chkTransparent.Checked = e.Transparency.IsTransparent;
                txtCreated.Text        = e.DateCreated.TimeZoneDateTime.ToString("G");
                txtLastModified.Text   = e.LastModified.TimeZoneDateTime.ToString("G");
                txtClass.Text          = e.Classification.Value;
                udcSequence.Value      = e.Sequence.SequenceNumber;
                udcPriority.Value      = e.Priority.PriorityValue;

                timeZoneId = e.StartDateTime.TimeZoneId;

                // General
                if (e.StartDateTime.TimeZoneDateTime == DateTime.MinValue)
                {
                    dtpStartDate.Checked = false;
                }
                else
                {
                    dtpStartDate.Value   = e.StartDateTime.TimeZoneDateTime;
                    dtpStartDate.Checked = true;
                }

                if (e.EndDateTime.TimeZoneDateTime == DateTime.MinValue)
                {
                    dtpEndDate.Checked = false;
                }
                else
                {
                    dtpEndDate.Value   = e.EndDateTime.TimeZoneDateTime;
                    dtpEndDate.Checked = true;
                }

                if (e.Duration.DurationValue != Duration.Zero)
                {
                    txtDuration.Text = e.Duration.DurationValue.ToString(Duration.MaxUnit.Weeks);
                }

                txtSummary.Text     = e.Summary.Value;
                txtLocation.Text    = e.Location.Value;
                txtDescription.Text = e.Description.Value;

                // Load status values and set status
                cboStatus.Items.AddRange(new[] { "None", "Tentative", "Confirmed", "Cancelled" });

                if (!cboStatus.Items.Contains(e.Status.StatusValue.ToString()))
                {
                    cboStatus.Items.Add(e.Status.StatusValue.ToString());
                }

                cboStatus.SelectedIndex = cboStatus.Items.IndexOf(e.Status.StatusValue.ToString());

                // We'll edit categories and resources as comma separated strings
                txtCategories.Text = e.Categories.CategoriesString;
                txtResources.Text  = e.Resources.ResourcesString;

                txtOrganizer.Text = e.Organizer.Value;

                // We could bind directly to the existing collections but that would modify them.  To preserve
                // the original items, we'll pass a copy of the collections instead.

                // Attendees
                ucAttendees.BindingSource.DataSource = new AttendeePropertyCollection().CloneRange(e.Attendees);

                // Recurrences and exceptions
                ucRecurrences.SetValues(e.RecurrenceRules, e.RecurDates);
                ucExceptions.SetValues(e.ExceptionRules, e.ExceptionDates);

                // Set attachments
                ucAttachments.SetValues(e.Attachments);

                // Set alarms
                ucAlarms.BindingSource.DataSource = new VAlarmCollection().CloneRange(e.Alarms);

                // Miscellaneous
                txtLatitude.Text  = e.GeographicPosition.Latitude.ToString();
                txtLongitude.Text = e.GeographicPosition.Longitude.ToString();

                ucRequestStatus.BindingSource.DataSource = new RequestStatusPropertyCollection().CloneRange(e.RequestStatuses);

                txtUrl.Text      = e.Url.Value;
                txtComments.Text = e.Comment.Value;
            }
            else if (oCal is VToDo td)
            {
                this.Text = "To-Do Properties";

                chkTransparent.Visible = lblLocation.Visible = txtLocation.Visible = false;

                lblCompleted.Visible = dtpCompleted.Visible = lblPercent.Visible = udcPercent.Visible = true;
                lblEndDate.Text      = "Due";

                // Header
                txtUniqueId.Text     = td.UniqueId.Value;
                txtCreated.Text      = td.DateCreated.TimeZoneDateTime.ToString("G");
                txtLastModified.Text = td.LastModified.TimeZoneDateTime.ToString("G");
                txtClass.Text        = td.Classification.Value;
                udcSequence.Value    = td.Sequence.SequenceNumber;
                udcPriority.Value    = td.Priority.PriorityValue;

                timeZoneId = td.StartDateTime.TimeZoneId;

                // General
                if (td.StartDateTime.TimeZoneDateTime == DateTime.MinValue)
                {
                    dtpStartDate.Checked = false;
                }
                else
                {
                    dtpStartDate.Value   = td.StartDateTime.TimeZoneDateTime;
                    dtpStartDate.Checked = true;
                }

                // We'll reuse End Date for Due Date
                if (td.DueDateTime.TimeZoneDateTime == DateTime.MinValue)
                {
                    dtpEndDate.Checked = false;
                }
                else
                {
                    dtpEndDate.Value   = td.DueDateTime.TimeZoneDateTime;
                    dtpEndDate.Checked = true;
                }

                if (td.CompletedDateTime.TimeZoneDateTime == DateTime.MinValue)
                {
                    dtpCompleted.Checked = false;
                }
                else
                {
                    dtpCompleted.Value   = td.CompletedDateTime.TimeZoneDateTime;
                    dtpCompleted.Checked = true;
                }

                if (td.Duration.DurationValue != Duration.Zero)
                {
                    txtDuration.Text = td.Duration.DurationValue.
                                       ToString(Duration.MaxUnit.Weeks);
                }

                udcPercent.Value    = td.PercentComplete.Percentage;
                txtSummary.Text     = td.Summary.Value;
                txtDescription.Text = td.Description.Value;

                // Load status values and set status
                cboStatus.Items.AddRange(new[] { "None", "NeedsAction", "Completed", "InProcess", "Cancelled" });

                if (!cboStatus.Items.Contains(td.Status.StatusValue.ToString()))
                {
                    cboStatus.Items.Add(td.Status.StatusValue.ToString());
                }

                cboStatus.SelectedIndex = cboStatus.Items.IndexOf(td.Status.StatusValue.ToString());

                // We'll edit categories and resources as comma separated strings
                txtCategories.Text = td.Categories.CategoriesString;
                txtResources.Text  = td.Resources.ResourcesString;

                txtOrganizer.Text = td.Organizer.Value;

                // We could bind directly to the existing collections but that would modify them.  To preserve
                // the original items, we'll pass a copy of the collections instead.

                // Attendees
                ucAttendees.BindingSource.DataSource = new AttendeePropertyCollection().CloneRange(td.Attendees);

                // Recurrences and exceptions
                ucRecurrences.SetValues(td.RecurrenceRules, td.RecurDates);
                ucExceptions.SetValues(td.ExceptionRules, td.ExceptionDates);

                // Set attachments
                ucAttachments.SetValues(td.Attachments);

                // Set alarms
                ucAlarms.BindingSource.DataSource = new VAlarmCollection().CloneRange(td.Alarms);

                // Miscellaneous
                txtLatitude.Text  = td.GeographicPosition.Latitude.ToString();
                txtLongitude.Text = td.GeographicPosition.Longitude.ToString();

                ucRequestStatus.BindingSource.DataSource = new RequestStatusPropertyCollection().CloneRange(td.RequestStatuses);

                txtUrl.Text      = td.Url.Value;
                txtComments.Text = td.Comment.Value;
            }
            else if (oCal is VJournal j)
            {
                this.Text = "Journal Properties";

                chkTransparent.Visible               = lblPriority.Visible = udcPriority.Visible = lblEndDate.Visible =
                    dtpEndDate.Visible               = lblDuration.Visible = txtDuration.Visible = lblLocation.Visible =
                        txtLocation.Visible          = lblResources.Visible = txtResources.Visible = lblLatitude.Visible =
                            txtLatitude.Visible      = lblLongitude.Visible = txtLongitude.Visible = btnFind.Visible =
                                lblCompleted.Visible = dtpCompleted.Visible = lblPercent.Visible = udcPercent.Visible = false;

                tabInfo.TabPages.Remove(pgAlarms);
                tabInfo.SelectedTab = pgGeneral;

                // Header
                txtUniqueId.Text     = j.UniqueId.Value;
                txtCreated.Text      = j.DateCreated.TimeZoneDateTime.ToString("G");
                txtLastModified.Text = j.LastModified.TimeZoneDateTime.ToString("G");
                txtClass.Text        = j.Classification.Value;
                udcSequence.Value    = j.Sequence.SequenceNumber;

                timeZoneId = j.StartDateTime.TimeZoneId;

                // General
                if (j.StartDateTime.TimeZoneDateTime == DateTime.MinValue)
                {
                    dtpStartDate.Checked = false;
                }
                else
                {
                    dtpStartDate.Value   = j.StartDateTime.TimeZoneDateTime;
                    dtpStartDate.Checked = true;
                }

                txtSummary.Text     = j.Summary.Value;
                txtDescription.Text = j.Description.Value;

                // Load status values and set status
                cboStatus.Items.AddRange(new[] { "None", "Draft", "Final", "Cancelled" });

                if (!cboStatus.Items.Contains(j.Status.StatusValue.ToString()))
                {
                    cboStatus.Items.Add(j.Status.StatusValue.ToString());
                }

                cboStatus.SelectedIndex = cboStatus.Items.IndexOf(j.Status.StatusValue.ToString());

                // We'll edit categories as a comma separated string
                txtCategories.Text = j.Categories.CategoriesString;

                txtOrganizer.Text = j.Organizer.Value;

                // We could bind directly to the existing collections but that would modify them.  To preserve
                // the original items, we'll pass a copy of the collections instead.

                // Attendees
                ucAttendees.BindingSource.DataSource = new AttendeePropertyCollection().CloneRange(j.Attendees);

                // Recurrences and exceptions
                ucRecurrences.SetValues(j.RecurrenceRules, j.RecurDates);
                ucExceptions.SetValues(j.ExceptionRules, j.ExceptionDates);

                // Set attachments
                ucAttachments.SetValues(j.Attachments);

                // Miscellaneous
                ucRequestStatus.BindingSource.DataSource = new RequestStatusPropertyCollection().CloneRange(j.RequestStatuses);

                txtUrl.Text      = j.Url.Value;
                txtComments.Text = j.Comment.Value;
            }

            // We use the start date's time zone ID for the combo box.  It should represent the time zone used
            // throughout the component.
            if (timeZoneId == null)
            {
                cboTimeZone.SelectedIndex = timeZoneIdx = 0;
            }
            else
            {
                timeZoneIdx = cboTimeZone.Items.IndexOf(timeZoneId);

                if (timeZoneIdx != -1)
                {
                    cboTimeZone.SelectedIndex = timeZoneIdx;
                }
                else
                {
                    cboTimeZone.SelectedIndex = timeZoneIdx = 0;
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Update the calendar object with the dialog control values
        /// </summary>
        /// <param name="oCal">The calendar object in which the settings are updated</param>
        public void GetValues(CalendarObject oCal)
        {
            // We'll use the TimeZoneDateTime property on all date/time values so that they are set literally
            // rather than being converted to the time zone as would happen with the DateTimeValue property.
            if (oCal is VEvent e)
            {
                // Header.  Unique ID and Created Date are not changed
                e.Transparency.IsTransparent    = chkTransparent.Checked;
                e.LastModified.TimeZoneDateTime = DateTime.Now;
                e.Classification.Value          = txtClass.Text;
                e.Sequence.SequenceNumber       = (int)udcSequence.Value;
                e.Priority.PriorityValue        = (int)udcPriority.Value;

                // General
                if (!dtpStartDate.Checked)
                {
                    e.StartDateTime.TimeZoneDateTime = DateTime.MinValue;
                }
                else
                {
                    e.StartDateTime.TimeZoneDateTime = dtpStartDate.Value;
                    e.StartDateTime.ValueLocation    = ValLocValue.DateTime;
                }

                if (!dtpEndDate.Checked)
                {
                    e.EndDateTime.TimeZoneDateTime = DateTime.MinValue;
                }
                else
                {
                    e.EndDateTime.TimeZoneDateTime = dtpEndDate.Value;
                    e.EndDateTime.ValueLocation    = ValLocValue.DateTime;
                }

                e.Duration.DurationValue = new Duration(txtDuration.Text);
                e.Summary.Value          = txtSummary.Text;
                e.Location.Value         = txtLocation.Text;
                e.Description.Value      = txtDescription.Text;

                // Get status value
                e.Status.StatusValue = (StatusValue)Enum.Parse(typeof(StatusValue),
                                                               cboStatus.Items[cboStatus.SelectedIndex].ToString(), true);

                // We'll edit categories and resources as comma separated strings
                e.Categories.CategoriesString = txtCategories.Text;
                e.Resources.ResourcesString   = txtResources.Text;

                e.Organizer.Value = txtOrganizer.Text;

                // For the collections, we'll clear the existing items and copy the modified items from the
                // browse control binding sources.

                // Attendees
                e.Attendees.Clear();
                e.Attendees.CloneRange((AttendeePropertyCollection)ucAttendees.BindingSource.DataSource);

                // Recurrences and exceptions.
                ucRecurrences.GetValues(e.RecurrenceRules, e.RecurDates);
                ucExceptions.GetValues(e.ExceptionRules, e.ExceptionDates);

                // Get attachments
                ucAttachments.GetValues(e.Attachments);

                // Get alarms
                e.Alarms.Clear();
                e.Alarms.CloneRange((VAlarmCollection)ucAlarms.BindingSource.DataSource);

                // Miscellaneous
                if (txtLatitude.Text.Length != 0 || txtLongitude.Text.Length != 0)
                {
                    e.GeographicPosition.Latitude  = Convert.ToDouble(txtLatitude.Text, CultureInfo.CurrentCulture);
                    e.GeographicPosition.Longitude = Convert.ToDouble(txtLongitude.Text, CultureInfo.CurrentCulture);
                }
                else
                {
                    e.GeographicPosition.Latitude = e.GeographicPosition.Longitude = 0.0F;
                }

                e.RequestStatuses.Clear();
                e.RequestStatuses.CloneRange((RequestStatusPropertyCollection)ucRequestStatus.BindingSource.DataSource);

                e.Url.Value     = txtUrl.Text;
                e.Comment.Value = txtComments.Text;
            }
            else if (oCal is VToDo td)
            {
                // Header.  Unique ID and Created Date are not changed
                td.LastModified.TimeZoneDateTime = DateTime.Now;
                td.Classification.Value          = txtClass.Text;
                td.Sequence.SequenceNumber       = (int)udcSequence.Value;
                td.Priority.PriorityValue        = (int)udcPriority.Value;

                // General
                if (!dtpStartDate.Checked)
                {
                    td.StartDateTime.TimeZoneDateTime = DateTime.MinValue;
                }
                else
                {
                    td.StartDateTime.TimeZoneDateTime = dtpStartDate.Value;
                    td.StartDateTime.ValueLocation    = ValLocValue.DateTime;
                }

                if (!dtpEndDate.Checked)
                {
                    td.DueDateTime.TimeZoneDateTime = DateTime.MinValue;
                }
                else
                {
                    td.DueDateTime.TimeZoneDateTime = dtpEndDate.Value;
                    td.DueDateTime.ValueLocation    = ValLocValue.DateTime;
                }

                if (!dtpCompleted.Checked)
                {
                    td.CompletedDateTime.TimeZoneDateTime = DateTime.MinValue;
                }
                else
                {
                    td.CompletedDateTime.TimeZoneDateTime = dtpCompleted.Value;
                    td.CompletedDateTime.ValueLocation    = ValLocValue.DateTime;
                }

                td.PercentComplete.Percentage = (int)udcPercent.Value;
                td.Duration.DurationValue     = new Duration(txtDuration.Text);
                td.Summary.Value     = txtSummary.Text;
                td.Description.Value = txtDescription.Text;

                // Get status value
                td.Status.StatusValue = (StatusValue)Enum.Parse(typeof(StatusValue),
                                                                cboStatus.Items[cboStatus.SelectedIndex].ToString(), true);

                // We'll edit categories and resources as comma separated strings
                td.Categories.CategoriesString = txtCategories.Text;
                td.Resources.ResourcesString   = txtResources.Text;

                td.Organizer.Value = txtOrganizer.Text;

                // For the collections, we'll clear the existing items and copy the modified items from the
                // browse control binding sources.

                // Attendees
                td.Attendees.Clear();
                td.Attendees.CloneRange((AttendeePropertyCollection)ucAttendees.BindingSource.DataSource);

                // Recurrences and exceptions.
                ucRecurrences.GetValues(td.RecurrenceRules, td.RecurDates);
                ucExceptions.GetValues(td.ExceptionRules, td.ExceptionDates);

                // Get attachments
                ucAttachments.GetValues(td.Attachments);

                // Get alarms
                td.Alarms.Clear();
                td.Alarms.CloneRange((VAlarmCollection)ucAlarms.BindingSource.DataSource);

                // Miscellaneous
                if (txtLatitude.Text.Length != 0 || txtLongitude.Text.Length != 0)
                {
                    td.GeographicPosition.Latitude  = Convert.ToDouble(txtLatitude.Text, CultureInfo.CurrentCulture);
                    td.GeographicPosition.Longitude = Convert.ToDouble(txtLongitude.Text, CultureInfo.CurrentCulture);
                }
                else
                {
                    td.GeographicPosition.Latitude = td.GeographicPosition.Longitude = 0.0F;
                }

                td.RequestStatuses.Clear();
                td.RequestStatuses.CloneRange((RequestStatusPropertyCollection)ucRequestStatus.BindingSource.DataSource);

                td.Url.Value     = txtUrl.Text;
                td.Comment.Value = txtComments.Text;
            }
            else if (oCal is VJournal j)
            {
                // Header.  Unique ID and Created Date are not changed
                j.LastModified.TimeZoneDateTime = DateTime.Now;
                j.Classification.Value          = txtClass.Text;
                j.Sequence.SequenceNumber       = (int)udcSequence.Value;

                // General
                if (!dtpStartDate.Checked)
                {
                    j.StartDateTime.TimeZoneDateTime = DateTime.MinValue;
                }
                else
                {
                    j.StartDateTime.TimeZoneDateTime = dtpStartDate.Value;
                    j.StartDateTime.ValueLocation    = ValLocValue.DateTime;
                }

                j.Summary.Value     = txtSummary.Text;
                j.Description.Value = txtDescription.Text;

                // Get status value
                j.Status.StatusValue = (StatusValue)Enum.Parse(typeof(StatusValue),
                                                               cboStatus.Items[cboStatus.SelectedIndex].ToString(), true);

                // We'll edit categories as a comma separated string
                j.Categories.CategoriesString = txtCategories.Text;

                j.Organizer.Value = txtOrganizer.Text;

                // For the collections, we'll clear the existing items and copy the modified items from the
                // browse control binding sources.

                // Attendees
                j.Attendees.Clear();
                j.Attendees.CloneRange((AttendeePropertyCollection)ucAttendees.BindingSource.DataSource);

                // Recurrences and exceptions.
                ucRecurrences.GetValues(j.RecurrenceRules, j.RecurDates);
                ucExceptions.GetValues(j.ExceptionRules, j.ExceptionDates);

                // Get attachments
                ucAttachments.GetValues(j.Attachments);

                // Miscellaneous
                j.RequestStatuses.Clear();
                j.RequestStatuses.CloneRange((RequestStatusPropertyCollection)ucRequestStatus.BindingSource.DataSource);

                j.Url.Value     = txtUrl.Text;
                j.Comment.Value = txtComments.Text;
            }

            // Set the time zone in the object after getting all the data.  The "Set" method will not modify the
            // date/times like the "Apply" method does.
            if (cboTimeZone.Enabled && cboTimeZone.SelectedIndex != 0)
            {
                oCal.SetTimeZone(VCalendar.TimeZones[cboTimeZone.SelectedIndex - 1]);
            }
            else
            {
                oCal.SetTimeZone(null);
            }
        }