public void Reading()
        {
            var attachment = new CalendarAttachment(new ContentLine("ATTACH;FMTTYPE=audio/basic:ftp://example.com/pub/sounds/bell-01.aud"));
            Assert.AreEqual(null, attachment.Content);
            Assert.AreEqual("audio/basic", attachment.ContentType);
            Assert.AreEqual("ftp://example.com/pub/sounds/bell-01.aud", attachment.Uri);

            attachment = new CalendarAttachment(new ContentLine("ATTACH:CID:[email protected]"));
            Assert.AreEqual(null, attachment.Content);
            Assert.AreEqual(null, attachment.ContentType);
            Assert.AreEqual("CID:[email protected]", attachment.Uri);

            attachment = new CalendarAttachment(new ContentLine("ATTACH;FMTTYPE=text/plain;ENCODING=BASE64;VALUE=BINARY:VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZy4="));
            Assert.AreEqual("The quick brown fox jumps over the lazy dog.", Encoding.ASCII.GetString(attachment.Content));
            Assert.AreEqual("text/plain", attachment.ContentType);
            Assert.AreEqual(null, attachment.Uri);
        }
        public void Writing()
        {
            var attachment = new CalendarAttachment()
            {
                ContentType = "audio/basic",
                Uri = "ftp://example.com/pub/sounds/bell-01.aud"
            };
            Assert.AreEqual("ATTACH;FMTTYPE=audio/basic:ftp://example.com/pub/sounds/bell-01.aud", attachment.ToString());

            attachment = new CalendarAttachment()
            {
                Uri = "CID:[email protected]"
            };
            Assert.AreEqual("ATTACH:CID:[email protected]", attachment.ToString());

            attachment = new CalendarAttachment()
            {
                ContentType = "text/plain",
                Content = Encoding.ASCII.GetBytes("The quick brown fox jumps over the lazy dog.")
            };
            Assert.AreEqual("ATTACH;FMTTYPE=text/plain;ENCODING=BASE64;VALUE=BINARY:VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZy4=", attachment.ToString());
        }
Example #3
0
        /// <inheritdoc/>
        public void ReadIcs(IcsReader reader)
        {
            ContentLine content;
            while (null != (content = reader.ReadContentLine()))
            {
                switch (content.Name.ToLowerInvariant())
                {
                    case "end":
                        if (!content.Value.Equals(Component.Names.Alarm, StringComparison.InvariantCultureIgnoreCase))
                            throw new CalendarException(String.Format("Expected 'END:{0}' not '{1}'.", Component.Names.TimeZone, content));
                        return;
                    case "attendee": Attendees.Add(new Attendee(content)); break;
                    case "action": Action = content.ToTag<AlarmAction>(); break;
                    case "trigger":
                    {
                        switch ((content.Parameters["value"] ?? "duration").ToLowerInvariant())
                        {
                            case "date-time":
                                TriggerOn = content.ToDate().Value;
                                break;
                            case "duration":
                                TriggerDuration = content.ToTimeSpan();
                                break;
                        }
                        switch ((content.Parameters["related"] ?? "start").ToLowerInvariant())
                        {
                            case "start":
                                TriggerEdge = TriggerEdge.Start;
                                break;
                            case "end":
                                TriggerEdge = TriggerEdge.End;
                                break;
                        }
                        break;
                    }
                    case "duration": Duration = content.ToTimeSpan(); break;
                    case "attach": Attachment = new CalendarAttachment(content); break;
                    case "description": Description = content.ToText(); break;
                    case "summary": Summary = content.ToText(); break;
                    case "repeat": Repeat = content.ToInt32(); break;

                }
            }

            throw new CalendarException("Unexpected end of file.");
        }