microsoft/teams.net
Publicmirrored from https://github.com/microsoft/teams.netAvailable
core/src/Microsoft.Teams.Apps/Schema/Entities/CitationEntity.cs
329lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | using System.Diagnostics.CodeAnalysis; |
| 5 | using System.Text.Json.Serialization; |
| 6 | |
| 7 | namespace Microsoft.Teams.Apps.Schema.Entities; |
| 8 | |
| 9 | /// <summary> |
| 10 | /// Citation entity representing a message with citation claims. |
| 11 | /// </summary> |
| 12 | public class CitationEntity : OMessageEntity |
| 13 | { |
| 14 | /// <summary> |
| 15 | /// Creates a new instance of <see cref="CitationEntity"/>. |
| 16 | /// </summary> |
| 17 | public CitationEntity() : base() |
| 18 | { |
| 19 | } |
| 20 | |
| 21 | /// <summary> |
| 22 | /// Creates a new instance of <see cref="CitationEntity"/> by copying data from an existing message entity. |
| 23 | /// </summary> |
| 24 | /// <param name="entity">The message entity to copy from. Cannot be null.</param> |
| 25 | public CitationEntity(OMessageEntity entity) : base() |
| 26 | { |
| 27 | ArgumentNullException.ThrowIfNull(entity); |
| 28 | OType = entity.OType; |
| 29 | OContext = entity.OContext; |
| 30 | Type = entity.Type; |
| 31 | Properties = new Core.Schema.ExtendedPropertiesDictionary(entity.Properties); |
| 32 | AdditionalType = entity.AdditionalType != null |
| 33 | ? new List<string>(entity.AdditionalType) |
| 34 | : null; |
| 35 | if (entity is CitationEntity citationEntity) |
| 36 | { |
| 37 | Citation = citationEntity.Citation != null |
| 38 | ? citationEntity.Citation.Select(c => new CitationClaim(c)).ToList() |
| 39 | : null; |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | /// <summary> |
| 44 | /// Gets or sets the list of citation claims. |
| 45 | /// </summary> |
| 46 | [JsonPropertyName("citation")] |
| 47 | public IList<CitationClaim>? Citation |
| 48 | { |
| 49 | get => base.Properties.Get<IList<CitationClaim>>("citation"); |
| 50 | set => base.Properties["citation"] = value; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | /// <summary> |
| 55 | /// Represents a citation claim with a position and appearance document. |
| 56 | /// </summary> |
| 57 | public class CitationClaim |
| 58 | { |
| 59 | /// <summary>Initializes a new instance of <see cref="CitationClaim"/>.</summary> |
| 60 | public CitationClaim() { } |
| 61 | |
| 62 | /// <summary>Creates a deep copy of <paramref name="other"/>.</summary> |
| 63 | [SetsRequiredMembers] |
| 64 | public CitationClaim(CitationClaim other) |
| 65 | { |
| 66 | ArgumentNullException.ThrowIfNull(other); |
| 67 | Type = other.Type; |
| 68 | Position = other.Position; |
| 69 | Appearance = new CitationAppearanceDocument(other.Appearance); |
| 70 | } |
| 71 | |
| 72 | /// <summary> |
| 73 | /// Gets or sets the schema.org type. Always "Claim". |
| 74 | /// </summary> |
| 75 | [JsonPropertyName("@type")] |
| 76 | public string Type { get; set; } = "Claim"; |
| 77 | |
| 78 | /// <summary> |
| 79 | /// Gets or sets the position of the citation in the message text. |
| 80 | /// </summary> |
| 81 | [JsonPropertyName("position")] |
| 82 | public required int Position { get; set; } |
| 83 | |
| 84 | /// <summary> |
| 85 | /// Gets or sets the appearance document describing the cited source. |
| 86 | /// </summary> |
| 87 | [JsonPropertyName("appearance")] |
| 88 | public required CitationAppearanceDocument Appearance { get; set; } |
| 89 | } |
| 90 | |
| 91 | /// <summary> |
| 92 | /// Represents the appearance of a cited document. |
| 93 | /// </summary> |
| 94 | public class CitationAppearanceDocument |
| 95 | { |
| 96 | /// <summary>Initializes a new instance of <see cref="CitationAppearanceDocument"/>.</summary> |
| 97 | public CitationAppearanceDocument() { } |
| 98 | |
| 99 | /// <summary>Creates a deep copy of <paramref name="other"/>.</summary> |
| 100 | [SetsRequiredMembers] |
| 101 | public CitationAppearanceDocument(CitationAppearanceDocument other) |
| 102 | { |
| 103 | ArgumentNullException.ThrowIfNull(other); |
| 104 | Type = other.Type; |
| 105 | Name = other.Name; |
| 106 | Text = other.Text; |
| 107 | Url = other.Url; |
| 108 | Abstract = other.Abstract; |
| 109 | EncodingFormat = other.EncodingFormat; |
| 110 | Image = other.Image is null ? null : new CitationImageObject { Type = other.Image.Type, Name = other.Image.Name }; |
| 111 | Keywords = other.Keywords != null ? new List<string>(other.Keywords) : null; |
| 112 | UsageInfo = other.UsageInfo; |
| 113 | } |
| 114 | |
| 115 | /// <summary> |
| 116 | /// Gets or sets the schema.org type. Always "DigitalDocument". |
| 117 | /// </summary> |
| 118 | [JsonPropertyName("@type")] |
| 119 | public string Type { get; set; } = "DigitalDocument"; |
| 120 | |
| 121 | /// <summary> |
| 122 | /// Gets or sets the name of the document (max length 80). |
| 123 | /// </summary> |
| 124 | [JsonPropertyName("name")] |
| 125 | public required string Name { get; set; } |
| 126 | |
| 127 | /// <summary> |
| 128 | /// Gets or sets a stringified adaptive card with additional information about the citation. |
| 129 | /// </summary> |
| 130 | [JsonPropertyName("text")] |
| 131 | public string? Text { get; set; } |
| 132 | |
| 133 | /// <summary> |
| 134 | /// Gets or sets the URL of the document. |
| 135 | /// </summary> |
| 136 | [JsonPropertyName("url")] |
| 137 | public Uri? Url { get; set; } |
| 138 | |
| 139 | /// <summary> |
| 140 | /// Gets or sets the extract of the referenced content (max length 160). |
| 141 | /// </summary> |
| 142 | [JsonPropertyName("abstract")] |
| 143 | public required string Abstract { get; set; } |
| 144 | |
| 145 | /// <summary> |
| 146 | /// Gets or sets the encoding format of the text. See <see cref="EncodingFormats"/> for known values. |
| 147 | /// </summary> |
| 148 | [JsonPropertyName("encodingFormat")] |
| 149 | public string? EncodingFormat { get; set; } |
| 150 | |
| 151 | /// <summary> |
| 152 | /// Gets or sets the citation icon information. |
| 153 | /// </summary> |
| 154 | [JsonPropertyName("image")] |
| 155 | public CitationImageObject? Image { get; set; } |
| 156 | |
| 157 | /// <summary> |
| 158 | /// Gets or sets the keywords (max length 3, max keyword length 28). |
| 159 | /// </summary> |
| 160 | [JsonPropertyName("keywords")] |
| 161 | public IList<string>? Keywords { get; set; } |
| 162 | |
| 163 | /// <summary> |
| 164 | /// Gets or sets the sensitivity usage information for the citation. |
| 165 | /// </summary> |
| 166 | [JsonPropertyName("usageInfo")] |
| 167 | public SensitiveUsageEntity? UsageInfo { get; set; } |
| 168 | } |
| 169 | |
| 170 | /// <summary> |
| 171 | /// Represents an image object used for citation icons. |
| 172 | /// </summary> |
| 173 | public class CitationImageObject |
| 174 | { |
| 175 | /// <summary> |
| 176 | /// Gets or sets the schema.org type. Always "ImageObject". |
| 177 | /// </summary> |
| 178 | [JsonPropertyName("@type")] |
| 179 | public string Type { get; set; } = "ImageObject"; |
| 180 | |
| 181 | /// <summary> |
| 182 | /// Gets or sets the icon name. See <see cref="CitationIcon"/> for known values. |
| 183 | /// </summary> |
| 184 | [JsonPropertyName("name")] |
| 185 | public required string Name { get; set; } |
| 186 | } |
| 187 | |
| 188 | /// <summary> |
| 189 | /// Known citation icon names. |
| 190 | /// </summary> |
| 191 | public static class CitationIcon |
| 192 | { |
| 193 | /// <summary>Microsoft Word icon.</summary> |
| 194 | public const string MicrosoftWord = "Microsoft Word"; |
| 195 | |
| 196 | /// <summary>Microsoft Excel icon.</summary> |
| 197 | public const string MicrosoftExcel = "Microsoft Excel"; |
| 198 | |
| 199 | /// <summary>Microsoft PowerPoint icon.</summary> |
| 200 | public const string MicrosoftPowerPoint = "Microsoft PowerPoint"; |
| 201 | |
| 202 | /// <summary>Microsoft OneNote icon.</summary> |
| 203 | public const string MicrosoftOneNote = "Microsoft OneNote"; |
| 204 | |
| 205 | /// <summary>Microsoft SharePoint icon.</summary> |
| 206 | public const string MicrosoftSharePoint = "Microsoft SharePoint"; |
| 207 | |
| 208 | /// <summary>Microsoft Visio icon.</summary> |
| 209 | public const string MicrosoftVisio = "Microsoft Visio"; |
| 210 | |
| 211 | /// <summary>Microsoft Loop icon.</summary> |
| 212 | public const string MicrosoftLoop = "Microsoft Loop"; |
| 213 | |
| 214 | /// <summary>Microsoft Whiteboard icon.</summary> |
| 215 | public const string MicrosoftWhiteboard = "Microsoft Whiteboard"; |
| 216 | |
| 217 | /// <summary>Adobe Illustrator icon.</summary> |
| 218 | public const string AdobeIllustrator = "Adobe Illustrator"; |
| 219 | |
| 220 | /// <summary>Adobe Photoshop icon.</summary> |
| 221 | public const string AdobePhotoshop = "Adobe Photoshop"; |
| 222 | |
| 223 | /// <summary>Adobe InDesign icon.</summary> |
| 224 | public const string AdobeInDesign = "Adobe InDesign"; |
| 225 | |
| 226 | /// <summary>Adobe Flash icon.</summary> |
| 227 | public const string AdobeFlash = "Adobe Flash"; |
| 228 | |
| 229 | /// <summary>Sketch icon.</summary> |
| 230 | public const string Sketch = "Sketch"; |
| 231 | |
| 232 | /// <summary>Source code icon.</summary> |
| 233 | public const string SourceCode = "Source Code"; |
| 234 | |
| 235 | /// <summary>Image icon.</summary> |
| 236 | public const string Image = "Image"; |
| 237 | |
| 238 | /// <summary>GIF icon.</summary> |
| 239 | public const string Gif = "GIF"; |
| 240 | |
| 241 | /// <summary>Video icon.</summary> |
| 242 | public const string Video = "Video"; |
| 243 | |
| 244 | /// <summary>Sound icon.</summary> |
| 245 | public const string Sound = "Sound"; |
| 246 | |
| 247 | /// <summary>ZIP icon.</summary> |
| 248 | public const string Zip = "ZIP"; |
| 249 | |
| 250 | /// <summary>Text icon.</summary> |
| 251 | public const string Text = "Text"; |
| 252 | |
| 253 | /// <summary>PDF icon.</summary> |
| 254 | public const string Pdf = "PDF"; |
| 255 | } |
| 256 | |
| 257 | /// <summary> |
| 258 | /// Known encoding format MIME types for citation documents. |
| 259 | /// </summary> |
| 260 | public static class EncodingFormats |
| 261 | { |
| 262 | /// <summary>Adaptive card encoding format.</summary> |
| 263 | public const string AdaptiveCard = "application/vnd.microsoft.card.adaptive"; |
| 264 | } |
| 265 | |
| 266 | /// <summary> |
| 267 | /// Helper class for building citation appearance documents. |
| 268 | /// </summary> |
| 269 | public class CitationAppearance |
| 270 | { |
| 271 | /// <summary> |
| 272 | /// Gets or sets the name of the document (max length 80). |
| 273 | /// </summary> |
| 274 | public required string Name { get; set; } |
| 275 | |
| 276 | /// <summary> |
| 277 | /// Gets or sets a stringified adaptive card with additional information. |
| 278 | /// </summary> |
| 279 | public string? Text { get; set; } |
| 280 | |
| 281 | /// <summary> |
| 282 | /// Gets or sets the URL of the document. |
| 283 | /// </summary> |
| 284 | public Uri? Url { get; set; } |
| 285 | |
| 286 | /// <summary> |
| 287 | /// Gets or sets the extract of the referenced content (max length 160). |
| 288 | /// </summary> |
| 289 | public required string Abstract { get; set; } |
| 290 | |
| 291 | /// <summary> |
| 292 | /// Gets or sets the encoding format of the text. See <see cref="EncodingFormats"/> for known values. |
| 293 | /// </summary> |
| 294 | public string? EncodingFormat { get; set; } |
| 295 | |
| 296 | /// <summary> |
| 297 | /// Gets or sets the citation icon name. See <see cref="CitationIcon"/> for known values. |
| 298 | /// </summary> |
| 299 | public string? Icon { get; set; } |
| 300 | |
| 301 | /// <summary> |
| 302 | /// Gets or sets the keywords (max length 3, max keyword length 28). |
| 303 | /// </summary> |
| 304 | public IList<string>? Keywords { get; set; } |
| 305 | |
| 306 | /// <summary> |
| 307 | /// Gets or sets the sensitivity usage information. |
| 308 | /// </summary> |
| 309 | public SensitiveUsageEntity? UsageInfo { get; set; } |
| 310 | |
| 311 | /// <summary> |
| 312 | /// Converts this appearance to a <see cref="CitationAppearanceDocument"/>. |
| 313 | /// </summary> |
| 314 | /// <returns>The appearance document.</returns> |
| 315 | public CitationAppearanceDocument ToDocument() |
| 316 | { |
| 317 | return new() |
| 318 | { |
| 319 | Name = Name, |
| 320 | Text = Text, |
| 321 | Url = Url, |
| 322 | Abstract = Abstract, |
| 323 | EncodingFormat = EncodingFormat, |
| 324 | Image = Icon is null ? null : new CitationImageObject() { Name = Icon }, |
| 325 | Keywords = Keywords, |
| 326 | UsageInfo = UsageInfo |
| 327 | }; |
| 328 | } |
| 329 | } |
| 330 | |