Ejemplo n.º 1
0
        /// <summary>
        /// Does the most basic deserialization. We will return when we reach the closing of
        /// the first opening block we find.
        /// </summary>
        /// <param name="input"></param>
        /// <remarks>
        /// iCal input is a series of lines (some are continued).
        /// </remarks>
        public static RawModel Deserialize(IEnumerable<string> lines)
        {
            var stack = new Stack<RawModel>();
            RawModel current = null;
            foreach (var line in lines.UnfoldLines())
            {
                var t = line.ParseAsICalContentLine();
                if (t.Name == "BEGIN")
                {
                    var r = new RawModel() { Name = t.Value };
                    stack.Push(current);
                    if (current != null)
                        current.AddBlock(r);
                    current = r;
                }
                else if (t.Name == "END")
                {
                    (t.Value != current.Name).ThrowiCalError("Opening ('{0}') and closing ('{1}') blocks do not match", current.Name, t.Value);
                    // Note that the first push we do will be a null - so the check here may look funny!
                    if (stack.Count == 1)
                        return current;
                    current = stack.Pop();
                }
                else
                {
                    (current == null).ThrowiCalError("iCal Key/Value pair outside block");
                    current.AddProperty(t.Name, t);
                }
            }

            return null;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Given a block that is a VEvent, do the translation.
 /// </summary>
 /// <param name="arg"></param>
 /// <returns></returns>
 private static object MakeVEvent(RawModel arg)
 {
     return new iCalVEvent()
     {
         Summary = arg.GetPropValueWithDefault("SUMMARY", "").AsiCalText(),
         UID = arg.GetPropValueWithDefault("UID", "").AsiCalText(),
         Location = arg.GetPropValueWithDefault("LOCATION", "").AsiCalText(),
         Description = arg.GetPropValueWithDefault("DESCRIPTION", "").AsiCalText(),
         DTEnd = arg.GetPropValueWithDefault("DTEND", "").AsiCalDateTime(),
         DTStart = arg.GetPropValueWithDefault("DTSTART", "").AsiCalDateTime(),
         URL = arg.GetPropValueWithDefault("URL", "").AsiCalUri(),
         Properties = arg.ContentLine,
     };
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Add a block to the list of blocks.
 /// </summary>
 /// <param name="r"></param>
 internal void AddBlock(RawModel r)
 {
     var inserter = new RawModel[] { r };
     if (!SubBlocks.ContainsKey(r.Name))
     {
         SubBlocks[r.Name] = inserter;
     }
     else
     {
         // TODO: Make efficient
         SubBlocks[r.Name] = SubBlocks[r.Name]
             .Concat(inserter)
             .ToArray();
     }
 }