示例#1
0
        public void TestTodoActive(string calendar, ArrayList items, params int[] numPeriods)
        {
            IICalendar iCal = iCalendar.LoadFromFile(@"Calendars\Todo\" + calendar)[0];

            ProgramTest.TestCal(iCal);
            ITodo todo = iCal.Todos[0];

            for (int i = 0; i < items.Count; i += 2)
            {
                iCalDateTime dt = (iCalDateTime)items[i];
                dt.TZID = tzid;

                bool tf = (bool)items[i + 1];
                if (tf)
                {
                    Assert.IsTrue(todo.IsActive(dt), "Todo should be active at " + dt);
                }
                else
                {
                    Assert.IsFalse(todo.IsActive(dt), "Todo should not be active at " + dt);
                }
            }

            if (numPeriods != null &&
                numPeriods.Length > 0)
            {
                IEvaluator evaluator = todo.GetService(typeof(IEvaluator)) as IEvaluator;
                Assert.IsNotNull(evaluator);
                Assert.AreEqual(
                    numPeriods[0],
                    evaluator.Periods.Count,
                    "Todo should have " + numPeriods[0] + " occurrences after evaluation; it had " + evaluator.Periods.Count);
            }
        }
示例#2
0
        public void Todo7_1()
        {
            IICalendar iCal = iCalendar.LoadFromFile(@"Calendars\Todo\Todo7.ics")[0];
            ITodo      todo = iCal.Todos[0];

            ArrayList items = new ArrayList();

            items.Add(new iCalDateTime(2006, 7, 28, 9, 0, 0, tzid));
            items.Add(new iCalDateTime(2006, 8, 4, 9, 0, 0, tzid));
            items.Add(new iCalDateTime(2006, 9, 1, 9, 0, 0, tzid));
            items.Add(new iCalDateTime(2006, 10, 6, 9, 0, 0, tzid));
            items.Add(new iCalDateTime(2006, 11, 3, 9, 0, 0, tzid));
            items.Add(new iCalDateTime(2006, 12, 1, 9, 0, 0, tzid));
            items.Add(new iCalDateTime(2007, 1, 5, 9, 0, 0, tzid));
            items.Add(new iCalDateTime(2007, 2, 2, 9, 0, 0, tzid));
            items.Add(new iCalDateTime(2007, 3, 2, 9, 0, 0, tzid));
            items.Add(new iCalDateTime(2007, 4, 6, 9, 0, 0, tzid));

            IList <Occurrence> occurrences = todo.GetOccurrences(
                new iCalDateTime(2006, 7, 1, 9, 0, 0),
                new iCalDateTime(2007, 7, 1, 9, 0, 0));

            // FIXME: Count is not properly restricting recurrences to 10.
            // What's going wrong here?
            Assert.AreEqual(
                items.Count,
                occurrences.Count,
                "TODO should have " + items.Count + " occurrences; it has " + occurrences.Count);

            for (int i = 0; i < items.Count; i++)
            {
                Assert.AreEqual(items[i], occurrences[i].Period.StartTime, "TODO should occur at " + items[i] + ", but does not.");
            }
        }
示例#3
0
        private void EventOccurrenceTest(
            IICalendar iCal,
            IDateTime fromDate,
            IDateTime toDate,
            IDateTime[] dateTimes,
            string[] timeZones,
            int eventIndex
        )
        {
            IEvent evt = iCal.Events[eventIndex];
            fromDate.AssociatedObject = iCal;
            toDate.AssociatedObject = iCal;

            IList<Occurrence> occurrences = evt.GetOccurrences(
                fromDate,
                toDate);

            Assert.AreEqual(
                dateTimes.Length,
                occurrences.Count,
                "There should be exactly " + dateTimes.Length + " occurrences; there were " + occurrences.Count);

            for (int i = 0; i < dateTimes.Length; i++)
            {
                // Associate each incoming date/time with the calendar.
                dateTimes[i].AssociatedObject = iCal;

                IDateTime dt = dateTimes[i];
                Assert.AreEqual(dt, occurrences[i].Period.StartTime, "Event should occur on " + dt);
                if (timeZones != null)
                    Assert.AreEqual(timeZones[i], dt.TimeZoneName, "Event " + dt + " should occur in the " + timeZones[i] + " timezone");
            }
        }
 /// <summary>
 ///     Serializes the specified i cal.
 /// </summary>
 /// <param name="iCal">The i cal.</param>
 /// <param name="filename">The filename.</param>
 public virtual void Serialize(IICalendar iCal, string filename)
 {
     using (var fs = new FileStream(filename, FileMode.Create))
     {
         Serialize(iCal, fs, new UTF8Encoding( ));
     }
 }
        /// <summary>
        ///     Sends the acceptance.
        /// </summary>
        /// <param name="calendar">The calendar.</param>
        /// <param name="iCalMessage">The i cal message.</param>
        /// <param name="eventEmail">The event email.</param>
        private static void SendAcceptance(IICalendar calendar, ReceivedICalEmailMessage iCalMessage, EventEmail eventEmail)
        {
            Inbox inbox = iCalMessage.FromInbox;

            string subject = string.Format("{0}: {1}", GlobalStrings.Accepted, iCalMessage.EmSubject ?? GlobalStrings.MeetingInvitation);

            /////
            // Create the new mail message.
            /////
            var sentMessage = new SentICalEmailMessage
            {
                Name            = subject,
                EmFrom          = inbox.InboxEmailAddress,
                EmTo            = iCalMessage.EmFrom,
                EmSubject       = subject,
                EmBody          = iCalMessage.EmBody ?? string.Empty,
                EmIsHtml        = iCalMessage.EmIsHtml ?? true,
                OwnerEventEmail = eventEmail
            };

            sentMessage.Save( );

            var emailServerSettings = Entity.Get <TenantEmailSetting>("core:tenantEmailSettingsInstance");

            iCalEmailHelper.SendICalEmail(calendar, sentMessage.As <SentEmailMessage>( ).ToMailMessage( ), emailServerSettings);
        }
示例#6
0
        public void icalbody(
            ISerializationContext ctx, IICalendar iCal
            ) //throws RecognitionException, TokenStreamException
        {
            ISerializerFactory        sf = ctx.GetService(typeof(ISerializerFactory)) as ISerializerFactory;
            ICalendarComponentFactory cf = ctx.GetService(typeof(ICalendarComponentFactory)) as ICalendarComponentFactory;

            {        // ( ... )*
                for (;;)
                {
                    switch (LA(1))
                    {
                    case IANA_TOKEN:
                    case X_NAME:
                    {
                        property(ctx, iCal);
                        break;
                    }

                    case BEGIN:
                    {
                        component(ctx, sf, cf, iCal);
                        break;
                    }

                    default:
                    {
                        goto _loop12_breakloop;
                    }
                    }
                }
                _loop12_breakloop :;
            }        // ( ... )*
        }
示例#7
0
        private void CopyCalendarTest(string filename)
        {
            IICalendar iCal1 = iCalendar.LoadFromFile(@"Calendars\Serialization\" + filename)[0];
            IICalendar iCal2 = iCal1.Copy <IICalendar>();

            SerializationTest.CompareCalendars(iCal1, iCal2);
        }
示例#8
0
        public void Journal2()
        {
            IICalendar iCal = iCalendar.LoadFromFile(@"Calendars\Journal\JOURNAL2.ics")[0];

            ProgramTest.TestCal(iCal);
            Assert.AreEqual(1, iCal.Journals.Count);
            IJournal j = iCal.Journals[0];

            Assert.IsNotNull(j, "Journal entry was null");
            Assert.AreEqual(JournalStatus.Final, j.Status, "Journal entry should have been in FINAL status, but it was in " + j.Status + " status.");
            Assert.AreEqual("PRIVATE", j.Class, "Journal class should have been PRIVATE, but was " + j.Class + ".");
            Assert.AreEqual("JohnSmith", j.Organizer.CommonName, "Organizer common name should have been JohnSmith, but was " + j.Organizer.CommonName);
            Assert.IsTrue(
                string.Equals(
                    j.Organizer.SentBy.OriginalString,
                    "mailto:[email protected]",
                    StringComparison.InvariantCultureIgnoreCase),
                "Organizer should have had been SENT-BY 'mailto:[email protected]'; it was sent by '" + j.Organizer.SentBy + "'");
            Assert.IsTrue(
                string.Equals(
                    j.Organizer.DirectoryEntry.OriginalString,
                    "ldap://host.com:6666/o=3DDC%20Associates,c=3DUS??(cn=3DJohn%20Smith)",
                    StringComparison.InvariantCultureIgnoreCase),
                "Organizer's directory entry should have been 'ldap://host.com:6666/o=3DDC%20Associates,c=3DUS??(cn=3DJohn%20Smith)', but it was '" + j.Organizer.DirectoryEntry + "'");
            Assert.AreEqual(
                "MAILTO:[email protected]",
                j.Organizer.Value.OriginalString);
            Assert.AreEqual(
                "jsmith",
                j.Organizer.Value.UserInfo);
            Assert.AreEqual(
                "host.com",
                j.Organizer.Value.Host);
            Assert.IsNull(j.Start);
        }
示例#9
0
        public void Merge3()
        {
            IICalendar iCal1 = iCalendar.LoadFromFile(@"Calendars\Recurrence\MonthlyCountByMonthDay3.ics")[0];
            IICalendar iCal2 = iCalendar.LoadFromFile(@"Calendars\Recurrence\YearlyByMonth1.ics")[0];

            iCal1.MergeWith(iCal2);

            Assert.AreEqual(1, iCal1.Events.Count);
        }
示例#10
0
        public void LoadFromFile()
        {
            string path = @"Calendars\Serialization\Calendar1.ics";

            Assert.IsTrue(File.Exists(path), "File '" + path + "' does not exist.");

            IICalendar iCal = iCalendar.LoadFromFile(path)[0];

            Assert.AreEqual(14, iCal.Events.Count);
        }
示例#11
0
 private void EventOccurrenceTest(
     IICalendar iCal,
     IDateTime fromDate,
     IDateTime toDate,
     IDateTime[] dateTimes,
     string[] timeZones
 )
 {
     EventOccurrenceTest(iCal, fromDate, toDate, dateTimes, timeZones, 0);
 }
示例#12
0
        public static void SendICalEmail(IICalendar iCal, MailMessage message, TenantEmailSetting emailServerSettings)
        {
            /////
            // Create an instance of the iCalendar serializer.
            /////
            var serializer = new iCalendarSerializer( );

            /////
            // Determine whether an alternate view of type HTML is required.
            /////
            if (message.IsBodyHtml && !string.IsNullOrEmpty(message.Body))
            {
                /////
                // Create the html content type.
                /////
                var htmlContentType = new ContentType(MediaTypeNames.Text.Html);

                /////
                // Add the html alternate view.
                /////
                AlternateView htmlAlternateView = AlternateView.CreateAlternateViewFromString(message.Body, htmlContentType);

                message.AlternateViews.Add(htmlAlternateView);
            }

            /////
            // Create the calendar content type.
            /////
            var calendarContentType = new ContentType("text/calendar");

            if (calendarContentType.Parameters != null)
            {
                calendarContentType.Parameters.Add("method", "REQUEST");
            }

            /////
            // Add the calendar alternate view.
            /////
            AlternateView calendarAlternateView = AlternateView.CreateAlternateViewFromString(serializer.SerializeToString(iCal), calendarContentType);

            message.AlternateViews.Add(calendarAlternateView);

            /////
            // Get a list of MailMessage instances.
            /////
            var messages = new List <MailMessage>
            {
                message
            };

            var emailsender = new SmtpEmailSender(emailServerSettings);

            emailsender.SendMessages(messages);
        }
示例#13
0
        public void LoadFromUri()
        {
            string path = Directory.GetCurrentDirectory();

            path = Path.Combine(path, "Calendars/Serialization/Calendar1.ics").Replace(@"\", "/");
            path = "file:///" + path;
            Uri        uri  = new Uri(path);
            IICalendar iCal = iCalendar.LoadFromUri(uri)[0];

            Assert.AreEqual(14, iCal.Events.Count);
        }
示例#14
0
        public void Merge2()
        {
            iCalendar  iCal    = new iCalendar();
            IICalendar tmp_cal = iCalendar.LoadFromFile(@"Calendars\Serialization\TimeZone3.ics")[0];

            iCal.MergeWith(tmp_cal);

            tmp_cal = iCalendar.LoadFromFile(@"Calendars\Serialization\TimeZone3.ics")[0];

            // Compare the two calendars -- they should match exactly
            SerializationTest.CompareCalendars(iCal, tmp_cal);
        }
示例#15
0
 static public void TestCal(IICalendar iCal)
 {
     Assert.IsNotNull(iCal, "The iCalendar was not loaded");
     if (iCal.Events.Count > 0)
     {
         Assert.IsTrue(iCal.Events.Count == 1, "Calendar should contain 1 event; however, the iCalendar loaded " + iCal.Events.Count + " events");
     }
     else if (iCal.Todos.Count > 0)
     {
         Assert.IsTrue(iCal.Todos.Count == 1, "Calendar should contain 1 todo; however, the iCalendar loaded " + iCal.Todos.Count + " todos");
     }
 }
示例#16
0
        public void Journal1()
        {
            IICalendar iCal = iCalendar.LoadFromFile(@"Calendars\Journal\JOURNAL1.ics")[0];

            ProgramTest.TestCal(iCal);
            Assert.AreEqual(1, iCal.Journals.Count);
            IJournal j = iCal.Journals[0];

            Assert.IsNotNull(j, "Journal entry was null");
            Assert.AreEqual(JournalStatus.Draft, j.Status, "Journal entry should have been in DRAFT status, but it was in " + j.Status.ToString() + " status.");
            Assert.AreEqual("PUBLIC", j.Class, "Journal class should have been PUBLIC, but was " + j.Class + ".");
            Assert.IsNull(j.Start);
        }
 public static string SerializeCalendar(IICalendar calendar)
 {
     try
     {
         var context    = new DDay.iCal.Serialization.SerializationContext();
         var factory    = new DDay.iCal.Serialization.iCalendar.SerializerFactory();
         var serializer = factory.Build(calendar.GetType(), context) as DDay.iCal.Serialization.IStringSerializer;
         return(serializer != null?serializer.SerializeToString(calendar) : null);
     }
     catch (Exception)
     {
         return(null);
     }
 }
        /// <summary>
        ///     Creates the and send acceptance.
        /// </summary>
        /// <param name="calendar">The calendar.</param>
        /// <param name="iCalMessage">The i cal message.</param>
        /// <param name="eventEmail">The event email.</param>
        private static void CreateAndSendAcceptance(IICalendar calendar, ReceivedICalEmailMessage iCalMessage, EventEmail eventEmail)
        {
            if (calendar == null || iCalMessage == null)
            {
                return;
            }

            IICalendar reply = CreateAcceptance(calendar, iCalMessage);

            if (reply != null)
            {
                SendAcceptance(reply, iCalMessage, eventEmail);
            }
        }
示例#19
0
        /// <summary>
        ///     Initializes the specified value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="tzid">The time zone id.</param>
        /// <param name="iCal">The i cal.</param>
        private void Initialize(DateTime value, string tzid, IICalendar iCal)
        {
            if (value.Kind == DateTimeKind.Utc)
            {
                IsUniversalTime = true;
            }

            // Convert all incoming values to UTC.
            Value            = DateTime.SpecifyKind(value, DateTimeKind.Utc);
            HasDate          = true;
            HasTime          = (value.Second != 0 || value.Minute != 0 || value.Hour != 0);
            TzId             = tzid;
            AssociatedObject = iCal;
        }
示例#20
0
        private void Initialize(DateTime value, string tzid, IICalendar iCal)
        {
            if (value.Kind == DateTimeKind.Utc)
            {
                this.IsUniversalTime = true;
            }

            // Convert all incoming values to UTC.
            this.Value            = DateTime.SpecifyKind(value, DateTimeKind.Utc);
            this.HasDate          = true;
            this.HasTime          = (value.Second == 0 && value.Minute == 0 && value.Hour == 0) ? false : true;
            this.TZID             = tzid;
            this.AssociatedObject = iCal;
        }
示例#21
0
        private void EventOccurrenceTest(
            IICalendar iCal,
            IDateTime fromDate,
            IDateTime toDate,
            IDateTime[] dateTimes,
            string[] timeZones,
            int eventIndex
        )
        {
            IEvent evt = iCal.Events.Skip(eventIndex).First();
            fromDate.AssociatedObject = iCal;
            toDate.AssociatedObject = iCal;

            IList<Occurrence> occurrences = evt.GetOccurrences(
                fromDate,
                toDate);

            Assert.AreEqual(
                dateTimes.Length,
                occurrences.Count,
                "There should be exactly " + dateTimes.Length + " occurrences; there were " + occurrences.Count);

            IRecurrencePattern pattern = null;
            if (evt != null && evt.RecurrenceRules.Count > 0)
            {
                Assert.AreEqual(1, evt.RecurrenceRules.Count);
                pattern = evt.RecurrenceRules[0];
            }

            for (int i = 0; i < dateTimes.Length; i++)
            {
                // Associate each incoming date/time with the calendar.
                dateTimes[i].AssociatedObject = iCal;

                IDateTime dt = dateTimes[i];
                Assert.AreEqual(dt, occurrences[i].Period.StartTime, "Event should occur on " + dt);
                if (timeZones != null)
                    Assert.AreEqual(timeZones[i], dt.TimeZoneName, "Event " + dt + " should occur in the " + timeZones[i] + " timezone");

                //// Now, verify that GetNextOccurrence() returns accurate results.
                //if (i < dateTimes.Length - 1)
                //{
                //    IPeriod nextOccurrence = pattern.GetNextOccurrence(dateTimes[i]);
                //    IPeriod p = new Period(dateTimes[i + 1]);
                //    Assert.AreEqual(p, nextOccurrence, "Next occurrence did not match the results of RecurrencePattern.GetNextOccurrence()");
                //}
            }            
        }
        static public void CompareCalendars(IICalendar iCal1, IICalendar iCal2)
        {
            CompareComponents(iCal1, iCal2);

            Assert.AreEqual(iCal1.Children.Count, iCal2.Children.Count, "Children count is different between calendars.");

            for (int i = 0; i < iCal1.Children.Count; i++)
            {
                var component1 = iCal1.Children[i] as ICalendarComponent;
                var component2 = iCal2.Children[i] as ICalendarComponent;
                if (component1 != null && component2 != null)
                {
                    CompareComponents(component1, component2);
                }
            }
        }
示例#23
0
        /// <summary>
        /// Loads the iCalendar found at the path indicated by <param name="filepath"/> and
        /// makes some small changes to the event with the UID indicated by <paramref name="eventUID"/>,
        /// and saves those changes to a file with "_Altered" appended to the name.
        /// </summary>
        static void EditAndSaveEvent(string filepath, string eventUID)
        {
            IICalendar iCal = iCalendar.LoadFromFile(filepath)[0];
            IEvent     evt  = iCal.Events[eventUID];

            if (evt != null)
            {
                evt.Summary = "New summary for event";
                // FIXME: re-implement this
                //evt.AddAttendee("*****@*****.**");
                evt.Sequence++;

                string newFilename = Path.GetFileNameWithoutExtension(filepath) + "_Altered" + Path.GetExtension(filepath);
                SaveCalendar(newFilename, iCal);
            }
        }
示例#24
0
        public void TestAlarm(string calendar, List <IDateTime> dates, iCalDateTime start, iCalDateTime end)
        {
            IICalendar iCal = iCalendar.LoadFromFile(@"Calendars\Alarm\" + calendar)[0];

            ProgramTest.TestCal(iCal);
            IEvent evt = iCal.Events[0];

            // Poll all alarms that occurred between Start and End
            IList <AlarmOccurrence> alarms = evt.PollAlarms(start, end);

            foreach (AlarmOccurrence alarm in alarms)
            {
                Assert.IsTrue(dates.Contains(alarm.DateTime), "Alarm triggers at " + alarm.Period.StartTime + ", but it should not.");
            }
            Assert.IsTrue(dates.Count == alarms.Count, "There were " + alarms.Count + " alarm occurrences; there should have been " + dates.Count + ".");
        }
示例#25
0
        virtual public void MergeWith(IMergeable obj)
        {
            IICalendar c = obj as IICalendar;

            if (c != null)
            {
                if (Name == null)
                {
                    Name = c.Name;
                }

                Method    = c.Method;
                Version   = c.Version;
                ProductID = c.ProductID;
                Scale     = c.Scale;

                foreach (ICalendarProperty p in c.Properties)
                {
                    if (!Properties.ContainsKey(p.Name))
                    {
                        Properties.Add(p.Copy <ICalendarProperty>());
                    }
                }
                foreach (ICalendarObject child in c.Children)
                {
                    if (child is IUniqueComponent)
                    {
                        if (!UniqueComponents.ContainsKey(((IUniqueComponent)child).UID))
                        {
                            AddChild(child.Copy <ICalendarObject>());
                        }
                    }
                    else if (child is ITimeZone)
                    {
                        ITimeZone tz = GetTimeZone(((ITimeZone)child).TZID);
                        if (tz == null)
                        {
                            AddChild(child.Copy <ICalendarObject>());
                        }
                    }
                    else
                    {
                        AddChild(child.Copy <ICalendarObject>());
                    }
                }
            }
        }
示例#26
0
        static public void CompareCalendars(IICalendar iCal1, IICalendar iCal2)
        {
            CompareComponents(iCal1, iCal2);

            Assert.AreEqual(iCal1.Children.Count, iCal2.Children.Count, "Children count is different between calendars.");

            for (int i = 0; i < iCal1.Events.Count; i++)
                CompareComponents(iCal1.Events[i], iCal2.Events[i]);
            for (int i = 0; i < iCal1.FreeBusy.Count; i++)
                CompareComponents(iCal1.FreeBusy[i], iCal2.FreeBusy[i]);
            for (int i = 0; i < iCal1.Journals.Count; i++)
                CompareComponents(iCal1.Journals[i], iCal2.Journals[i]);
            for (int i = 0; i < iCal1.Todos.Count; i++)
                CompareComponents(iCal1.Todos[i], iCal2.Todos[i]);
            for (int i = 0; i < iCal1.TimeZones.Count; i++)
                CompareComponents(iCal1.TimeZones[i], iCal2.TimeZones[i]);
        }
示例#27
0
        static void Main(string[] args)
        {
            // First, create a calendar
            IICalendar iCal = CreateCalendar();

            // Make a copy of the calendar and save it!
            IICalendar newCal = iCal.Copy <IICalendar>();

            SaveCalendar("Copied.ics", newCal);

            // Show the calendar in a specific time zone
            ShowCalendar(iCal, "America/New_York");
            ShowCalendar(iCal, "America/Denver");

            // Save the calendar to file
            SaveCalendar("Output.ics", iCal);
            EditAndSaveEvent("Output.ics", "1234567890");
        }
示例#28
0
        virtual public void MergeWith(IMergeable obj)
        {
            IICalendar c = obj as IICalendar;

            if (c != null)
            {
                if (Name == null)
                {
                    Name = c.Name;
                }

                foreach (ICalendarProperty p in c.Properties)
                {
                    if (!Properties.ContainsKey(p.Name))
                    {
                        Properties.Add(p.Copy <ICalendarProperty>());
                    }
                }
                foreach (ICalendarObject child in c.Children)
                {
                    if (child is IUniqueComponent)
                    {
                        var component = UniqueComponents[((IUniqueComponent)child).UID];
                        if (component == null)
                        {
                            this.AddChild(child.Copy <ICalendarObject>());
                        }
                    }
                    else if (child is ITimeZone)
                    {
                        ITimeZone tz = GetTimeZone(((ITimeZone)child).TZID);
                        if (tz == null)
                        {
                            this.AddChild(child.Copy <ICalendarObject>());
                        }
                    }
                    else
                    {
                        this.AddChild(child.Copy <ICalendarObject>());
                    }
                }
            }
        }
示例#29
0
        public override bool Equals(object obj)
        {
            IICalendar iCal = obj as iCalendar;

            if (iCal != null)
            {
                bool isEqual =
                    object.Equals(Version, iCal.Version) &&
                    object.Equals(ProductID, iCal.ProductID) &&
                    object.Equals(Scale, iCal.Scale) &&
                    object.Equals(Method, iCal.Method) &&
                    (
                        (UniqueComponents == null && iCal.UniqueComponents == null) ||
                        (UniqueComponents != null && iCal.UniqueComponents != null && object.Equals(UniqueComponents.Count, iCal.UniqueComponents.Count))
                    );

                if (isEqual)
                {
                    if (UniqueComponents.Count != iCal.UniqueComponents.Count)
                    {
                        return(false);
                    }

                    IEnumerator <IUniqueComponent> e1 = UniqueComponents.GetEnumerator();
                    IEnumerator <IUniqueComponent> e2 = iCal.UniqueComponents.GetEnumerator();
                    while (e1.MoveNext())
                    {
                        if (!e2.MoveNext())
                        {
                            return(false);
                        }
                        if (!object.Equals(e1.Current, e2.Current))
                        {
                            return(false);
                        }
                    }
                    return(!e2.MoveNext());
                }
                return(false);
            }
            return(base.Equals(obj));
        }
示例#30
0
        public void LoadAndDisplayCalendar()
        {
            // The following code loads and displays an iCalendar
            // with US Holidays for 2006.
            //
            IICalendar iCal = iCalendar.LoadFromFile(@"Calendars\Serialization\USHolidays.ics")[0];

            Assert.IsNotNull(iCal, "iCalendar did not load.  Are you connected to the internet?");

            IList <Occurrence> occurrences = iCal.GetOccurrences(
                new iCalDateTime(2006, 1, 1, "US-Eastern"),
                new iCalDateTime(2006, 12, 31, "US-Eastern"));

            foreach (Occurrence o in occurrences)
            {
                IEvent evt = o.Source as IEvent;
                if (evt != null)
                {
                    // Display the date of the event
                    Console.Write(o.Period.StartTime.Local.Date.ToString("MM/dd/yyyy") + " -\t");

                    // Display the event summary
                    Console.Write(evt.Summary);

                    // Display the time the event happens (unless it's an all-day event)
                    if (evt.Start.HasTime)
                    {
                        Console.Write(" (" + evt.Start.Local.ToShortTimeString() + " - " + evt.End.Local.ToShortTimeString());
                        if (evt.Start.TimeZoneObservance != null && evt.Start.TimeZoneObservance.HasValue)
                        {
                            Console.Write(" " + evt.Start.TimeZoneObservance.Value.TimeZoneInfo.TimeZoneName);
                        }
                        Console.Write(")");
                    }

                    Console.Write(Environment.NewLine);
                }
            }
        }
示例#31
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();
        }
        public override string SerializeToString(object obj)
        {
            IICalendar iCal = obj as IICalendar;

            if (iCal != null)
            {
                // Ensure VERSION and PRODUCTID are both set,
                // as they are required by RFC5545.
                IICalendar copy = iCal.Copy <IICalendar>();
                if (string.IsNullOrEmpty(copy.Version))
                {
                    copy.Version = CalendarVersions.v2_0;
                }
                if (string.IsNullOrEmpty(copy.ProductID))
                {
                    copy.ProductID = CalendarProductIDs.Default;
                }

                return(base.SerializeToString(copy));
            }

            return(base.SerializeToString(obj));
        }
示例#33
0
        public void TestTodoCompleted(string calendar, ArrayList items)
        {
            IICalendar iCal = iCalendar.LoadFromFile(@"Calendars\Todo\" + calendar)[0];

            ProgramTest.TestCal(iCal);
            ITodo todo = iCal.Todos[0];

            for (int i = 0; i < items.Count; i += 2)
            {
                IDateTime dt = (IDateTime)items[i];
                dt.TZID = tzid;

                bool tf = (bool)items[i + 1];
                if (tf)
                {
                    Assert.IsTrue(todo.IsCompleted(dt), "Todo should be completed at " + dt);
                }
                else
                {
                    Assert.IsFalse(todo.IsCompleted(dt), "Todo should not be completed at " + dt);
                }
            }
        }
示例#34
0
        public override bool Equals(object obj)
        {
            IICalendar iCal = obj as iCalendar;

            if (iCal != null)
            {
                //bool isEqual =
                //    object.Equals(Version, iCal.Version) &&
                //    object.Equals(ProductID, iCal.ProductID) &&
                //    object.Equals(Scale, iCal.Scale) &&
                //    object.Equals(Method, iCal.Method) &&
                //    (
                //        (UniqueComponents == null && iCal.UniqueComponents == null) ||
                //        (UniqueComponents != null && iCal.UniqueComponents != null && object.Equals(UniqueComponents.Count, iCal.UniqueComponents.Count))
                //    );

                //if (isEqual)
                //{
                //    if (UniqueComponents.Count != iCal.UniqueComponents.Count)
                //        return false;

                //    IEnumerator<IUniqueComponent> e1 = UniqueComponents.GetEnumerator();
                //    IEnumerator<IUniqueComponent> e2 = iCal.UniqueComponents.GetEnumerator();
                //    while (e1.MoveNext())
                //    {
                //        if (!e2.MoveNext())
                //            return false;
                //        if (!object.Equals(e1.Current, e2.Current))
                //            return false;
                //    }
                //    return !e2.MoveNext();
                //}
                //return false;
            }
            return(base.Equals(obj));
        }
 /// <summary>
 /// Initialise a new wrapper object, with a blank iCal.
 /// </summary>
 public iCalWrapper()
 {
     miCalObject = new iCalendar();
 }
示例#36
0
 /// <summary>
 /// Saves the calendar to the specified <paramref name="filepath"/>.
 /// </summary>
 static void SaveCalendar(string filepath, IICalendar iCal)
 {
     iCalendarSerializer serializer = new iCalendarSerializer();
     serializer.Serialize(iCal, filepath);
 }
 public static string SerializeICalendar (IICalendar calendar)
 {
   return _calendarSerializer.SerializeToString (calendar);
 }
示例#38
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();
        }
示例#39
0
	public void icalbody(
		ISerializationContext ctx, IICalendar iCal
	) //throws RecognitionException, TokenStreamException
{
		
		
		
			ISerializerFactory sf = ctx.GetService(typeof(ISerializerFactory)) as ISerializerFactory;
			ICalendarComponentFactory cf = ctx.GetService(typeof(ICalendarComponentFactory)) as ICalendarComponentFactory;
			ICalendarComponent c;
			ICalendarProperty p;
		
		{    // ( ... )*
			for (;;)
			{
				switch ( LA(1) )
				{
				case IANA_TOKEN:
				case X_NAME:
				{
					property(ctx, iCal);
					break;
				}
				case BEGIN:
				{
					component(ctx, sf, cf, iCal);
					break;
				}
				default:
				{
					goto _loop12_breakloop;
				}
				 }
			}
_loop12_breakloop:			;
		}    // ( ... )*
	}
 /// <summary>
 ///     Initializes a new instance of the <see cref="iCalendarSerializer" /> class.
 /// </summary>
 /// <param name="iCal">The i cal.</param>
 public iCalendarSerializer(IICalendar iCal)
 {
     _iCalendar = iCal;
 }
示例#41
0
        /** <summary>
         * Given a URI/URL, we call iCalendar's LoadFromURI, select the first element in the return, then return true.
         * </summary>
         */
        public bool Load(Uri path)
        {
            iCalc = iCalendar.LoadFromUri(path);

            iCal = iCalc.FirstOrDefault();
            this.Uri = path;
            return true;
        }
示例#42
0
 public iCalDateTime(int year, int month, int day, int hour, int minute, int second, string tzid, IICalendar iCal)
 {
     Initialize(year, month, day, hour, minute, second, tzid, iCal);
     HasTime = true;
 }
示例#43
0
 static public void TestCal(IICalendar iCal)
 {
     Assert.IsNotNull(iCal, "The iCalendar was not loaded");
     if (iCal.Events.Count > 0)
         Assert.IsTrue(iCal.Events.Count == 1, "Calendar should contain 1 event; however, the iCalendar loaded " + iCal.Events.Count + " events");
     else if (iCal.Todos.Count > 0)
         Assert.IsTrue(iCal.Todos.Count == 1, "Calendar should contain 1 todo; however, the iCalendar loaded " + iCal.Todos.Count + " todos");
 }
示例#44
0
 private void Initialize(int year, int month, int day, int hour, int minute, int second, string tzid, IICalendar iCal)
 {
     Initialize(CoerceDateTime(year, month, day, hour, minute, second, DateTimeKind.Local), tzid, iCal);
 }
示例#45
0
        private void Initialize(DateTime value, string tzid, IICalendar iCal)
        {
            if (value.Kind == DateTimeKind.Utc)
                this.IsUniversalTime = true;

            // Convert all incoming values to UTC.
            this.Value = DateTime.SpecifyKind(value, DateTimeKind.Utc);
            this.HasDate = true;
            this.HasTime = (value.Second == 0 && value.Minute == 0 && value.Hour == 0) ? false : true;
            this.TZID = tzid;
            this.AssociatedObject = iCal;
        }