Update the Thought.vCards package

This commit is contained in:
abdelkader
2020-12-27 15:21:18 -05:00
parent fe2d1adec2
commit 90eb345ddb
17 changed files with 3375 additions and 2304 deletions

View File

@@ -39,7 +39,7 @@ namespace Thought.vCards {
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Thought.vCards.WarningMessages", typeof(WarningMessages).Assembly);
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("vCardEditor.Thought.vCards.WarningMessages", typeof(WarningMessages).Assembly);
resourceMan = temp;
}
return resourceMan;

View File

@@ -72,6 +72,8 @@ namespace Thought.vCards
private vCardPhotoCollection photos;
private vCardSourceCollection sources;
private vCardWebsiteCollection websites;
private vCardIMPPCollection ims;
private vCardSocialProfileCollection sps;
/// <summary>
/// Initializes a new instance of the <see cref="vCard"/> class.
@@ -111,6 +113,8 @@ namespace Thought.vCards
this.photos = new vCardPhotoCollection();
this.sources = new vCardSourceCollection();
this.websites = new vCardWebsiteCollection();
this.ims = new vCardIMPPCollection();
this.sps = new vCardSocialProfileCollection();
}
@@ -147,32 +151,9 @@ namespace Thought.vCards
vCardReader reader = new vCardStandardReader();
reader.ReadInto(this, streamReader);
}
//String example = "BEGIN:VCARD\nVERSION:3.0\nN:;Saad;;;\nFN:Saad\nTEL;TYPE=CELL:418-271-3874\nTEL;TYPE=HOME:418-524-7721\nEND:VCARD";
// using (MemoryStream s = GenerateStreamFromString(example))
//{
// vCardReader reader = new vCardStandardReader();
// TextReader streamReader = new StreamReader(s, Encoding.Default);
// reader.ReadInto(this, streamReader);
//}
}
/// <summary>
///
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public MemoryStream GenerateStreamFromString(string s)
{
MemoryStream stream = new MemoryStream();
StreamWriter writer = new StreamWriter(stream);
writer.Write(s);
writer.Flush();
stream.Position = 0;
return stream;
}
/// <summary>
/// The security access classification of the vCard owner (e.g. private).
@@ -764,5 +745,21 @@ namespace Thought.vCards
}
}
/// <summary>
/// IMPP Collection
/// </summary>
public vCardIMPPCollection IMs
{
get { return this.ims; }
}
/// <summary>
/// SocialProfile collection for the vCard in the X-SOCIALPROFILE property
/// </summary>
public vCardSocialProfileCollection SocialProfiles
{
get { return this.sps; }
}
}
}

View File

@@ -6,6 +6,7 @@
* ======================================================================= */
using System;
using System.Collections.Generic;
namespace Thought.vCards
{
@@ -18,7 +19,7 @@ namespace Thought.vCards
public class vCardDeliveryAddress
{
private vCardDeliveryAddressTypes addressType;
private List<vCardDeliveryAddressTypes> addressType;
private string city;
private string country;
private string postalCode;
@@ -36,13 +37,14 @@ namespace Thought.vCards
this.postalCode = string.Empty;
this.region = string.Empty;
this.street = string.Empty;
this.addressType = new List<vCardDeliveryAddressTypes>();
}
/// <summary>
/// The type of postal address.
/// </summary>
public vCardDeliveryAddressTypes AddressType
public List<vCardDeliveryAddressTypes> AddressType
{
get
{
@@ -94,21 +96,7 @@ namespace Thought.vCards
{
get
{
return (this.addressType & vCardDeliveryAddressTypes.Domestic) ==
vCardDeliveryAddressTypes.Domestic;
}
set
{
if (value)
{
this.addressType |= vCardDeliveryAddressTypes.Domestic;
}
else
{
this.addressType &= ~vCardDeliveryAddressTypes.Domestic;
}
return (addressType.Contains(vCardDeliveryAddressTypes.Domestic));
}
}
@@ -120,20 +108,7 @@ namespace Thought.vCards
{
get
{
return (this.addressType & vCardDeliveryAddressTypes.Home) ==
vCardDeliveryAddressTypes.Home;
}
set
{
if (value)
{
this.addressType |= vCardDeliveryAddressTypes.Home;
}
else
{
this.addressType &= ~vCardDeliveryAddressTypes.Home;
}
return (addressType.Contains(vCardDeliveryAddressTypes.Home));
}
}
@@ -145,19 +120,7 @@ namespace Thought.vCards
{
get
{
return (this.addressType & vCardDeliveryAddressTypes.International) ==
vCardDeliveryAddressTypes.International;
}
set
{
if (value)
{
this.addressType |= vCardDeliveryAddressTypes.International;
}
else
{
this.addressType &= ~vCardDeliveryAddressTypes.International;
}
return (addressType.Contains(vCardDeliveryAddressTypes.International));
}
}
@@ -169,19 +132,7 @@ namespace Thought.vCards
{
get
{
return (this.addressType & vCardDeliveryAddressTypes.Parcel) ==
vCardDeliveryAddressTypes.Parcel;
}
set
{
if (value)
{
this.addressType |= vCardDeliveryAddressTypes.Parcel;
}
else
{
this.addressType &= ~vCardDeliveryAddressTypes.Parcel;
}
return (addressType.Contains(vCardDeliveryAddressTypes.Parcel));
}
}
@@ -193,19 +144,7 @@ namespace Thought.vCards
{
get
{
return (this.addressType & vCardDeliveryAddressTypes.Postal) ==
vCardDeliveryAddressTypes.Postal;
}
set
{
if (value)
{
this.addressType |= vCardDeliveryAddressTypes.Postal;
}
else
{
this.addressType &= ~vCardDeliveryAddressTypes.Postal;
}
return (addressType.Contains(vCardDeliveryAddressTypes.Postal));
}
}
@@ -217,19 +156,18 @@ namespace Thought.vCards
{
get
{
return (this.addressType & vCardDeliveryAddressTypes.Work) ==
vCardDeliveryAddressTypes.Work;
return (addressType.Contains(vCardDeliveryAddressTypes.Work));
}
set
}
/// <summary>
/// Indicates a preferred address
/// </summary>
public bool IsPreferred
{
get
{
if (value)
{
this.addressType |= vCardDeliveryAddressTypes.Work;
}
else
{
this.addressType &= ~vCardDeliveryAddressTypes.Work;
}
return (addressType.Contains(vCardDeliveryAddressTypes.Preferred));
}
}

View File

@@ -13,7 +13,6 @@ namespace Thought.vCards
/// <summary>
/// The type of a delivery address.
/// </summary>
[Flags]
public enum vCardDeliveryAddressTypes
{
@@ -50,7 +49,12 @@ namespace Thought.vCards
/// <summary>
/// A work delivery address.
/// </summary>
Work
Work,
/// <summary>
/// you can mark an address as Preferred type="pref"
/// </summary>
Preferred
}
}

View File

@@ -6,6 +6,7 @@
* ======================================================================= */
using System;
using System.Collections.Generic;
namespace Thought.vCards
{
@@ -18,7 +19,7 @@ namespace Thought.vCards
public class vCardDeliveryLabel
{
private vCardDeliveryAddressTypes addressType;
private List<vCardDeliveryAddressTypes> addressType;
private string text;
@@ -27,6 +28,7 @@ namespace Thought.vCards
/// </summary>
public vCardDeliveryLabel()
{
this.addressType = new List<vCardDeliveryAddressTypes>();
}
@@ -42,170 +44,107 @@ namespace Thought.vCards
public vCardDeliveryLabel(string text)
{
this.text = text == null ? string.Empty : text;
this.addressType = new List<vCardDeliveryAddressTypes>();
}
/// <summary>
/// The type of delivery address for the label.
/// </summary>
public vCardDeliveryAddressTypes AddressType
{
get
{
return this.addressType;
}
set
{
this.addressType = value;
}
}
/// <summary>
/// The type of postal address.
/// </summary>
public List<vCardDeliveryAddressTypes> AddressType
{
get
{
return this.addressType;
}
set
{
this.addressType = value;
}
}
/// <summary>
/// Indicates a domestic delivery address.
/// </summary>
public bool IsDomestic
{
get
{
return (this.addressType & vCardDeliveryAddressTypes.Domestic) ==
vCardDeliveryAddressTypes.Domestic;
}
set
{
if (value)
{
this.addressType |= vCardDeliveryAddressTypes.Domestic;
}
else
{
this.addressType &= ~vCardDeliveryAddressTypes.Domestic;
}
}
}
/// <summary>
/// Indicates a domestic delivery address.
/// </summary>
public bool IsDomestic
{
get
{
return (addressType.Contains(vCardDeliveryAddressTypes.Domestic));
}
}
/// <summary>
/// Indicates a home address.
/// </summary>
public bool IsHome
{
get
{
return (this.addressType & vCardDeliveryAddressTypes.Home) ==
vCardDeliveryAddressTypes.Home;
}
set
{
if (value)
{
this.addressType |= vCardDeliveryAddressTypes.Home;
}
else
{
this.addressType &= ~vCardDeliveryAddressTypes.Home;
}
}
}
/// <summary>
/// Indicates a home address.
/// </summary>
public bool IsHome
{
get
{
return (addressType.Contains(vCardDeliveryAddressTypes.Home));
}
}
/// <summary>
/// Indicates an international address.
/// </summary>
public bool IsInternational
{
get
{
return (this.addressType & vCardDeliveryAddressTypes.International) ==
vCardDeliveryAddressTypes.International;
}
set
{
if (value)
{
this.addressType |= vCardDeliveryAddressTypes.International;
}
else
{
this.addressType &= ~vCardDeliveryAddressTypes.International;
}
}
}
/// <summary>
/// Indicates an international address.
/// </summary>
public bool IsInternational
{
get
{
return (addressType.Contains(vCardDeliveryAddressTypes.International));
}
}
/// <summary>
/// Indicates a parcel delivery address.
/// </summary>
public bool IsParcel
{
get
{
return (this.addressType & vCardDeliveryAddressTypes.Parcel) ==
vCardDeliveryAddressTypes.Parcel;
}
set
{
if (value)
{
this.addressType |= vCardDeliveryAddressTypes.Parcel;
}
else
{
this.addressType &= ~vCardDeliveryAddressTypes.Parcel;
}
}
}
/// <summary>
/// Indicates a parcel delivery address.
/// </summary>
public bool IsParcel
{
get
{
return (addressType.Contains(vCardDeliveryAddressTypes.Parcel));
}
}
/// <summary>
/// Indicates a postal address.
/// </summary>
public bool IsPostal
{
get
{
return (this.addressType & vCardDeliveryAddressTypes.Postal) ==
vCardDeliveryAddressTypes.Postal;
}
set
{
if (value)
{
this.addressType |= vCardDeliveryAddressTypes.Postal;
}
else
{
this.addressType &= ~vCardDeliveryAddressTypes.Postal;
}
}
}
/// <summary>
/// Indicates a postal address.
/// </summary>
public bool IsPostal
{
get
{
return (addressType.Contains(vCardDeliveryAddressTypes.Postal));
}
}
/// <summary>
/// Indicates a work address.
/// </summary>
public bool IsWork
{
get
{
return (this.addressType & vCardDeliveryAddressTypes.Work) ==
vCardDeliveryAddressTypes.Work;
}
set
{
if (value)
{
this.addressType |= vCardDeliveryAddressTypes.Work;
}
else
{
this.addressType &= ~vCardDeliveryAddressTypes.Work;
}
}
}
/// <summary>
/// Indicates a work address.
/// </summary>
public bool IsWork
{
get
{
return (addressType.Contains(vCardDeliveryAddressTypes.Work));
}
}
/// <summary>
/// Indicates a preferred address
/// </summary>
public bool IsPreferred
{
get
{
return (addressType.Contains(vCardDeliveryAddressTypes.Preferred));
}
}
/// <summary>

View File

@@ -26,9 +26,10 @@ namespace Thought.vCards
private string address;
private vCardEmailAddressType emailType;
private ItemType itemType;
private bool isPreferred;
/// <summary>
/// Creates a new <see cref="vCardEmailAddress"/>.
/// </summary>
@@ -36,6 +37,7 @@ namespace Thought.vCards
{
this.address = string.Empty;
this.emailType = vCardEmailAddressType.Internet;
this.itemType = ItemType.UNSPECIFIED;
}
@@ -45,29 +47,19 @@ namespace Thought.vCards
/// <param name="address">
/// The Internet email address.
/// </param>
public vCardEmailAddress(string address)
/// <param name="emailType">type of address, usually Internet. Internet is the default.</param>
/// <param name="itemType">HOME,WORK, unspecified</param>
public vCardEmailAddress(string address, vCardEmailAddressType emailType = vCardEmailAddressType.Internet, ItemType itemType = ItemType.UNSPECIFIED)
{
this.address = address == null ? string.Empty : address;
this.emailType = vCardEmailAddressType.Internet;
}
/// <summary>
/// Creates a new <see cref="vCardEmailAddress"/> of the specified type.
/// </summary>
/// <param name="address">
/// The email address.
/// </param>
/// <param name="emailType">
/// The type of email address.
/// </param>
public vCardEmailAddress(string address, vCardEmailAddressType emailType)
{
this.address = address;
this.emailType = emailType;
this.itemType = itemType;
}
/// <summary>
/// The email address.
/// </summary>
@@ -118,6 +110,16 @@ namespace Thought.vCards
}
}
/// <summary>
/// ItemType for this element (HOME,WORK,etc)
/// </summary>
public ItemType ItemType {
get { return this.itemType; }
set { this.itemType = value; }
}
/// <summary>
/// Builds a string that represents the email address.

View File

@@ -94,4 +94,24 @@ namespace Thought.vCards
}
/// <summary>
/// Identifies the HOME,WORK,ETC typing of an element
/// </summary>
public enum ItemType
{
/// <summary>
/// default - unknown
/// </summary>
UNSPECIFIED =0,
/// <summary>
/// work
/// </summary>
WORK = 1,
/// <summary>
/// home
/// </summary>
HOME =2,
}
}

View File

@@ -0,0 +1,319 @@
/* =======================================================================
* vCard Library for .NET
* Copyright (c) 2007-2009 David Pinch; http://wwww.thoughtproject.com
* See LICENSE.TXT for licensing information.
* ======================================================================= */
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
namespace Thought.vCards
{
/// <summary>
/// IM info <see cref="vCard"/>.
/// </summary>
[Serializable]
public class vCardIMPP
{
private string handle;
private ItemType itemType;
private IMServiceType serviceType;
/// <summary>
/// Creates a new <see cref="vCardIMPP"/> object.
/// </summary>
public vCardIMPP()
{
this.serviceType = IMServiceType.Unspecified;
}
/// <summary>
/// Creates a new <see cref="vCardIMPP"/> object with the specified handle.
/// </summary>
/// <param name="handle">the im handle</param>
/// <param name="serviceType">skype, aim, etc</param>
/// <param name="itemType">the type of IM, defaults to Unspecified</param>
public vCardIMPP(string handle, IMServiceType serviceType, ItemType itemType = ItemType.UNSPECIFIED)
{
this.handle = handle;
this.itemType = itemType;
this.serviceType = serviceType;
}
/// <summary>
/// The full IM handle.
/// </summary>
public string Handle
{
get
{
return this.handle ?? string.Empty;
}
set
{
this.handle = value;
}
}
/// <summary>
/// the IMServiceType AIM, googletalk, etc
/// </summary>
public IMServiceType ServiceType
{
get { return serviceType; }
set { serviceType = value; }
}
/// <summary>
/// The IM ItemType. home work, unspecified
/// </summary>
public ItemType ItemType
{
get
{
return this.itemType;
}
set
{
this.itemType = value;
}
}
/// <summary>
/// is PREF set on this IMPP item
/// </summary>
public bool IsPreferred { get; set; }
}
/// <summary>
/// simple enum for various types of IM services
/// </summary>
public enum IMServiceType
{
/// <summary>
/// unspecified
/// </summary>
Unspecified = 0,
/// <summary>
/// for Skype
/// </summary>
Skype,
/// <summary>
/// aim
/// </summary>
AIM,
/// <summary>
/// gtalk
/// </summary>
GoogleTalk,
/// <summary>
/// msn
/// </summary>
MSN,
/// <summary>
/// yahoo
/// </summary>
Yahoo,
/// <summary>
/// facebook
/// </summary>
Facebook,
/// <summary>
/// jabber
/// </summary>
Jabber,
/// <summary>
/// icq
/// </summary>
ICQ,
/// <summary>
/// qq
/// </summary>
QQ,
/// <summary>
/// gadu gadu
/// </summary>
GaduGadu
}
/// <summary>
/// simple class to generate the strings for given IMServiceType
/// </summary>
public static class IMTypeUtils
{
private static Dictionary<IMServiceType, string> lookup;
static IMTypeUtils()
{
lookup = new Dictionary<IMServiceType, string>();
lookup.Add(IMServiceType.AIM, "AIM:aim");
lookup.Add(IMServiceType.Facebook, "Facebook:xmpp");
lookup.Add(IMServiceType.GoogleTalk, "GoogleTalk:xmpp");
lookup.Add(IMServiceType.ICQ, "ICQ:aim");
lookup.Add(IMServiceType.Jabber, "Jabber:xmpp");
lookup.Add(IMServiceType.MSN, "MSN:msnim");
lookup.Add(IMServiceType.QQ, "QQ:x-apple");
lookup.Add(IMServiceType.Skype, "Skype:skype");
lookup.Add(IMServiceType.Yahoo, "Yahoo:ymsgr");
lookup.Add(IMServiceType.GaduGadu, "GaduGadu:x-apple");
}
/// <summary>
/// will return the property meta info to be written for a given IM serviceType
/// </summary>
///
/// <param name="serviceType">IMServiceType to get the subproperty info for </param>
/// <returns>for example GoogleTalk:xmpp, or for yahoo Yahoo:ymsgr</returns>
public static string GetIMTypePropertyFull(IMServiceType serviceType)
{
if (lookup.ContainsKey(serviceType))
{
return lookup[serviceType];
}
return null;
}
/// <summary>
/// returns the xmpp or aim or ymsgr portion of the lookup for AIM:aim, Yahoo:ysmgr, etc
/// </summary>
/// <param name="serviceType">IMServiceType to fetch the lookup for</param>
/// <returns>xmpp or msnim</returns>
public static string GetIMTypePropertySuffix(IMServiceType serviceType)
{
string suffix = null;
if (lookup.ContainsKey(serviceType))
{
string full = lookup[serviceType];
suffix = full.Substring(full.IndexOf(":") + 1);
}
return suffix;
}
/// <summary>
/// this method will return the first part of the AIM:aim , or MSN:msnim string used for writing out the property subproperty info for IMPP values
/// </summary>
/// <param name="serviceType">the IM service type to fetch from the dictionary</param>
/// <returns>AIM or QQ or Yahoo, the first string component for the lookup of serviceTypes</returns>
public static string GetIMTypePropertyPrefix(IMServiceType serviceType)
{
string prefix = null;
if (lookup.ContainsKey(serviceType))
{
string full = lookup[serviceType];
prefix = full.Substring(0, full.IndexOf(":"));
}
return prefix;
}
/// <summary>
/// the handle is coming back with the msnim:handle, so we want to return the pure handle minus the msnim:
/// </summary>
/// <param name="serviceType"></param>
/// <param name="handle"></param>
/// <returns></returns>
public static string StripHandlePrefix(IMServiceType serviceType, string handle)
{
string property = GetIMTypePropertyFull(serviceType);
if (property != null)
{
string prefix = property.Substring(property.IndexOf(":") + 1);
int prefixLength = prefix.Length + 1;
if (handle.StartsWith(prefix))
{
handle = handle.Substring(handle.IndexOf(prefix + ":") + prefixLength);
}
}
return handle;
}
/// <summary>
/// for parsing the
/// </summary>
/// <param name="imType"></param>
/// <returns></returns>
public static IMServiceType? GetIMServiceType(string imType)
{
IMServiceType? serviceType = null;
switch (imType.ToLowerInvariant())
{
case "aim":
serviceType = IMServiceType.AIM;
break;
case "facebook":
serviceType = IMServiceType.Facebook;
break;
case "googletalk":
case "google":
serviceType = IMServiceType.GoogleTalk;
break;
case "icq":
serviceType = IMServiceType.ICQ;
break;
case "jabber":
case "xmpp":
serviceType = IMServiceType.Jabber;
break;
case "msn":
serviceType = IMServiceType.MSN;
break;
case "qq":
serviceType = IMServiceType.QQ;
break;
case "skype":
serviceType = IMServiceType.Skype;
break;
case "yahoo":
case "ymsgr":
serviceType = IMServiceType.Yahoo;
break;
case "gadugadu":
case "gadu":
serviceType = IMServiceType.GaduGadu;
break;
}
return serviceType;
}
}
}

View File

@@ -0,0 +1,21 @@

/* =======================================================================
* vCard Library for .NET
* Copyright (c) 2007-2009 David Pinch; http://wwww.thoughtproject.com
* See LICENSE.TXT for licensing information.
* ======================================================================= */
using System;
using System.Collections.ObjectModel;
namespace Thought.vCards
{
/// <summary>
/// A collection of <see cref="vCardIMPP"/> objects.
/// </summary>
public class vCardIMPPCollection : Collection<vCardIMPP>
{
}
}

View File

@@ -143,6 +143,52 @@ namespace Thought.vCards
}
}
/// <summary>
/// Indicates an iphone
/// </summary>
/// <seealso cref="vCardPhoneTypes"/>
public bool IsiPhone
{
get
{
return (this.phoneType & vCardPhoneTypes.IPhone) == vCardPhoneTypes.IPhone;
}
set
{
if (value)
{
this.phoneType = this.phoneType | vCardPhoneTypes.IPhone;
}
else
{
this.phoneType = this.phoneType & ~vCardPhoneTypes.IPhone;
}
}
}
/// <summary>
/// Indicates a main number
/// </summary>
/// <seealso cref="vCardPhoneTypes"/>
public bool IsMain
{
get
{
return (this.phoneType & vCardPhoneTypes.Main) == vCardPhoneTypes.Main;
}
set
{
if (value)
{
this.phoneType = this.phoneType | vCardPhoneTypes.Main;
}
else
{
this.phoneType = this.phoneType & ~vCardPhoneTypes.Main;
}
}
}
/// <summary>
/// Indicates a fax number.

View File

@@ -107,7 +107,18 @@ namespace Thought.vCards
/// <summary>
/// Indicates a work and voice number.
/// </summary>
WorkVoice = Work + Voice
WorkVoice = Work + Voice,
/// <summary>
/// to handle iPhone type in NAB for phone
/// </summary>
IPhone = 8192,
/// <summary>
/// to handle Main type for NAB
/// </summary>
Main = 16384
}
}

View File

@@ -49,6 +49,10 @@ namespace Thought.vCards
private Uri url;
private string encodedData;
/// <summary>
/// Loads a photograph from an array of bytes.
/// </summary>
@@ -97,6 +101,27 @@ namespace Thought.vCards
}
/// <summary>
/// Creates a new vCard photo from already encoded data.
/// </summary>
/// <param name="data">
/// The base64 encoded string of the image.
/// </param>
/// <param name="isEncoded">
/// Boolean true if is encoded.
/// </param>
public vCardPhoto(string data, bool isEncoded)
{
if (string.IsNullOrEmpty(data))
{
throw new ArgumentNullException("data");
}
this.encodedData = data;
}
/// <summary>
/// Creates a new vCard photo from an existing Bitmap object.
@@ -198,8 +223,19 @@ namespace Thought.vCards
/// </remarks>
public Bitmap GetBitmap()
{
MemoryStream stream = new MemoryStream(this.data);
return new Bitmap(stream);
if (HasEncodedData)
{
var bytes = Convert.FromBase64String(this.EncodedData);
MemoryStream stream = new MemoryStream(bytes);
return new Bitmap(stream);
}
else
{
MemoryStream stream = new MemoryStream(this.data);
return new Bitmap(stream);
}
}
@@ -233,6 +269,28 @@ namespace Thought.vCards
}
}
/// <summary>
/// property used to check if the data is already encoded in base64
/// </summary>
public bool HasEncodedData
{
get
{
return this.encodedData != null;
}
}
/// <summary>
/// get base64 encoded data
/// </summary>
public string EncodedData
{
get
{
return this.encodedData;
}
}
/// <summary>
/// The URL of the image.

View File

@@ -0,0 +1,206 @@
/* =======================================================================
* vCard Library for .NET
* Copyright (c) 2007-2009 David Pinch; http://wwww.thoughtproject.com
* See LICENSE.TXT for licensing information.
* ======================================================================= */
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
namespace Thought.vCards
{
/// <summary>
/// IM info <see cref="vCard"/>.
/// </summary>
[Serializable]
public class vCardSocialProfile
{
private string username;
private SocialProfileServiceType serviceType;
private string fullProfileUrl;
/// <summary>
/// Creates a new <see cref="vCardIMPP"/> object.
/// </summary>
public vCardSocialProfile()
{
this.serviceType = SocialProfileServiceType.Unspecified;
}
/// <summary>
/// Creates a new <see cref="vCardIMPP"/> object with the specified handle.
/// </summary>
/// <param name="username">the social profile username handle</param>
/// <param name="serviceType">Facebook, Twitter, Flickr, etc</param>
/// <param name="fullProfileUrl">the full url for the profile => http://twitter.com/username </param>
public vCardSocialProfile(string username, SocialProfileServiceType serviceType, string fullProfileUrl)
{
this.username = username;
this.serviceType = serviceType;
this.fullProfileUrl = fullProfileUrl;
}
/// <summary>
/// the full profile url of the socialProfile (http://twitter.com/username)
/// </summary>
public string ProfileUrl
{
get
{
return this.fullProfileUrl ?? string.Empty;
}
set
{
this.fullProfileUrl = value;
}
}
/// <summary>
/// The username on the socialProfile
/// </summary>
public string Username
{
get
{
return this.username ?? string.Empty;
}
set
{
this.username = value;
}
}
/// <summary>
/// the IMServiceType AIM, googletalk, etc
/// </summary>
public SocialProfileServiceType ServiceType
{
get { return serviceType; }
set { serviceType = value; }
}
}
/// <summary>
/// simple enum for various types of SocialProfile services
/// </summary>
public enum SocialProfileServiceType
{
/// <summary>
/// unspecified
/// </summary>
Unspecified = 0,
/// <summary>
/// Facebook
/// </summary>
Facebook,
/// <summary>
/// LinkedIn
/// </summary>
LinkedIn,
/// <summary>
/// Twitter
/// </summary>
Twitter,
/// <summary>
/// Flickr
/// </summary>
Flickr,
/// <summary>
/// Myspace
/// </summary>
Myspace
}
/// <summary>
/// utisl to handle string to enum conversion in one spot for SocialProfile types
/// </summary>
public static class SocialProfileTypeUtils
{
/// <summary>
/// for parsing the type string
/// </summary>
/// <param name="profileType"></param>
/// <returns>nullable ServiceType for matching string of serviceType</returns>
public static SocialProfileServiceType? GetSocialProfileServiceType(string profileType)
{
SocialProfileServiceType? serviceType = null;
switch (profileType.ToLowerInvariant())
{
case "facebook":
serviceType = SocialProfileServiceType.Facebook;
break;
case "flickr":
serviceType = SocialProfileServiceType.Flickr;
break;
case "linkedin":
serviceType = SocialProfileServiceType.LinkedIn;
break;
case "myspace":
serviceType = SocialProfileServiceType.Myspace;
break;
case "twitter":
serviceType = SocialProfileServiceType.Twitter;
break;
}
return serviceType;
}
/// <summary>
/// for returning the socialProfile type string that will be used in the type=twitter for reading socialProfile vCard data
/// </summary>
/// <param name="serviceType">the SocialProfile Type to get the lowercase string for to include in the type value</param>
/// <returns>facebook,twitter,etc</returns>
public static string GetSocialProfileServicePropertyType(SocialProfileServiceType serviceType)
{
string profileType = null;
switch (serviceType)
{
case SocialProfileServiceType.Facebook :
profileType = "facebook";
break;
case SocialProfileServiceType.Flickr:
profileType = "flickr";
break;
case SocialProfileServiceType.LinkedIn:
profileType = "linkedin";
break;
case SocialProfileServiceType.Myspace:
profileType = "myspace";
break;
case SocialProfileServiceType.Twitter:
profileType = "twitter";
break;
}
return profileType;
}
}
}

View File

@@ -0,0 +1,21 @@

/* =======================================================================
* vCard Library for .NET
* Copyright (c) 2007-2009 David Pinch; http://wwww.thoughtproject.com
* See LICENSE.TXT for licensing information.
* ======================================================================= */
using System;
using System.Collections.ObjectModel;
namespace Thought.vCards
{
/// <summary>
/// A collection of <see cref="vCardSocialProfile"/> objects.
/// </summary>
public class vCardSocialProfileCollection : Collection<vCardSocialProfile>
{
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -22,7 +22,7 @@ namespace Thought.vCards
private bool embedLocalImages;
private vCardStandardWriterOptions options;
private string productId;
private const string TYPE = "TYPE";
/// <summary>
/// The characters that are escaped per the original
@@ -156,7 +156,7 @@ namespace Thought.vCards
// See section 2.1.1 of RFC 2426.
properties.Add(new vCardProperty("BEGIN", "VCARD"));
properties.Add(new vCardProperty("VERSION", "3.0"));
BuildProperties_NAME(
properties,
card);
@@ -197,6 +197,8 @@ namespace Thought.vCards
properties,
card);
BuildProperties_IMPP(properties, card);
BuildProperties_KEY(
properties,
card);
@@ -257,6 +259,8 @@ namespace Thought.vCards
properties,
card);
BuildProperties_XSOCIALPROFILE(properties, card);
BuildProperties_X_WAB_GENDER(
properties,
card);
@@ -309,7 +313,7 @@ namespace Thought.vCards
values.Add(string.Empty);
values.Add(string.Empty);
values.Add(address.Street);
values.Add(!string.IsNullOrEmpty(address.Street) ? address.Street.Replace("\r\n", "\n") : string.Empty);
values.Add(address.City);
values.Add(address.Region);
values.Add(address.PostalCode);
@@ -319,22 +323,27 @@ namespace Thought.vCards
new vCardProperty("ADR", values);
if (address.IsDomestic)
property.Subproperties.Add("DOM");
property.Subproperties.Add(TYPE, "DOM");
if (address.IsInternational)
property.Subproperties.Add("INTL");
property.Subproperties.Add(TYPE, "INTL");
if (address.IsParcel)
property.Subproperties.Add("PARCEL");
property.Subproperties.Add(TYPE, "PARCEL");
if (address.IsPostal)
property.Subproperties.Add("POSTAL");
property.Subproperties.Add(TYPE, "POSTAL");
if (address.IsHome)
property.Subproperties.Add("HOME");
property.Subproperties.Add(TYPE, "HOME");
if (address.IsWork)
property.Subproperties.Add("WORK");
property.Subproperties.Add(TYPE, "WORK");
if (address.IsPreferred)
{
property.Subproperties.Add(TYPE, "PREF");
}
properties.Add(property);
@@ -359,16 +368,16 @@ namespace Thought.vCards
// The BDAY property indicates the birthdate
// of the person. The output format here is based on
// Microsoft Outlook, which writes the date as YYYMMDD.
// FIXES DateFormat with ToString
if (card.BirthDate.HasValue)
{
vCardProperty property =
new vCardProperty("BDAY", card.BirthDate.Value);
new vCardProperty("BDAY", card.BirthDate.Value.ToString("yyyy-MM-dd"));
properties.Add(property);
}
}
#endregion
@@ -467,66 +476,83 @@ namespace Thought.vCards
if (emailAddress.IsPreferred)
{
property.Subproperties.Add("PREF");
property.Subproperties.Add(TYPE, "PREF");
}
switch (emailAddress.EmailType)
{
case vCardEmailAddressType.Internet:
property.Subproperties.Add("INTERNET");
property.Subproperties.Add(TYPE, "INTERNET");
break;
case vCardEmailAddressType.AOL:
property.Subproperties.Add("AOL");
property.Subproperties.Add(TYPE, "AOL");
break;
case vCardEmailAddressType.AppleLink:
property.Subproperties.Add("AppleLink");
property.Subproperties.Add(TYPE, "AppleLink");
break;
case vCardEmailAddressType.AttMail:
property.Subproperties.Add("ATTMail");
property.Subproperties.Add(TYPE, "ATTMail");
break;
case vCardEmailAddressType.CompuServe:
property.Subproperties.Add("CIS");
property.Subproperties.Add(TYPE, "CIS");
break;
case vCardEmailAddressType.eWorld:
property.Subproperties.Add("eWorld");
property.Subproperties.Add(TYPE, "eWorld");
break;
case vCardEmailAddressType.IBMMail:
property.Subproperties.Add("IBMMail");
property.Subproperties.Add(TYPE, "IBMMail");
break;
case vCardEmailAddressType.MCIMail:
property.Subproperties.Add("MCIMail");
property.Subproperties.Add(TYPE, "MCIMail");
break;
case vCardEmailAddressType.PowerShare:
property.Subproperties.Add("POWERSHARE");
property.Subproperties.Add(TYPE, "POWERSHARE");
break;
case vCardEmailAddressType.Prodigy:
property.Subproperties.Add("PRODIGY");
property.Subproperties.Add(TYPE, "PRODIGY");
break;
case vCardEmailAddressType.Telex:
property.Subproperties.Add("TLX");
property.Subproperties.Add(TYPE, "TLX");
break;
case vCardEmailAddressType.X400:
property.Subproperties.Add("X400");
property.Subproperties.Add(TYPE, "X400");
break;
default:
property.Subproperties.Add("INTERNET");
property.Subproperties.Add(TYPE, "INTERNET");
break;
}
switch (emailAddress.ItemType)
{
case ItemType.UNSPECIFIED:
//do nothing
break;
case ItemType.HOME:
property.Subproperties.Add(TYPE, ItemType.HOME.ToString());
break;
case ItemType.WORK:
property.Subproperties.Add(TYPE, ItemType.WORK.ToString());
break;
default:
break;
}
properties.Add(property);
}
@@ -588,14 +614,76 @@ namespace Thought.vCards
}
#endregion
#endregion
#region [ BuildProperties_KEY ]
/// <summary>
/// Builds KEY properties.
/// </summary>
private void BuildProperties_KEY(
private void BuildProperties_IMPP(vCardPropertyCollection properties, vCard card)
{
// adding support for IMPP (IM handles) in the vCard
//iOS outputs this => IMPP;X-SERVICE-TYPE=Skype;type=HOME;type=pref:skype:skypeusernameee
foreach (var im in card.IMs)
{
vCardProperty property = new vCardProperty();
property.Name = "IMPP";
string prefix = IMTypeUtils.GetIMTypePropertyPrefix(im.ServiceType);
string suffix = IMTypeUtils.GetIMTypePropertySuffix(im.ServiceType);
if (!string.IsNullOrEmpty(prefix) && !string.IsNullOrEmpty(suffix))
{
property.Subproperties.Add("X-SERVICE-TYPE", prefix);
property.Value = string.Concat(suffix, ":", im.Handle);
}
else
{
property.Value = im.Handle;
}
if (im.IsPreferred)
{
property.Subproperties.Add(TYPE, "PREF");
}
switch (im.ItemType)
{
case ItemType.HOME:
property.Subproperties.Add(TYPE, ItemType.HOME.ToString());
break;
case ItemType.WORK:
property.Subproperties.Add(TYPE, ItemType.WORK.ToString());
break;
case ItemType.UNSPECIFIED:
default:
property.Subproperties.Add(TYPE, "OTHER");
break;
}
properties.Add(property);
if (im.ServiceType == IMServiceType.AIM)
{
var propertyXAim = new vCardProperty("X-AIM", im.Handle);
properties.Add(propertyXAim);
}
}
}
#region [ BuildProperties_KEY ]
/// <summary>
/// Builds KEY properties.
/// </summary>
private void BuildProperties_KEY(
vCardPropertyCollection properties,
vCard card)
{
@@ -609,7 +697,7 @@ namespace Thought.vCards
property.Name = "KEY";
property.Value = certificate.Data;
property.Subproperties.Add(certificate.KeyType);
property.Subproperties.Add(TYPE, certificate.KeyType);
properties.Add(property);
@@ -635,26 +723,23 @@ namespace Thought.vCards
vCardProperty property = new vCardProperty("LABEL", label.Text);
if (label.IsDomestic)
property.Subproperties.Add("DOM");
property.Subproperties.Add(TYPE, "DOM");
if (label.IsInternational)
property.Subproperties.Add("INTL");
property.Subproperties.Add(TYPE, "INTL");
if (label.IsParcel)
property.Subproperties.Add("PARCEL");
property.Subproperties.Add(TYPE, "PARCEL");
if (label.IsPostal)
property.Subproperties.Add("POSTAL");
property.Subproperties.Add(TYPE, "POSTAL");
if (label.IsHome)
property.Subproperties.Add("HOME");
property.Subproperties.Add(TYPE, "HOME");
if (label.IsWork)
property.Subproperties.Add("WORK");
property.Subproperties.Add(TYPE, "WORK");
// Give a hint to use QUOTED-PRINTABLE.
property.Subproperties.Add("ENCODING", "QUOTED-PRINTABLE");
properties.Add(property);
@@ -803,14 +888,13 @@ namespace Thought.vCards
vCardProperty property = new vCardProperty();
property.Name = "NOTE";
property.Value = note.Text;
property.Value = note.Text.Replace("\r\n", "\n");
if (!string.IsNullOrEmpty(note.Language))
{
property.Subproperties.Add("language", note.Language);
}
property.Subproperties.Add("ENCODING", "QUOTED-PRINTABLE");
properties.Add(property);
}
@@ -839,8 +923,20 @@ namespace Thought.vCards
if (!string.IsNullOrEmpty(card.Organization))
{
vCardProperty property =
new vCardProperty("ORG", 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);
@@ -860,80 +956,89 @@ namespace Thought.vCards
foreach (vCardPhoto photo in card.Photos)
{
if (photo.Url == null)
if (photo.Url == null)
{
// This photo does not have a URL associated
// with it. Therefore a property can be
// generated only if the image data is loaded.
// Otherwise there is not enough information.
vCardProperty property = null;
if (photo.IsLoaded)
{
property = new vCardProperty("PHOTO", photo.GetBytes());
}
else if (photo.HasEncodedData)
{
property = new vCardProperty("PHOTO", photo.EncodedData);
}
if (property != null)
{
property.Subproperties.Add("TYPE", "JPEG");
properties.Add(property);
}
}
else
{
// This photo has a URL associated with it. The
// PHOTO property can either be linked as an image
// or embedded, if desired.
bool doEmbedded =
photo.Url.IsFile ? this.embedLocalImages : this.embedInternetImages;
if (doEmbedded)
{
// This photo does not have a URL associated
// with it. Therefore a property can be
// generated only if the image data is loaded.
// Otherwise there is not enough information.
// According to the settings of the card writer,
// this linked image should be embedded into the
// vCard data. Attempt to fetch the data.
if (photo.IsLoaded)
{
try
{
photo.Fetch();
}
catch
{
properties.Add(
new vCardProperty("PHOTO", photo.GetBytes()));
// An error was encountered. The image can
// still be written as a link, however.
}
doEmbedded = false;
}
}
// At this point, doEmbedded is true only if (a) the
// writer was configured to embed the image, and (b)
// the image was successfully downloaded.
if (doEmbedded)
{
properties.Add(
new vCardProperty("PHOTO", photo.GetBytes()));
}
else
{
// This photo has a URL associated with it. The
// PHOTO property can either be linked as an image
// or embedded, if desired.
vCardProperty uriPhotoProperty =
new vCardProperty("PHOTO");
bool doEmbedded =
photo.Url.IsFile ? this.embedLocalImages : this.embedInternetImages;
// Set the VALUE property to indicate that
// the data for the photo is a URI.
if (doEmbedded)
{
// According to the settings of the card writer,
// this linked image should be embedded into the
// vCard data. Attempt to fetch the data.
try
{
photo.Fetch();
}
catch
{
// An error was encountered. The image can
// still be written as a link, however.
doEmbedded = false;
}
}
// At this point, doEmbedded is true only if (a) the
// writer was configured to embed the image, and (b)
// the image was successfully downloaded.
if (doEmbedded)
{
properties.Add(
new vCardProperty("PHOTO", photo.GetBytes()));
}
else
{
vCardProperty uriPhotoProperty =
new vCardProperty("PHOTO");
// Set the VALUE property to indicate that
// the data for the photo is a URI.
uriPhotoProperty.Subproperties.Add("VALUE", "URI");
uriPhotoProperty.Value = photo.Url.ToString();
properties.Add(uriPhotoProperty);
}
uriPhotoProperty.Subproperties.Add("VALUE", "URI");
uriPhotoProperty.Value = photo.Url.ToString();
properties.Add(uriPhotoProperty);
}
}
}
}
@@ -975,7 +1080,7 @@ namespace Thought.vCards
{
vCardProperty property =
new vCardProperty("REV", card.RevisionDate.Value.ToString());
new vCardProperty("REV", card.RevisionDate.Value.ToString("s") + "Z");
properties.Add(property);
@@ -1072,43 +1177,64 @@ namespace Thought.vCards
property.Name = "TEL";
if (phone.IsBBS)
property.Subproperties.Add("BBS");
property.Subproperties.Add(TYPE, "BBS");
if (phone.IsCar)
property.Subproperties.Add("CAR");
property.Subproperties.Add(TYPE, "CAR");
if (phone.IsCellular)
property.Subproperties.Add("CELL");
property.Subproperties.Add(TYPE, "CELL");
if (phone.IsFax)
property.Subproperties.Add("FAX");
{
if (!phone.IsHome && !phone.IsWork)
{
property.Subproperties.Add(TYPE, "OTHER");
}
property.Subproperties.Add(TYPE, "FAX");
}
if (phone.IsHome)
property.Subproperties.Add("HOME");
property.Subproperties.Add(TYPE, "HOME");
if (phone.IsISDN)
property.Subproperties.Add("ISDN");
property.Subproperties.Add(TYPE, "ISDN");
if (phone.IsMessagingService)
property.Subproperties.Add("MSG");
property.Subproperties.Add(TYPE, "MSG");
if (phone.IsModem)
property.Subproperties.Add("MODEM");
property.Subproperties.Add(TYPE, "MODEM");
if (phone.IsPager)
property.Subproperties.Add("PAGER");
property.Subproperties.Add(TYPE, "PAGER");
if (phone.IsPreferred)
property.Subproperties.Add("PREF");
property.Subproperties.Add(TYPE, "PREF");
if (phone.IsVideo)
property.Subproperties.Add("VIDEO");
property.Subproperties.Add(TYPE, "VIDEO");
if (phone.IsVoice)
property.Subproperties.Add("VOICE");
{
if (!phone.IsHome && !phone.IsWork)
{
property.Subproperties.Add(TYPE, "OTHER");
}
property.Subproperties.Add(TYPE, "VOICE");
}
if (phone.IsWork)
property.Subproperties.Add("WORK");
property.Subproperties.Add(TYPE, "WORK");
if (phone.IsiPhone)
{
property.Subproperties.Add(TYPE, "IPHONE");
}
if (phone.IsMain)
{
property.Subproperties.Add(TYPE, "MAIN");
}
property.Value = phone.FullNumber;
properties.Add(property);
@@ -1195,7 +1321,10 @@ namespace Thought.vCards
new vCardProperty("URL", webSite.Url.ToString());
if (webSite.IsWorkSite)
property.Subproperties.Add("WORK");
property.Subproperties.Add(TYPE, "WORK");
// Add Subproperty for HOME aswell
if (webSite.IsPersonalSite)
property.Subproperties.Add(TYPE, "HOME");
properties.Add(property);
}
@@ -1206,6 +1335,32 @@ namespace Thought.vCards
#endregion
private void BuildProperties_XSOCIALPROFILE(vCardPropertyCollection properties, vCard card)
{
// adding support for X-SOCIALPROFILE) in the vCard
foreach (var sp in card.SocialProfiles)
{
vCardProperty property = new vCardProperty();
property.Name = "X-SOCIALPROFILE";
string propertyType = SocialProfileTypeUtils.GetSocialProfileServicePropertyType(sp.ServiceType);
property.Subproperties.Add("TYPE", propertyType);
property.Subproperties.Add("X-USER", sp.Username);
property.Value = sp.ProfileUrl;
properties.Add(property);
}
}
#region [ BuildProperties_X_WAB_GENDER ]
private void BuildProperties_X_WAB_GENDER(
@@ -1502,10 +1657,16 @@ namespace Thought.vCards
// A byte array should be encoded in BASE64 format.
builder.Append(";ENCODING=BASE64:");
builder.Append(";ENCODING=b:");
builder.Append(EncodeBase64((byte[])property.Value));
}
else if (property.Name.Equals("PHOTO", StringComparison.OrdinalIgnoreCase) && valueType == typeof(string))
{
//already base64 encoded
builder.Append(";ENCODING=b:");
builder.Append(property.Value);
}
else if (valueType == typeof(vCardValueCollection))
{

View File

@@ -77,6 +77,8 @@
<Compile Include="Thought.vCards\vCardException.cs" />
<Compile Include="Thought.vCards\vCardFormat.cs" />
<Compile Include="Thought.vCards\vCardGender.cs" />
<Compile Include="Thought.vCards\vCardIMPP.cs" />
<Compile Include="Thought.vCards\vCardIMPPCollection.cs" />
<Compile Include="Thought.vCards\vCardNote.cs" />
<Compile Include="Thought.vCards\vCardNoteCollection.cs" />
<Compile Include="Thought.vCards\vCardPhone.cs" />
@@ -87,6 +89,8 @@
<Compile Include="Thought.vCards\vCardProperty.cs" />
<Compile Include="Thought.vCards\vCardPropertyCollection.cs" />
<Compile Include="Thought.vCards\vCardReader.cs" />
<Compile Include="Thought.vCards\vCardSocialProfile.cs" />
<Compile Include="Thought.vCards\vCardSocialProfileCollection.cs" />
<Compile Include="Thought.vCards\vCardSource.cs" />
<Compile Include="Thought.vCards\vCardSourceCollection.cs" />
<Compile Include="Thought.vCards\vCardStandardReader.cs" />