public void doComponentBegin(Token t) { _component.Push(t); switch (t.TokenVal) { case TokenValue.Tvcalendar: _curCalendar = new iCalendar(); break; case TokenValue.Tvevent: case TokenValue.Tvjournal: _curEvent = new iCalEvent(); _curCalendar.Events.Add(_curEvent); _curEvent.CalendarId = _curCalendar.Id; break; } }
public bool MoveNext() { current = scanner.GetNextToken(); return current != null; }
internal Enumerator(Scanner _scanner) { scanner = _scanner; current = null; }
public void doID(Token t) { _curPropToken = t; }
public void doResourceBegin(Token t) { _curPropToken = t; }
public void doBegin(Token t) { }
public void doResource(Token t) { }
public void doURIResource(Token t) { }
public void doRest(Token t, Token id) { _curPropToken = null; if (_component.Count <= 0) return; switch (_component.Peek().TokenVal) { case TokenValue.Tvcalendar: case TokenValue.Tvtimezone: switch (id.TokenText.ToLower()) { case "tzid": _curCalendar.TZID = t.TokenText; break; case "x:wrtimezone": _curCalendar.xTimeZone = t.TokenText; break; case "x:wrcalname": _curCalendar.Name = t.TokenText; break; case "x:wrcaldesc": _curCalendar.Description = t.TokenText; break; } break; case TokenValue.Tvevent: switch (id.TokenText.ToLower()) { case "description": _curEvent.Description = t.TokenText; break; case "summary": _curEvent.Name = t.TokenText; break; case "uid": _curEvent.Id = t.TokenText; break; } break; } }
public void doAttribute(Token key, Token val) { if (_component.Count <= 0) return; //event timezone if ((_curPropToken.TokenVal == TokenValue.Tdtstart || _curPropToken.TokenVal == TokenValue.Tdtend) && _component.Peek().TokenVal == TokenValue.Tvevent) { switch (key.TokenText.ToLower()) { case "tzid": var tz = TimeZoneConverter.GetTimeZone(val.TokenText); if (_curPropToken.TokenVal == TokenValue.Tdtstart) _curEvent.UtcStartDate = _curEvent.OriginalStartDate.AddMinutes((-1) * (int)tz.BaseUtcOffset.TotalMinutes); else if (_curPropToken.TokenVal == TokenValue.Tdtend) _curEvent.UtcEndDate = _curEvent.OriginalEndDate.AddMinutes((-1) * (int)tz.BaseUtcOffset.TotalMinutes); break; } } //event rrule if (_curPropToken.TokenVal == TokenValue.Trrule && _component.Peek().TokenVal == TokenValue.Tvevent) { switch(key.TokenText.ToLower()) { case "freq": _curEvent.RecurrenceRule.Freq = RecurrenceRule.ParseFrequency(val.TokenText); break; case "until": bool isDate, isUTC; _curEvent.RecurrenceRule.Until = Token.ParseDateTime(val.TokenText, out isDate, out isUTC); break; case "count": _curEvent.RecurrenceRule.Count = Convert.ToInt32(val.TokenText); break; case "interval": _curEvent.RecurrenceRule.Interval = Convert.ToInt32(val.TokenText); break; case "bysecond": _curEvent.RecurrenceRule.BySecond = val.TokenText.Split(',').Select(v => Convert.ToInt32(v)).ToArray(); break; case "byminute": _curEvent.RecurrenceRule.ByMinute= val.TokenText.Split(',').Select(v => Convert.ToInt32(v)).ToArray(); break; case "byhour": _curEvent.RecurrenceRule.ByHour = val.TokenText.Split(',').Select(v => Convert.ToInt32(v)).ToArray(); break; case "byday": _curEvent.RecurrenceRule.ByDay = val.TokenText.Split(',').Select(v => RecurrenceRule.WeekDay.Parse(v)).ToArray(); break; case "bymonthday": _curEvent.RecurrenceRule.ByMonthDay = val.TokenText.Split(',').Select(v => Convert.ToInt32(v)).ToArray(); break; case "byyearday": _curEvent.RecurrenceRule.ByYearDay = val.TokenText.Split(',').Select(v => Convert.ToInt32(v)).ToArray(); break; case "byweekno": _curEvent.RecurrenceRule.ByWeekNo = val.TokenText.Split(',').Select(v => Convert.ToInt32(v)).ToArray(); break; case "bymonth": _curEvent.RecurrenceRule.ByMonth = val.TokenText.Split(',').Select(v => Convert.ToInt32(v)).ToArray(); break; case "bysetpos": _curEvent.RecurrenceRule.BySetPos= val.TokenText.Split(',').Select(v => Convert.ToInt32(v)).ToArray(); break; case "wkst": _curEvent.RecurrenceRule.WKST = RecurrenceRule.WeekDay.Parse(val.TokenText); break; } } }
public void doIprop(Token t, Token iprop) { }
public void doValueProperty(Token t, Token iprop) { var dateTime = DateTime.MinValue; bool isAllDay = true; bool isUTC = true; if (_curPropToken.TokenVal == TokenValue.Tdtstart || _curPropToken.TokenVal == TokenValue.Tdtend || _curPropToken.TokenVal == TokenValue.Texdate) { if (iprop != null && iprop.TokenText.ToLower() == "date") dateTime = Token.ParseDate(t.TokenText); else dateTime = Token.ParseDateTime(t.TokenText, out isAllDay, out isUTC); } if (_component.Count > 0) { switch (_component.Peek().TokenVal) { case TokenValue.Tvevent: if (_curPropToken.TokenVal == TokenValue.Tdtstart) { _curEvent.AllDayLong = isAllDay; _curEvent.OriginalStartDate = dateTime; if (!isAllDay && !isUTC && _curCalendar.TimeZone != null) _curEvent.UtcStartDate = dateTime.AddMinutes((-1) * (int)_curCalendar.TimeZone.BaseUtcOffset.TotalMinutes); else _curEvent.UtcStartDate = dateTime; } else if (_curPropToken.TokenVal == TokenValue.Tdtend) { _curEvent.OriginalEndDate = dateTime; if (!isAllDay && !isUTC && _curCalendar.TimeZone != null) _curEvent.UtcEndDate = dateTime.AddMinutes((-1) * (int)_curCalendar.TimeZone.BaseUtcOffset.TotalMinutes); else if (isAllDay) _curEvent.UtcEndDate = dateTime.AddDays(-1); else _curEvent.UtcEndDate = dateTime; } else if (_curPropToken.TokenVal == TokenValue.Texdate) { _curEvent.RecurrenceRule.ExDates.Add(new RecurrenceRule.ExDate() { Date = dateTime, isDateTime = !isAllDay }); } break; } } }
public void doMailto(Token t) { }
/// <summary> /// Alternate entry point for starting the parser. /// </summary> /// <param name="emitHandT">Indicates if the emitter should be told to emit headers /// and trailers before and after emitting the iCalendar body</param> public void Parse(bool emitHandT) { stack = new Stack(); linenumber = 0; attributes = new Stack(); // a stack of key-value pairs (implemented as a stack of DitionaryEntry) if (emitHandT) { emitter.doIntro(); } // each time through the loop will get a single (maybe folded) line while (true) { // check for termination condition if (scanner.isEOF()) { // end of file - do cleanup and go break; } // empty the attribute stack and the iprop value... attributes.Clear(); iprop = null; id = null; //FIXME: linenumber doesn't really keep track of actual line numbers because // it is not aware of folded lines... linenumber++; //DEBUG: emit line number //emitter.emit( linenumber + ". " ); if (!parseID()) { continue; } // we now have to parse a set of attributes (semi-colon separated) or // a value (delimited by a colon) Token sep = scanner.GetNextToken(ScannerState.ParseSimple); if (sep == null || sep.TokenVal == TokenValue.Error) { // some kind of error - skip rest of line and continue reportError(scanner, " expecting : or ; after id - found nothing."); continue; } else if (sep.TokenVal == TokenValue.SemiColon) { if (!parseAttributes(scanner)) { continue; } // now we have to parse the value sep = scanner.GetNextToken(ScannerState.ParseSimple); if (!parseValue()) { continue; } } else if (sep.TokenVal == TokenValue.Colon) { if (!parseValue()) { continue; } } else { reportError(scanner, "expecting : or ; after id - found: " + sep.TokenText); continue; } // now sploosh out the attributes (if any) and finish the ID tag while (attributes.Count > 0) { DictionaryEntry entry = (DictionaryEntry)attributes.Pop(); Token key = (Token)entry.Key; Token val = (Token)entry.Value; emitter.doAttribute(key, val); } emitter.doEnd(id); } if (emitHandT) { emitter.doOutro(); } }
public void doEnd(Token t) { _curPropToken = null; }
/// <summary> /// Parse the first field (ID) of the line. Returns a boolean on weather or not the /// method sucesfully recognized an ID. If not, the method insures that the scanner /// will start at the beginning of a new line. /// </summary> /// <returns></returns> protected virtual bool parseID() { Token t; // re-usable token variable id = scanner.GetNextToken(ScannerState.ParseID); if (id == null || id.TokenVal == TokenValue.Error) { // some kind of error - skip rest of line and continue reportError(scanner, "expecting ID - found nothing."); return false; } switch (id.TokenVal) { case TokenValue.Tbegin: t = scanner.GetNextToken(ScannerState.ParseSimple); if (t == null || t.isError() || t.TokenVal != TokenValue.Colon) { if (t == null) reportError(scanner, " expecting : - found nothing."); else reportError(scanner, " expecting : - found " + t.TokenText); return false; } t = scanner.GetNextToken(ScannerState.ParseID); if (t == null || t.isError() || (!t.isBeginEndValue() && !t.isResourceProperty())) { if (t == null) reportError(scanner, " expecting a valid beginend value - found nothing."); else reportError(scanner, " expecting a valid beginend value - found " + t.TokenText); return false; } // check for the different types of begin tags if (t.isResourceProperty()) { emitter.doResourceBegin(t); } else if (t.isComponent()) { emitter.doComponent(); emitter.doComponentBegin(t); } else if (t.TokenVal == TokenValue.Tvcalendar) { emitter.doComponentBegin(t); } else { emitter.doBegin(t); } stack.Push(t); // to match up to the corresponding end value //scanner.ConsumeToEOL(); return false; case TokenValue.Tend: t = scanner.GetNextToken(ScannerState.ParseSimple); if (t == null || t.isError() || t.TokenVal != TokenValue.Colon) { if (t == null) reportError(scanner, " expecting : - found nothing."); else reportError(scanner, " expecting : - found " + t.TokenText); return false; } t = scanner.GetNextToken(ScannerState.ParseID); if (t == null || t.isError() || (!t.isBeginEndValue() && !t.isResourceProperty())) { if (t == null) reportError(scanner, " expecting a valid beginend value - found nothing."); else reportError(scanner, " expecting a valid beginend value - found " + t.TokenText); return false; } // the end is easier - ignore the last one... if (stack.Count != 0) { emitter.doEnd(t); if (t.isComponent()) { emitter.doEndComponent(); } stack.Pop(); } else { reportError(scanner, "stack stuff is weird - probably illformed .ics file - parsing " + id.TokenText); } //scanner.ConsumeToEOL(); return false; case TokenValue.Trrule: emitter.doResourceBegin(id); break; default: emitter.doID(id); break; } return true; }
public void doSymbolic(Token t) { }