-
Notifications
You must be signed in to change notification settings - Fork 14
AddEventListener support for IDesktopAgent and IPrivateChannel #170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2675229
AddEventListener support for IDesktopAgent and IPrivateChannel
bingenito 3e40f0f
Update src/Fdc3/Fdc3Event.cs
bingenito cf2fc10
Change event type string literals to be camel cased and match fdc3 np…
bingenito 8215464
Merge branch 'AddEventListener' of https://github.com/bingenito/fdc3-…
bingenito 4228190
Merge branch 'main' into AddEventListener
bingenito File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,124 @@ | ||
| /* | ||
| * Morgan Stanley makes this available to you under the Apache License, | ||
| * Version 2.0 (the "License"). You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0. | ||
| * | ||
| * See the NOTICE file distributed with this work for additional information | ||
| * regarding copyright ownership. Unless required by applicable law or agreed | ||
| * to in writing, software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
| * or implied. See the License for the specific language governing permissions | ||
| * and limitations under the License. | ||
| */ | ||
|
|
||
| using System; | ||
|
|
||
| namespace Finos.Fdc3 | ||
| { | ||
| /// <summary> | ||
| /// Interface representing the format of event objects that may be received via the FDC3 API's AddEventListener function. | ||
| /// </summary> | ||
| public interface IFdc3Event | ||
| { | ||
| public string Type { get; } | ||
| public object? Details { get; } | ||
| } | ||
|
|
||
| public delegate void Fdc3EventHandler(IFdc3Event fdc3Event); | ||
|
|
||
| /// <summary> | ||
| /// Type representing the format of event objects that may be received via the FDC3 API's addEventListener function | ||
| /// </summary> | ||
| public class Fdc3Event : IFdc3Event | ||
| { | ||
| public string Type { get; } | ||
| public object? Details { get; } | ||
|
|
||
| public Fdc3Event(string type, object? details = null) | ||
| { | ||
| this.Type = type ?? throw new ArgumentNullException(nameof(type)); | ||
| this.Details = details; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Valid type strings for DesktopAgent interface events. | ||
| /// </summary> | ||
| public static class Fdc3EventType | ||
| { | ||
| public const string UserChannelChanged = "userChannelChanged"; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Valid type strings for Private Channel events. | ||
| /// </summary> | ||
| public static class Fdc3PrivateChannelEventType | ||
| { | ||
| public const string AddContextListener = "addContextListener"; | ||
| public const string Unsubscribe = "unsubscribe"; | ||
| public const string Disconnect = "disconnect"; | ||
| } | ||
|
|
||
| public interface IFdc3ChannelChangedEventDetails | ||
| { | ||
| string? CurrentChannelId { get; } | ||
| } | ||
|
|
||
| public class Fdc3ChannelChangedEventDetails : IFdc3ChannelChangedEventDetails | ||
| { | ||
| public string? CurrentChannelId { get; } | ||
|
|
||
| public Fdc3ChannelChangedEventDetails(string? channelId) | ||
| { | ||
| this.CurrentChannelId = channelId; | ||
| } | ||
| } | ||
|
|
||
| public class Fdc3ChannelChangedEvent : Fdc3Event | ||
| { | ||
| public Fdc3ChannelChangedEvent(string? channelId) | ||
| : base(Fdc3EventType.UserChannelChanged, new Fdc3ChannelChangedEventDetails(channelId)) | ||
| { | ||
| } | ||
| } | ||
|
|
||
| public interface IFdc3PrivateChannelEventDetails | ||
| { | ||
| string? ContextType { get; } | ||
| } | ||
|
|
||
| public class Fdc3PrivateChannelEventDetails : IFdc3PrivateChannelEventDetails | ||
| { | ||
| public string? ContextType { get; } | ||
|
|
||
| public Fdc3PrivateChannelEventDetails(string? contextType) | ||
| { | ||
| this.ContextType = contextType; | ||
| } | ||
| } | ||
|
|
||
| public class Fdc3PrivateChannelAddContextListenerEvent : Fdc3Event | ||
| { | ||
| public Fdc3PrivateChannelAddContextListenerEvent(string? contextType) | ||
| : base(Fdc3PrivateChannelEventType.AddContextListener, new Fdc3PrivateChannelEventDetails(contextType)) | ||
| { | ||
| } | ||
| } | ||
|
|
||
| public class Fdc3PrivateChannelUnsubscribeListenerEvent : Fdc3Event | ||
| { | ||
| public Fdc3PrivateChannelUnsubscribeListenerEvent(string? contextType) | ||
| : base(Fdc3PrivateChannelEventType.Unsubscribe, new Fdc3PrivateChannelEventDetails(contextType)) | ||
| { | ||
| } | ||
| } | ||
|
|
||
| public class Fdc3PrivateChanneDisconnectEvent : Fdc3Event | ||
| { | ||
| public Fdc3PrivateChanneDisconnectEvent() | ||
| : base(Fdc3PrivateChannelEventType.Disconnect) | ||
| { | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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,92 @@ | ||
| /* | ||
| * Morgan Stanley makes this available to you under the Apache License, | ||
| * Version 2.0 (the "License"). You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0. | ||
| * | ||
| * See the NOTICE file distributed with this work for additional information | ||
| * regarding copyright ownership. Unless required by applicable law or agreed | ||
| * to in writing, software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
| * or implied. See the License for the specific language governing permissions | ||
| * and limitations under the License. | ||
| */ | ||
|
|
||
| namespace Finos.Fdc3.Tests; | ||
|
|
||
| public class Fdc3EventTests | ||
| { | ||
| [Fact] | ||
| public void Fdc3Event_PropertiesMatchParams() | ||
| { | ||
| IFdc3Event fdc3Event = new Fdc3Event("type", new Fdc3ChannelChangedEventDetails("channelid")); | ||
| Assert.Same("type", fdc3Event.Type); | ||
| Assert.IsType<Fdc3ChannelChangedEventDetails>(fdc3Event.Details); | ||
| Assert.Same("channelid", ((Fdc3ChannelChangedEventDetails)fdc3Event.Details).CurrentChannelId); | ||
|
|
||
| fdc3Event = new Fdc3Event("type", null); | ||
| Assert.Null(fdc3Event.Details); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Fdc3ChannelChangedEventDetails_PropertiesMatchParams() | ||
| { | ||
| IFdc3ChannelChangedEventDetails details = new Fdc3ChannelChangedEventDetails("channelid"); | ||
| Assert.Same("channelid", details.CurrentChannelId); | ||
|
|
||
| details = new Fdc3ChannelChangedEventDetails(null); | ||
| Assert.Null(details.CurrentChannelId); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Fdc3ChannelChangedEvent_PropertiesMatchParams() | ||
| { | ||
| IFdc3Event fdc3Event = new Fdc3ChannelChangedEvent("channelid"); | ||
| Assert.Same(Fdc3EventType.UserChannelChanged, fdc3Event.Type); | ||
| Assert.IsType<Fdc3ChannelChangedEventDetails>(fdc3Event.Details); | ||
| Assert.Same("channelid", ((Fdc3ChannelChangedEventDetails)fdc3Event.Details).CurrentChannelId); | ||
|
|
||
| fdc3Event = new Fdc3ChannelChangedEvent(null); | ||
| Fdc3ChannelChangedEventDetails? details = fdc3Event.Details as Fdc3ChannelChangedEventDetails; | ||
| Assert.Null(details?.CurrentChannelId); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Fdc3PrivateChannelEventDetails_PropertiesMatchParams() | ||
| { | ||
| IFdc3PrivateChannelEventDetails details = new Fdc3PrivateChannelEventDetails("contexttype"); | ||
| Assert.Same("contexttype", details.ContextType); | ||
|
|
||
| details = new Fdc3PrivateChannelEventDetails(null); | ||
| Assert.Null(details.ContextType); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Fdc3PrivateChannelAddContextListenerEvent_PropertiesMatchParams() | ||
| { | ||
| IFdc3Event fdc3Event = new Fdc3PrivateChannelAddContextListenerEvent("contextType"); | ||
| Assert.Same(Fdc3PrivateChannelEventType.AddContextListener, fdc3Event.Type); | ||
|
|
||
| IFdc3PrivateChannelEventDetails? details = fdc3Event.Details as IFdc3PrivateChannelEventDetails; | ||
| Assert.Same("contextType", details?.ContextType); | ||
|
|
||
| } | ||
|
|
||
| [Fact] | ||
| public void Fdc3PrivateChannelUnsubscribeListenerEvent_PropertiesMatchParams() | ||
| { | ||
| IFdc3Event fdc3Event = new Fdc3PrivateChannelUnsubscribeListenerEvent("contextType"); | ||
| Assert.Same(Fdc3PrivateChannelEventType.Unsubscribe, fdc3Event.Type); | ||
|
|
||
| IFdc3PrivateChannelEventDetails? details = fdc3Event.Details as IFdc3PrivateChannelEventDetails; | ||
| Assert.Same("contextType", details?.ContextType); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Fdc3PrivateChanneDisconnectEvent_PropertiesMatchParams() | ||
| { | ||
| IFdc3Event fdc3Event = new Fdc3PrivateChanneDisconnectEvent(); | ||
| Assert.Same(Fdc3PrivateChannelEventType.Disconnect, fdc3Event.Type); | ||
| Assert.Null(fdc3Event.Details); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.