Skip to content

Commit 231fb45

Browse files
[Communication] - Identifier serialization new schema (Azure#18120)
* Identity Derialization Requires Id * Add cloud environment to MicrosoftTeamsIdentifier * Update description Co-authored-by: Dominik <domessin@microsoft.com>
1 parent 8468943 commit 231fb45

10 files changed

+275
-45
lines changed

sdk/communication/Azure.Communication.Common/api/Azure.Communication.Common.netstandard2.0.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,25 @@ public CallingApplicationIdentifier(string id) { }
88
public override int GetHashCode() { throw null; }
99
public override string ToString() { throw null; }
1010
}
11+
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
12+
public readonly partial struct CommunicationCloudEnvironment : System.IEquatable<Azure.Communication.CommunicationCloudEnvironment>
13+
{
14+
private readonly object _dummy;
15+
private readonly int _dummyPrimitive;
16+
public CommunicationCloudEnvironment(string value) { throw null; }
17+
public static Azure.Communication.CommunicationCloudEnvironment Dod { get { throw null; } }
18+
public static Azure.Communication.CommunicationCloudEnvironment Gcch { get { throw null; } }
19+
public static Azure.Communication.CommunicationCloudEnvironment Public { get { throw null; } }
20+
public bool Equals(Azure.Communication.CommunicationCloudEnvironment other) { throw null; }
21+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
22+
public override bool Equals(object obj) { throw null; }
23+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
24+
public override int GetHashCode() { throw null; }
25+
public static bool operator ==(Azure.Communication.CommunicationCloudEnvironment left, Azure.Communication.CommunicationCloudEnvironment right) { throw null; }
26+
public static implicit operator Azure.Communication.CommunicationCloudEnvironment (string value) { throw null; }
27+
public static bool operator !=(Azure.Communication.CommunicationCloudEnvironment left, Azure.Communication.CommunicationCloudEnvironment right) { throw null; }
28+
public override string ToString() { throw null; }
29+
}
1130
public abstract partial class CommunicationIdentifier : System.IEquatable<Azure.Communication.CommunicationIdentifier>
1231
{
1332
protected CommunicationIdentifier() { }
@@ -37,7 +56,9 @@ public CommunicationUserIdentifier(string id) { }
3756
}
3857
public partial class MicrosoftTeamsUserIdentifier : Azure.Communication.CommunicationIdentifier
3958
{
40-
public MicrosoftTeamsUserIdentifier(string userId, bool isAnonymous = false) { }
59+
public MicrosoftTeamsUserIdentifier(string userId, bool isAnonymous = false, string? id = null, Azure.Communication.CommunicationCloudEnvironment? cloud = default(Azure.Communication.CommunicationCloudEnvironment?)) { }
60+
public Azure.Communication.CommunicationCloudEnvironment Cloud { get { throw null; } }
61+
public string? Id { get { throw null; } }
4162
public bool IsAnonymous { get { throw null; } }
4263
public string UserId { get { throw null; } }
4364
public override bool Equals(Azure.Communication.CommunicationIdentifier other) { throw null; }
@@ -46,7 +67,8 @@ public MicrosoftTeamsUserIdentifier(string userId, bool isAnonymous = false) { }
4667
}
4768
public partial class PhoneNumberIdentifier : Azure.Communication.CommunicationIdentifier
4869
{
49-
public PhoneNumberIdentifier(string phoneNumber) { }
70+
public PhoneNumberIdentifier(string phoneNumber, string? id = null) { }
71+
public string? Id { get { throw null; } }
5072
public string PhoneNumber { get { throw null; } }
5173
public override bool Equals(Azure.Communication.CommunicationIdentifier other) { throw null; }
5274
public override int GetHashCode() { throw null; }
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using System.ComponentModel;
6+
7+
namespace Azure.Communication
8+
{
9+
/// <summary> The cloud that the identifier belongs to. </summary>
10+
public readonly partial struct CommunicationCloudEnvironment : IEquatable<CommunicationCloudEnvironment>
11+
{
12+
private readonly string _value;
13+
14+
/// <summary> Determines if two <see cref="CommunicationCloudEnvironment"/> values are the same. </summary>
15+
/// <exception cref="ArgumentNullException"> <paramref name="value"/> is null. </exception>
16+
public CommunicationCloudEnvironment(string value)
17+
=> _value = value ?? throw new ArgumentNullException(nameof(value));
18+
19+
private const string PublicValue = "public";
20+
private const string DodValue = "dod";
21+
private const string GcchValue = "gcch";
22+
23+
/// <summary> public. </summary>
24+
public static CommunicationCloudEnvironment Public { get; } = new CommunicationCloudEnvironment(PublicValue);
25+
/// <summary> dod. </summary>
26+
public static CommunicationCloudEnvironment Dod { get; } = new CommunicationCloudEnvironment(DodValue);
27+
/// <summary> gcch. </summary>
28+
public static CommunicationCloudEnvironment Gcch { get; } = new CommunicationCloudEnvironment(GcchValue);
29+
/// <summary> Determines if two <see cref="CommunicationCloudEnvironment"/> values are the same. </summary>
30+
public static bool operator ==(CommunicationCloudEnvironment left, CommunicationCloudEnvironment right) => left.Equals(right);
31+
/// <summary> Determines if two <see cref="CommunicationCloudEnvironment"/> values are not the same. </summary>
32+
public static bool operator !=(CommunicationCloudEnvironment left, CommunicationCloudEnvironment right) => !left.Equals(right);
33+
/// <summary> Converts a string to a <see cref="CommunicationCloudEnvironment"/>. </summary>
34+
public static implicit operator CommunicationCloudEnvironment(string value) => new CommunicationCloudEnvironment(value);
35+
36+
/// <inheritdoc />
37+
[EditorBrowsable(EditorBrowsableState.Never)]
38+
public override bool Equals(object obj) => obj is CommunicationCloudEnvironment other && Equals(other);
39+
/// <inheritdoc />
40+
public bool Equals(CommunicationCloudEnvironment other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase);
41+
42+
/// <inheritdoc />
43+
[EditorBrowsable(EditorBrowsableState.Never)]
44+
public override int GetHashCode() => _value?.GetHashCode() ?? 0;
45+
/// <inheritdoc />
46+
public override string ToString() => _value;
47+
}
48+
}

sdk/communication/Azure.Communication.Common/src/MicrosoftTeamsUserIdentifier.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,38 @@ namespace Azure.Communication
88
/// <summary>Represents a Microsoft Teams user.</summary>
99
public class MicrosoftTeamsUserIdentifier : CommunicationIdentifier
1010
{
11+
/// <summary>The full id of the Microsoft Teams User identifier.</summary>
12+
public string? Id { get; }
13+
1114
/// <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>
1215
public string UserId { get; }
1316

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

20+
/// <summary> The cloud that the identifier belongs to. </summary>
21+
public CommunicationCloudEnvironment Cloud { get; }
22+
1723
/// <summary>
1824
/// Initializes a new instance of <see cref="MicrosoftTeamsUserIdentifier"/>.
1925
/// </summary>
2026
/// <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>
2127
/// <param name="isAnonymous">Set this to true if the user is anonymous, for example when joining a meeting with a share link.</param>
28+
/// <param name="id">Full id of the Microsoft Teams user, optional.</param>
29+
/// <param name="cloud">The cloud that the Microsoft Team user belongs to. A null value translates to the Public cloud.</param>
2230
/// <exception cref="System.ArgumentNullException">
2331
/// Thrown when the <paramref name="userId"/> is null.
2432
/// </exception>
2533
/// <exception cref="System.ArgumentException">
2634
/// Thrown when the <paramref name="userId"/> is empty.
2735
/// </exception>
28-
public MicrosoftTeamsUserIdentifier(string userId, bool isAnonymous = false)
36+
public MicrosoftTeamsUserIdentifier(string userId, bool isAnonymous = false, string? id = null, CommunicationCloudEnvironment? cloud = null)
2937
{
3038
Argument.AssertNotNullOrEmpty(userId, nameof(userId));
3139
UserId = userId;
3240
IsAnonymous = isAnonymous;
41+
Cloud = cloud ?? CommunicationCloudEnvironment.Public;
42+
Id = id;
3343
}
3444

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

4151
/// <inheritdoc />
4252
public override bool Equals(CommunicationIdentifier other)
43-
=> other is MicrosoftTeamsUserIdentifier otherId && otherId.UserId == UserId && otherId.IsAnonymous == IsAnonymous;
53+
=> other is MicrosoftTeamsUserIdentifier otherId
54+
&& otherId.UserId == UserId
55+
&& otherId.IsAnonymous == IsAnonymous
56+
&& otherId.Cloud == Cloud
57+
&& (Id is null || otherId.Id is null || Id == otherId.Id);
4458
}
4559
}

sdk/communication/Azure.Communication.Common/src/PhoneNumberIdentifier.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,26 @@ namespace Azure.Communication
99
/// <summary>Represents a Phone Number.</summary>
1010
public class PhoneNumberIdentifier : CommunicationIdentifier
1111
{
12+
/// <summary>The full id of the phone number.</summary>
13+
public string? Id { get; }
14+
1215
/// <summary>The phone number in E.164 format.</summary>
1316
public string PhoneNumber { get; }
1417

1518
/// <summary> Initializes a new instance of <see cref="PhoneNumberIdentifier"/>.</summary>
1619
/// <param name="phoneNumber">The phone number in E.164 format.</param>
20+
/// <param name="id">Full id of the phone number.</param>
1721
/// <exception cref="System.ArgumentNullException">
1822
/// Thrown when the <paramref name="phoneNumber"/> is null.
1923
/// </exception>
2024
/// <exception cref="System.ArgumentException">
2125
/// Thrown when the <paramref name="phoneNumber"/> is empty.
2226
/// </exception>
23-
public PhoneNumberIdentifier(string phoneNumber)
27+
public PhoneNumberIdentifier(string phoneNumber, string? id = null)
2428
{
2529
Argument.AssertNotNullOrEmpty(phoneNumber, nameof(phoneNumber));
2630
PhoneNumber = phoneNumber;
31+
Id = id;
2732
}
2833

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

3540
/// <inheritdoc />
3641
public override bool Equals(CommunicationIdentifier other)
37-
=> other is PhoneNumberIdentifier otherId && otherId.PhoneNumber == PhoneNumber;
42+
=> other is PhoneNumberIdentifier otherId && otherId.PhoneNumber == PhoneNumber && (Id is null || otherId.Id is null || Id == otherId.Id);
3843
}
3944
}

sdk/communication/Azure.Communication.Common/tests/Azure.Communication.Common.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<Compile Include="..\..\Shared\src\CommunicationIdentifierKind.cs" Link="Shared\Communication\%(RecursiveDir)\%(Filename)%(Extension)" />
1818
<Compile Include="..\..\Shared\src\CommunicationIdentifierModel.cs" Link="Shared\Communication\%(RecursiveDir)\%(Filename)%(Extension)" />
1919
<Compile Include="..\..\Shared\src\CommunicationIdentifierSerializer.cs" Link="Shared\Communication\%(RecursiveDir)\%(Filename)%(Extension)" />
20+
<Compile Include="..\..\Shared\src\CommunicationCloudEnvironmentModel.cs" Link="Shared\Communication\%(RecursiveDir)\%(Filename)%(Extension)" />
2021
<ProjectReference Include="$(AzureCoreTestFramework)" />
2122
<ProjectReference Include="..\src\Azure.Communication.Common.csproj" />
2223
</ItemGroup>

0 commit comments

Comments
 (0)