public static List <IEvent> parseics(String path)
        {
            try
            {
                IICalendarCollection    calendars    = iCalendar.LoadFromFile(@path);
                List <IDateTime>        listdatetime = new List <IDateTime>();
                List <DDay.iCal.IEvent> listevent    = new List <DDay.iCal.IEvent>();

                IList <Occurrence> occurrences = calendars.GetOccurrences(new DateTime(2017, 1, 1), new DateTime(2018, 3, 26));


                int i = 0;
                foreach (Occurrence occurrence in occurrences)
                {
                    DateTime            occurrenceTime = occurrence.Period.StartTime.Local.AddHours(1);
                    IRecurringComponent rc             = occurrence.Source as IRecurringComponent;
                    if (rc != null)
                    {
                        rc.Calendar.Events[i].Start.AddHours(1);
                        rc.Calendar.Events[i].End.AddHours(1);
                        listevent.Add(rc.Calendar.Events[i]);
                        i++;
                    }
                }

                return(listevent);
            }
            catch (Exception e) {
                Console.WriteLine("ERREUR : " + e.Message);
                return(null);
            }
        }
Пример #2
0
        static void DoCalendarStuff()
        {
            IICalendarCollection calendars = iCalendar.LoadFromFile(@"a.ics");

            // Termine in den nächsten 2 Tagen finden. Wenn gefunden: Alarmicon!
            IList <Occurrence> occurrences = calendars.GetOccurrences(DateTime.Today.AddDays(1), DateTime.Today.AddDays(2));

            foreach (Occurrence occurrence in occurrences)
            {
                DateTime occurrenceTime = occurrence.Period.StartTime.Local;
                if (occurrence.Source is IRecurringComponent rc)
                {
                    if (CheckMessage(rc.Summary, occurrenceTime))
                    {
                        text += rc.Summary + ": " + occurrenceTime.ToShortDateString() + CRLF;
                    }
                }
            }

            // Wenn Termine gefunden, dann Alarmicon. Sonst den Nächstbesten suchen, aber keinen Alarm und kein Balloon.
            if (text != "")
            {
                lock (notifyIcon)
                {
                    notifyIcon.Icon = iconAchtung;
                    ShowBalloon();
                }
            }
            else
            {
                // Wenn keine Termime in den nächsten 2 Tagen anliegen, dann den nächsten suchen, aber Icon nicht setzen und
                // Balloon nicht auslösen
                occurrences = calendars.GetOccurrences(DateTime.Today.AddDays(3), DateTime.Today.AddDays(365));
                foreach (Occurrence occurrence in occurrences)
                {
                    DateTime occurrenceTime = occurrence.Period.StartTime.Local;
                    if (occurrence.Source is IRecurringComponent rc)
                    {
                        if (CheckMessage(rc.Summary, occurrenceTime))
                        {
                            text = "Nächster: " + rc.Summary + ": " + occurrenceTime.ToShortDateString() + CRLF;
                            break;
                        }
                    }
                }
            }
        }
Пример #3
0
        static void Main(string[] args)
        {
            // Load the calendar file
            IICalendarCollection calendars = iCalendar.LoadFromFile(@"Business.ics");

            //
            // Get all events that occur today.
            //
            IList <Occurrence> occurrences = calendars.GetOccurrences(DateTime.Today, DateTime.Today.AddDays(1));

            Console.WriteLine("Today's Events:");

            // Iterate through each occurrence and display information about it
            foreach (Occurrence occurrence in occurrences)
            {
                DateTime            occurrenceTime = occurrence.Period.StartTime.Local;
                IRecurringComponent rc             = occurrence.Source as IRecurringComponent;
                if (rc != null)
                {
                    Console.WriteLine(rc.Summary + ": " + occurrenceTime.ToShortTimeString());
                }
            }

            //
            // Get all occurrences for the next 7 days, starting tomorrow.
            //
            occurrences = calendars.GetOccurrences(DateTime.Today.AddDays(1), DateTime.Today.AddDays(7));

            Console.WriteLine(Environment.NewLine + "Upcoming Events:");

            // Start with tomorrow
            foreach (Occurrence occurrence in occurrences)
            {
                DateTime            occurrenceTime = occurrence.Period.StartTime.Local;
                IRecurringComponent rc             = occurrence.Source as IRecurringComponent;
                if (rc != null)
                {
                    Console.WriteLine(rc.Summary + ": " + occurrenceTime.ToString());
                }
            }
        }
Пример #4
0
        protected List <string> GetUpcomingEvents(string filepath)
        {
            IICalendarCollection calendars    = Calendar.LoadFromFile(Path.Combine(@"C:\ICSFiles\" + filepath + ".ics"));
            IList <Occurrence>   occurrencesn = calendars.GetOccurrences(DateTime.Today.AddDays(1), DateTime.Today.AddDays(7)).ToList();
            List <string>        Events       = new List <string>();

            foreach (Occurrence occurrence in occurrencesn)
            {
                DateTime            occurrenceTime  = occurrence.Period.StartTime.AsSystemLocal;
                DateTime            occurrenceTimee = occurrence.Period.EndTime.AsSystemLocal;
                IRecurringComponent rc = occurrence.Source as IRecurringComponent;
                if (rc != null)
                {
                    Events.Add(rc.Summary + ": " + occurrenceTime.ToShortTimeString() + " - " + occurrenceTimee.ToShortTimeString());
                }
            }

            return(Events);
        }
Пример #5
0
        protected void loadButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                string saveDir = @"\Calendars\";
                string appPath = Request.PhysicalApplicationPath;
                //Getting the duration and max days to check
                int  durationMinutes, maxDays;
                bool minutesInputBool = int.TryParse(minutesInput.Text, out durationMinutes);
                bool maxDaysBool      = int.TryParse(maxDaysInput.Text, out maxDays);
                if (FileUpload1.HasFile && FileUpload2.HasFile)
                {
                    //Saving both calendars
                    string savePath1 = appPath + saveDir + Server.HtmlEncode(FileUpload1.FileName);
                    FileUpload1.SaveAs(savePath1);
                    string savePath2 = appPath + saveDir + Server.HtmlEncode(FileUpload2.FileName);
                    FileUpload2.SaveAs(savePath2);

                    //Creating the calendars and getting the occurences (events).
                    IICalendarCollection firstCalendar  = iCalendar.LoadFromFile(savePath1);
                    IICalendarCollection secondCalendar = iCalendar.LoadFromFile(savePath2);
                    IList <Occurrence>   occurrences1   = firstCalendar.GetOccurrences(DateTime.Today, DateTime.Today.AddDays(maxDays));
                    IList <Occurrence>   occurrences2   = secondCalendar.GetOccurrences(DateTime.Today, DateTime.Today.AddDays(maxDays));
                    List <DateTime>      freeSlots      = new List <DateTime>();

                    //This list will contain all the occurences from both calendars
                    List <Occurrence> allOccurences = new List <Occurrence>();
                    //Merging the calendars into @allOccurences
                    mergeCalendars(occurrences1, occurrences2, allOccurences);
                    //Finding free spots
                    findFreeSpots(durationMinutes, maxDays, freeSlots, allOccurences);

                    Label1.Text = "This options are available:<br />";
                    //Printing all the available spots
                    foreach (DateTime dt in freeSlots)
                    {
                        Label1.Text += dt.ToShortDateString() + " at " + dt.ToShortTimeString() + "<br />";
                    }
                }
                minutesInput.Text = "";
                maxDaysInput.Text = "";
            }
        }
Пример #6
0
        public ActionResult ImportEvents(HttpPostedFileBase file, string from = "", string to = "", bool showEndDate = false)
        {
            int courseId = ActiveCourseUser.AbstractCourseID;

            DateTime fromDate  = new DateTime();
            DateTime toDate    = new DateTime();
            bool     fromParse = false;
            bool     toParse   = false;

            fromParse = DateTime.TryParse(from, out fromDate);
            toParse   = DateTime.TryParse(to, out toDate);

            IICalendarCollection calendars = iCalendar.LoadFromStream(new StreamReader(file.InputStream));

            IList <Occurrence> occurrences = fromParse && toParse?calendars.GetOccurrences(fromDate, toDate) : calendars.GetOccurrences(DateTime.Today.AddYears(-1), DateTime.Today.AddYears(1));  //if no range specified, arbitrarily choose +/- 1 year max future/past range

            List <OSBLE.Models.HomePage.Event> events = new List <OSBLE.Models.HomePage.Event>();
            List <OSBLE.Models.HomePage.Event> nullDescriptionEvents = new List <OSBLE.Models.HomePage.Event>();

            foreach (Occurrence occurrence in occurrences)
            {
                IRecurringComponent component = occurrence.Source as IRecurringComponent;

                OSBLE.Models.HomePage.Event newEvent = new OSBLE.Models.HomePage.Event
                {
                    Poster    = ActiveCourseUser,
                    Approved  = true,
                    StartDate = DateTime.SpecifyKind(occurrence.Period.StartTime.Local.Date, DateTimeKind.Unspecified).CourseToUTC(courseId),
                    EndDate   = showEndDate ?
                                (occurrence.Period.EndTime.IsUniversalTime ?
                                 DateTime.SpecifyKind(occurrence.Period.EndTime.Local.Date, DateTimeKind.Unspecified) :
                                 DateTime.SpecifyKind(occurrence.Period.EndTime.Local.Date, DateTimeKind.Unspecified).CourseToUTC(courseId)) :
                                (DateTime?)null,
                    StartTime = occurrence.Period.StartTime.IsUniversalTime ?
                                DateTime.SpecifyKind(occurrence.Period.StartTime.Local, DateTimeKind.Unspecified) :
                                DateTime.SpecifyKind(occurrence.Period.StartTime.Local, DateTimeKind.Unspecified).CourseToUTC(courseId),
                    EndTime = occurrence.Period.EndTime.IsUniversalTime ?
                              DateTime.SpecifyKind(occurrence.Period.EndTime.Local, DateTimeKind.Unspecified) :
                              DateTime.SpecifyKind(occurrence.Period.EndTime.Local, DateTimeKind.Unspecified).CourseToUTC(courseId),
                    Description = component.Description,
                    Title       = String.IsNullOrEmpty(((DDay.iCal.Event)component).Location) ?
                                  component.Summary :
                                  component.Summary + " - " + ((DDay.iCal.Event)component).Location,
                };

                if (String.IsNullOrEmpty(newEvent.Description))
                {
                    nullDescriptionEvents.Add(newEvent);
                }
                else
                {
                    events.Add(newEvent);
                }
            }

            //add non duplicate events with null description. doing this because it seems google saves an additional event when you
            //edit an event in a recurring series to add more description
            foreach (var nullDescriptionEvent in nullDescriptionEvents)
            {
                if (events.Where(e => e.StartDate == nullDescriptionEvent.StartDate &&
                                 e.EndDate == nullDescriptionEvent.EndDate &&
                                 e.StartTime == nullDescriptionEvent.StartTime &&
                                 e.EndTime == nullDescriptionEvent.EndTime).Count() == 0)
                {
                    events.Add(nullDescriptionEvent);
                }
            }

            CreateEvents(events);

            return(RedirectToAction("Index", "Event"));
        }