public CalendarViewModel (DDay.iCal.IICalendar ic)
		{
			this.Name = ic.Name;
			this.FreeBusy = ic.FreeBusy
				.Select(fb=>new FreeBusyViewModel {
					Start = fb.Start.Value,
					End = fb.End.Value,
				}).ToList();
		}
 public static void FixTimeZoneDSTRRules (TimeZoneInfo tz, DDay.iCal.iCalTimeZone iCalTz)
 {
   var adjustments = tz.GetAdjustmentRules();
   foreach (var tziItems in iCalTz.TimeZoneInfos)
   {
     var matchingAdj = adjustments.FirstOrDefault (a => (a.DateStart.Year == tziItems.Start.Year)) ?? adjustments.FirstOrDefault();
     if (matchingAdj != null && matchingAdj.DateEnd.Year != 9999)
     {
       if (!(tziItems.Name.Equals ("STANDARD") && matchingAdj == adjustments.Last()))
       {
         tziItems.RecurrenceRules[0].Until = DateTime.SpecifyKind (matchingAdj.DateEnd.Date.AddDays (1).Subtract (tz.BaseUtcOffset), DateTimeKind.Utc);
       }
     }
   }
 }
Example #3
0
        private void IncludeFutureEvent(List<DDay.iCal.Event> events_to_include, Dictionary<DDay.iCal.Event, RecurrenceType> event_recurrence_types, DDay.iCal.Event evt, DateTime midnight_in_tz, DateTime then, bool skip_date_only)
        {
            try
            {
                /*if (evt.RecurrenceRules.Count > 0)                    // check for unbounded recurrence
                    foreach (var rrule in evt.RecurrenceRules)
                        if (rrule.Until < DateTime.UtcNow)            // i.e. FREQ=DAILY but not FREQ=DAILY;UNTIL=20120101
                             return; */

                var occurrences = evt.GetOccurrences(midnight_in_tz, then);
                foreach (Occurrence occurrence in occurrences)
                {
                    try
                    {
                        var recurrence_type = occurrence.Source.RecurrenceRules.Count == 0 ? RecurrenceType.NonRecurring : RecurrenceType.Recurring;

                        if (recurrence_type == RecurrenceType.Recurring && skip_date_only && evt.DTStart.HasTime == false) // workaround for https://github.com/dougrday/icalvalid/issues/7 and 8
                            continue;                                                                                      // note: this is now a fallback because MassageFeedText tries to patch date-only UNTIL, adding T000000

                        if (IsCurrentOrFutureDTStartInTz(occurrence.Period.StartTime.UTC, this.calinfo.tzinfo))
                        {
                            var instance = PeriodizeRecurringEvent(evt, occurrence.Period);
                            events_to_include.Add(instance);
                            event_recurrence_types.AddOrUpdateDictionary<DDay.iCal.Event, Collector.RecurrenceType>(instance, recurrence_type);
                        }
                    }
                    catch (Exception e)
                    {
                        try
                        {
                            GenUtils.PriorityLogMsg("exception", "IncludeFutureEvent (per occurrence)", evt.Summary + ", " + e.Message + e.StackTrace);
                        }
                        catch { continue; }
                    }
                }
            }

            catch (Exception e)
            {
                try
                {
                    GenUtils.PriorityLogMsg("exception", "IncludeFutureEvent (GetOccurrences) detail: " + evt.Summary, e.Message + e.StackTrace);
                }
                catch { return; }
            }
        }
Example #4
0
 public iCalendarSerializer(DDay.iCal.iCalendar iCal) : base(iCal)
 {
     iCalendar = iCal;
 }
Example #5
0
        // put the event into a) the eventstore, and b) the per-type intermediate icalendar object
        public void AddIcalEvent(DDay.iCal.Event evt, FeedRegistry fr, ZonedEventStore es, string feedurl, string source)
        {
            try
            {
                evt = NormalizeIcalEvt(evt, feedurl, source);

                DateTimeWithZone dtstart;
                DateTimeWithZone dtend;
                var tzinfo = this.calinfo.tzinfo;

                //dtstart = Utils.DtWithZoneFromICalDateTime(evt.Start.Value, tzinfo);
                //dtend = (evt.DTEnd == null) ? new Utils.DateTimeWithZone(DateTime.MinValue, tzinfo) : Utils.DtWithZoneFromICalDateTime(evt.End.Value, tzinfo);

                //dtstart = new Utils.DateTimeWithZone(evt.Start.Value,tzinfo);
                //dtend = new Utils.DateTimeWithZone(evt.End.Value,tzinfo);

                var localstart = evt.DTStart.IsUniversalTime ? TimeZoneInfo.ConvertTimeFromUtc(evt.Start.UTC, tzinfo) : evt.Start.Local;
                dtstart = new DateTimeWithZone(localstart, tzinfo);

                var localend = evt.DTEnd.IsUniversalTime ? TimeZoneInfo.ConvertTimeFromUtc(evt.End.UTC, tzinfo) : evt.End.Local;
                dtend = new DateTimeWithZone(localend, tzinfo);

                MakeGeo(this.calinfo, evt, this.calinfo.lat, this.calinfo.lon);

                string categories = null;
                if (evt.Categories != null && evt.Categories.Count() > 0)
                    categories = string.Join(",", evt.Categories.ToList().Select(cat => cat.ToString().ToLower()));

                string description = this.calinfo.has_descriptions ? evt.Description : null;

                string location = this.calinfo.has_locations ? evt.Location : null;

                es.AddEvent(title: evt.Summary, url: evt.Url.ToString(), source: source, dtstart: dtstart, dtend: dtend, lat: this.calinfo.lat, lon: this.calinfo.lon, allday: evt.IsAllDay, categories: categories, description: description, location: location);

                var evt_tmp = MakeTmpEvt(this.calinfo, dtstart: dtstart, dtend: dtend, title: evt.Summary, url: evt.Url.ToString(), location: evt.Location, description: source, lat: this.calinfo.lat, lon: this.calinfo.lon, allday: evt.IsAllDay);
                AddEventToDDayIcal(ical_ical, evt_tmp);

                if ( fr.stats.ContainsKey(feedurl) )   // won't be true when adding to the per-feed obj cache
                    fr.stats[feedurl].loaded++;        // and this will have already been counted by the all-feeds AddIcalEvent

            }
            catch (Exception e)
            {
                GenUtils.PriorityLogMsg("exception", "AddIcalEvent", source + ": " + e.Message + ": " + evt.Summary);
            }
        }
Example #6
0
	public void icalbody(
		DDay.iCal.iCalendar iCal
	) //throws RecognitionException, TokenStreamException
{
		
		
		{
			switch ( LA(1) )
			{
			case IANA_TOKEN:
			case X_NAME:
			case PRODID:
			case VERSION:
			case CALSCALE:
			case METHOD:
			{
				calprops(iCal);
				break;
			}
			case BEGIN:
			case CRLF:
			case END:
			{
				break;
			}
			default:
			{
				throw new NoViableAltException(LT(1), getFilename());
			}
			 }
		}
		{
			switch ( LA(1) )
			{
			case BEGIN:
			case CRLF:
			{
				component(iCal);
				break;
			}
			case END:
			{
				break;
			}
			default:
			{
				throw new NoViableAltException(LT(1), getFilename());
			}
			 }
		}
	}
Example #7
0
 private static bool ParseFails(string feedtext, DDay.iCal.iCalendar ical)
 {
     StringReader sr;
     try
     {
         sr = new StringReader(feedtext);
         ical = (DDay.iCal.iCalendar)iCalendar.LoadFromStream(sr).FirstOrDefault().iCalendar;
     }
     catch
     {
         Assert.IsNull(ical);
         return true;
     }
     return false;
 }
Example #8
0
 public FieldSerializer(DDay.iCal.DataTypes.iCalDataType dataType) : base(dataType) {}
Example #9
0
 /// <summary>
 /// A default constructor for iCalendar objects
 /// </summary>
 /// <param name="parent">The parent object that contains this one, or NULL.</param>
 public CustomEvent(DDay.iCal.Objects.iCalObject parent) : base(parent) { }
Example #10
0
	public void icalbody(
		DDay.iCal.iCalendar iCal
	) //throws RecognitionException, TokenStreamException
{
		
		
		{    // ( ... )*
			for (;;)
			{
				if ((LA(1)==IANA_TOKEN||LA(1)==X_NAME))
				{
					calprop(iCal);
				}
				else
				{
					goto _loop12_breakloop;
				}
				
			}
_loop12_breakloop:			;
		}    // ( ... )*
		{
			switch ( LA(1) )
			{
			case BEGIN:
			{
				component(iCal);
				break;
			}
			case END:
			{
				break;
			}
			default:
			{
				throw new NoViableAltException(LT(1), getFilename());
			}
			 }
		}
	}
Example #11
0
 public RecurSerializer(DDay.iCal.DataTypes.Recur recur)
     : base(recur)
 {
     this.m_Recur = recur;
 }
Example #12
0
 public static void AddCategoriesFromCatString(DDay.iCal.Event evt, string cats)
 {
     try
     {
         var catlist = cats.Split(',');
         foreach (var cat in catlist)
         {
             var c = cat.Trim();
             evt.Categories.Add(c);
         }
     }
     catch
     {
         GenUtils.PriorityLogMsg("exception", "AddCategoriesFromCatString: " + evt.Summary + ": " + cats, null);
     }
 }
Example #13
0
 public static void AddEventToDDayIcal(iCalendar ical, DDay.iCal.Event evt)
 {
     var ical_evt = new DDay.iCal.Event();
     ical_evt.Categories = evt.Categories;
     ical_evt.Summary = evt.Summary;
     ical_evt.Url = evt.Url;
     ical_evt.Location = evt.Location;
     ical_evt.Description = evt.Description;
     ical_evt.Start = evt.Start;
     if (evt.DTEnd != null && evt.DTEnd.Year != 1)
         ical_evt.End = evt.DTEnd;
     ical_evt.IsAllDay = evt.IsAllDay;
     ical_evt.UID = Event.MakeEventUid(ical_evt);
     ical_evt.GeographicLocation = evt.GeographicLocation;
     ical.Events.Add(ical_evt);
 }
Example #14
0
        private static void SetUrl(DDay.iCal.Event evt, Dictionary<string, string> feed_metadict, Dictionary<string, string> metadata_from_description)
        {
            if (EventUrlPropertyIsHttp(evt))  // use the URL property if it exists and is http:
                return;

            if (feed_metadict.ContainsKey("url"))  // use the feed metadata's URL if it exists
            {
                try
                {
                    evt.Url = new Uri(feed_metadict["url"]);
                }
                catch
                {
                    GenUtils.LogMsg("warning", "SetUrl: no url for " + feed_metadict["source"], null);
                }
            }

            /*
            if (DescriptionStartsWithUrl(evt)) // override with event's Description if URL-like
            {
                evt.Url = new Uri(evt.Description.ToString());
            }*/

            if (LocationStartsWithUrl(evt))   // override with the event's Location if URL-like
            {
                evt.Url = new Uri(evt.Location.ToString());
            }

            if (metadata_from_description.ContainsKey("url")) // override with event's url=URL if it exists
            {
                evt.Url = new Uri(metadata_from_description["url"]);
            }

            if (evt.Url == null)
                evt.Url = new Uri("http://unspecified");	// finally this
        }
Example #15
0
 private static bool LocationStartsWithUrl(DDay.iCal.Event evt)
 {
     string location = evt.Location.ToString();
     return !String.IsNullOrEmpty(location) && Utils.StartsWithUrl(location) != null;
 }
Example #16
0
 private static bool EventUrlPropertyIsHttp(DDay.iCal.Event evt)
 {
     string url = (evt.Url == null) ? null : evt.Url.ToString();
     return !String.IsNullOrEmpty(url) && url.StartsWith("http:"); // URL:message:%3C001401cbb263$05c84af0$1158e0d0$@net%3E doesn't qualify
 }
Example #17
0
 private static bool DescriptionStartsWithUrl(DDay.iCal.Event evt)
 {
     string description = evt.Description.ToString();
     return !String.IsNullOrEmpty(description) && Utils.StartsWithUrl(description) != null;
 }
Example #18
0
        // normalize url, description, location, category properties
        public DDay.iCal.Event NormalizeIcalEvt(DDay.iCal.Event evt, string feedurl, string source)
        {
            try
            {
                if (evt.Description == null) evt.Description = "";

                if (evt.Location == null) evt.Location = "";

                if (evt.Summary.StartsWith("Event: ")) // zvents does this, it's annoying
                    evt.Summary = evt.Summary.Replace("Event: ", "");

                var feed_metadict = GetFeedMetadictWithCaching(feedurl);
                var metadata_from_description = Utils.GetMetadataFromDescription(Configurator.ical_description_metakeys, evt.Description);
                SetUrl(evt, feed_metadict, metadata_from_description);

                // evt.Categories.Clear(); // not needed now that we are scoping tags down to the active taxonomy

                try
                {
                    SetCategories(evt, feed_metadict, metadata_from_description, id, source);
                }
                catch (Exception e)
                {
                    GenUtils.PriorityLogMsg("exception", "NormalizeIcalEvt: " + this.id + ", " + evt.Summary + ", " + JsonConvert.SerializeObject(feed_metadict) + ", " + JsonConvert.SerializeObject(metadata_from_description), e.Message + e.StackTrace);
                }

                //var re = new Regex("<.*?>", RegexOptions.Compiled); // strip html tags  <- move into Collector
                //evt.Description = re.Replace(evt.Description, String.Empty);
                //evt.Summary = re.Replace(evt.Summary, String.Empty);
            }
            catch (Exception e)
            {
                GenUtils.PriorityLogMsg("exception", this.id + ": NormalizeIcalEvent", e.Message + e.StackTrace);
            }

            return evt;
        }
Example #19
0
        private void MaybeAugmentEventfulCategories(DDay.iCal.Event evt, Dictionary<string, List<string>> eids_and_cats)
        {
            if (eids_and_cats.Count == 0)
                return;

            if ( evt.Url == null )
                return;

            try
            {
                var eid = evt.Url.ToString().Split('/').Last();
                if (eids_and_cats.ContainsKey(eid))
                {
                    var cats = eids_and_cats[eid].Intersect(this.tags);
                    foreach (var cat in cats)
                        evt.Categories.Add(cat);
                }
            }
            catch (Exception e)
            {
                GenUtils.PriorityLogMsg("exception", "MaybeAugmentEventfulCategories", e.Message + e.StackTrace);
            }
        }
Example #20
0
        // add VTIMEZONE to intermediate or final ics outputs
        public static void AddTimezoneToDDayICal(DDay.iCal.iCalendar ical, TimeZoneInfo tzinfo)
        {
            var timezone = DDay.iCal.iCalTimeZone.FromSystemTimeZone(tzinfo);

            //timezone.TZID = tzinfo.Id; // not being set in DDay.iCal 0.8 for some reason

            /*
             *  Interesting situation if the source calendar says, e.g., America/Chicago, but
             *  the OS says, e.g., Central. In that case, DDay's UTC property method will fail to match
             *  the names and it will fall back to the OS conversion:
             *
             *  value = DateTime.SpecifyKind(Value, DateTimeKind.Local).ToUniversalTime();
             *
             *  This happens when:
             *    - A recurring event has a start and end
             *    - DDay substracts DTEnd.UTC - DTStart.UTC
             *
             *  Todo: Recheck all this when upgraded to DDay 1.0
             */

            if (timezone.TimeZoneInfos.Count == 0)
            {
                var dday_tzinfo_standard = new DDay.iCal.iCalTimeZoneInfo();
                dday_tzinfo_standard.Name = "STANDARD";
                dday_tzinfo_standard.TimeZoneName = tzinfo.StandardName;
                //dday_tzinfo_standard.Start.Date = new DateTime(1970, 1, 1);
                var utcOffset = tzinfo.BaseUtcOffset;
                dday_tzinfo_standard.TZOffsetFrom = new DDay.iCal.UTCOffset(utcOffset);
                dday_tzinfo_standard.TZOffsetTo = new DDay.iCal.UTCOffset(utcOffset);
                // Add the "standard" time rule to the time zone
                timezone.AddChild(dday_tzinfo_standard);
            }

            ical.AddChild(timezone);
        }
 public iCalendarSerializer(DDay.iCal.iCalendar iCal) : base(iCal)
 {
     this.m_iCal = iCal;
 }
Example #22
0
        private void SetCategories(DDay.iCal.Event evt, Dictionary<string, string> feed_metadict, Dictionary<string, string> metadata_from_description, string id, string source)
        {
            var list = evt.Categories.ToList();

            try
            {
                list = PrepareCats(list, feed_metadict, id, source);  // normalize, and apply catmap if it exists
            }
            catch (Exception e)
            {
                GenUtils.PriorityLogMsg("exception", "PrepareCats: " + JsonConvert.SerializeObject(feed_metadict), e.Message);
                return;
            }

            // foreach (var cat in evt.Categories)                         // restrict to active taxonomy -- but not for now
            //	list = list.RemoveUnlessFound(cat.ToLower(), this.tags);

            evt.Categories.Clear();
            foreach (var cat in list)
            {
                var c = cat.ToLower();
                if (c.StartsWith("http:"))								// lose bogus categories
                    continue;
                if (this.tags.HasItem(c))                      // if matches a tag in the active taxonomy
                    evt.Categories.Add(c);								// use unmodified
                else
                    evt.Categories.Add("{" + c + "}");                  // else mark as contributor-provided
            }

            if (feed_metadict.ContainsKey("category"))				// apply feed-level categories from feed metadata
            {
                var cat_string = feed_metadict["category"];
                AddCategoriesFromCatString(evt, cat_string);
            }

            if (metadata_from_description.ContainsKey("category"))			// apply event-level categories from Description
            {
                var cat_string = metadata_from_description["category"];
                AddCategoriesFromCatString(evt, cat_string);
            }

            list = evt.Categories.ToList();   // sort
            list.Sort(String.CompareOrdinal);
            evt.Categories.Clear();
            foreach (var cat in list)
                evt.Categories.Add(cat);
        }
 public iCalObjectSerializer(DDay.iCal.Components.iCalObject iCalObject)
 {
     Object = iCalObject;
 }
Example #24
0
        public static void MakeGeo(Calinfo calinfo, DDay.iCal.Event evt, string lat, string lon)
        {
            if (String.IsNullOrEmpty(lat) || string.IsNullOrEmpty(lon))
                return;

            if ( calinfo.hub_enum == HubType.where)
            {
                if (evt.GeographicLocation == null)           // override with hub's location
                {
                    try
                    {
                        if (lat == null)                // e.g., because called from IcsFromRssPlusXcal
                            lat = calinfo.lat;

                        if (lon == null)
                            lon = calinfo.lon;

                        MakeGeo(evt, lat, lon);
                    }
                    catch (Exception e)
                    {
                        GenUtils.PriorityLogMsg("exception", "AddIcalEvent: " + calinfo.id + " cannot make evt.Geo", e.Message + evt.Summary.ToString());
                    }
                }
            }
        }
 private static void HillsideExampleIsCorrectIcs(DDay.iCal.iCalendar ical)
 {
     Assert.That(ical.Events.Count > 0);  // it's a recurring event, don't need/want to test for exact count
     var evt = ical.Events[0];
     Assert.That(evt.Summary.StartsWith("Afternoon Tea 3"));
     Assert.That(evt.Start.Hour == 15);
     Assert.That(evt.Start.Minute == 0);
     Assert.That(evt.Start.Second == 0);
 }
Example #26
0
        public static void MakeGeo(DDay.iCal.Event evt, string lat, string lon)
        {
            if (String.IsNullOrEmpty(lat) || string.IsNullOrEmpty(lon))
                return;

            evt.GeographicLocation = new GeographicLocation();
            try
                {
                evt.GeographicLocation.Latitude = Double.Parse(lat);
                evt.GeographicLocation.Longitude = Double.Parse(lon);
                }
            catch (Exception e)
                {
                GenUtils.LogMsg("warning", "MakeGeo cannot parse " + lat + "," + lon, e.Message);
                }
        }
Example #27
0
	public void calprops(
		DDay.iCal.iCalendar iCal
	) //throws RecognitionException, TokenStreamException
{
		
		
		calprop(iCal);
		{ // ( ... )+
			int _cnt20=0;
			for (;;)
			{
				if ((tokenSet_0_.member(LA(1))))
				{
					calprop(iCal);
				}
				else
				{
					if (_cnt20 >= 1) { goto _loop20_breakloop; } else { throw new NoViableAltException(LT(1), getFilename());; }
				}
				
				_cnt20++;
			}
_loop20_breakloop:			;
		}    // ( ... )+
	}
Example #28
0
        // clone the DDay.iCal event, update dtstart (and maybe dtend) with Year/Month/Day for this occurrence
        public static DDay.iCal.Event PeriodizeRecurringEvent(DDay.iCal.Event evt, IPeriod period)
        {
            var kind = evt.Start.IsUniversalTime ? DateTimeKind.Utc : DateTimeKind.Local;

            var dtstart = new DateTime(
                period.StartTime.Year,
                period.StartTime.Month,
                period.StartTime.Day,
                evt.Start.Hour,
                evt.Start.Minute,
                evt.Start.Second,
                kind);

            var idtstart = new iCalDateTime(dtstart);

            var idtend = default(iCalDateTime);
            DateTime dtend = default(DateTime);

            if (evt.DTEnd != null && evt.DTEnd.Year != 1 )
            {
                dtend = new DateTime(
                    period.EndTime.Year,
                    period.EndTime.Month,
                    period.EndTime.Day,
                    evt.End.Hour,
                    evt.End.Minute,
                    evt.End.Second,
                    kind);

                idtend = new iCalDateTime(dtend);
            }

            var instance = new DDay.iCal.Event();
            instance.Start = idtstart;
            instance.End = idtend;
            instance.Summary = evt.Summary;
            instance.Description = evt.Description;
            foreach (var cat in evt.Categories)
                instance.Categories.Add(cat);
            instance.Location = evt.Location;
            instance.GeographicLocation = evt.GeographicLocation;
            instance.UID = evt.UID;
            instance.Url = evt.Url;
            return instance;
        }
 public DataTypeSerializer(DDay.iCal.DataTypes.iCalDataType dataType)
 {
     this.m_dataType = dataType;
 }
 public iCalObjectSerializer(DDay.iCal.Objects.iCalObject iCalObject)
 {
     this.m_object = iCalObject;
 }