Ejemplo n.º 1
0
        /// <summary>
        ///     Builds the ORG property.
        /// </summary>
        private void BuildProperties_ORG(
            vCardPropertyCollection properties,
            vCard card)
        {
            // The ORG property specifies the name of the
            // person's company or organization. Example:
            //
            // ORG:FairMetric LLC

            if (!string.IsNullOrEmpty(card.Organization))
            {
                vCardProperty property;

                // Add department also
                if (!string.IsNullOrEmpty(card.Department))
                {
                    vCardValueCollection values = new vCardValueCollection(';');
                    values.Add(card.Organization);
                    values.Add(card.Department);
                    property = new vCardProperty("ORG", values);
                }
                else
                {
                    property = new vCardProperty("ORG", card.Organization);
                }

                properties.Add(property);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Builds the NICKNAME property.
        /// </summary>
        private void BuildProperties_NICKNAME(
            vCardPropertyCollection properties,
            vCard card)
        {
            // The NICKNAME property specifies the familiar name
            // of the person, such as Jim.  This is defined in
            // section 3.1.3 of RFC 2426.  Multiple names can
            // be listed, separated by commas.

            if (card.Nicknames.Count > 0)
            {

                // A NICKNAME property is a comma-separated
                // list of values.  Create a value list and
                // add the nicknames collection to it.

                vCardValueCollection values = new vCardValueCollection(',');
                values.Add(card.Nicknames);

                // Create the new properties with each name separated
                // by a comma.

                vCardProperty property =
                    new vCardProperty("NICKNAME", values);

                properties.Add(property);

            }
        }
Ejemplo n.º 3
0
        private void BuildProperties_N(
            vCardPropertyCollection properties,
            vCard card)
        {
            // The property has the following components: Family Name,
            // Given Name, Additional Names, Name Prefix, and Name
            // Suffix.  Example:
            //
            //   N:Pinch;David
            //   N:Pinch;David;John
            //
            // The N property is required (see section 3.1.2 of RFC 2426).

            vCardValueCollection values = new vCardValueCollection(';');

            values.Add(card.FamilyName);
            values.Add(card.GivenName);
            values.Add(card.AdditionalNames);
            values.Add(card.NamePrefix);
            values.Add(card.NameSuffix);

            vCardProperty property = new vCardProperty("N", values);

            properties.Add(property);
        }
        /// <summary>
        ///     Initializes the vCard property with the specified
        ///     name and values.
        /// </summary>
        public vCardProperty(string name, vCardValueCollection values)
            : this()
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            if (values == null)
            {
                throw new ArgumentNullException("values");
            }

            this.subproperties = new vCardSubpropertyCollection();
            this.name          = name;
            this.value         = values;
        }
Ejemplo n.º 5
0
        private void BuildProperties_CATEGORIES(
            vCardPropertyCollection properties,
            vCard card)
        {
            if (card.Categories.Count > 0)
            {
                vCardValueCollection values = new vCardValueCollection(',');

                foreach (string category in card.Categories)
                {
                    if (!string.IsNullOrEmpty(category))
                    {
                        values.Add(category);
                    }
                }

                properties.Add(
                    new vCardProperty("CATEGORIES", values));
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Builds the NICKNAME property.
        /// </summary>
        private void BuildProperties_NICKNAME(
            vCardPropertyCollection properties,
            vCard card)
        {

            // The NICKNAME property specifies the familiar name
            // of the person, such as Jim.  This is defined in
            // section 3.1.3 of RFC 2426.  Multiple names can
            // be listed, separated by commas.

            if (card.Nicknames.Count > 0)
            {

                // A NICKNAME property is a comma-separated
                // list of values.  Create a value list and
                // add the nicknames collection to it.

                vCardValueCollection values = new vCardValueCollection(',');
                values.Add(card.Nicknames);

                // Create the new properties with each name separated
                // by a comma.

                vCardProperty property =
                    new vCardProperty("NICKNAME", values);

                properties.Add(property);

            }

        }
Ejemplo n.º 7
0
        private void BuildProperties_N(
            vCardPropertyCollection properties,
            vCard card)
        {

            // The property has the following components: Family Name,
            // Given Name, Additional Names, Name Prefix, and Name
            // Suffix.  Example:
            //
            //   N:Pinch;David
            //   N:Pinch;David;John
            //
            // The N property is required (see section 3.1.2 of RFC 2426).

            vCardValueCollection values = new vCardValueCollection(';');
            values.Add(card.FamilyName);
            values.Add(card.GivenName);
            values.Add(card.AdditionalNames);
            values.Add(card.NamePrefix);
            values.Add(card.NameSuffix);

            vCardProperty property = new vCardProperty("N", values);

            properties.Add(property);

        }
Ejemplo n.º 8
0
        private void BuildProperties_CATEGORIES(
            vCardPropertyCollection properties,
            vCard card)
        {

            if (card.Categories.Count > 0)
            {

                vCardValueCollection values = new vCardValueCollection(',');

                foreach (string category in card.Categories)
                {

                    if (!string.IsNullOrEmpty(category))
                        values.Add(category);
                }

                properties.Add(
                    new vCardProperty("CATEGORIES", values));

            }

        }
Ejemplo n.º 9
0
        /// <summary>
        ///     Builds ADR properties.
        /// </summary>
        private void BuildProperties_ADR(
            vCardPropertyCollection properties,
            vCard card)
        {

            foreach (vCardDeliveryAddress address in card.DeliveryAddresses)
            {

                // Do not generate a postal address (ADR) property
                // if the entire address is blank.

                if (
                    (!string.IsNullOrEmpty(address.City)) ||
                    (!string.IsNullOrEmpty(address.Country)) ||
                    (!string.IsNullOrEmpty(address.PostalCode)) ||
                    (!string.IsNullOrEmpty(address.Region)) ||
                    (!string.IsNullOrEmpty(address.Street)))
                {

                    // The ADR property contains the following
                    // subvalues in order.  All are required:
                    //
                    //   - Post office box
                    //   - Extended address
                    //   - Street address
                    //   - Locality (e.g. city)
                    //   - Region (e.g. province or state)
                    //   - Postal code (e.g. ZIP code)
                    //   - Country name

                    vCardValueCollection values = new vCardValueCollection(';');

                    values.Add(string.Empty);
                    values.Add(string.Empty);
                    values.Add(address.Street);
                    values.Add(address.City);
                    values.Add(address.Region);
                    values.Add(address.PostalCode);
                    values.Add(address.Country);

                    vCardProperty property =
                        new vCardProperty("ADR", values);

                    if (address.IsDomestic)
                        property.Subproperties.Add("DOM");

                    if (address.IsInternational)
                        property.Subproperties.Add("INTL");

                    if (address.IsParcel)
                        property.Subproperties.Add("PARCEL");

                    if (address.IsPostal)
                        property.Subproperties.Add("POSTAL");

                    if (address.IsHome)
                        property.Subproperties.Add("HOME");

                    if (address.IsWork)
                        property.Subproperties.Add("WORK");

                    properties.Add(property);

                }

            }

        }
Ejemplo n.º 10
0
        /// <summary>
        ///     Builds ADR properties.
        /// </summary>
        private void BuildProperties_ADR(
            vCardPropertyCollection properties,
            vCard card)
        {
            foreach (vCardDeliveryAddress address in card.DeliveryAddresses)
            {

                // Do not generate a postal address (ADR) property
                // if the entire address is blank.

                if (
                    (!string.IsNullOrEmpty(address.City)) ||
                    (!string.IsNullOrEmpty(address.Country)) ||
                    (!string.IsNullOrEmpty(address.PostalCode)) ||
                    (!string.IsNullOrEmpty(address.Region)) ||
                    (!string.IsNullOrEmpty(address.Street)))
                {

                    // The ADR property contains the following
                    // subvalues in order.  All are required:
                    //
                    //   - Post office box
                    //   - Extended address
                    //   - Street address
                    //   - Locality (e.g. city)
                    //   - Region (e.g. province or state)
                    //   - Postal code (e.g. ZIP code)
                    //   - Country name

                    vCardValueCollection values = new vCardValueCollection(';');

                    values.Add(string.Empty);
                    values.Add(string.Empty);
                    values.Add(address.Street);
                    values.Add(address.City);
                    values.Add(address.Region);
                    values.Add(address.PostalCode);
                    values.Add(address.Country);

                    vCardProperty property =
                        new vCardProperty("ADR", values);

                    if (address.IsDomestic)
                        property.Subproperties.Add("DOM");

                    if (address.IsInternational)
                        property.Subproperties.Add("INTL");

                    if (address.IsParcel)
                        property.Subproperties.Add("PARCEL");

                    if (address.IsPostal)
                        property.Subproperties.Add("POSTAL");

                    if (address.IsHome)
                        property.Subproperties.Add("HOME");

                    if (address.IsWork)
                        property.Subproperties.Add("WORK");

                    properties.Add(property);

                }

            }
        }
Ejemplo n.º 11
0
        /// <summary>
        ///     Returns property encoded into a standard vCard NAME:VALUE format.
        /// </summary>
        public string EncodeProperty(vCardProperty property)
        {
            if (property == null)
                throw new ArgumentNullException("property");

            if (string.IsNullOrEmpty(property.Name))
                throw new ArgumentException();

            StringBuilder builder = new StringBuilder();

            builder.Append(property.Name);

            foreach (vCardSubproperty subproperty in property.Subproperties)
            {
                builder.Append(';');
                builder.Append(subproperty.Name);

                if (!string.IsNullOrEmpty(subproperty.Value))
                {
                    builder.Append('=');
                    builder.Append(subproperty.Value);
                }
            }

            // The property name and all subproperties have been
            // written to the string builder (the colon separator
            // has not been written).  The next step is to write
            // the value.  Depending on the type of value and any
            // characters in the value, it may be necessary to
            // use an non-default encoding.  For example, byte arrays
            // are written encoded in BASE64.

            if (property.Value == null)
            {
                builder.Append(':');
            }
            else
            {

                Type valueType = property.Value.GetType();

                if (valueType == typeof(byte[]))
                {

                    // A byte array should be encoded in BASE64 format.

                    builder.Append(";ENCODING=BASE64:");
                    builder.Append(EncodeBase64((byte[])property.Value));

                }
                else if (valueType == typeof(vCardValueCollection))
                {

                    vCardValueCollection values = (vCardValueCollection)property.Value;

                    builder.Append(':');
                    for (int index = 0; index < values.Count; index++)
                    {

                        builder.Append(EncodeEscaped(values[index]));
                        if (index < values.Count - 1)
                        {
                            builder.Append(values.Separator);
                        }
                    }

                }
                else
                {

                    // The object will be converted to a string (if it is
                    // not a string already) and encoded if necessary.
                    // The first step is to get the string value.

                    string stringValue = null;

                    if (valueType == typeof(char[]))
                    {
                        stringValue = new string(((char[])property.Value));
                    }
                    else
                    {
                        stringValue = property.Value.ToString();
                    }

                    builder.Append(':');

                    switch (property.Subproperties.GetValue("ENCODING"))
                    {

                        case "QUOTED-PRINTABLE":
                            builder.Append(EncodeQuotedPrintable(stringValue));
                            break;

                        default:
                            builder.Append(EncodeEscaped(stringValue));
                            break;

                    }

                }

            }

            return builder.ToString();
        }
      /// <summary>
      ///     Builds the ORG property.
      /// </summary>
      private void BuildProperties_ORG(
          vCardPropertyCollection properties,
          vCard card)
      {

        // The ORG property specifies the name of the
        // person's company or organization. Example:
        //
        // ORG:FairMetric LLC

        if (!string.IsNullOrEmpty(card.Organization))
        {

          vCardProperty property;

          // Add department also
          if (!string.IsNullOrEmpty(card.Department))
          {
            vCardValueCollection values = new vCardValueCollection(';');
            values.Add(card.Organization);
            values.Add(card.Department);
            property = new vCardProperty("ORG", values);
          }
          else
          {
            property = new vCardProperty("ORG", card.Organization);
          }

          properties.Add(property);

        }

      }
Ejemplo n.º 13
0
        /// <summary>
        ///     Initializes the vCard property with the specified
        ///     name and values.
        /// </summary>
        public vCardProperty(string name, vCardValueCollection values)
            : this()
        {
            if (string.IsNullOrEmpty(name))
                throw new ArgumentNullException("name");

            if (values == null)
                throw new ArgumentNullException("values");

            this.subproperties = new vCardSubpropertyCollection();
            this.name = name;
            this.value = values;
        }