Skip to content

Commit

Permalink
updated default logger to use system diagnostics to make it compatibl…
Browse files Browse the repository at this point in the history
…e to all targets
  • Loading branch information
Mohit Tejani authored and Mohit Tejani committed Mar 3, 2025
1 parent 85efc37 commit 95458d3
Show file tree
Hide file tree
Showing 19 changed files with 629 additions and 432 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,13 @@ public GetAllChannelMetadataOperation QueryParam(Dictionary<string, object> cust
public void Execute(PNCallback<PNGetAllChannelMetadataResult> callback)
{
this.savedCallback = callback;
logger.Trace($"{GetType().Name} Execute invoked");
GetAllChannelMetadataList(this.page, this.limit, this.includeCount, this.includeCustom, this.channelsFilter, this.sortField, this.queryParam, savedCallback);
}

public async Task<PNResult<PNGetAllChannelMetadataResult>> ExecuteAsync()
{
logger.Trace($"{GetType().Name} ExecuteAsync invoked.");
return await GetAllChannelMetadataList(this.page, this.limit, this.includeCount, this.includeCustom, this.channelsFilter, this.sortField, this.queryParam).ConfigureAwait(false);
}

Expand All @@ -109,13 +111,15 @@ private void GetAllChannelMetadataList(PNPageObject page, int limit, bool includ
if (callback == null) {
throw new ArgumentException("Missing callback");
}

RequestState<PNGetAllChannelMetadataResult> requestState = new RequestState<PNGetAllChannelMetadataResult>();
requestState.ResponseType = PNOperationType.PNGetAllChannelMetadataOperation;
requestState.PubnubCallback = callback;
requestState.Reconnect = false;
requestState.EndPointOperation = this;
requestState.UsePostMethod = false;
logger.Debug($"{GetType().Name} parameter validated.");
RequestState<PNGetAllChannelMetadataResult> requestState = new RequestState<PNGetAllChannelMetadataResult>
{
ResponseType = PNOperationType.PNGetAllChannelMetadataOperation,
PubnubCallback = callback,
Reconnect = false,
EndPointOperation = this,
UsePostMethod = false
};
var requestParameter = CreateRequestParameter();

var transportRequest = PubnubInstance.transportMiddleware.PreapareTransportRequest(requestParameter: requestParameter, operationType: PNOperationType.PNGetAllChannelMetadataOperation);
Expand All @@ -125,13 +129,15 @@ private void GetAllChannelMetadataList(PNPageObject page, int limit, bool includ
var responseString = Encoding.UTF8.GetString(transportResponse.Content);
if (!string.IsNullOrEmpty(responseString)) {
requestState.GotJsonResponse = true;
logger.Info($"{GetType().Name} request finished with status code {requestState.Response.StatusCode}");
List<object> result = ProcessJsonResponse(requestState, responseString);
ProcessResponseCallbacks(result, requestState);
}
} else {
int statusCode = PNStatusCodeHelper.GetHttpStatusCode(transportResponse.Error.Message);
PNStatusCategory category = PNStatusCategoryHelper.GetPNStatusCategory(statusCode, transportResponse.Error.Message);
PNStatus status = new StatusBuilder(config, jsonLibrary).CreateStatusResponse(PNOperationType.PNGetAllChannelMetadataOperation, category, requestState, statusCode, new PNException(transportResponse.Error.Message, transportResponse.Error));
logger.Info($"{GetType().Name} request finished with status code {requestState.Response.StatusCode}");
requestState.PubnubCallback.OnResponse(default, status);
}
});
Expand All @@ -140,11 +146,13 @@ private void GetAllChannelMetadataList(PNPageObject page, int limit, bool includ
private async Task<PNResult<PNGetAllChannelMetadataResult>> GetAllChannelMetadataList(PNPageObject page, int limit, bool includeCount, bool includeCustom, string filter, List<string> sort, Dictionary<string, object> externalQueryParam)
{
PNResult<PNGetAllChannelMetadataResult> returnValue = new PNResult<PNGetAllChannelMetadataResult>();
RequestState<PNGetAllChannelMetadataResult> requestState = new RequestState<PNGetAllChannelMetadataResult>();
requestState.ResponseType = PNOperationType.PNGetAllChannelMetadataOperation;
requestState.Reconnect = false;
requestState.EndPointOperation = this;
requestState.UsePostMethod = false;
RequestState<PNGetAllChannelMetadataResult> requestState = new RequestState<PNGetAllChannelMetadataResult>
{
ResponseType = PNOperationType.PNGetAllChannelMetadataOperation,
Reconnect = false,
EndPointOperation = this,
UsePostMethod = false
};
Tuple<string, PNStatus> JsonAndStatusTuple;
var requestParameter = CreateRequestParameter();
var transportRequest = PubnubInstance.transportMiddleware.PreapareTransportRequest(requestParameter: requestParameter, operationType: PNOperationType.PNGetAllChannelMetadataOperation);
Expand Down Expand Up @@ -175,7 +183,7 @@ private async Task<PNResult<PNGetAllChannelMetadataResult>> GetAllChannelMetadat
PNStatus status = new StatusBuilder(config, jsonLibrary).CreateStatusResponse(PNOperationType.PNGetAllChannelMetadataOperation, category, requestState, statusCode, new PNException(transportResponse.Error.Message, transportResponse.Error));
returnValue.Status = status;
}

logger.Info($"{GetType().Name} request finished with status code {returnValue.Status.StatusCode}");
return returnValue;
}

Expand Down
55 changes: 31 additions & 24 deletions src/Api/PubnubApi/EndPoint/Objects/GetAllUuidMetadataOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class GetAllUuidMetadataOperation : PubnubCoreBase
private PNCallback<PNGetAllUuidMetadataResult> savedCallback;
private Dictionary<string, object> queryParam;

public GetAllUuidMetadataOperation(PNConfiguration pubnubConfig, IJsonPluggableLibrary jsonPluggableLibrary, IPubnubUnitTest pubnubUnit, IPubnubLog log, EndPoint.TokenManager tokenManager, Pubnub instance) : base(pubnubConfig, jsonPluggableLibrary, pubnubUnit, log, tokenManager, instance)
public GetAllUuidMetadataOperation(PNConfiguration pubnubConfig, IJsonPluggableLibrary jsonPluggableLibrary, IPubnubUnitTest pubnubUnit, IPubnubLog log, TokenManager tokenManager, Pubnub instance) : base(pubnubConfig, jsonPluggableLibrary, pubnubUnit, log, tokenManager, instance)
{
config = pubnubConfig;
jsonLibrary = jsonPluggableLibrary;
Expand All @@ -52,59 +52,61 @@ public GetAllUuidMetadataOperation(PNConfiguration pubnubConfig, IJsonPluggableL

public GetAllUuidMetadataOperation Page(PNPageObject pageObject)
{
this.page = pageObject;
page = pageObject;
return this;
}

public GetAllUuidMetadataOperation Limit(int numberOfUuids)
{
this.limit = numberOfUuids;
limit = numberOfUuids;
return this;
}
public GetAllUuidMetadataOperation IncludeCount(bool includeTotalCount)
{
this.includeCount = includeTotalCount;
includeCount = includeTotalCount;
return this;
}

public GetAllUuidMetadataOperation IncludeCustom(bool includeCustomData)
{
this.includeCustom = includeCustomData;
includeCustom = includeCustomData;
return this;
}
public GetAllUuidMetadataOperation Filter(string filterExpression)
{
this.usersFilter = filterExpression;
usersFilter = filterExpression;
return this;
}

public GetAllUuidMetadataOperation Sort(List<string> sortByField)
{
this.sortField = sortByField;
sortField = sortByField;
return this;
}

public GetAllUuidMetadataOperation QueryParam(Dictionary<string, object> customQueryParam)
{
this.queryParam = customQueryParam;
queryParam = customQueryParam;
return this;
}

public void Execute(PNCallback<PNGetAllUuidMetadataResult> callback)
{
this.savedCallback = callback;
GetUuidMetadataList(this.page, this.limit, this.includeCount, this.includeCustom, this.usersFilter, this.sortField, this.queryParam, savedCallback);
savedCallback = callback;
logger.Trace($"{GetType().Name} Execute invoked");
GetUuidMetadataList(page, limit, includeCount, includeCustom, usersFilter, sortField, queryParam, savedCallback);
}

public async Task<PNResult<PNGetAllUuidMetadataResult>> ExecuteAsync()
{
return await GetUuidMetadataList(this.page, this.limit, this.includeCount, this.includeCustom, this.usersFilter, this.sortField, this.queryParam).ConfigureAwait(false);
logger.Trace($"{GetType().Name} ExecuteAsync invoked.");
return await GetUuidMetadataList(page, limit, includeCount, includeCustom, usersFilter, sortField, queryParam).ConfigureAwait(false);
}


internal void Retry()
{
GetUuidMetadataList(this.page, this.limit, this.includeCount, this.includeCustom, this.usersFilter, this.sortField, this.queryParam, savedCallback);
GetUuidMetadataList(page, limit, includeCount, includeCustom, usersFilter, sortField, queryParam, savedCallback);
}

private void GetUuidMetadataList(PNPageObject page, int limit, bool includeCount, bool includeCustom, string filter, List<string> sort, Dictionary<string, object> externalQueryParam, PNCallback<PNGetAllUuidMetadataResult> callback)
Expand All @@ -113,11 +115,13 @@ private void GetUuidMetadataList(PNPageObject page, int limit, bool includeCount
{
throw new ArgumentException("Missing callback");
}
RequestState<PNGetAllUuidMetadataResult> requestState = new RequestState<PNGetAllUuidMetadataResult>();
requestState.ResponseType = PNOperationType.PNGetAllUuidMetadataOperation;
requestState.PubnubCallback = callback;
requestState.Reconnect = false;
requestState.EndPointOperation = this;
RequestState<PNGetAllUuidMetadataResult> requestState = new RequestState<PNGetAllUuidMetadataResult>
{
ResponseType = PNOperationType.PNGetAllUuidMetadataOperation,
PubnubCallback = callback,
Reconnect = false,
EndPointOperation = this
};

var requestParameter = CreateRequestParameter();
var transportRequest = PubnubInstance.transportMiddleware.PreapareTransportRequest(requestParameter: requestParameter, operationType: PNOperationType.PNGetAllUuidMetadataOperation);
Expand All @@ -127,13 +131,15 @@ private void GetUuidMetadataList(PNPageObject page, int limit, bool includeCount
var responseString = Encoding.UTF8.GetString(transportResponse.Content);
if (!string.IsNullOrEmpty(responseString)) {
requestState.GotJsonResponse = true;
logger.Info($"{GetType().Name} request finished with status code {requestState.Response.StatusCode}");
List<object> result = ProcessJsonResponse(requestState, responseString);
ProcessResponseCallbacks(result, requestState);
}
} else {
int statusCode = PNStatusCodeHelper.GetHttpStatusCode(transportResponse.Error.Message);
PNStatusCategory category = PNStatusCategoryHelper.GetPNStatusCategory(statusCode, transportResponse.Error.Message);
PNStatus status = new StatusBuilder(config, jsonLibrary).CreateStatusResponse(PNOperationType.PNGetAllUuidMetadataOperation, category, requestState, statusCode, new PNException(transportResponse.Error.Message, transportResponse.Error));
logger.Info($"{GetType().Name} request finished with status code {requestState.Response.StatusCode}");
requestState.PubnubCallback.OnResponse(default(PNGetAllUuidMetadataResult), status);
}
});
Expand All @@ -142,11 +148,13 @@ private void GetUuidMetadataList(PNPageObject page, int limit, bool includeCount
private async Task<PNResult<PNGetAllUuidMetadataResult>> GetUuidMetadataList(PNPageObject page, int limit, bool includeCount, bool includeCustom, string filter, List<string> sort, Dictionary<string, object> externalQueryParam)
{
PNResult<PNGetAllUuidMetadataResult> returnValue = new PNResult<PNGetAllUuidMetadataResult>();
RequestState<PNGetAllUuidMetadataResult> requestState = new RequestState<PNGetAllUuidMetadataResult>();
requestState.ResponseType = PNOperationType.PNGetAllUuidMetadataOperation;
requestState.Reconnect = false;
requestState.UsePostMethod = false;
requestState.EndPointOperation = this;
RequestState<PNGetAllUuidMetadataResult> requestState = new RequestState<PNGetAllUuidMetadataResult>
{
ResponseType = PNOperationType.PNGetAllUuidMetadataOperation,
Reconnect = false,
UsePostMethod = false,
EndPointOperation = this
};
Tuple<string, PNStatus> JsonAndStatusTuple;

var requestParameter = CreateRequestParameter();
Expand Down Expand Up @@ -180,7 +188,7 @@ private async Task<PNResult<PNGetAllUuidMetadataResult>> GetUuidMetadataList(PNP
PNStatus status = new StatusBuilder(config, jsonLibrary).CreateStatusResponse(PNOperationType.PNGetAllUuidMetadataOperation, category, requestState, statusCode, new PNException(transportResponse.Error.Message, transportResponse.Error));
returnValue.Status = status;
}

logger.Info($"{GetType().Name} request finished with status code {returnValue.Status.StatusCode}");
return returnValue;
}

Expand Down Expand Up @@ -234,7 +242,6 @@ private RequestParameter CreateRequestParameter()
}
}
}
string queryString = UriUtil.BuildQueryString(requestQueryStringParams);
var requestParameter = new RequestParameter() {
RequestType = Constants.GET,
PathSegment = pathSegments,
Expand Down
Loading

0 comments on commit 95458d3

Please sign in to comment.