-
Notifications
You must be signed in to change notification settings - Fork 484
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix class model, update reference. unit test. unit tests pass, manual…
… tests pass
- Loading branch information
Ying Du
committed
Jan 21, 2023
1 parent
9d9997b
commit 2779c8c
Showing
19 changed files
with
340 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
libraries/Microsoft.Bot.Schema/Converters/SurfaceConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using Microsoft.Bot.Schema.Teams; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace Microsoft.Bot.Schema.Converters | ||
{ | ||
/// <summary> | ||
/// Converter which allows json to be expression to object or static object. | ||
/// </summary> | ||
public class SurfaceConverter : JsonConverter | ||
{ | ||
/// <summary> | ||
/// Gets a value indicating whether this Converter can write JSON. | ||
/// </summary> | ||
/// <value>true if this Converter can write JSON; otherwise, false.</value> | ||
public override bool CanWrite => false; | ||
|
||
/// <summary> | ||
/// Gets a value indicating whether this Converter can read JSON. | ||
/// </summary> | ||
/// <value>true if this Converter can read JSON; otherwise, false.</value> | ||
public override bool CanRead => true; | ||
|
||
/// <summary> | ||
/// Determines whether this instance can convert the specified object type. | ||
/// </summary> | ||
/// <param name="objectType">Type of the object.</param> | ||
/// <returns> | ||
/// <c>true</c> if this instance can convert the specified object type; otherwise, <c>false</c>. | ||
/// </returns> | ||
public override bool CanConvert(Type objectType) | ||
{ | ||
return objectType == typeof(Surface); | ||
} | ||
|
||
/// <summary> | ||
/// Reads the JSON representation of the object. | ||
/// </summary> | ||
/// <param name="reader">The <see cref="JsonReader"/> to read from.</param> | ||
/// <param name="objectType">Type of the object.</param> | ||
/// <param name="existingValue">The existing value of object being read.</param> | ||
/// <param name="serializer">The calling serializer.</param> | ||
/// <returns>The object value.</returns> | ||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) | ||
{ | ||
var jsonObject = JObject.Load(reader); | ||
var surfaceType = jsonObject["surface"]?.ToObject<SurfaceType>(); | ||
|
||
Surface parsedSurface; | ||
switch (surfaceType) | ||
{ | ||
case SurfaceType.MeetingStage: | ||
var contentType = jsonObject["contentType"]?.ToObject<ContentType>(); | ||
parsedSurface = CreateMeetingStageSurfaceWithContentType(contentType); | ||
break; | ||
default: | ||
throw new ArgumentException($"Invalid surface type: {surfaceType}"); | ||
} | ||
|
||
serializer.Populate(jsonObject.CreateReader(), parsedSurface); | ||
return parsedSurface; | ||
} | ||
|
||
/// <summary> | ||
/// Writes the JSON representation of the object. | ||
/// </summary> | ||
/// <param name="writer">The Newtonsoft.Json.JsonWriter to write to.</param> | ||
/// <param name="value">The value.</param> | ||
/// <param name="serializer">The calling serializer.</param> | ||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) | ||
{ | ||
throw new NotSupportedException(); | ||
} | ||
|
||
private static Surface CreateMeetingStageSurfaceWithContentType(ContentType? contentType) | ||
{ | ||
switch (contentType) | ||
{ | ||
case ContentType.Task: | ||
return new MeetingStageSurface<TaskModuleContinueResponse>(); | ||
default: | ||
throw new ArgumentException($"Invalid content type: {contentType}"); | ||
} | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
libraries/Microsoft.Bot.Schema/Teams/BotMeetingNotification.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace Microsoft.Bot.Schema.Teams | ||
{ | ||
using Newtonsoft.Json; | ||
|
||
/// <summary> | ||
/// Specifies bot meeting notification including channel data, type and value. | ||
/// </summary> | ||
/// <typeparam name="T">The first generic type parameter.</typeparam>. | ||
public abstract class BotMeetingNotification<T> : BotMeetingNotificationBase | ||
{ | ||
/// <summary> | ||
/// Gets or sets Teams meeting notification information. | ||
/// </summary> | ||
/// <value> | ||
/// Teams meeting notification information. | ||
/// </value> | ||
[JsonProperty(PropertyName = "value")] | ||
public T Value { get; set; } | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
libraries/Microsoft.Bot.Schema/Teams/BotMeetingNotificationBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using Newtonsoft.Json; | ||
|
||
namespace Microsoft.Bot.Schema.Teams | ||
{ | ||
/// <summary> | ||
/// Specifies bot meeting notification base including channel data and type. | ||
/// </summary> | ||
public class BotMeetingNotificationBase | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="BotMeetingNotificationBase"/> class. | ||
/// </summary> | ||
protected BotMeetingNotificationBase() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets Activty type. | ||
/// </summary> | ||
/// <value> | ||
/// Activity type. | ||
/// </value> | ||
[JsonProperty("type")] | ||
public string Type { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets Teams meeting notification channel data. | ||
/// </summary> | ||
/// <value> | ||
/// Teams meeting notification channel data. | ||
/// </value> | ||
[JsonProperty("channelData")] | ||
public BotMeetingNotificationChannelData ChannelData { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace Microsoft.Bot.Schema.Teams | ||
{ | ||
/// <summary> | ||
/// Defines content type type. | ||
/// </summary> | ||
public enum ContentType | ||
{ | ||
/// <summary> | ||
/// Content type is Unknown. | ||
/// </summary> | ||
Unknown, | ||
|
||
/// <summary> | ||
/// Content type is Task. | ||
/// </summary> | ||
Task | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
libraries/Microsoft.Bot.Schema/Teams/MeetingStageSurface.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
namespace Microsoft.Bot.Schema.Teams | ||
{ | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Converters; | ||
|
||
/// <summary> | ||
/// Specifies if a notification is to be sent for the mentions. | ||
/// </summary> | ||
/// <typeparam name="T">The first generic type parameter.</typeparam>. | ||
public partial class MeetingStageSurface<T> : Surface | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="MeetingStageSurface{T}"/> class. | ||
/// </summary> | ||
public MeetingStageSurface() | ||
: base(SurfaceType.MeetingStage) | ||
{ | ||
CustomInit(); | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the content type of this <see cref="MeetingStageSurface{T}"/>. | ||
/// </summary> | ||
/// <value> | ||
/// The content type of this <see cref="MeetingStageSurface{T}"/>. | ||
/// </value> | ||
[JsonConverter(typeof(StringEnumConverter))] | ||
[JsonProperty(PropertyName = "contentType")] | ||
public ContentType ContentType { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the content for this <see cref="MeetingStageSurface{T}"/>. | ||
/// </summary> | ||
/// <value> | ||
/// The content type of this <see cref="MeetingStageSurface{T}"/>. | ||
/// </value> | ||
[JsonProperty(PropertyName = "content")] | ||
public T Content { get; set; } | ||
|
||
/// <summary> | ||
/// An initialization method that performs custom operations like setting defaults. | ||
/// </summary> | ||
partial void CustomInit(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.