-
-
Save nozzlegear/756f07b2d4bc34930e26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using DDay.iCal; | |
using Newtonsoft.Json; | |
public class YourClass | |
{ | |
public string YourMethod() | |
{ | |
//Download the .ics file using DDay.iCal package from nuget (install-package dday.ical) | |
var calendar = iCalendar.LoadFromUri(new Uri("http://spacexstats.com/calendar.php?launch=all")).FirstOrDefault(); | |
//Ensure calendar is not null | |
if (calendar != null) | |
{ | |
//Get the first event ordered by start date. | |
var calEvent = calendar.Events.OrderBy(x => x.Start).FirstOrDefault(); | |
//Ensure event is not null | |
if (calEvent != null) | |
{ | |
//Will return something like this: "Event found. Summary: AsiaSat 6 Launch. Description: AsiaSat 6 is a communications satellite being launched for Asia Satellite Telecommunications Company Ltd. Once in orbit, it will be renamed AsiaSat 6 / Thaicom 7.. Start Date: Aug 26, 2014 UTC. End Date: Aug 26, 2014 UTC." | |
return String.Format("Event found. Summary: {0}. Description: {1}. Start Date: {2}. End Date: {3}.", calEvent.Summary, calEvent.Description, calEvent.Start.ToString("MMM dd, yyyy"), calEvent.End.ToString("MMM dd, yyyy")); | |
} | |
else | |
{ | |
return "This calendar does not contain any events."; | |
} | |
} | |
else | |
{ | |
return "This calendar was not found."; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment