Skip to content

Commit

Permalink
feat/event-listeners (#220)
Browse files Browse the repository at this point in the history
* add entity classes

* added entity implementation

* support for `User` and `Channel`-`Metadata` entities

* UWP: added entity class references

* typo in method name

* acceptance tests using new enttities and event listeners

* remove magic strings

* set `EnableEventEngine` and fix relevant issues

* fix vulnerability alert: example code #199

* fix: handling connection failure status with additional information to user

* `EventListener` class for registering event handlers for each type of event

* refactor: Remove `TelemetryManager` from sdk (#224)

* Remove TelemetryManager from the sdk

* Transport layer (#225)

* * Target framework upgrade
* Initial code for HttpClient

* Integration of TransportLayer with all endpoints except File and Subscribe operations

* send and download file apis refactoring

* code cleanup: removed unnecessary usings for threading.channels

* removed support for older netstandartds

* Fix build issues for Unity and UWP projects

* retire old httpWebRequest

* CI Tests Fix (#228)

* temporarily remove one assert from TestSubscribeDecryptionOnNonEncryptedMessage

* re-enable unit tests on branch

* disable stub test

* remove channels argument exception from UrlRequestBuilder

* temporarily disable tests that were causing the CI to hang

* update key-set used by tests

* Fix broken Encryption tests

* Disable global HereNow tests (for now)

* re-enable access manager dependant tests

* Revert "re-enable access manager dependant tests"

This reverts commit dff644b.

* Test increased timeouts in ThenManageMembershipShouldReturnEventInfo

* Revert "Test increased timeouts in ThenManageMembershipShouldReturnEventInfo"

This reverts commit fc129da.

* Fix potentially faulty async calls in EncryptionTests

* Increase verbosity for CI debugging

* test increasing --logger verbosity

* add a NUnit ConsoleTraceListener

* add a simple debug writeline to test logging

* Update .pubnub.yml for .Net version support (#223)

* fix encryption tests PAM issue

* Fix more of file tests

* add missing test teardowns, replace v2 PAM access grants with v3 ones in tests that got a PAM 403

* change to PAM v3 in WhenObjectChannelMetadata

* failing test debug assert

* add temp debug method for PubnubCommon values

* Change PAM v2 to v3 in more tests, more failing test debug

* update .yml test keys ids

* add debug to failing ci test

* debug on file tests

* tests yml sdk keys change

* remove old test debugs

* Remove deprecated build targets

* Fix missing UWP includes

---------

Co-authored-by: Mohit Tejani <[email protected]>

* fix acceptance tests errors

* * fixes issue reported by acceptance tests in AppContextApi.
* Added support for Patch requests in client library

* * added missing includes for UWP (missed in last merge!)
* fix current userId memenership issue for AppContext Api

* * fix: removed references of old http client code,
added request timeout mechanism,
fixes to adhere to existing response generation mechanism by applying request state values as per response

* fix: removeMembership for current user scenario execution

* refactor: moved out enumToUrlParamName conversation utility to build utility directory, moved unnecessary log messages from internet utility method

* fixes issues found in channelGroup, audit, publish, signal operation through unit/integration tests

* files: fix issue of uploading and downloading files due to wrong header information sent through default http client component

* Unit and Integration Tests: increased delay value for Grant response wait.

* * Code cleanup: removed commented code in client library, better error handling in default http client library,
removed code for UrlProcess request from PubNubCore class,
fixed issues with generate file url

* build: update default runner group value with organization

* Add/re-add ConfigureAwait(false) in await calls to prevent Unity-side deadlocks

* Add few more missing ConfigureAwait(false)

* Added Support for Porxy.
Code Cleanup for Pubnub, PubnubCoreBase, PNConfiguration class,
Code Cleanup - removed dead codes in various files and removed old PubnubHttpClient footprints.

* fix: Serialization failure for User publish/signal message at NewtonsoftJsonNet library

* BREAKING CHANGE: Default Reconnection Policy set to `EXPONENTIAL`.
* File upload failure edge cases handling with proper exception messages.
* Refactored Check Internet status execution a bit (many more to come) to fix Unity engine impact.
* Old subscription logic cleanup: removing many state/internetstatus information store

* Unsubscribe operation refactoring: removed unncessary processings

* set default event engine enabled

* removed timer.cs, tuple.cs which was there for older .net versions

* fix: presence tests (passing locally)

* reverted eventengine enabled flag reset for Presence Tests

* update test to have different channel names for presence tests

* presence test fix for 403 permission

* attempt to fix unit/integartion test for subscribe

* fix: Patch work for internet status chekcing execution to make it compatible with single threaded environment.
Disable ee for unit/integration tests

---------

Co-authored-by: PUBNUB\jakub.grzesiowski <[email protected]>
Co-authored-by: jakub-grzesiowski <[email protected]>

---------

Co-authored-by: PUBNUB\jakub.grzesiowski <[email protected]>
Co-authored-by: jakub-grzesiowski <[email protected]>

* fix: unsubscribe issue due to duplicate channles/groups

* fix: `HereNow` issue with async- showing error: true even with status 200

* added logging to httpClient Service, optional parameter support in Pubnub constructor for middleware and client library

* Add some more missinng ConfigureAwait(false)

* PubNub SDK v7.0.0.0 release.

---------

Co-authored-by: PUBNUB\jakub.grzesiowski <[email protected]>
Co-authored-by: jakub-grzesiowski <[email protected]>
Co-authored-by: PubNub Release Bot <[email protected]>
  • Loading branch information
4 people authored Oct 31, 2024
1 parent aedbf5c commit 7f4180c
Show file tree
Hide file tree
Showing 161 changed files with 16,337 additions and 21,255 deletions.
18 changes: 10 additions & 8 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,22 @@ jobs:
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
3.x
5.0.x
6.0.x
7.0.x
- name: Build packages
env:
WORKSPACE_PATH: ${{ github.workspace }}
run: .\\.github\\workflows\\release\\build-packages.ps1
# - name: Run unit tests
# env:
# PN_PUB_KEY: ${{ secrets.PN_PUB_KEY }}
# PN_SUB_KEY: ${{ secrets.PN_SUB_KEY }}
# PN_SEC_KEY: ${{ secrets.PN_SEC_KEY }}
# run: dotnet test .\\src\\UnitTests\\PubnubApiPCL.Tests\\PubnubApiPCL.Tests.csproj --verbosity normal --logger trx
- name: Run unit tests
env:
PN_PUB_KEY: ${{ secrets.SDK_PUB_KEY }}
PN_SUB_KEY: ${{ secrets.SDK_SUB_KEY }}
PN_SEC_KEY: ${{ secrets.SDK_SEC_KEY }}
PN_PAM_PUB_KEY: ${{ secrets.SDK_PAM_PUB_KEY }}
PN_PAM_SUB_KEY: ${{ secrets.SDK_PAM_SUB_KEY }}
PN_PAM_SEC_KEY: ${{ secrets.SDK_PAM_SEC_KEY }}
run: dotnet test .\\src\\UnitTests\\PubnubApiPCL.Tests\\PubnubApiPCL.Tests.csproj --verbosity normal --logger "console;verbosity=detailed"
- name: Cancel workflow runs for commit on error
if: failure()
uses: ./.github/.release/actions/actions/utils/fast-jobs-failure
Expand Down Expand Up @@ -91,7 +93,7 @@ jobs:
run: |
Copy-Item -Path "${{ github.workspace }}/sdk-specifications/features/access/*" -Destination "${{ github.workspace }}/src/UnitTests/AcceptanceTests/Features" -Recurse
cd ./UnitTests/AcceptanceTests
dotnet test --no-build --verbosity normal --logger trx --results-directory ./results
dotnet test --no-build --verbosity normal --logger "console;verbosity=detailed" --results-directory ./results
- name: Upload acceptance tests reports
if: always()
uses: actions/upload-artifact@v4
Expand Down
29 changes: 21 additions & 8 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
name: c-sharp
version: "6.20.2"
version: "7.0.0"
schema: 1
scm: github.com/pubnub/c-sharp
changelog:
- date: 2024-10-30
version: v7.0.0
changes:
- type: feature
text: "Added support for `Channel`, `ChannelGroup`, `Subscription` and `SubscriptionSet`, `ChannelMetadata`, `UserMetadata` entities for Subscribe related operation."
- type: feature
text: "BREAKING CHANGES: Added new event listeners support."
- type: feature
text: "BREAKING CHANGES: All apis calls will be made through `HttpClient` by default."
- type: feature
text: "Default value for `EnableEventEngine` is set to `true`, Subscribe operation will be executed by event engine by default."
- type: improvement
text: "Removed telemetry manager."
- date: 2024-10-03
version: v6.20.2
changes:
Expand Down Expand Up @@ -793,7 +806,7 @@ features:
- QUERY-PARAM
supported-platforms:
-
version: Pubnub 'C#' 6.20.2
version: Pubnub 'C#' 7.0.0
platforms:
- Windows 10 and up
- Windows Server 2008 and up
Expand All @@ -804,7 +817,7 @@ supported-platforms:
- .Net Framework 4.6.1+
- .Net Framework 6.0
-
version: PubnubPCL 'C#' 6.20.2
version: PubnubPCL 'C#' 7.0.0
platforms:
- Xamarin.Android
- Xamarin.iOS
Expand All @@ -824,7 +837,7 @@ supported-platforms:
- .Net Core
- .Net 6.0
-
version: PubnubUWP 'C#' 6.20.2
version: PubnubUWP 'C#' 7.0.0
platforms:
- Windows Phone 10
- Universal Windows Apps
Expand All @@ -848,7 +861,7 @@ sdks:
distribution-type: source
distribution-repository: GitHub
package-name: Pubnub
location: https://github.com/pubnub/c-sharp/releases/tag/v6.20.2.0
location: https://github.com/pubnub/c-sharp/releases/tag/v7.0.0.0
requires:
-
name: ".Net"
Expand Down Expand Up @@ -1131,7 +1144,7 @@ sdks:
distribution-type: source
distribution-repository: GitHub
package-name: PubNubPCL
location: https://github.com/pubnub/c-sharp/releases/tag/v6.20.2.0
location: https://github.com/pubnub/c-sharp/releases/tag/v7.0.0.0
requires:
-
name: ".Net Core"
Expand Down Expand Up @@ -1490,7 +1503,7 @@ sdks:
distribution-type: source
distribution-repository: GitHub
package-name: PubnubUWP
location: https://github.com/pubnub/c-sharp/releases/tag/v6.20.2.0
location: https://github.com/pubnub/c-sharp/releases/tag/v7.0.0.0
requires:
-
name: "Universal Windows Platform Development"
Expand Down Expand Up @@ -1649,4 +1662,4 @@ sdks:
- Windows Server 2012 R2 Foundation
- Windows Server 2012 R2 Essentials
- Windows Server 2012 R2 Standard
- Windows Server 2012 R2 Datacenter
- Windows Server 2012 R2 Datacenter
9 changes: 9 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
v7.0.0 - October 30 2024
-----------------------------
- Added: added support for `Channel`, `ChannelGroup`, `Subscription` and `SubscriptionSet`, `ChannelMetadata`, `UserMetadata` entities for Subscribe related operation.
- BREAKING CHANGES: Added new event listeners support.
- BREAKING CHANGES: All apis calls will be made through `HttpClient` by default.
- Added: default value for `EnableEventEngine` is set to `true`, Subscribe operation will be executed by event engine by default.

- Modified: removed telemetry manager.

v6.20.2 - October 03 2024
-----------------------------
- Fixed: fixes issue of listener not being removed on RemoveListener call.
Expand Down
13 changes: 5 additions & 8 deletions src/Api/PubnubApi/Builder/ResponseBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Generic;

namespace PubnubApi
{
Expand All @@ -13,9 +10,9 @@ internal class ResponseBuilder

public ResponseBuilder(PNConfiguration pubnubConfig, IJsonPluggableLibrary jsonPluggableLibrary, IPubnubLog log)
{
this.config = pubnubConfig;
this.jsonLib = jsonPluggableLibrary;
this.pubnubLog = log;
config = pubnubConfig;
jsonLib = jsonPluggableLibrary;
pubnubLog = log;
}

public T JsonToObject<T>(List<object> result, bool internalObject)
Expand All @@ -28,7 +25,7 @@ public T JsonToObject<T>(List<object> result, bool internalObject)
}
else
{
NewtonsoftJsonDotNet jsonNewtonLib = new NewtonsoftJsonDotNet(this.config, this.pubnubLog);
NewtonsoftJsonDotNet jsonNewtonLib = new NewtonsoftJsonDotNet(config, pubnubLog);
ret = jsonNewtonLib.DeserializeToObject<T>(result);
}

Expand Down
10 changes: 4 additions & 6 deletions src/Api/PubnubApi/Builder/StatusBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;

namespace PubnubApi
{
public class StatusBuilder
public class StatusBuilder
{
private readonly PNConfiguration config;
private readonly IJsonPluggableLibrary jsonLibrary;
Expand Down Expand Up @@ -98,11 +96,11 @@ public PNStatus CreateStatusResponse<T>(PNOperationType type, PNStatusCategory c

if (asyncRequestState != null)
{
if (asyncRequestState.Request != null)
if (asyncRequestState.RequestCancellationTokenSource != null)
{
status.ClientRequest = asyncRequestState.Request;
status.ClientRequest = asyncRequestState.RequestCancellationTokenSource;

HttpValueCollection restUriQueryCollection = HttpUtility.ParseQueryString(asyncRequestState.Request.RequestUri.Query);
HttpValueCollection restUriQueryCollection = HttpUtility.ParseQueryString(new Uri(asyncRequestState.Response.RequestUrl).Query);
if (restUriQueryCollection.ContainsKey("auth"))
{
string auth = restUriQueryCollection["auth"];
Expand Down
45 changes: 34 additions & 11 deletions src/Api/PubnubApi/Builder/UriUtil.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using PubnubApi.EndPoint;

namespace PubnubApi
{
public class UriUtil
public static class UriUtil
{
public static string EncodeUriComponent(string s, PNOperationType type, bool ignoreComma, bool ignoreColon, bool ignorePercent2fEncode)
{
Expand Down Expand Up @@ -75,13 +78,7 @@ public static string EncodeUriComponent(string s, PNOperationType type, bool ign
}
else
{
string escapeChar = System.Uri.EscapeDataString(ch.ToString());
#if NET35 || NET40
if (escapeChar == ch.ToString() && IsUnsafeToEncode(ch, ignoreComma, ignoreColon))
{
escapeChar = string.Format(CultureInfo.InvariantCulture, "%{0}{1}", ToHex(ch / 16), ToHex(ch % 16));
}
#endif
string escapeChar = Uri.EscapeDataString(ch.ToString());
o.Append(escapeChar);
}
}
Expand Down Expand Up @@ -160,7 +157,7 @@ private static int ConvertToUtf32(string s, int index)
}

// Check if the character at index is a high surrogate.
int temp1 = (int)s[index] - HighSurrogateStart;
int temp1 = s[index] - HighSurrogateStart;
if (temp1 >= 0 && temp1 <= 0x7ff)
{
// Found a surrogate char.
Expand All @@ -169,7 +166,7 @@ private static int ConvertToUtf32(string s, int index)
// Found a high surrogate.
if (index < s.Length - 1)
{
int temp2 = (int)s[index + 1] - LowSurrogateStart;
int temp2 = s[index + 1] - LowSurrogateStart;
if (temp2 >= 0 && temp2 <= 0x3ff)
{
// Found a low surrogate.
Expand All @@ -194,7 +191,33 @@ private static int ConvertToUtf32(string s, int index)
}

// Not a high-surrogate or low-surrogate. Genereate the UTF32 value for the BMP characters.
return (int)s[index];
return s[index];
}

public static string BuildQueryString(Dictionary<string, string> queryStringParamMap)
{
return string.Join("&", queryStringParamMap?.OrderBy(kvp => kvp.Key, StringComparer.Ordinal).Select(kvp => string.Format(CultureInfo.InvariantCulture, "{0}={1}", kvp.Key, kvp.Value)).ToArray() ?? Array.Empty<string>());
}

public static string GetFileUrl(string fileId, string fileName, string channel, PNConfiguration pnConfiguration, Pubnub pubnub, TokenManager tokenmanager)
{
var requestParameters = new RequestParameter()
{
RequestType = Constants.GET,
PathSegment = [
"v1",
"files",
pnConfiguration.SubscribeKey,
"channels",
channel,
"files",
fileId,
fileName
],
Query = new Dictionary<string, string>()
};
var transportRequest = pubnub.transportMiddleware.PreapareTransportRequest(requestParameter:requestParameters, PNOperationType.PNFileUrlOperation);
return transportRequest.RequestUrl;
}
}
}
35 changes: 35 additions & 0 deletions src/Api/PubnubApi/Builder/UrlParameterConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;

namespace PubnubApi.EndPoint
{

internal static class UrlParameterConverter
{
public static string MapEnumValueToEndpoint(string enumValue)
{
string endpointParameterName = String.Empty;
if (enumValue.ToLowerInvariant() == "custom")
{
endpointParameterName = "custom";
}
else if (enumValue.ToLowerInvariant() == "uuid")
{
endpointParameterName = "uuid";
}
else if (enumValue.ToLowerInvariant() == "channel")
{
endpointParameterName = "channel";
}
else if (enumValue.ToLowerInvariant() == "channel_custom")
{
endpointParameterName = "channel.custom";
}
else if (enumValue.ToLowerInvariant() == "uuid_custom")
{
endpointParameterName = "uuid.custom";
}

return endpointParameterName;
}
}
}
Loading

0 comments on commit 7f4180c

Please sign in to comment.