public static IEnumerable <Post> ToPosts(this IList <Occurrence> occurrences)
        {
            foreach (Occurrence occurrence in occurrences)
            {
                IRecurringComponent rc = occurrence.Source as IRecurringComponent;
                if (rc != null)
                {
                    IEvent ev = occurrence.Source as IEvent;

                    Post post = new Post();
                    post.Title           = rc.Summary;
                    post.Name            = "FAKEPOST";
                    post.CategoryId      = categoryId;
                    post["Event Date"]   = occurrence.Period.StartTime.Local.ToShortDateString();
                    post["Start Time"]   = occurrence.Period.StartTime.Local.ToShortTimeString();
                    post["End Time"]     = occurrence.Period.EndTime.Local.ToShortTimeString();
                    post["External Url"] = rc.Url == null ? null : rc.Url.ToString();
                    post["UID"]          = rc.UID;
                    post["Description"]  = rc.Description;

                    if (ev != null)
                    {
                        post["Location"] = ev.Location;
                    }

                    post.ContentType = "External";

                    yield return(post);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Gets a list of alarm occurrences for the given recurring component, <paramref name="rc"/>
        /// that occur between <paramref name="fromDate"/> and <paramref name="toDate"/>.
        /// </summary>
        public virtual IList <AlarmOccurrence> GetOccurrences(IRecurringComponent rc, IDateTime fromDate, IDateTime toDate)
        {
            Occurrences.Clear();

            if (Trigger != null)
            {
                // If the trigger is relative, it can recur right along with
                // the recurring items, otherwise, it happens once and
                // only once (at a precise time).
                if (Trigger.IsRelative)
                {
                    // Ensure that "FromDate" has already been set
                    if (fromDate == null)
                    {
                        fromDate = rc.Start.Copy <IDateTime>();
                    }

                    var d = default(TimeSpan);
                    foreach (var o in rc.GetOccurrences(fromDate, toDate))
                    {
                        var dt = o.Period.StartTime;
                        if (Trigger.Related == TriggerRelation.End)
                        {
                            if (o.Period.EndTime != null)
                            {
                                dt = o.Period.EndTime;
                                if (d == default(TimeSpan))
                                {
                                    d = o.Period.Duration;
                                }
                            }
                            // Use the "last-found" duration as a reference point
                            else if (d != default(TimeSpan))
                            {
                                dt = o.Period.StartTime.Add(d);
                            }
                            else
                            {
                                throw new ArgumentException(
                                          "Alarm trigger is relative to the END of the occurrence; however, the occurence has no discernible end.");
                            }
                        }

                        Occurrences.Add(new AlarmOccurrence(this, dt.Add(Trigger.Duration.Value), rc));
                    }
                }
                else
                {
                    var dt = Trigger.DateTime.Copy <IDateTime>();
                    dt.AssociatedObject = this;
                    Occurrences.Add(new AlarmOccurrence(this, dt, rc));
                }

                // If a REPEAT and DURATION value were specified,
                // then handle those repetitions here.
                AddRepeatedItems();
            }

            return(Occurrences);
        }
        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);
            }
        }
Exemple #4
0
        public string EventToString(IRecurringComponent calendarEvent, int width = int.MaxValue)
        {
            var actualWidth = Math.Min(new[] { calendarEvent.Name.Length, calendarEvent.Description.Length }.Max(),
                                       width);

            return($@"{WithLineBreaks(calendarEvent.Name, width)}
{"".PadLeft(actualWidth, '-')}
{WithLineBreaks(calendarEvent.Description, width)}
{"".PadLeft(actualWidth, '-')}

");
        }
Exemple #5
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);
        }
        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());
                }
            }
        }
Exemple #7
0
        /// <summary>
        /// Displays the calendar in the time zone identified by <paramref name="tzid"/>.
        /// </summary>
        static void ShowCalendar(IICalendar iCal, string tzid)
        {
            IDateTime start = new iCalDateTime(2007, 3, 1);
            IDateTime end   = new iCalDateTime(2007, 4, 1).AddSeconds(-1);

            IList <Occurrence> occurrences = iCal.GetOccurrences(start, end);

            Console.WriteLine("====Events/Todos/Journal Entries in " + tzid + "====");
            foreach (Occurrence o in occurrences)
            {
                IRecurringComponent rc = o.Source as IRecurringComponent;
                if (rc != null)
                {
                    Console.WriteLine(
                        o.Period.StartTime.ToTimeZone(tzid).ToString("ddd, MMM d - h:mm") + " to " +
                        o.Period.EndTime.ToTimeZone(tzid).ToString("h:mm tt") + Environment.NewLine +
                        rc.Summary + Environment.NewLine);
                }
            }

            Console.WriteLine("====Alarms in " + tzid + "====");
            foreach (object obj in iCal.Children)
            {
                IRecurringComponent rc = obj as IRecurringComponent;
                if (rc != null)
                {
                    foreach (AlarmOccurrence ao in rc.PollAlarms(start, end))
                    {
                        Console.WriteLine(
                            "Alarm: " +
                            ao.DateTime.ToTimeZone(tzid).ToString("ddd, MMM d - h:mm") + ": " +
                            ao.Alarm.Summary);
                    }
                }
            }

            Console.WriteLine();
        }
Exemple #8
0
 private int GetWeekNumber(IRecurringComponent rc)
 {
     var numbers = Regex.Split(rc.Description, @"\D+");
     return int.Parse(numbers[2]);
 }
Exemple #9
0
        /// <summary>
        /// Gets a list of alarm occurrences for the given recurring component, <paramref name="rc"/>
        /// that occur between <paramref name="FromDate"/> and <paramref name="ToDate"/>.
        /// </summary>
        virtual public IList<AlarmOccurrence> GetOccurrences(IRecurringComponent rc, IDateTime FromDate, IDateTime ToDate)
        {
            Occurrences.Clear();

            if (Trigger != null)
            {
                // If the trigger is relative, it can recur right along with
                // the recurring items, otherwise, it happens once and
                // only once (at a precise time).
                if (Trigger.IsRelative)
                {
                    // Ensure that "FromDate" has already been set
                    if (FromDate == null)
                        FromDate = rc.Start.Copy<IDateTime>();

                    TimeSpan d = default(TimeSpan);
                    foreach (Occurrence o in rc.GetOccurrences(FromDate, ToDate))
                    {
                        IDateTime dt = o.Period.StartTime;
                        if (Trigger.Related == TriggerRelation.End)
                        {
                            if (o.Period.EndTime != null)
                            {
                                dt = o.Period.EndTime;
                                if (d == default(TimeSpan))
                                    d = o.Period.Duration;
                            }
                            // Use the "last-found" duration as a reference point
                            else if (d != default(TimeSpan))
                                dt = o.Period.StartTime.Add(d);
                            else throw new ArgumentException("Alarm trigger is relative to the END of the occurrence; however, the occurence has no discernible end.");
                        }

                        Occurrences.Add(new AlarmOccurrence(this, dt.Add(Trigger.Duration.Value), rc));
                    }
                }
                else
                {
                    IDateTime dt = Trigger.DateTime.Copy<IDateTime>();
                    dt.AssociatedObject = this;
                    Occurrences.Add(new AlarmOccurrence(this, dt, rc));
                }

                // If a REPEAT and DURATION value were specified,
                // then handle those repetitions here.
                AddRepeatedItems();
            }

            return Occurrences;
        }
Exemple #10
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="AlarmOccurrence" /> structure.
 /// </summary>
 /// <param name="ao">The occurrence.</param>
 public AlarmOccurrence(AlarmOccurrence ao)
 {
     _period    = ao.Period;
     _component = ao.Component;
     _alarm     = ao.Alarm;
 }
 public RecurringComponentDTStartRequiredValidation(IResourceManager mgr, IRecurringComponent rc, string componentName)
     : base(mgr, rc, componentName, "DTSTART", 0, 1)
 {
 }
        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"));
        }
Exemple #13
0
 public AlarmOccurrence(IAlarm a, IDateTime dt, IRecurringComponent rc)
 {
     _mAlarm     = a;
     _mPeriod    = new Period(dt);
     _mComponent = rc;
 }
Exemple #14
0
 public AlarmOccurrence(AlarmOccurrence ao)
 {
     _mPeriod    = ao.Period;
     _mComponent = ao.Component;
     _mAlarm     = ao.Alarm;
 }
 public AlarmOccurrence(AlarmOccurrence ao)
 {
     m_Period    = ao.Period;
     m_Component = ao.Component;
     m_Alarm     = ao.Alarm;
 }
        static void Main(string[] args)
        {
            String sUrl = "https://planification.univ-lorraine.fr/jsp/custom/modules/plannings/anonymous_cal.jsp?resources=5424&projectId=5&calType=ical&firstDate=2018-01-29&lastDate=2018-02-04";



            Download.copyURLToFile(sUrl, "ade.ics");
            List <IEvent> ilist = ParseIcsFile.parseics("ade.ics");

            if (!System.IO.File.Exists("tmp.ics"))
            {
                try
                {
                    using (FileStream s = File.Create("tmp.ics"))
                    {
                        string content = File.ReadAllText("ade.ics");
                        s.Close();
                        File.WriteAllText("tmp.ics", content);
                    }
                }
                catch (System.IO.IOException e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            else
            {
                List <IEvent> ilist1 = ParseIcsFile.parseics("tmp.ics");



                //Detecter les evenements qui ont été modifiés la derniere fois(Supprimer- Inserer - Modifier)
                ParseIcsFile.compareEvents(ilist, ilist1);

                Console.WriteLine("Element supprimé par rapport à la derniere synchronisation: ");
                foreach (IEvent e in ParseIcsFile.listeSuppression)
                {
                    Console.WriteLine(e.Summary);
                }

                Console.WriteLine("\nElement inséré par rapport à la derniere synchronisation:  ");
                foreach (IEvent e in ParseIcsFile.listeInsertion)
                {
                    Console.WriteLine(e.Summary);
                }

                Console.WriteLine("\nElement modif par rapport à la derniere synchronisation:  ");
                foreach (IEvent e in ParseIcsFile.listeModification)
                {
                    Console.WriteLine(e.Summary);
                }

                FileStream s       = File.Create("tmp.ics");
                string     content = File.ReadAllText("ade.ics");
                s.Close();
                File.WriteAllText("tmp.ics", content);
            }

            //ADD GOOGLE API AND ADD TEST EVENT
            string[] Scopes          = { CalendarService.Scope.Calendar };
            string   ApplicationName = "Google Calendar API .NET Quickstart";


            UserCredential credential;

            using (var stream =
                       new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
            {
                string credPath = System.Environment.GetFolderPath(
                    System.Environment.SpecialFolder.Personal);
                credPath = Path.Combine(credPath, ".credentials/calendar-dotnet-quickstart.json");

                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }

            // Create Google Calendar API service.
            var service = new CalendarService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });

            // TEST  ONE EVENT

            /* Google.Apis.Calendar.v3.Data.Event newEvent1 = new Google.Apis.Calendar.v3.Data.Event();
             * newEvent1.Summary = "Summary";
             * newEvent1.Description = "New EVent Test";
             * newEvent1.Start = new EventDateTime();
             * newEvent1.Start.DateTime = new DateTime(2018, 5, 16, 15, 13, 13, 12);
             *
             * newEvent1.End = new EventDateTime();
             * newEvent1.End.DateTime = new DateTime(2018, 7, 16, 15, 13, 13, 12);
             * service.Events.Insert(newEvent1, "primary").Execute();*/


            var calendars = iCalendar.LoadFromFile("tmp.ics");
            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)
                {
                    Google.Apis.Calendar.v3.Data.Event newEvent = new Google.Apis.Calendar.v3.Data.Event();
                    newEvent.Summary = rc.Calendar.Events[i].Summary;

                    DateTime o = new DateTime(rc.Calendar.Events[i].Start.Year, rc.Calendar.Events[i].Start.Month,
                                              rc.Calendar.Events[i].Start.Day, rc.Calendar.Events[i].Start.Hour + 1, rc.Calendar.Events[i].Start.Minute,
                                              rc.Calendar.Events[i].Start.Second);
                    newEvent.Start          = new EventDateTime();
                    newEvent.Start.DateTime = o;
                    o = new DateTime(rc.Calendar.Events[i].DTEnd.Year, rc.Calendar.Events[i].DTEnd.Month,
                                     rc.Calendar.Events[i].DTEnd.Day, rc.Calendar.Events[i].DTEnd.Hour + 1, rc.Calendar.Events[i].DTEnd.Minute,
                                     rc.Calendar.Events[i].DTEnd.Second);
                    newEvent.End          = new EventDateTime();
                    newEvent.End.DateTime = o;
                    newEvent.Description  = rc.Calendar.Events[i].Description;
                    newEvent.Location     = rc.Calendar.Events[i].Location;

                    if (!CalendarHelper.IsUniqueId(service, newEvent))
                    {
                        service.Events.Insert(newEvent, "primary").Execute();
                        Console.WriteLine(rc.Calendar.Events[i].Summary);
                    }
                    i++;
                }
            }

            Console.Read();
        }
 public AlarmOccurrence(IAlarm a, IDateTime dt, IRecurringComponent rc)
 {
     m_Alarm     = a;
     m_Period    = new Period(dt);
     m_Component = rc;
 }
Exemple #18
0
 public AlarmOccurrence(Alarm a, IDateTime dt, IRecurringComponent rc)
 {
     Alarm     = a;
     Period    = new Period(dt);
     Component = rc;
 }