Skip to content

Commit

Permalink
add - Added IsBlob
Browse files Browse the repository at this point in the history
---

We've added a property that determines if the encoded photo/logo/sound is a blob or not.

---

Type: add
Breaking: False
Doc Required: False
Backport Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Jul 1, 2024
1 parent fe6e47c commit a8e9283
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion VisualCard.ShowContacts/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ static void Main(string[] args)
TextWriterColor.Write("Photo encoding: {0}", Photo.Encoding);
TextWriterColor.Write("Photo value type: {0}", string.Join(",", Photo.ElementTypes));
TextWriterColor.Write("ALTID: {0}", Photo.AltId);
TextWriterColor.Write("Photo data: \n{0}", Photo.PhotoEncoded);
TextWriterColor.Write("Photo data [blob: {0}]: \n{1}", true, Photo.IsBlob, Photo.PhotoEncoded);
}

// List roles
Expand Down
9 changes: 9 additions & 0 deletions VisualCard/Parsers/VcardParserTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,5 +335,14 @@ internal static IEnumerable<int> GetDigits(int num)
yield return individualFactor;
}
}

internal static bool IsEncodingBlob(string[] args)
{
string encoding = GetValuesString(args, "b", VcardConstants._encodingArgumentSpecifier);
return
encoding.Equals("b", StringComparison.OrdinalIgnoreCase) ||
encoding.Equals("BASE64", StringComparison.OrdinalIgnoreCase) ||
encoding.Equals("BLOB", StringComparison.OrdinalIgnoreCase);
}
}
}
9 changes: 6 additions & 3 deletions VisualCard/Parts/Implementations/LogoInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public class LogoInfo : BaseCardPartInfo, IEquatable<LogoInfo>
/// Encoded logo
/// </summary>
public string LogoEncoded { get; }
/// <summary>
/// Whether this logo is a blob or not
/// </summary>
public bool IsBlob =>
VcardParserTools.IsEncodingBlob(Arguments) || LogoEncoded.StartsWith("data:");

internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) =>
new LogoInfo().FromStringVcardInternal(value, finalArgs, altId, elementTypes, valueType, cardVersion);
Expand All @@ -63,9 +68,7 @@ internal override BaseCardPartInfo FromStringVcardInternal(string value, string[
{
// 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) &&
!logoEncoding.Equals("BLOB", StringComparison.OrdinalIgnoreCase))
if (!VcardParserTools.IsEncodingBlob(finalArgs))
{
// Since we don't need embedded logos, we need to check a URL.
if (!Uri.TryCreate(value, UriKind.Absolute, out Uri uri))
Expand Down
9 changes: 6 additions & 3 deletions VisualCard/Parts/Implementations/PhotoInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public class PhotoInfo : BaseCardPartInfo, IEquatable<PhotoInfo>
/// Encoded photo
/// </summary>
public string PhotoEncoded { get; }
/// <summary>
/// Whether this photo is a blob or not
/// </summary>
public bool IsBlob =>
VcardParserTools.IsEncodingBlob(Arguments) || PhotoEncoded.StartsWith("data:");

internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) =>
new PhotoInfo().FromStringVcardInternal(value, finalArgs, altId, elementTypes, valueType, cardVersion);
Expand All @@ -63,9 +68,7 @@ internal override BaseCardPartInfo FromStringVcardInternal(string value, string[
{
// 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) &&
!photoEncoding.Equals("BLOB", StringComparison.OrdinalIgnoreCase))
if (!VcardParserTools.IsEncodingBlob(finalArgs))
{
// Since we don't need embedded photos, we need to check a URL.
if (!Uri.TryCreate(value, UriKind.Absolute, out Uri uri))
Expand Down
9 changes: 6 additions & 3 deletions VisualCard/Parts/Implementations/SoundInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public class SoundInfo : BaseCardPartInfo, IEquatable<SoundInfo>
/// Encoded sound
/// </summary>
public string SoundEncoded { get; }
/// <summary>
/// Whether this sound is a blob or not
/// </summary>
public bool IsBlob =>
VcardParserTools.IsEncodingBlob(Arguments) || SoundEncoded.StartsWith("data:");

internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) =>
new SoundInfo().FromStringVcardInternal(value, finalArgs, altId, elementTypes, valueType, cardVersion);
Expand All @@ -63,9 +68,7 @@ internal override BaseCardPartInfo FromStringVcardInternal(string value, string[
{
// 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) &&
!soundEncoding.Equals("BLOB", StringComparison.OrdinalIgnoreCase))
if (!VcardParserTools.IsEncodingBlob(finalArgs))
{
// Since we don't need embedded sounds, we need to check a URL.
if (!Uri.TryCreate(value, UriKind.Absolute, out Uri uri))
Expand Down

0 comments on commit a8e9283

Please sign in to comment.