Exemple #1
0
        /// <summary>
        ///     Writes a card, then reads it back and compares fields.
        /// </summary>
        public static void CycleStandard21(vCard card)
        {

            if (card == null)
                throw new ArgumentNullException("cycle");

            // Create a memory stream to hold the contents of the card.

            MemoryStream stream = new MemoryStream();

            StreamWriter textWriter = new StreamWriter(stream);

            // Create a standard vCard writer and export the
            // card data to the stream.

            vCardStandardWriter writer = new vCardStandardWriter();
            writer.Write(card, textWriter);
            textWriter.Flush();

            // Reset the stream (back to its beginning), then
            // create a stream reader capable of reading text
            // lines from the stream.

            stream.Seek(0, SeekOrigin.Begin);
            StreamReader streamReader = new StreamReader(stream);

            vCardStandardReader standardReader = new vCardStandardReader();
            vCard reloaded = standardReader.Read(streamReader);

            Equals(card, reloaded);

        }
        public void EncodeEscaped_Comma_Text_Comma()
        {

            vCardStandardWriter writer = new vCardStandardWriter();

            Assert.AreEqual(
                @"\,text\,",
                writer.EncodeEscaped(",text,"));

        }
Exemple #3
0
    /// <summary>
    ///     Executed when the Submit button is clicked.
    /// </summary>
    protected void SubmitButton_Click(object sender, EventArgs e)
    {

        vCard card = new vCard();

        // Simple properties

        card.AdditionalNames = AdditionalNames.Text;
        card.FamilyName = FamilyName.Text;
        card.GivenName = GivenName.Text;
        card.NamePrefix = NamePrefix.Text;
        card.NameSuffix = NameSuffix.Text;
        card.Organization = Organization.Text;
        card.Role = Role.Text;
        card.Title = Title.Text;

        // ---------------------------------------------------------------
        // Email Addresses
        // ---------------------------------------------------------------
        // A vCard supports any number of email addresses.

        if (!string.IsNullOrEmpty(WorkEmail.Text))
        {
            card.EmailAddresses.Add(
                new vCardEmailAddress(WorkEmail.Text));

        }

        // ---------------------------------------------------------------
        // Notes
        // ---------------------------------------------------------------
        // The vCard specification allows for multiple notes, although
        // most applications seem to support a maximum of one note.

        if (Note.Text.Length > 0)
        {
            card.Notes.Add(new vCardNote(Note.Text));
        }


        // ---------------------------------------------------------------
        // Phones
        // ---------------------------------------------------------------
        //
        // A vCard supports any number of telephones.  Each telephone can
        // have a different type (such as a video phone or a fax) and a
        // purpose (e.g. a home number or a work number).

        if (!string.IsNullOrEmpty(WorkPhone.Text))
        {
            card.Phones.Add(
                new vCardPhone(WorkPhone.Text, vCardPhoneType.WorkVoice));
        }

        if (!string.IsNullOrEmpty(WorkFax.Text))
        {
            card.Phones.Add(
                new vCardPhone(WorkFax.Text, vCardPhoneType.WorkFax));
        }


        // ---------------------------------------------------------------
        // Web Sites
        // ---------------------------------------------------------------

        if (WorkWebSite.Text.Length > 0)
        {
            card.WebSites.Add(
                new vCardWebSite(WorkWebSite.Text, vCardWebSiteType.Work));
        }

        // ---------------------------------------------------------------
        // Nicknames
        // ---------------------------------------------------------------

        string[] nicklist = Nicknames.Text.Split(new char[] { ',' });
        foreach (string nick in nicklist)
        {
            if (nick.Length > 0)
                card.Nicknames.Add(nick);
        }

        // The vCard object has been populated.  The rest of
        // the code generates the vCard file format and exports
        // it to the response stream.

        Response.ContentType = "text/x-vcard";

        // The "content-disposition" is a special HTTP header
        // that tells the web browser how to interpreted the
        // output.  In this case, the browser is informed the
        // content should be treated as an attachment with
        // a default filename.  This should cause the browser
        // to display a dialog box to save the vCard (instead
        // of displaying the vCard as inline text).

        Response.AppendHeader(
            "content-disposition", "attachment;filename=vCard.vcf");

        vCardStandardWriter writer = new vCardStandardWriter();

        writer.EmbedInternetImages = false;
        writer.EmbedLocalImages = true;
        writer.Options = vCardStandardWriterOptions.IgnoreCommas;

        writer.Write(card, Response.Output);
        Response.End();

    }
        public void EncodeEscaped_CRLF_Text()
        {

            vCardStandardWriter writer = new vCardStandardWriter();

            Assert.AreEqual(
                @"\r\ntext",
                writer.EncodeEscaped("\r\ntext"));

        }
        public void EncodeProperty_Null()
        {

            vCardStandardWriter writer =
                new vCardStandardWriter();

            writer.EncodeProperty(null);

        }
        public void EncodeProperty_Name_Subproperty_Subvalue_Subproperty_Value()
        {

            vCardStandardWriter writer =
                new vCardStandardWriter();

            vCardProperty property =
                new vCardProperty("NAME", "VALUE");

            property.Subproperties.Add("SUB1", "SUBVALUE");
            property.Subproperties.Add("SUB2");

            Assert.AreEqual(
                "NAME;SUB1=SUBVALUE;SUB2:VALUE",
                writer.EncodeProperty(property));

        }
        public void EncodeProperty_Name_Value()
        {

            vCardStandardWriter writer =
                new vCardStandardWriter();

            vCardProperty property =
                new vCardProperty("NAME", "VALUE");

            Assert.AreEqual(
                "NAME:VALUE",
                writer.EncodeProperty(property));

        }
        public void EncodeProperty_Name_Subproperty()
        {

            vCardStandardWriter writer =
                new vCardStandardWriter();

            vCardProperty property =
                new vCardProperty("NAME");

            property.Subproperties.Add("SUB");

            Assert.AreEqual(
                "NAME;SUB:",
                writer.EncodeProperty(property));

        }
        public void EncodeEscaped_Semicolon_CRLF()
        {

            vCardStandardWriter writer = new vCardStandardWriter();

            Assert.AreEqual(
                @"\;\r\n",
                writer.EncodeEscaped(";\r\n"));

        }
        public void EncodeEscaped_Semicolon_Space_Semicolon()
        {

            vCardStandardWriter writer = new vCardStandardWriter();

            Assert.AreEqual(
                @"\; \;",
                writer.EncodeEscaped("; ;"));

        }
        public void EncodeEscaped_Null()
        {

            vCardStandardWriter writer = new vCardStandardWriter();

            Assert.AreEqual(
                null,
                writer.EncodeEscaped((string)null));

        }
        public void EncodeEscaped_Empty()
        {

            vCardStandardWriter writer = new vCardStandardWriter();

            Assert.AreEqual(
                string.Empty,
                writer.EncodeEscaped(string.Empty));

        }