public EventRequestData GetEventRequestFromVCard(VCardGroup document)
        {
            StringBuilder output = new StringBuilder();
            WriteGroup(output, document);

            return CreateResult(output.ToString());
        }
        private void WriteGroup(StringBuilder output, VCardGroup group)
        {
            output.AppendFormat("BEGIN:{0}\r\n", group.Name);

            foreach (VCardEntity child in group.Children)
            {
                if (child is VCardGroup)
                {
                    WriteGroup(output, (VCardGroup)child);
                    continue;
                }
                else if (child is VCardValue)
                {
                    VCardValue value = (VCardValue)child;

                    output.Append(value.Name);

                    foreach (var p in value.Parameters)
                        output.AppendFormat(";{0}={1}", p.Name, p.EscapedValue);

                    output.AppendFormat(":{0}\r\n", value.EscapedValue);
                }
            }

            output.AppendFormat("END:{0}\r\n", group.Name);
        }
        public void FakeVCalendarRequestParser_GetEventRequestFromVCard_Returns_Text_In_Event_Summary()
        {
            const string heading = "Heading";
            const string value = "value";
            const string expected = heading + ":" + value;

            var input = new VCardGroup("TestGroup");
            input.Children.Add(new VCardValue(heading, value));

            var actual = new FakeVCalendarRequestParser().GetEventRequestFromVCard(input);

            Assert.That(actual.Event.Summary, Contains.Substring(expected));
        }
Пример #4
0
        private VCardEntity GetEntityFromLine(TextReader reader, VCardLineReader line)
        {
            switch (line.Type)
            {
                case VCardLineType.Value:
                    return GetValueFromLine(line);

                case VCardLineType.GroupEnding:
                    throw new InvalidVCardFormatException("Encountered unexpected group ending " + line.Name, line.EntireLine);

                case VCardLineType.GroupBeginning:
                    VCardGroup group = new VCardGroup(line.Name);
                    ReadAllGroupChildren(reader, group);
                    return group;

                default:
                    throw new NotSupportedException("Unknown Line Type " + line.Type.ToString());
            }
        }
Пример #5
0
        private void ReadAllGroupChildren(TextReader reader, VCardGroup group)
        {
            while (true)
            {
                string unfoldedLine = ReadUnfoldedLine(reader);
                if (unfoldedLine == null)
                    throw new InvalidVCardFormatException("Encountered end of VCard content before ending of group " + group.Name, null);

                VCardLineReader line = new VCardLineReader(unfoldedLine);

                if (line.Type == VCardLineType.GroupEnding)
                {
                    if (!String.Equals(group.Name, line.Name, StringComparison.InvariantCultureIgnoreCase))
                        throw new InvalidVCardFormatException("Encountered end of Group " + line.Name + " before current group " + group.Name, line.EntireLine);
                    break;
                }

                VCardEntity child = GetEntityFromLine(reader, line);
                group.Children.Add(child);
            }
        }