Skip to content

Commit

Permalink
[Communication] - Identifier serialization new schema (#18120)
Browse files Browse the repository at this point in the history
* Identity Derialization Requires Id

* Add cloud environment to MicrosoftTeamsIdentifier

* Update description

Co-authored-by: Dominik <domessin@microsoft.com>
  • Loading branch information
RezaJooyandeh and DominikMe authored Jan 22, 2021
1 parent 8468943 commit 231fb45
Show file tree
Hide file tree
Showing 10 changed files with 275 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@ public CallingApplicationIdentifier(string id) { }
public override int GetHashCode() { throw null; }
public override string ToString() { throw null; }
}
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public readonly partial struct CommunicationCloudEnvironment : System.IEquatable<Azure.Communication.CommunicationCloudEnvironment>
{
private readonly object _dummy;
private readonly int _dummyPrimitive;
public CommunicationCloudEnvironment(string value) { throw null; }
public static Azure.Communication.CommunicationCloudEnvironment Dod { get { throw null; } }
public static Azure.Communication.CommunicationCloudEnvironment Gcch { get { throw null; } }
public static Azure.Communication.CommunicationCloudEnvironment Public { get { throw null; } }
public bool Equals(Azure.Communication.CommunicationCloudEnvironment other) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override bool Equals(object obj) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override int GetHashCode() { throw null; }
public static bool operator ==(Azure.Communication.CommunicationCloudEnvironment left, Azure.Communication.CommunicationCloudEnvironment right) { throw null; }
public static implicit operator Azure.Communication.CommunicationCloudEnvironment (string value) { throw null; }
public static bool operator !=(Azure.Communication.CommunicationCloudEnvironment left, Azure.Communication.CommunicationCloudEnvironment right) { throw null; }
public override string ToString() { throw null; }
}
public abstract partial class CommunicationIdentifier : System.IEquatable<Azure.Communication.CommunicationIdentifier>
{
protected CommunicationIdentifier() { }
Expand Down Expand Up @@ -37,7 +56,9 @@ public CommunicationUserIdentifier(string id) { }
}
public partial class MicrosoftTeamsUserIdentifier : Azure.Communication.CommunicationIdentifier
{
public MicrosoftTeamsUserIdentifier(string userId, bool isAnonymous = false) { }
public MicrosoftTeamsUserIdentifier(string userId, bool isAnonymous = false, string? id = null, Azure.Communication.CommunicationCloudEnvironment? cloud = default(Azure.Communication.CommunicationCloudEnvironment?)) { }
public Azure.Communication.CommunicationCloudEnvironment Cloud { get { throw null; } }
public string? Id { get { throw null; } }
public bool IsAnonymous { get { throw null; } }
public string UserId { get { throw null; } }
public override bool Equals(Azure.Communication.CommunicationIdentifier other) { throw null; }
Expand All @@ -46,7 +67,8 @@ public MicrosoftTeamsUserIdentifier(string userId, bool isAnonymous = false) { }
}
public partial class PhoneNumberIdentifier : Azure.Communication.CommunicationIdentifier
{
public PhoneNumberIdentifier(string phoneNumber) { }
public PhoneNumberIdentifier(string phoneNumber, string? id = null) { }
public string? Id { get { throw null; } }
public string PhoneNumber { get { throw null; } }
public override bool Equals(Azure.Communication.CommunicationIdentifier other) { throw null; }
public override int GetHashCode() { throw null; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.ComponentModel;

namespace Azure.Communication
{
/// <summary> The cloud that the identifier belongs to. </summary>
public readonly partial struct CommunicationCloudEnvironment : IEquatable<CommunicationCloudEnvironment>
{
private readonly string _value;

/// <summary> Determines if two <see cref="CommunicationCloudEnvironment"/> values are the same. </summary>
/// <exception cref="ArgumentNullException"> <paramref name="value"/> is null. </exception>
public CommunicationCloudEnvironment(string value)
=> _value = value ?? throw new ArgumentNullException(nameof(value));

private const string PublicValue = "public";
private const string DodValue = "dod";
private const string GcchValue = "gcch";

/// <summary> public. </summary>
public static CommunicationCloudEnvironment Public { get; } = new CommunicationCloudEnvironment(PublicValue);
/// <summary> dod. </summary>
public static CommunicationCloudEnvironment Dod { get; } = new CommunicationCloudEnvironment(DodValue);
/// <summary> gcch. </summary>
public static CommunicationCloudEnvironment Gcch { get; } = new CommunicationCloudEnvironment(GcchValue);
/// <summary> Determines if two <see cref="CommunicationCloudEnvironment"/> values are the same. </summary>
public static bool operator ==(CommunicationCloudEnvironment left, CommunicationCloudEnvironment right) => left.Equals(right);
/// <summary> Determines if two <see cref="CommunicationCloudEnvironment"/> values are not the same. </summary>
public static bool operator !=(CommunicationCloudEnvironment left, CommunicationCloudEnvironment right) => !left.Equals(right);
/// <summary> Converts a string to a <see cref="CommunicationCloudEnvironment"/>. </summary>
public static implicit operator CommunicationCloudEnvironment(string value) => new CommunicationCloudEnvironment(value);

/// <inheritdoc />
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool Equals(object obj) => obj is CommunicationCloudEnvironment other && Equals(other);
/// <inheritdoc />
public bool Equals(CommunicationCloudEnvironment other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase);

/// <inheritdoc />
[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode() => _value?.GetHashCode() ?? 0;
/// <inheritdoc />
public override string ToString() => _value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,38 @@ namespace Azure.Communication
/// <summary>Represents a Microsoft Teams user.</summary>
public class MicrosoftTeamsUserIdentifier : CommunicationIdentifier
{
/// <summary>The full id of the Microsoft Teams User identifier.</summary>
public string? Id { get; }

/// <summary>The id of the Microsoft Teams user. If the user isn't anonymous, the id is the AAD object id of the user.</summary>
public string UserId { get; }

/// <summary>True if the user is anonymous, for example when joining a meeting with a share link.</summary>
public bool IsAnonymous { get; }

/// <summary> The cloud that the identifier belongs to. </summary>
public CommunicationCloudEnvironment Cloud { get; }

/// <summary>
/// Initializes a new instance of <see cref="MicrosoftTeamsUserIdentifier"/>.
/// </summary>
/// <param name="userId">Id of the Microsoft Teams user. If the user isn't anonymous, the id is the AAD object id of the user.</param>
/// <param name="isAnonymous">Set this to true if the user is anonymous, for example when joining a meeting with a share link.</param>
/// <param name="id">Full id of the Microsoft Teams user, optional.</param>
/// <param name="cloud">The cloud that the Microsoft Team user belongs to. A null value translates to the Public cloud.</param>
/// <exception cref="System.ArgumentNullException">
/// Thrown when the <paramref name="userId"/> is null.
/// </exception>
/// <exception cref="System.ArgumentException">
/// Thrown when the <paramref name="userId"/> is empty.
/// </exception>
public MicrosoftTeamsUserIdentifier(string userId, bool isAnonymous = false)
public MicrosoftTeamsUserIdentifier(string userId, bool isAnonymous = false, string? id = null, CommunicationCloudEnvironment? cloud = null)
{
Argument.AssertNotNullOrEmpty(userId, nameof(userId));
UserId = userId;
IsAnonymous = isAnonymous;
Cloud = cloud ?? CommunicationCloudEnvironment.Public;
Id = id;
}

/// <inheritdoc />
Expand All @@ -40,6 +50,10 @@ public MicrosoftTeamsUserIdentifier(string userId, bool isAnonymous = false)

/// <inheritdoc />
public override bool Equals(CommunicationIdentifier other)
=> other is MicrosoftTeamsUserIdentifier otherId && otherId.UserId == UserId && otherId.IsAnonymous == IsAnonymous;
=> other is MicrosoftTeamsUserIdentifier otherId
&& otherId.UserId == UserId
&& otherId.IsAnonymous == IsAnonymous
&& otherId.Cloud == Cloud
&& (Id is null || otherId.Id is null || Id == otherId.Id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,26 @@ namespace Azure.Communication
/// <summary>Represents a Phone Number.</summary>
public class PhoneNumberIdentifier : CommunicationIdentifier
{
/// <summary>The full id of the phone number.</summary>
public string? Id { get; }

/// <summary>The phone number in E.164 format.</summary>
public string PhoneNumber { get; }

/// <summary> Initializes a new instance of <see cref="PhoneNumberIdentifier"/>.</summary>
/// <param name="phoneNumber">The phone number in E.164 format.</param>
/// <param name="id">Full id of the phone number.</param>
/// <exception cref="System.ArgumentNullException">
/// Thrown when the <paramref name="phoneNumber"/> is null.
/// </exception>
/// <exception cref="System.ArgumentException">
/// Thrown when the <paramref name="phoneNumber"/> is empty.
/// </exception>
public PhoneNumberIdentifier(string phoneNumber)
public PhoneNumberIdentifier(string phoneNumber, string? id = null)
{
Argument.AssertNotNullOrEmpty(phoneNumber, nameof(phoneNumber));
PhoneNumber = phoneNumber;
Id = id;
}

/// <inheritdoc />
Expand All @@ -34,6 +39,6 @@ public PhoneNumberIdentifier(string phoneNumber)

/// <inheritdoc />
public override bool Equals(CommunicationIdentifier other)
=> other is PhoneNumberIdentifier otherId && otherId.PhoneNumber == PhoneNumber;
=> other is PhoneNumberIdentifier otherId && otherId.PhoneNumber == PhoneNumber && (Id is null || otherId.Id is null || Id == otherId.Id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<Compile Include="..\..\Shared\src\CommunicationIdentifierKind.cs" Link="Shared\Communication\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="..\..\Shared\src\CommunicationIdentifierModel.cs" Link="Shared\Communication\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="..\..\Shared\src\CommunicationIdentifierSerializer.cs" Link="Shared\Communication\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="..\..\Shared\src\CommunicationCloudEnvironmentModel.cs" Link="Shared\Communication\%(RecursiveDir)\%(Filename)%(Extension)" />
<ProjectReference Include="$(AzureCoreTestFramework)" />
<ProjectReference Include="..\src\Azure.Communication.Common.csproj" />
</ItemGroup>
Expand Down
Loading

0 comments on commit 231fb45

Please sign in to comment.