Skip to content

Commit

Permalink
imp - Changed how photos, logos, and sounds are parsed
Browse files Browse the repository at this point in the history
---

We've changed how VisualCard parses logos, sounds, and photos. This makes it easier for applications that utilize VisualCard to utilize this kind of data.

---

Type: imp
Breaking: False
Doc Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Apr 4, 2024
1 parent 5f60539 commit 02852de
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 7 deletions.
2 changes: 1 addition & 1 deletion VisualCard.ShowContacts/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ static void Main(string[] args)
foreach (var Photo in Contact.GetPartsArray<PhotoInfo>())
{
TextWriterColor.Write("Photo encoding: {0}", Photo.Encoding);
TextWriterColor.Write("Photo value type: {0}", Photo.ValueType);
TextWriterColor.Write("Photo value type: {0}", string.Join(",", Photo.ElementTypes));
TextWriterColor.Write("ALTID: {0}", Photo.AltId);
TextWriterColor.Write("Photo data: \n{0}", Photo.PhotoEncoded);
}
Expand Down
6 changes: 3 additions & 3 deletions VisualCard/Parsers/VcardParserTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,13 @@ prefix switch
VcardConstants._emailSpecifier => (PartType.PartsArray, PartsArrayEnum.Mails, typeof(EmailInfo), EmailInfo.FromStringVcardStatic, "HOME", "", ["AOL", "APPLELINK", "ATTMAIL", "CIS", "EWORLD", "INTERNET", "IBMMAIL", "MCIMAIL", "POWERSHARE", "PRODIGY", "TLX", "X400"]),
VcardConstants._orgSpecifier => (PartType.PartsArray, PartsArrayEnum.Organizations, typeof(OrganizationInfo), OrganizationInfo.FromStringVcardStatic, "WORK", "", []),
VcardConstants._titleSpecifier => (PartType.PartsArray, PartsArrayEnum.Titles, typeof(TitleInfo), TitleInfo.FromStringVcardStatic, "", "", []),
VcardConstants._photoSpecifier => (PartType.PartsArray, PartsArrayEnum.Photos, typeof(PhotoInfo), PhotoInfo.FromStringVcardStatic, "", "JPEG", []),
VcardConstants._photoSpecifier => (PartType.PartsArray, PartsArrayEnum.Photos, typeof(PhotoInfo), PhotoInfo.FromStringVcardStatic, "JPEG", "", ["JPG", "GIF", "CGM", "WMF", "BMP", "MET", "PMB", "DIB", "PICT", "TIFF", "PS", "PDF", "JPEG", "MPEG", "MPEG2", "AVI", "QTIME", "PNG", "WEBP"]),
VcardConstants._nicknameSpecifier => (PartType.PartsArray, PartsArrayEnum.Nicknames, typeof(NicknameInfo), NicknameInfo.FromStringVcardStatic, "HOME", "", []),
VcardConstants._roleSpecifier => (PartType.PartsArray, PartsArrayEnum.Roles, typeof(RoleInfo), RoleInfo.FromStringVcardStatic, "", "", []),
VcardConstants._logoSpecifier => (PartType.PartsArray, PartsArrayEnum.Logos, typeof(LogoInfo), LogoInfo.FromStringVcardStatic, "", "JPEG", []),
VcardConstants._logoSpecifier => (PartType.PartsArray, PartsArrayEnum.Logos, typeof(LogoInfo), LogoInfo.FromStringVcardStatic, "JPEG", "", ["JPG", "GIF", "CGM", "WMF", "BMP", "MET", "PMB", "DIB", "PICT", "TIFF", "PS", "PDF", "JPEG", "MPEG", "MPEG2", "AVI", "QTIME", "PNG", "WEBP"]),
VcardConstants._timeZoneSpecifier => (PartType.PartsArray, PartsArrayEnum.TimeZone, typeof(TimeDateZoneInfo), TimeDateZoneInfo.FromStringVcardStatic, "", "", []),
VcardConstants._geoSpecifier => (PartType.PartsArray, PartsArrayEnum.Geo, typeof(GeoInfo), GeoInfo.FromStringVcardStatic, "", "uri", []),
VcardConstants._soundSpecifier => (PartType.PartsArray, PartsArrayEnum.Sounds, typeof(SoundInfo), SoundInfo.FromStringVcardStatic, "", "MP3", []),
VcardConstants._soundSpecifier => (PartType.PartsArray, PartsArrayEnum.Sounds, typeof(SoundInfo), SoundInfo.FromStringVcardStatic, "MP3", "", ["MP3", "WAVE", "PCM", "AIFF", "AAC"]),
VcardConstants._imppSpecifier => (PartType.PartsArray, PartsArrayEnum.Impps, typeof(ImppInfo), ImppInfo.FromStringVcardStatic, "SIP", "", ["SIP"]),
VcardConstants._categoriesSpecifier => (PartType.PartsArray, PartsArrayEnum.Categories, typeof(CategoryInfo), CategoryInfo.FromStringVcardStatic, "", "", []),
VcardConstants._langSpecifier => (PartType.PartsArray, PartsArrayEnum.Langs, typeof(LangInfo), LangInfo.FromStringVcardStatic, "HOME", "", []),
Expand Down
24 changes: 23 additions & 1 deletion VisualCard/Parts/Implementations/LogoInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using VisualCard.Parsers;

namespace VisualCard.Parts.Implementations
Expand Down Expand Up @@ -47,8 +48,29 @@ public class LogoInfo : BaseCardPartInfo, IEquatable<LogoInfo>

internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion)
{
bool vCard4 = cardVersion.Major >= 4;

// Check to see if the value is prepended by the ENCODING= argument
string logoEncoding = VcardParserTools.GetValuesString(finalArgs, "BASE64", VcardConstants._encodingArgumentSpecifier);
string logoEncoding = "";
if (vCard4)
{
// We're on a vCard 4.0 contact that contains this information
if (!Uri.TryCreate(value, UriKind.Absolute, out Uri uri))
throw new InvalidDataException($"URL {value} is invalid");
value = uri.ToString();
}
else
{
// vCard 3.0 handles this in a different way
logoEncoding = VcardParserTools.GetValuesString(finalArgs, "b", VcardConstants._encodingArgumentSpecifier);
if (!logoEncoding.Equals("b", StringComparison.OrdinalIgnoreCase) && !logoEncoding.Equals("BASE64", StringComparison.OrdinalIgnoreCase))
{
// Since we don't need embedded logos, we need to check a URL.
if (!Uri.TryCreate(value, UriKind.Absolute, out Uri uri))
throw new InvalidDataException($"URL {value} is invalid");
value = uri.ToString();
}
}

// Populate the fields
LogoInfo _logo = new(altId, finalArgs, elementTypes, valueType, logoEncoding, value);
Expand Down
24 changes: 23 additions & 1 deletion VisualCard/Parts/Implementations/PhotoInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using VisualCard.Parsers;

namespace VisualCard.Parts.Implementations
Expand Down Expand Up @@ -47,8 +48,29 @@ public class PhotoInfo : BaseCardPartInfo, IEquatable<PhotoInfo>

internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion)
{
bool vCard4 = cardVersion.Major >= 4;

// Check to see if the value is prepended by the ENCODING= argument
string photoEncoding = VcardParserTools.GetValuesString(finalArgs, "BASE64", VcardConstants._encodingArgumentSpecifier);
string photoEncoding = "";
if (vCard4)
{
// We're on a vCard 4.0 contact that contains this information
if (!Uri.TryCreate(value, UriKind.Absolute, out Uri uri))
throw new InvalidDataException($"URL {value} is invalid");
value = uri.ToString();
}
else
{
// vCard 3.0 handles this in a different way
photoEncoding = VcardParserTools.GetValuesString(finalArgs, "b", VcardConstants._encodingArgumentSpecifier);
if (!photoEncoding.Equals("b", StringComparison.OrdinalIgnoreCase) && !photoEncoding.Equals("BASE64", StringComparison.OrdinalIgnoreCase))
{
// Since we don't need embedded photos, we need to check a URL.
if (!Uri.TryCreate(value, UriKind.Absolute, out Uri uri))
throw new InvalidDataException($"URL {value} is invalid");
value = uri.ToString();
}
}

// Populate the fields
PhotoInfo _photo = new(altId, finalArgs, elementTypes, valueType, photoEncoding, value);
Expand Down
24 changes: 23 additions & 1 deletion VisualCard/Parts/Implementations/SoundInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using VisualCard.Parsers;

namespace VisualCard.Parts.Implementations
Expand Down Expand Up @@ -47,8 +48,29 @@ public class SoundInfo : BaseCardPartInfo, IEquatable<SoundInfo>

internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion)
{
bool vCard4 = cardVersion.Major >= 4;

// Check to see if the value is prepended by the ENCODING= argument
string soundEncoding = VcardParserTools.GetValuesString(finalArgs, "BASE64", VcardConstants._encodingArgumentSpecifier);
string soundEncoding = "";
if (vCard4)
{
// We're on a vCard 4.0 contact that contains this information
if (!Uri.TryCreate(value, UriKind.Absolute, out Uri uri))
throw new InvalidDataException($"URL {value} is invalid");
value = uri.ToString();
}
else
{
// vCard 3.0 handles this in a different way
soundEncoding = VcardParserTools.GetValuesString(finalArgs, "b", VcardConstants._encodingArgumentSpecifier);
if (!soundEncoding.Equals("b", StringComparison.OrdinalIgnoreCase) && !soundEncoding.Equals("BASE64", StringComparison.OrdinalIgnoreCase))
{
// Since we don't need embedded sounds, we need to check a URL.
if (!Uri.TryCreate(value, UriKind.Absolute, out Uri uri))
throw new InvalidDataException($"URL {value} is invalid");
value = uri.ToString();
}
}

// Populate the fields
SoundInfo _sound = new(altId, finalArgs, elementTypes, valueType, soundEncoding, value);
Expand Down

0 comments on commit 02852de

Please sign in to comment.