public void FilterAllDayEvents1()
        {
            VCalendarParser calendar = new VCalendarParser();
            calendar.ParseFile("SampleCalendar.ics");

            VEvent ev_allday = calendar.VCalendar.Events.AddNew();
            ev_allday.UniqueId.Value = Guid.NewGuid().ToString();
            ev_allday.StartDateTime.DateTimeValue = new DateTime(2015, 01, 01);
            ev_allday.EndDateTime.DateTimeValue = ev_allday.StartDateTime.DateTimeValue.AddDays(1);

            VEvent ev_notallday = calendar.VCalendar.Events.AddNew();
            ev_notallday.UniqueId.Value = Guid.NewGuid().ToString();
            ev_notallday.StartDateTime.DateTimeValue = new DateTime(2015, 01, 01).AddHours(2);
            ev_notallday.EndDateTime.DateTimeValue = ev_notallday.StartDateTime.DateTimeValue.AddDays(1).AddHours(-2);

            Assert.AreEqual(calendar.VCalendar.Events.Where(ev => ev.UniqueId == ev_allday.UniqueId).Count(), 1);
            Assert.AreEqual(calendar.VCalendar.Events.Where(ev => ev.UniqueId == ev_notallday.UniqueId).Count(), 1);

            // filter out all-day events
            EventManager em = new Helpers.EventManager(calendar);
            em.Filter(new FilteringOptions("h=true"));
            var eventsAfterFiltering = em.GetEventList();

            Assert.AreEqual(eventsAfterFiltering.Where(ev => ev.UniqueId == ev_allday.UniqueId).Count(), 0);
            Assert.AreEqual(eventsAfterFiltering.Where(ev => ev.UniqueId == ev_notallday.UniqueId).Count(), 1);
        }
        public void HideIfTitleContainsString()
        {
            VCalendarParser calendar = new VCalendarParser();
            calendar.ParseFile("SampleCalendar.ics");

            VEvent ev_str1 = calendar.VCalendar.Events.AddNew();
            ev_str1.UniqueId.Value = Guid.NewGuid().ToString();
            ev_str1.StartDateTime.DateTimeValue = new DateTime(2015, 01, 01);
            ev_str1.EndDateTime.DateTimeValue = ev_str1.StartDateTime.DateTimeValue.AddDays(1);
            ev_str1.Summary.Value = "this is a [hidden] event";

            VEvent ev_str2 = calendar.VCalendar.Events.AddNew();
            ev_str2.UniqueId.Value = Guid.NewGuid().ToString();
            ev_str2.StartDateTime.DateTimeValue = new DateTime(2015, 01, 01);
            ev_str2.EndDateTime.DateTimeValue = ev_str2.StartDateTime.DateTimeValue.AddDays(1);
            ev_str2.Summary.Value = "[hidden] event too";

            VEvent ev_nostr = calendar.VCalendar.Events.AddNew();
            ev_nostr.UniqueId.Value = Guid.NewGuid().ToString();
            ev_nostr.StartDateTime.DateTimeValue = new DateTime(2015, 01, 01).AddHours(2);
            ev_nostr.EndDateTime.DateTimeValue = ev_nostr.StartDateTime.DateTimeValue.AddDays(1).AddHours(-2);
            ev_nostr.Summary.Value = "this is not hidden";

            Assert.AreEqual(calendar.VCalendar.Events.Where(ev => ev.UniqueId == ev_str1.UniqueId).Count(), 1);
            Assert.AreEqual(calendar.VCalendar.Events.Where(ev => ev.UniqueId == ev_str2.UniqueId).Count(), 1);
            Assert.AreEqual(calendar.VCalendar.Events.Where(ev => ev.UniqueId == ev_nostr.UniqueId).Count(), 1);

            // filter out all-day events
            EventManager em = new EventManager(calendar);
            em.Filter(new FilteringOptions("st=[hidden]"));
            var eventsAfterFiltering = em.GetEventList();

            Assert.AreEqual(eventsAfterFiltering.Where(ev => ev.UniqueId == ev_str1.UniqueId).Count(), 0);
            Assert.AreEqual(eventsAfterFiltering.Where(ev => ev.UniqueId == ev_str2.UniqueId).Count(), 0);
            Assert.AreEqual(eventsAfterFiltering.Where(ev => ev.UniqueId == ev_nostr.UniqueId).Count(), 1);
        }
Beispiel #3
0
		static void Main(string[] args)
		{
            string outputFolder, outputFile;

            if(args.GetUpperBound(0) < 1)
            {
                Console.WriteLine("Specify a folder name containing PDI files and a different one for the " +
                    "output files.");
                return;
            }

            try
            {
                // Set the default encoding to iso-8859-1 (Western European) as several of the files are encoded
                // that way.
                PDIParser.DefaultEncoding = BaseProperty.DefaultEncoding = Encoding.GetEncoding("iso-8859-1");

                outputFolder = args[1];

                if(!outputFolder.EndsWith(@"\", StringComparison.Ordinal))
                    outputFolder += @"\";

                if(!Directory.Exists(outputFolder))
                    Directory.CreateDirectory(outputFolder);

                Console.WriteLine("Parsing vCard files...");

                // Since we'll be parsing multiple files, we'll create an instance of the parser and re-use it
                // rather than using the static parsing methods.
                VCardParser vcardp = new VCardParser();

                foreach(string file in Directory.EnumerateFiles(args[0], "*.vcf"))
                {
                    Console.WriteLine("\n{0}", file);

                    vcardp.ParseFile(file);

                    Console.WriteLine(vcardp.VCards.ToString());

                    // Write it to a stream
                    outputFile = outputFolder + Path.GetFileName(file);

                    // NOTE: We must use the same encoding method when writing the file back out
                    using(var sw = new StreamWriter(outputFile, false, PDIParser.DefaultEncoding))
                    {
                        vcardp.VCards.WriteToStream(sw);
                    }

                    // Clear the collection ready for the next run
                    vcardp.VCards.Clear();
                }

                Console.WriteLine("\nParsing vCalendar files...");

                // Since we'll be parsing multiple files, we'll create an instance of the parser and re-use it
                // rather than using the static parser methods.
                VCalendarParser vcalp = new VCalendarParser();

                foreach(string file in Directory.EnumerateFiles(args[0], "*.vcs"))
                {
                    Console.WriteLine("\n{0}", file);

                    vcalp.ParseFile(file);

                    Console.WriteLine(vcalp.VCalendar.ToString());

                    // Write it to a stream
                    outputFile = outputFolder + Path.GetFileName(file);

                    // NOTE: We must use the same encoding method when writing the file back out
                    using(var sw = new StreamWriter(outputFile, false, PDIParser.DefaultEncoding))
                    {
                        vcalp.VCalendar.WriteToStream(sw);
                    }

                    // Clear the calendar ready for the next run
                    vcalp.VCalendar.ClearProperties();
                }

                Console.WriteLine("\nParsing iCalendar files...");

                // Get a list of iCalendar files to parse.  It uses the same parser as the vCalendar files
                foreach(string file in Directory.EnumerateFiles(args[0], "*.ics"))
                {
                    Console.WriteLine("\n{0}", file);

                    vcalp.ParseFile(file);

                    Console.WriteLine(vcalp.VCalendar.ToString());

                    // Write it to a stream
                    outputFile = outputFolder + Path.GetFileName(file);

                    // NOTE: We must use the same encoding method when writing the file back out
                    using(var sw = new StreamWriter(outputFile, false, PDIParser.DefaultEncoding))
                    {
                        vcalp.VCalendar.WriteToStream(sw);
                    }

                    // Clear the calendar ready for the next run
                    vcalp.VCalendar.ClearProperties();
                }

                Console.WriteLine("\nParsing vNote files...");

                // Since we'll be parsing multiple files, we'll create an instance of the parser and re-use it
                // rather than using the static parser methods.
                VNoteParser vnp = new VNoteParser();

                foreach(string file in Directory.EnumerateFiles(args[0], "*.vnt"))
                {
                    Console.WriteLine("\n{0}", file);

                    vnp.ParseFile(file);

                    Console.WriteLine(vnp.VNotes.ToString());

                    // Write it to a stream
                    outputFile = outputFolder + Path.GetFileName(file);

                    // NOTE: We must use the same encoding method when writing the file back out
                    using(var sw = new StreamWriter(outputFile, false, PDIParser.DefaultEncoding))
                    {
                        vnp.VNotes.WriteToStream(sw);
                    }

                    // Clear the collection ready for the next run
                    vnp.VNotes.Clear();
                }
            }
            catch(PDIParserException pe)
            {
                Console.WriteLine("\n\nError at line #{0}\n\n{1}", pe.LineNumber, pe.ToString());
            }
            catch(Exception ex)
            {
                Console.WriteLine("Unexpected failure:\n{0}", ex.ToString());
            }
        }
Beispiel #4
0
 /// <summary>
 /// Alternative constructor that initialises object based on given calendar object, without parsing anything
 /// </summary>
 /// <param name="calendar"></param>
 public EventManager(VCalendarParser calendar)
 {
     this.calendar = calendar;
 }
Beispiel #5
0
 /// <summary>
 /// Constructor. Parses given VCalendar string and stores internally as VCalendar object.
 /// </summary>
 /// <param name="icalContent"></param>
 public EventManager(string icalContent)
 {
     calendar = new VCalendarParser();
     calendar.ParseString(icalContent);
 }
Beispiel #6
0
        /// <summary>
        /// This static method can be used to load property values into a new instance of a calendar from a
        /// <see cref="TextReader"/> derived object such as a <see cref="StreamReader"/> or a <see cref="StringReader"/>.
        /// </summary>
        /// <param name="stream">An IO stream from which to read the vCards.  It is up to you to open the stream
        /// with the appropriate text encoding method if necessary.</param>
        /// <returns>A new calendar as created from the IO stream</returns>
        /// <example>
        /// <code language="cs">
        /// StreamReader sr = new StreamReader(@"C:\Test.ics");
        /// VCalendar vCal1 = VCalendarParser.ParseFromStream(sr);
        /// sr.Close();
        /// </code>
        /// <code language="vbnet">
        /// Dim sr As New StreamReader("C:\Test.ics")
        /// Dim vCal1 As VCalendar = VCalendarParser.ParseFromStream(sr)
        /// sr.Close()
        /// </code>
        /// </example>
        public static VCalendar ParseFromStream(TextReader stream)
        {
            VCalendarParser vcp = new VCalendarParser();
            vcp.ParseReader(stream);

            return vcp.VCalendar;
        }
Beispiel #7
0
        /// <summary>
        /// This static method can be used to load property values into a new instance of a calendar from a file.
        /// The filename can be a disk file or a URL.
        /// </summary>
        /// <param name="filename">A path or URL to a file containing or more calendar objects</param>
        /// <returns>A new calendar as created from the file</returns>
        /// <example>
        /// <code language="cs">
        /// VCalendar vCal1 = VCalendarParser.ParseFromFile(@"C:\MySchedule.ics");
        /// VCalendar vCal2 = VCalendarParser.ParseFromFile(
        ///     "http://www.mydomain.com/Calendars/MySchedule.ics");
        /// </code>
        /// <code language="vbnet">
        /// Dim vCal1 As VCalendar = VCalendarParser.ParseFromFile("C:\MySchedule.ics")
        /// Dim vCal2 As VCalendar = VCalendarParser.ParseFromFile(
        ///     "http://www.mydomain.com/Calendars/MySchedule.ics")
        /// </code>
        /// </example>
        public static VCalendar ParseFromFile(string filename)
        {
            VCalendarParser vcp = new VCalendarParser();
            vcp.ParseFile(filename);

            return vcp.VCalendar;
        }
Beispiel #8
0
 /// <summary>
 /// This static method can be used to load property values into an existing instance of a calendar from a
 /// string.
 /// </summary>
 /// <param name="calendarText">A set of calendar properties in a string</param>
 /// <param name="calendar">The calendar instance into which the properties will be loaded</param>
 /// <remarks>The properties of the specified calendar will be cleared before the new properties are
 /// loaded into it.</remarks>
 /// <example>
 /// <code language="cs">
 /// VCalendar vCalendar = new VCalendar();
 /// VCalendarParser.ParseFromString(calendarString, vCalendar);
 /// </code>
 /// <code language="vbnet">
 /// Dim vCalendar As New VCalendar
 /// VCalendarParser.ParseFromString(calendarString, vCalendar)
 /// </code>
 /// </example>
 public static void ParseFromString(string calendarText, VCalendar calendar)
 {
     VCalendarParser vcp = new VCalendarParser(calendar);
     vcp.ParseString(calendarText);
 }
Beispiel #9
0
        /// <summary>
        /// This static method can be used to load property values into a new instance of a calendar from a
        /// string.
        /// </summary>
        /// <param name="calendarText">A set of calendar properties in a string</param>
        /// <returns>A new calendar instance as created from the string</returns>
        /// <example>
        /// <code language="cs">
        /// VCalendar vCal = VCalendarParser.ParseFromString(calendar);
        /// </code>
        /// <code language="vbnet">
        /// Dim vCal As VCalendar = VCalendarParser.ParseFromString(calendar)
        /// </code>
        /// </example>
        public static VCalendar ParseFromString(string calendarText)
        {
            VCalendarParser vcp = new VCalendarParser();
            vcp.ParseString(calendarText);

            return vcp.VCalendar;
        }
        public void HideShorterThan10Minutes()
        {
            VCalendarParser calendar = new VCalendarParser();
            calendar.ParseFile("SampleCalendar.ics");

            VEvent ev_5minutes = calendar.VCalendar.Events.AddNew();
            ev_5minutes.UniqueId.Value = Guid.NewGuid().ToString();
            ev_5minutes.StartDateTime.DateTimeValue = new DateTime(2015, 01, 01);
            ev_5minutes.EndDateTime.DateTimeValue = ev_5minutes.StartDateTime.DateTimeValue.AddMinutes(5);

            VEvent ev_10minutes = calendar.VCalendar.Events.AddNew();
            ev_10minutes.UniqueId.Value = Guid.NewGuid().ToString();
            ev_10minutes.StartDateTime.DateTimeValue = new DateTime(2015, 01, 01);
            ev_10minutes.EndDateTime.DateTimeValue = ev_10minutes.StartDateTime.DateTimeValue.AddMinutes(10);

            VEvent ev_15minutes = calendar.VCalendar.Events.AddNew();
            ev_15minutes.UniqueId.Value = Guid.NewGuid().ToString();
            ev_15minutes.StartDateTime.DateTimeValue = new DateTime(2015, 01, 01).AddHours(2);
            ev_15minutes.EndDateTime.DateTimeValue = ev_15minutes.StartDateTime.DateTimeValue.AddMinutes(15);

            Assert.AreEqual(calendar.VCalendar.Events.Where(ev => ev.UniqueId == ev_5minutes.UniqueId).Count(), 1);
            Assert.AreEqual(calendar.VCalendar.Events.Where(ev => ev.UniqueId == ev_10minutes.UniqueId).Count(), 1);
            Assert.AreEqual(calendar.VCalendar.Events.Where(ev => ev.UniqueId == ev_15minutes.UniqueId).Count(), 1);

            // filter out all-day events
            EventManager em = new EventManager(calendar);
            em.Filter(new FilteringOptions("min=10"));
            var eventsAfterFiltering = em.GetEventList();

            Assert.AreEqual(eventsAfterFiltering.Where(ev => ev.UniqueId == ev_5minutes.UniqueId).Count(), 0);
            Assert.AreEqual(eventsAfterFiltering.Where(ev => ev.UniqueId == ev_10minutes.UniqueId).Count(), 1);
            Assert.AreEqual(eventsAfterFiltering.Where(ev => ev.UniqueId == ev_15minutes.UniqueId).Count(), 1);
        }
        public void SkipEventsFromProjectX()
        {
            VCalendarParser calendar = new VCalendarParser();
            calendar.ParseFile("SampleCalendar.ics");

            VEvent ev_projectX = calendar.VCalendar.Events.AddNew();
            ev_projectX.UniqueId.Value = Guid.NewGuid().ToString();
            ev_projectX.StartDateTime.DateTimeValue = new DateTime(2015, 01, 01);
            ev_projectX.EndDateTime.DateTimeValue = ev_projectX.StartDateTime.DateTimeValue.AddDays(1);
            ev_projectX.Description.Value = @"Proyecto: Project X\n\nCompletar este elemento: \nhttp://todoist.com/#project/999999999";

            VEvent ev_projectY = calendar.VCalendar.Events.AddNew();
            ev_projectY.UniqueId.Value = Guid.NewGuid().ToString();
            ev_projectY.StartDateTime.DateTimeValue = new DateTime(2015, 01, 01).AddHours(2);
            ev_projectY.EndDateTime.DateTimeValue = ev_projectY.StartDateTime.DateTimeValue.AddDays(1).AddHours(-2);
            ev_projectY.Description.Value = @"Proyecto: Project Y\n\nCompletar este elemento: \nhttp://todoist.com/#project/999999999";

            VEvent ev_projectZ = calendar.VCalendar.Events.AddNew();
            ev_projectZ.UniqueId.Value = Guid.NewGuid().ToString();
            ev_projectZ.StartDateTime.DateTimeValue = new DateTime(2015, 01, 01).AddHours(2);
            ev_projectZ.EndDateTime.DateTimeValue = ev_projectZ.StartDateTime.DateTimeValue.AddDays(1).AddHours(-2);
            ev_projectZ.Description.Value = @"Proyecto: Project\n\nCompletar este elemento: \nhttp://todoist.com/#project/999999999";

            Assert.AreEqual(calendar.VCalendar.Events.Where(ev => ev.UniqueId == ev_projectX.UniqueId).Count(), 1);
            Assert.AreEqual(calendar.VCalendar.Events.Where(ev => ev.UniqueId == ev_projectY.UniqueId).Count(), 1);
            Assert.AreEqual(calendar.VCalendar.Events.Where(ev => ev.UniqueId == ev_projectZ.UniqueId).Count(), 1);

            // filter out all-day events
            EventManager em = new EventManager(calendar);
            em.Filter(new FilteringOptions("&pr=Project X"));
            var eventsAfterFiltering = em.GetEventList();

            Assert.AreEqual(eventsAfterFiltering.Where(ev => ev.UniqueId == ev_projectX.UniqueId).Count(), 0);
            Assert.AreEqual(eventsAfterFiltering.Where(ev => ev.UniqueId == ev_projectY.UniqueId).Count(), 1);
            Assert.AreEqual(eventsAfterFiltering.Where(ev => ev.UniqueId == ev_projectZ.UniqueId).Count(), 1);
        }
        public void ShortenEvents()
        {
            VCalendarParser calendar = new VCalendarParser();
            calendar.ParseFile("SampleCalendar.ics");

            VEvent ev_1h = calendar.VCalendar.Events.AddNew();
            ev_1h.UniqueId.Value = Guid.NewGuid().ToString();
            ev_1h.StartDateTime.DateTimeValue = new DateTime(2015, 01, 01);
            ev_1h.EndDateTime.DateTimeValue = ev_1h.StartDateTime.DateTimeValue.AddHours(1);

            VEvent ev_2h = calendar.VCalendar.Events.AddNew();
            ev_2h.UniqueId.Value = Guid.NewGuid().ToString();
            ev_2h.StartDateTime.DateTimeValue = new DateTime(2015, 01, 01);
            ev_2h.EndDateTime.DateTimeValue = ev_2h.StartDateTime.DateTimeValue.AddHours(2);

            VEvent ev_3h = calendar.VCalendar.Events.AddNew();
            ev_3h.UniqueId.Value = Guid.NewGuid().ToString();
            ev_3h.StartDateTime.DateTimeValue = new DateTime(2015, 01, 01).AddHours(2);
            ev_3h.EndDateTime.DateTimeValue = ev_3h.StartDateTime.DateTimeValue.AddHours(3);

            Assert.AreEqual(calendar.VCalendar.Events.Where(ev => ev.UniqueId == ev_1h.UniqueId).First().DurationBasedOnDates().TotalHours, 1);
            Assert.AreEqual(calendar.VCalendar.Events.Where(ev => ev.UniqueId == ev_2h.UniqueId).First().DurationBasedOnDates().TotalHours, 2);
            Assert.AreEqual(calendar.VCalendar.Events.Where(ev => ev.UniqueId == ev_3h.UniqueId).First().DurationBasedOnDates().TotalHours, 3);

            // filter out all-day events
            EventManager em = new EventManager(calendar);
            em.Filter(new FilteringOptions("lt=60&mt=60"));
            var eventsAfterFiltering = em.GetEventList();

            Assert.AreEqual(calendar.VCalendar.Events.Where(ev => ev.UniqueId == ev_1h.UniqueId).First().DurationBasedOnDates().TotalHours, 1);
            Assert.AreEqual(calendar.VCalendar.Events.Where(ev => ev.UniqueId == ev_2h.UniqueId).First().DurationBasedOnDates().TotalHours, 1);
            Assert.AreEqual(calendar.VCalendar.Events.Where(ev => ev.UniqueId == ev_3h.UniqueId).First().DurationBasedOnDates().TotalHours, 1);
        }