Ejemplo n.º 1
0
        /// <summary>
        /// This is used to store the value of the e-mail type checkbox
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void CheckBox_Parse(object sender, ConvertEventArgs e)
        {
            EMailProperty email     = (EMailProperty)this.BindingSource.Current;
            CheckBox      cb        = (CheckBox)((Binding)sender).Control;
            EMailTypes    checkType = (EMailTypes)cb.Tag;

            if (cb.Checked)
            {
                email.EMailTypes |= checkType;
            }
            else
            {
                email.EMailTypes &= ~checkType;
            }

            // Only one address can be the preferred address
            if (checkType == EMailTypes.Preferred)
            {
                ((EMailPropertyCollection)this.BindingSource.DataSource).SetPreferred(email);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This method can be used to find the first e-mail address that has one of the specified e-mail types
        /// </summary>
        /// <param name="emailType">The e-mail type to match</param>
        /// <returns>The first e-mail address with an e-mail type matching one of those specified or null if not
        /// found.</returns>
        /// <remarks>Multiple e-mail types can be specified.  Including <c>Preferred</c> will limit the match to
        /// the one with the <c>Preferred</c> flag set.  If a preferred e-mail address with one of the given
        /// types cannot be found, it will return the first e-mail address matching one of the given types
        /// without the <c>Preferred</c> flag set.  If no e-mail address can be found, it returns null.</remarks>
        public EMailProperty FindFirstByType(EMailTypes emailType)
        {
            EMailTypes emailNoPref  = emailType & ~EMailTypes.Preferred;
            bool       usePreferred = (emailNoPref != emailType);

            foreach (EMailProperty email in this)
            {
                if ((email.EMailTypes & emailNoPref) != 0 && (!usePreferred || (email.EMailTypes & EMailTypes.Preferred) != 0))
                {
                    return(email);
                }
            }

            // Try again without the preferred flag?
            if (usePreferred)
            {
                return(this.FindFirstByType(emailNoPref));
            }

            return(null);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This is overridden to provide custom handling of the TYPE parameter
        /// </summary>
        /// <param name="parameters">The parameters for the property</param>
        public override void DeserializeParameters(StringCollection parameters)
        {
            string[] types;
            int      idx, subIdx;

            if (parameters == null || parameters.Count == 0)
            {
                return;
            }

            EMailTypes et = EMailTypes.None;

            for (int paramIdx = 0; paramIdx < parameters.Count; paramIdx++)
            {
                for (idx = 0; idx < ntv.Length; idx++)
                {
                    if (ntv[idx].IsMatch(parameters[paramIdx]))
                    {
                        break;
                    }
                }

                if (idx == ntv.Length)
                {
                    // If it was a parameter name, skip the value too
                    if (parameters[paramIdx].EndsWith("=", StringComparison.Ordinal))
                    {
                        paramIdx++;
                    }

                    continue;   // Not an e-mail parameter
                }

                // Parameters may appear as a pair (name followed by value) or by value alone
                if (!ntv[idx].IsParameterValue && paramIdx < parameters.Count - 1)
                {
                    // Remove the TYPE parameter name so that the base class won't put it in the custom
                    // parameters.  We'll skip this one and decode the parameter value.
                    parameters.RemoveAt(paramIdx);

                    // If the values contain a comma, split it on the comma and parse the types (i.e. vCard 3.0
                    // spec).  If not, just continue and handle it as normal.
                    if (reSplit.IsMatch(parameters[paramIdx]))
                    {
                        types = reSplit.Split(parameters[paramIdx]);

                        foreach (string s in types)
                        {
                            for (subIdx = 1; subIdx < ntv.Length; subIdx++)
                            {
                                if (ntv[subIdx].IsMatch(s))
                                {
                                    break;
                                }
                            }

                            // Unrecognized ones are ignored
                            if (subIdx < ntv.Length)
                            {
                                et |= ntv[subIdx].EnumValue;
                            }
                        }

                        parameters.RemoveAt(paramIdx);
                    }
                }
                else
                {
                    et |= ntv[idx].EnumValue;

                    // As above, remove the value
                    parameters.RemoveAt(paramIdx);
                }

                paramIdx--;
            }

            if (et != EMailTypes.None)
            {
                this.EMailTypes = et;
            }

            // Let the base class handle all other parameters
            base.DeserializeParameters(parameters);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// This is overridden to allow copying of the additional properties
 /// </summary>
 /// <param name="p">The PDI object from which the settings are to be copied</param>
 protected override void Clone(PDIObject p)
 {
     this.EMailTypes = ((EMailProperty)p).EMailTypes;
     base.Clone(p);
 }
Ejemplo n.º 5
0
        //=====================================================================

        /// <summary>
        /// Constructor.  Unless the version is changed, the object will conform to the vCard 3.0 specification.
        /// </summary>
        public EMailProperty()
        {
            this.Version    = SpecificationVersions.vCard30;
            this.EMailTypes = EMailTypes.Internet;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// This is overridden to provide custom handling of the TYPE parameter
        /// </summary>
        /// <param name="parameters">The parameters for the property</param>
        public override void DeserializeParameters(StringCollection parameters)
        {
            string[] types;
            int idx, subIdx;

            if(parameters == null || parameters.Count == 0)
                return;

            EMailTypes et = EMailTypes.None;

            for(int paramIdx = 0; paramIdx < parameters.Count; paramIdx++)
            {
                for(idx = 0; idx < ntv.Length; idx++)
                    if(ntv[idx].IsMatch(parameters[paramIdx]))
                        break;

                if(idx == ntv.Length)
                {
                    // If it was a parameter name, skip the value too
                    if(parameters[paramIdx].EndsWith("=", StringComparison.Ordinal))
                        paramIdx++;

                    continue;   // Not an e-mail parameter
                }

                // Parameters may appear as a pair (name followed by value) or by value alone
                if(!ntv[idx].IsParameterValue && paramIdx < parameters.Count - 1)
                {
                    // Remove the TYPE parameter name so that the base class won't put it in the custom
                    // parameters.  We'll skip this one and decode the parameter value.
                    parameters.RemoveAt(paramIdx);

                    // If the values contain a comma, split it on the comma and parse the types (i.e. vCard 3.0
                    // spec).  If not, just continue and handle it as normal.
                    if(reSplit.IsMatch(parameters[paramIdx]))
                    {
                        types = reSplit.Split(parameters[paramIdx]);

                        foreach(string s in types)
                        {
                            for(subIdx = 1; subIdx < ntv.Length; subIdx++)
                                if(ntv[subIdx].IsMatch(s))
                                    break;

                            // Unrecognized ones are ignored
                            if(subIdx < ntv.Length)
                                et |= ntv[subIdx].EnumValue;
                        }

                        parameters.RemoveAt(paramIdx);
                    }
                }
                else
                {
                    et |= ntv[idx].EnumValue;

                    // As above, remove the value
                    parameters.RemoveAt(paramIdx);
                }

                paramIdx--;
            }

            if(et != EMailTypes.None)
                this.EMailTypes = et;

            // Let the base class handle all other parameters
            base.DeserializeParameters(parameters);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// This is overridden to allow copying of the additional properties
 /// </summary>
 /// <param name="p">The PDI object from which the settings are to be copied</param>
 protected override void Clone(PDIObject p)
 {
     this.EMailTypes = ((EMailProperty)p).EMailTypes;
     base.Clone(p);
 }
Ejemplo n.º 8
0
        //=====================================================================

        /// <summary>
        /// Constructor.  Unless the version is changed, the object will conform to the vCard 3.0 specification.
        /// </summary>
        public EMailProperty()
        {
            this.Version = SpecificationVersions.vCard30;
            this.EMailTypes = EMailTypes.Internet;
        }