public void AddressPropertyTest3() { VcfRow row = VcfRow.Parse("ADR:", new VcfDeserializationInfo()) !; var prop = new AddressProperty(row, VCdVersion.V3_0); Assert.IsNotNull(prop.Value); }
public void ToStringTest() { var adr = new AddressProperty(STREET, LOCALITY, POSTAL_CODE, REGION, COUNTRY, PO_BOX, EXTENDED_ADDRESS); string s = adr.ToString(); Assert.IsNotNull(s); Assert.AreNotEqual(0, s.Length); }
private static void SetAddressFields(Contact contact, AddressPropertyCollection addresses) { if (addresses != null && addresses.Count > 0) { AddressProperty addressProperty = addresses.OrderBy(a => a.PreferredOrder).FirstOrDefault(); contact.AddressType = ConvertVCardAddressType(addressProperty); contact.Street = addressProperty.StreetAddress; contact.City = addressProperty.Locality; contact.State = addressProperty.Region; contact.Zip = addressProperty.PostalCode; contact.CountryRegion = addressProperty.Country; } }
public void AddressPropertyTest() { var adr = new AddressProperty(STREET, LOCALITY, POSTAL_CODE, REGION, COUNTRY, PO_BOX, EXTENDED_ADDRESS, propertyGroup: GROUP); Assert.IsNotNull(adr); Assert.AreEqual(STREET, adr.Value.Street[0]); Assert.AreEqual(LOCALITY, adr.Value.Locality[0]); Assert.AreEqual(POSTAL_CODE, adr.Value.PostalCode[0]); Assert.AreEqual(REGION, adr.Value.Region[0]); Assert.AreEqual(COUNTRY, adr.Value.Country[0]); Assert.AreEqual(PO_BOX, adr.Value.PostOfficeBox[0]); Assert.AreEqual(EXTENDED_ADDRESS, adr.Value.ExtendedAddress[0]); Assert.AreEqual(GROUP, adr.Group); Assert.IsFalse(adr.IsEmpty); }
/// <summary> /// Copy ctor /// </summary> /// <param name="vCard">The vCard to clone.</param> private VCard(VCard vCard) { Version = vCard.Version; Func <ICloneable?, object?> cloner = Cloned; foreach (KeyValuePair <VCdProp, object> kvp in vCard._propDic) { Set(kvp.Key, kvp.Value switch { XmlProperty xmlProp => xmlProp.Clone(), IEnumerable <XmlProperty?> xmlPropEnumerable => xmlPropEnumerable.Select(cloner).Cast <XmlProperty?>().ToArray(), ProfileProperty profProp => profProp.Clone(), TextProperty txtProp => txtProp.Clone(), IEnumerable <TextProperty?> txtPropEnumerable => txtPropEnumerable.Select(cloner).Cast <TextProperty?>().ToArray(), DateTimeProperty dtTimeProp => dtTimeProp.Clone(), IEnumerable <DateTimeProperty?> dtTimePropEnumerable => dtTimePropEnumerable.Select(cloner).Cast <DateTimeProperty?>().ToArray(), AddressProperty adrProp => adrProp.Clone(), IEnumerable <AddressProperty?> adrPropEnumerable => adrPropEnumerable.Select(cloner).Cast <AddressProperty?>().ToArray(), NameProperty nameProp => nameProp.Clone(), IEnumerable <NameProperty?> namePropEnumerable => namePropEnumerable.Select(cloner).Cast <NameProperty?>().ToArray(), RelationProperty relProp => relProp.Clone(), IEnumerable <RelationProperty?> relPropEnumerable => relPropEnumerable.Select(cloner).Cast <RelationProperty?>().ToArray(), OrganizationProperty orgProp => orgProp.Clone(), IEnumerable <OrganizationProperty?> orgPropEnumerable => orgPropEnumerable.Select(cloner).Cast <OrganizationProperty?>().ToArray(), StringCollectionProperty strCollProp => strCollProp.Clone(), IEnumerable <StringCollectionProperty?> strCollPropEnumerable => strCollPropEnumerable.Select(cloner).Cast <StringCollectionProperty?>().ToArray(), GenderProperty sexProp => sexProp.Clone(), IEnumerable <GenderProperty?> sexPropEnumerable => sexPropEnumerable.Select(cloner).Cast <GenderProperty?>().ToArray(), GeoProperty geoProp => geoProp.Clone(), IEnumerable <GeoProperty?> geoPropEnumerable => geoPropEnumerable.Select(cloner).Cast <GeoProperty?>().ToArray(), DataProperty dataProp => dataProp.Clone(), IEnumerable <DataProperty?> dataPropEnumerable => dataPropEnumerable.Select(cloner).Cast <DataProperty?>().ToArray(), NonStandardProperty nStdProp => nStdProp.Clone(), IEnumerable <NonStandardProperty?> nStdPropEnumerable => nStdPropEnumerable.Select(cloner).Cast <NonStandardProperty?>().ToArray(), PropertyIDMappingProperty pidMapProp => pidMapProp.Clone(), IEnumerable <PropertyIDMappingProperty?> pidMapPropEnumerable => pidMapPropEnumerable.Select(cloner).Cast <PropertyIDMappingProperty?>().ToArray(), TimeZoneProperty tzProp => tzProp.Clone(), IEnumerable <TimeZoneProperty?> tzPropEnumerable => tzPropEnumerable.Select(cloner).Cast <TimeZoneProperty?>().ToArray(), ICloneable cloneable => cloneable.Clone(), // AccessProperty, KindProperty, TimeStampProperty, UuidProperty _ => kvp.Value });
protected override void AppendAddresses(IEnumerable <AddressProperty?> value) { Debug.Assert(value != null); AddressProperty[] arr = value.Where(x => x != null).OrderBy(x => x !.Parameters.Preference).ToArray() !; for (int i = 0; i < arr.Length; i++) { AddressProperty prop = arr[i]; BuildProperty(VCard.PropKeys.ADR, prop, i == 0 && prop.Parameters.Preference < 100); string?label = prop.Parameters.Label; if (label != null) { var labelProp = new TextProperty(label, prop.Group); labelProp.Parameters.Assign(prop.Parameters); BuildProperty(VCard.PropKeys.LABEL, labelProp); } } }
/// <summary> /// This is used to store the value of the address 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) { AddressProperty a = (AddressProperty)this.BindingSource.Current; CheckBox cb = (CheckBox)((Binding)sender).Control; AddressTypes checkType = (AddressTypes)cb.Tag; if (cb.Checked) { a.AddressTypes |= checkType; } else { a.AddressTypes &= ~checkType; } // Only one address can be the preferred address if (checkType == AddressTypes.Preferred) { ((AddressPropertyCollection)this.BindingSource.DataSource).SetPreferred(a); } }
private static Contact.AddressTypes ConvertVCardAddressType(AddressProperty addressProperty) { Contact.AddressTypes addressType; if (addressProperty.AddressTypes.HasFlag(AddressTypes.Home) || addressProperty.AddressTypes.HasFlag(AddressTypes.Preferred)) { addressType = Contact.AddressTypes.Home; } else if (addressProperty.AddressTypes.HasFlag(AddressTypes.None)) { addressType = Contact.AddressTypes.None; } else if (addressProperty.AddressTypes.HasFlag(AddressTypes.Domestic)) { addressType = Contact.AddressTypes.Domestic; } else if (addressProperty.AddressTypes.HasFlag(AddressTypes.International)) { addressType = Contact.AddressTypes.International; } else if (addressProperty.AddressTypes.HasFlag(AddressTypes.Postal)) { addressType = Contact.AddressTypes.Postal; } else if (addressProperty.AddressTypes.HasFlag(AddressTypes.Parcel)) { addressType = Contact.AddressTypes.Parcel; } else if (addressProperty.AddressTypes.HasFlag(AddressTypes.Work)) { addressType = Contact.AddressTypes.Work; } else { addressType = Contact.AddressTypes.None; } return(addressType); }
internal static VCard CreateVCard() { var sortAs = new string[] { "Entenhausen", "Elmstreet" }; var tel1 = new TextProperty("123"); tel1.Parameters.TelephoneType = default(TelTypes); tel1.Parameters.TelephoneType = TelTypes.Voice | TelTypes.Cell | TelTypes.Text | TelTypes.Msg; tel1.Parameters.Preference = -50; tel1.Parameters.Preference = 500; tel1.Parameters.Preference = 1; tel1.Parameters.PropertyClass = default(PropertyClassTypes); tel1.Parameters.PropertyClass = PropertyClassTypes.Home | PropertyClassTypes.Work; var hobby1 = new TextProperty("Swimming"); hobby1.Parameters.InterestLevel = InterestLevel.Medium; var expertise1 = new TextProperty("C#"); expertise1.Parameters.ExpertiseLevel = ExpertiseLevel.Average; var adr1 = new AddressProperty("Elmstraße 13", "Entenhausen", "01234"); adr1.Parameters.Label = " "; adr1.Parameters.Label = "Elmstreet 13; bei Müller" + Environment.NewLine + "01234 Entenhausen"; adr1.Parameters.GeoPosition = new Models.GeoCoordinate(12.98, 7.86); adr1.Parameters.TimeZone = new Models.TimeZoneID(TimeZoneInfo.Local.Id); adr1.Parameters.AltID = "Address"; adr1.Parameters.Calendar = "GREGORIAN"; adr1.Parameters.ContentLocation = VCdContentLocation.Inline; adr1.Parameters.Index = 0; adr1.Parameters.Language = "de"; adr1.Parameters.SortAs = sortAs; var pidMap = new PropertyIDMapping(5, new Uri("http://folkerkinzel.de")); adr1.Parameters.PropertyIDs = new PropertyID[] { new PropertyID(3, pidMap), new PropertyID(2) }; adr1.Parameters.AddressType = AddressTypes.Dom | AddressTypes.Intl | AddressTypes.Parcel | AddressTypes.Postal; var logo1 = new DataProperty(new Uri("https://folker-kinzel.de/logo.jpg")); logo1.Parameters.MediaType = "image/jpeg"; var photo1 = new DataProperty(new Uri("https://folker-kinzel.de/photo.png")); logo1.Parameters.MediaType = "image/png"; var sound1 = new DataProperty(new Uri("https://folker-kinzel.de/audio.mp3")); logo1.Parameters.MediaType = "audio/mpeg"; var key1 = new DataProperty(new Uri("https://folker-kinzel.de/pgp")); logo1.Parameters.MediaType = "application/pgp-keys"; var email1 = new TextProperty("*****@*****.**"); email1.Parameters.EmailType = " "; email1.Parameters.EmailType = EmailType.SMTP; var name1 = new NameProperty("Künzel", "Folker"); name1.Parameters.SortAs = new string[] { "Kinzel", "Folker" }; var name2 = new NameProperty("Кинцэл", "Фолкер"); name2.Parameters.SortAs = new string[] { "Kinzel", "Folker" }; name2.Parameters.Language = "ru-RU"; name2.Parameters.AltID = " "; var names = new NameProperty[] { name1, name2 }; var impp1 = new TextProperty("aim:uri.com"); impp1.Parameters.InstantMessengerType = ImppTypes.Personal; var impp2 = new TextProperty("gg:uri.com"); impp1.Parameters.InstantMessengerType = ImppTypes.Business; var impp3 = new TextProperty("gtalk:uri.com"); impp1.Parameters.InstantMessengerType = ImppTypes.Mobile; var impp4 = new TextProperty("com.google.hangouts:uri.com"); var impp5 = new TextProperty("icq:uri.com"); var impp6 = new TextProperty("icq:uri.com"); var impp7 = new TextProperty("xmpp:uri.com"); var impp8 = new TextProperty("msnim:uri.com"); var impp9 = new TextProperty("sip:uri.com"); var impp10 = new TextProperty("skype:uri.com"); var impp11 = new TextProperty("twitter:uri.com"); var impp12 = new TextProperty("ymsgr:uri.com"); var rel1 = new RelationTextProperty("Agent", RelationTypes.Agent); var rel2 = new RelationTextProperty("Spouse"); rel2.Parameters.RelationType = default(RelationTypes); rel2.Parameters.RelationType = RelationTypes.Spouse | RelationTypes.CoResident; var nonStandard1 = new NonStandardProperty("X-NON-STANDARD", "The value"); nonStandard1.Parameters.NonStandardParameters = new KeyValuePair <string, string>[] { new KeyValuePair <string, string>("X-NONSTD", "para-value") }; var nonStandard2 = new NonStandardProperty("X-WAKEUP", "07:00:00"); nonStandard2.Parameters.DataType = VCdDataType.Time; var nonStandard = new NonStandardProperty[] { nonStandard1, nonStandard2 }; var xName = XName.Get("{TheNs}TheLocal"); var xEl = new XElement(xName, "The content"); var xml1 = new XmlProperty(xEl); var bday = new DateTimeOffsetProperty(new DateTime(1977, 11, 11)); bday.Parameters.Calendar = " "; var source = new TextProperty("http://neu.de/"); source.Parameters.Context = " "; source.Parameters.Context = "VCARD"; return(new VCard { NameViews = names, PhoneNumbers = tel1, Hobbies = hobby1, Interests = hobby1, Expertises = expertise1, BirthDayViews = bday, AnniversaryViews = new DateTimeOffsetProperty(new DateTime(2001, 9, 11)), Logos = logo1, Photos = photo1, Sounds = sound1, Keys = key1, DeathDateViews = new DateTimeTextProperty("Later"), DeathPlaceViews = new TextProperty("Somewhere"), BirthPlaceViews = new TextProperty("Dessau"), ProdID = new TextProperty("Testcode"), Addresses = adr1, CalendarAddresses = new TextProperty("Calender address"), CalendarUserAddresses = new TextProperty("Calendar user address"), FreeOrBusyUrls = new TextProperty("Free Busy"), Sources = source, TimeZones = new TimeZoneProperty(new TimeZoneID(TimeZoneInfo.Local.Id)), DisplayNames = new TextProperty("Folker"), OrgDirectories = new TextProperty("OrgDirectory"), Profile = new ProfileProperty("Group"), Categories = new StringCollectionProperty(new string[] { "Person", "Data" }), TimeStamp = new TimeStampProperty(), EmailAddresses = email1, Roles = new TextProperty("Rechte Hand"), Titles = new TextProperty("Sündenbock"), UniqueIdentifier = new UuidProperty(), URLs = new TextProperty("www.folker.com"), DirectoryName = new TextProperty("Webseite"), Access = new AccessProperty(VCdAccess.Confidential), GenderViews = new GenderProperty(VCdSex.NonOrNotApplicable), GeoCoordinates = new GeoProperty(new Models.GeoCoordinate(23.456, 49.654)), NickNames = new StringCollectionProperty(new string[] { "Genius", "The Brain" }), Kind = new KindProperty(VCdKind.Organization), Mailer = new TextProperty("The Mailer"), Languages = new TextProperty("de"), Notes = new TextProperty("Kommentar"), PropertyIDMappings = new PropertyIDMappingProperty(new PropertyIDMapping(7, new Uri("http://folkerkinzel.de"))), InstantMessengerHandles = new TextProperty[] { impp1, impp2, impp3, impp4, impp5, impp6, impp7, impp8, impp9, impp10, impp11, impp12 }, Relations = new RelationProperty[] { rel1, rel2 }, Organizations = new OrganizationProperty("The ÄÖÜ Organization", new string[] { "Department", "Office" }), NonStandardProperties = nonStandard, XmlProperties = xml1, }); }
/// <summary> /// This is implemented to handle properties as they are parsed from the data stream /// </summary> /// <param name="propertyName">The name of the property.</param> /// <param name="parameters">A string collection containing the parameters and their values. If empty, /// there are no parameters.</param> /// <param name="propertyValue">The value of the property.</param> /// <remarks><para>There may be a mixture of name/value pairs or values alone in the parameters string /// collection. It is up to the derived class to process the parameter list based on the specification /// to which it conforms. For entries that are parameter names, the entry immediately following it in /// the collection is its associated parameter value. The property name, parameter names, and their /// values may be in upper, lower, or mixed case.</para> /// /// <para>The value may be an encoded string. The properties are responsible for any decoding that may /// need to occur (i.e. base 64 encoded image data).</para></remarks> /// <exception cref="PDIParserException">This is thrown if an error is encountered while parsing the data /// stream. Refer to the and inner exceptions for information on the cause of the problem.</exception> protected override void PropertyParser(string propertyName, StringCollection parameters, string propertyValue) { SpecificationVersions version = SpecificationVersions.None; string temp, group = null; int idx; // Parse out the group name if there is one idx = propertyName.IndexOf('.'); if (idx != -1) { group = propertyName.Substring(0, idx).Trim(); propertyName = propertyName.Substring(idx + 1).Trim(); } // The last entry is always CustomProperty so scan for length minus one for (idx = 0; idx < ntv.Length - 1; idx++) { if (ntv[idx].IsMatch(propertyName)) { break; } } // An opening BEGIN:VCARD property must have been seen if (currentCard == null && ntv[idx].EnumValue != PropertyType.Begin) { throw new PDIParserException(this.LineNumber, LR.GetString("ExParseNoBeginProp", "BEGIN:VCARD", propertyName)); } // Handle or create the property switch (ntv[idx].EnumValue) { case PropertyType.Begin: // The value must be VCARD if (String.Compare(propertyValue.Trim(), "VCARD", StringComparison.OrdinalIgnoreCase) != 0) { throw new PDIParserException(this.LineNumber, LR.GetString("ExParseUnrecognizedTagValue", ntv[idx].Name, propertyValue)); } // NOTE: If serializing into an existing instance, this may not be null. If so, it is // ignored. if (currentCard == null) { currentCard = new VCard(); vCards.Add(currentCard); } currentCard.Group = group; break; case PropertyType.End: // The value must be VCARD if (String.Compare(propertyValue.Trim(), "VCARD", StringComparison.OrdinalIgnoreCase) != 0) { throw new PDIParserException(this.LineNumber, LR.GetString("ExParseUnrecognizedTagValue", ntv[idx].Name, propertyValue)); } // The group must match too if (currentCard.Group != group) { throw new PDIParserException(this.LineNumber, LR.GetString("ExParseUnexpectedGroupTag", currentCard.Group, group)); } // When done, we'll propagate the version number to all objects to make it consistent currentCard.PropagateVersion(); // The vCard is added to the collection when created so we don't have to rely on an END:VCARD // to add it. currentCard = null; break; case PropertyType.Profile: // The value must be VCARD if (String.Compare(propertyValue.Trim(), "VCARD", StringComparison.OrdinalIgnoreCase) != 0) { throw new PDIParserException(this.LineNumber, LR.GetString("ExParseUnrecognizedTagValue", ntv[idx].Name, propertyValue)); } currentCard.AddProfile = true; break; case PropertyType.Version: // Version must be 2.1 or 3.0 temp = propertyValue.Trim(); if (temp == "2.1") { version = SpecificationVersions.vCard21; } else if (temp == "3.0") { version = SpecificationVersions.vCard30; } else { throw new PDIParserException(this.LineNumber, LR.GetString("ExParseUnrecognizedVersion", "vCard", temp)); } currentCard.Version = version; break; case PropertyType.MimeName: currentCard.MimeName.EncodedValue = propertyValue; break; case PropertyType.MimeSource: currentCard.MimeSource.DeserializeParameters(parameters); currentCard.MimeSource.EncodedValue = propertyValue; break; case PropertyType.ProductId: currentCard.ProductId.EncodedValue = propertyValue; break; case PropertyType.Nickname: currentCard.Nickname.DeserializeParameters(parameters); currentCard.Nickname.EncodedValue = propertyValue; currentCard.Nickname.Group = group; break; case PropertyType.SortString: currentCard.SortString.DeserializeParameters(parameters); currentCard.SortString.EncodedValue = propertyValue; currentCard.SortString.Group = group; break; case PropertyType.Class: currentCard.Classification.EncodedValue = propertyValue; currentCard.Classification.Group = group; break; case PropertyType.Categories: currentCard.Categories.DeserializeParameters(parameters); currentCard.Categories.EncodedValue = propertyValue; currentCard.Categories.Group = group; break; case PropertyType.FormattedName: currentCard.FormattedName.DeserializeParameters(parameters); currentCard.FormattedName.EncodedValue = propertyValue; currentCard.FormattedName.Group = group; break; case PropertyType.Name: currentCard.Name.DeserializeParameters(parameters); currentCard.Name.EncodedValue = propertyValue; currentCard.Name.Group = group; break; case PropertyType.Title: currentCard.Title.DeserializeParameters(parameters); currentCard.Title.EncodedValue = propertyValue; currentCard.Title.Group = group; break; case PropertyType.Role: currentCard.Role.DeserializeParameters(parameters); currentCard.Role.EncodedValue = propertyValue; currentCard.Role.Group = group; break; case PropertyType.Mailer: currentCard.Mailer.DeserializeParameters(parameters); currentCard.Mailer.EncodedValue = propertyValue; currentCard.Mailer.Group = group; break; case PropertyType.Url: currentCard.Url.DeserializeParameters(parameters); currentCard.Url.EncodedValue = propertyValue; currentCard.Url.Group = group; break; case PropertyType.Organization: currentCard.Organization.DeserializeParameters(parameters); currentCard.Organization.EncodedValue = propertyValue; currentCard.Organization.Group = group; break; case PropertyType.UniqueId: currentCard.UniqueId.EncodedValue = propertyValue; currentCard.UniqueId.Group = group; break; case PropertyType.BirthDate: currentCard.BirthDate.DeserializeParameters(parameters); currentCard.BirthDate.EncodedValue = propertyValue; currentCard.BirthDate.Group = group; break; case PropertyType.Revision: currentCard.LastRevision.DeserializeParameters(parameters); currentCard.LastRevision.EncodedValue = propertyValue; currentCard.LastRevision.Group = group; break; case PropertyType.TimeZone: currentCard.TimeZone.DeserializeParameters(parameters); currentCard.TimeZone.EncodedValue = propertyValue; currentCard.TimeZone.Group = group; break; case PropertyType.GeographicPosition: currentCard.GeographicPosition.EncodedValue = propertyValue; currentCard.GeographicPosition.Group = group; break; case PropertyType.PublicKey: currentCard.PublicKey.DeserializeParameters(parameters); currentCard.PublicKey.EncodedValue = propertyValue; currentCard.PublicKey.Group = group; break; case PropertyType.Photo: currentCard.Photo.DeserializeParameters(parameters); currentCard.Photo.EncodedValue = propertyValue; currentCard.Photo.Group = group; break; case PropertyType.Logo: currentCard.Logo.DeserializeParameters(parameters); currentCard.Logo.EncodedValue = propertyValue; currentCard.Logo.Group = group; break; case PropertyType.Sound: currentCard.Sound.DeserializeParameters(parameters); currentCard.Sound.EncodedValue = propertyValue; currentCard.Sound.Group = group; break; case PropertyType.Note: NoteProperty n = new NoteProperty(); n.DeserializeParameters(parameters); n.EncodedValue = propertyValue; n.Group = group; currentCard.Notes.Add(n); break; case PropertyType.Address: AddressProperty a = new AddressProperty(); a.DeserializeParameters(parameters); a.EncodedValue = propertyValue; a.Group = group; currentCard.Addresses.Add(a); break; case PropertyType.Label: LabelProperty l = new LabelProperty(); l.DeserializeParameters(parameters); l.EncodedValue = propertyValue; l.Group = group; currentCard.Labels.Add(l); break; case PropertyType.Telephone: TelephoneProperty t = new TelephoneProperty(); t.DeserializeParameters(parameters); t.EncodedValue = propertyValue; t.Group = group; currentCard.Telephones.Add(t); break; case PropertyType.EMail: EMailProperty e = new EMailProperty(); e.DeserializeParameters(parameters); e.EncodedValue = propertyValue; e.Group = group; currentCard.EMailAddresses.Add(e); break; case PropertyType.Agent: AgentProperty ag = new AgentProperty(); ag.DeserializeParameters(parameters); ag.EncodedValue = propertyValue; ag.Group = group; currentCard.Agents.Add(ag); break; default: // Anything else is a custom property CustomProperty c = new CustomProperty(propertyName); c.DeserializeParameters(parameters); c.EncodedValue = propertyValue; c.Group = group; currentCard.CustomProperties.Add(c); break; } }
set => SetValue(AddressProperty, value);