Example #1
0
        private VEvent ParseVEvent(TokenNode node)
        {
            var cEvent = new VEvent();

            var refDate = DateTime.MinValue;
            bool refBool = false;
            string refString = "";

            if (TryFindDate(node, "DTSTART", ref refDate, out refBool))
            {
                cEvent.From = refDate;
                cEvent.IsFullDayEvent = refBool;
            }
            if (TryFindDate(node, "DTEND", ref refDate, out refBool))
            {
                cEvent.To = refDate;
                cEvent.IsFullDayEvent = refBool;
            }
            if ((refString = TryFindString(node, "SUMMARY")) != null)
                cEvent.Title = refString;
            if ((refString = TryFindString(node, "DESCRIPTION")) != null)
                cEvent.Description = refString;
            
            return cEvent;
        }
Example #2
0
        private string TryFindString(TokenNode node, string tokenName)
        {
            var tokenQuery = node.Tokens.Where(o => o.NamingKey == tokenName).ToArray();

            if (tokenQuery.Any())
            {
                return tokenQuery.First().Value.DecodedValue;
            }
            return null;
        }
        public static void UpdateStringToken(TokenNode icalEvent, string tokenName, string value,string subKey = "")
        {
            var tquery = icalEvent.Tokens.SingleOrDefault(o => o.NamingKey.ToLower() == tokenName.ToLower()) ?? new Token { Key = tokenName };

            tquery.SubKey = subKey;
            tquery.Value = new EncodedTokenValue {DecodedValue = value};

            if (!icalEvent.Tokens.Contains(tquery))
                icalEvent.Tokens.Add(tquery);
        }
Example #4
0
        private TokenNode FindNextChild(TokenNode rootNode,int minIndex, string objectName)
        {
            var calendarQuery = rootNode.Childs.Where(o => o.Name == objectName);

            if (calendarQuery.Count() > minIndex)
            {
                return calendarQuery.Skip(minIndex).Take(1).Single();
            }

            return null;
        }
Example #5
0
        /// <summary>
        /// Schreibt ein TokenNode mit allen TOkens und Unterelementen in einen Writer
        /// </summary>
        public static void WriteTokenNode(TokenNode tokenNode, TextWriter writer)
        {
            writer.WriteLine("BEGIN:" + tokenNode.Name);

            foreach (var token in tokenNode.Tokens)
                WriteToken(token, writer);

            foreach (var childNode in tokenNode.Childs)
                WriteTokenNode(childNode, writer);

            writer.WriteLine("END:" + tokenNode.Name);
        }
 public static void UpdateDateToken(TokenNode icalEvent, string tokenName, DateTime value, bool isFullDayEvent)
 {
     if (isFullDayEvent)
         UpdateStringToken(icalEvent, tokenName, value.ToString("yyyyMMdd"), "VALUE=DATE-TIME");
     else
     {
         value = value.ToUniversalTime();
         UpdateStringToken(icalEvent, tokenName, value.ToString("yyyyMMdd") + "T"
                                                 + value.ToString("HHmmss") + "Z"
                           , "VALUE=DATE-TIME");
     }
 }
Example #7
0
        private bool TryFindDate(TokenNode node, string tokenName, ref DateTime result, out bool isFullDayTime)
        {
            var tokenQuery = node.Tokens.Where(o => o.NamingKey == tokenName).ToArray();

            if (tokenQuery.Any())
            {
                var dateTime = ParserDateTime.Parse(tokenQuery.First().Value.EncodedValue, out isFullDayTime);

                if (dateTime.HasValue)
                    result = dateTime.Value;
                else
                    return false;

                return true;
            }
            else isFullDayTime = false;

            return false;
        }
Example #8
0
        public TokenNode Parse(Stream value)
        {
            var rootNode = new TokenNode();
            var tokenStack = new Stack<TokenNode>();

            using (var reader = new StreamReader(value))
            {
                string line = "";
                while ((line = reader.ReadLine()) != null)
                {
                    if (line.StartsWith(" "))
                    {
                        tokenStack.Peek().Tokens.Last().Value.EncodedValue += line.Substring(1, line.Length - 1);
                        continue;
                    }

                    var currentToken = new Token();
                    ParseSingleToken(ref currentToken, line);

                    switch (currentToken.NamingKey)
                    {
                        case TokenBegin:
                            tokenStack.Push(new TokenNode{ Name = currentToken.Value.EncodedValue});
                            break;
                        case TokenEnd:
                            var endElement = tokenStack.Pop();
                            if (currentToken.Value.EncodedValue != endElement.Name)
                                throw new ParsingICalException();
                            if (tokenStack.Count == 0)
                                rootNode.Childs.Add(endElement);
                            else
                                tokenStack.Peek().Childs.Add(endElement);
                            break;
                        default:
                            tokenStack.Peek().Tokens.Add(currentToken);
                            break;
                    }
                }
            }

            return rootNode;
        }
Example #9
0
 /// <summary>
 /// Schreibt ein TokenNode mit allen Tokens und Unterelementen in einen Stream
 /// </summary>
 public static void WriteTokenNode(TokenNode tokenNode, Stream target)
 {
     TextWriter writer = new StreamWriter(target);
     WriteTokenNode(tokenNode, writer);
     writer.Flush();
 }