Skip to content

Update for .net 8 swing release. Remove of Microsoft.Rest.Client Dependnacy #476

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 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Build.Common.core.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
</PropertyGroup>

<PropertyGroup Condition="'$(ProjectSpecificFx)' == ''">
<TargetFrameworks>net462;net472;net48;netstandard2.0;net6.0</TargetFrameworks>
<TargetFrameworks>net462;net472;net48;netstandard2.0;net6.0;net8.0</TargetFrameworks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<NoWarn>NU5104</NoWarn>
</PropertyGroup>

<PropertyGroup>
Expand Down
3 changes: 2 additions & 1 deletion src/GeneralTools/DataverseClient/Client/ConnectionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
using Microsoft.PowerPlatform.Dataverse.Client.Auth.TokenCache;
using Microsoft.PowerPlatform.Dataverse.Client.Connector;
using Microsoft.PowerPlatform.Dataverse.Client.Connector.OnPremises;
using Microsoft.PowerPlatform.Dataverse.Client.Exceptions;
using Microsoft.PowerPlatform.Dataverse.Client.HttpUtils;
using Microsoft.PowerPlatform.Dataverse.Client.InternalExtensions;
using Microsoft.PowerPlatform.Dataverse.Client.Model;
using Microsoft.PowerPlatform.Dataverse.Client.Utils;
using Microsoft.Rest;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Discovery;
using Microsoft.Xrm.Sdk.Messages;
Expand Down
53 changes: 18 additions & 35 deletions src/GeneralTools/DataverseClient/Client/DataverseTraceLogger.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Microsoft.Extensions.Logging;
using Microsoft.PowerPlatform.Dataverse.Client.Utils;
using Microsoft.Rest;
using Microsoft.Xrm.Sdk;
using Newtonsoft.Json.Linq;
using System;
Expand All @@ -12,6 +11,7 @@
using System.ServiceModel;
using System.Linq;
using System.Text;
using Microsoft.PowerPlatform.Dataverse.Client.Exceptions;

namespace Microsoft.PowerPlatform.Dataverse.Client
{
Expand All @@ -21,9 +21,6 @@ namespace Microsoft.PowerPlatform.Dataverse.Client
[LocalizableAttribute(false)]
internal sealed class DataverseTraceLogger : TraceLoggerBase
{
// Internal connection of exceptions since last clear.
private List<Exception> _ActiveExceptionsList;

internal ILogger _logger;

#region Properties
Expand Down Expand Up @@ -79,16 +76,13 @@ public DataverseTraceLogger(string traceSourceName = "")
TraceSourceName = traceSourceName;
}

_ActiveExceptionsList = new List<Exception>();

base.Initialize();
}

public DataverseTraceLogger(ILogger logger)
{
_logger = logger;
TraceSourceName = DefaultTraceSourceName;
_ActiveExceptionsList = new List<Exception>();
base.Initialize();
}

Expand All @@ -98,7 +92,6 @@ public override void ResetLastError()
if (base.LastError.Length > 0)
base.LastError = base.LastError.Remove(0, LastError.Length - 1);
LastException = null;
_ActiveExceptionsList.Clear();
}

/// <summary>
Expand Down Expand Up @@ -151,39 +144,34 @@ public override void Log(string message, TraceEventType eventType, Exception exc
exception = new Exception(message);
}

StringBuilder detailedDump = new StringBuilder();
StringBuilder lastMessage = new StringBuilder();
StringBuilder detailedDump = new StringBuilder(4096);
StringBuilder lastMessage = new StringBuilder(2048);

lastMessage.AppendLine(message); // Added to fix missing last error line.
detailedDump.AppendLine(message); // Added to fix missing error line.

if (!(exception != null && _ActiveExceptionsList.Contains(exception))) // Skip this line if its already been done.
GetExceptionDetail(exception, detailedDump, 0, lastMessage);
GetExceptionDetail(exception, detailedDump, 0, lastMessage);

TraceEvent(eventType, (int)eventType, detailedDump.ToString(), exception);
if (eventType == TraceEventType.Error)
{
base.LastError += lastMessage.ToString();
if (!(exception != null && _ActiveExceptionsList.Contains(exception))) // Skip this line if its already been done.
// check and or alter the exception is its and HTTPOperationExecption.
if (exception is HttpOperationException httpOperationException)
{
// check and or alter the exception is its and HTTPOperationExecption.
if (exception is HttpOperationException httpOperationException)
string errorMessage = "Not Provided";
if (!string.IsNullOrWhiteSpace(httpOperationException.Response.Content))
{
string errorMessage = "Not Provided";
if (!string.IsNullOrWhiteSpace(httpOperationException.Response.Content))
{
JObject contentBody = JObject.Parse(httpOperationException.Response.Content);
errorMessage = string.IsNullOrEmpty(contentBody["error"]["message"]?.ToString()) ? "Not Provided" : GetFirstLineFromString(contentBody["error"]["message"]?.ToString()).Trim();
}

Utils.DataverseOperationException webApiExcept = new Utils.DataverseOperationException(errorMessage, httpOperationException);
LastException = webApiExcept;
JObject contentBody = JObject.Parse(httpOperationException.Response.Content);
errorMessage = string.IsNullOrEmpty(contentBody["error"]["message"]?.ToString()) ? "Not Provided" : GetFirstLineFromString(contentBody["error"]["message"]?.ToString()).Trim();
}
else
LastException = exception;

Utils.DataverseOperationException webApiExcept = new Utils.DataverseOperationException(errorMessage, httpOperationException);
LastException = webApiExcept;
}
else
LastException = exception;
}
_ActiveExceptionsList.Add(exception);

detailedDump.Clear();
lastMessage.Clear();
Expand All @@ -196,18 +184,13 @@ public override void Log(string message, TraceEventType eventType, Exception exc
/// <param name="exception"></param>
public override void Log(Exception exception)
{
if (exception != null && _ActiveExceptionsList.Contains(exception))
return; // already logged this one .

StringBuilder detailedDump = new StringBuilder();
StringBuilder lastMessage = new StringBuilder();
StringBuilder detailedDump = new StringBuilder(4096);
StringBuilder lastMessage = new StringBuilder(2048);
GetExceptionDetail(exception, detailedDump, 0, lastMessage);
TraceEvent(TraceEventType.Error, (int)TraceEventType.Error, detailedDump.ToString(), exception);
base.LastError += lastMessage.ToString();
LastException = exception;

_ActiveExceptionsList.Add(exception);

detailedDump.Clear();
lastMessage.Clear();
}
Expand Down Expand Up @@ -594,7 +577,7 @@ private static string GenerateOrgErrorDetailsInfo(ErrorDetailCollection errorDet
{
if (errorDetails != null && errorDetails.Count > 0)
{
StringBuilder sw = new StringBuilder();
StringBuilder sw = new StringBuilder(2048);
sw.AppendLine("Error Details\t:");
foreach (var itm in errorDetails)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
//using Microsoft.Rest;
using Microsoft.PowerPlatform.Dataverse.Client.Exceptions;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;

namespace Microsoft.PowerPlatform.Dataverse.Client.Utils
{
/// <summary>
/// Used to encompass a ServiceClient Connection Centric exceptions
/// </summary>
[Serializable]
public class DataverseConnectionException : Exception
{
/// <summary>
/// Creates a dataverse connection Exception
/// </summary>
/// <param name="message">Error Message</param>
public DataverseConnectionException(string message)
: base(message)
{
}

/// <summary>
/// Creates a dataverse connection Exception
/// </summary>
/// <param name="message">Error Message</param>
/// <param name="innerException">Supporting Exception</param>
public DataverseConnectionException(string message, Exception innerException)
: base(message, innerException)
{
this.HResult = innerException.HResult;
}

/// <summary>
/// Creates a dataverse connection Exception
/// </summary>
/// <param name="message">Error Message</param>
/// <param name="errorCode">Error code</param>
/// <param name="data">Data Properties</param>
/// <param name="helpLink">Help Link</param>
/// <param name="httpOperationException"></param>
public DataverseConnectionException(string message, int errorCode, string helpLink, IDictionary<string, string> data, HttpOperationException httpOperationException = null)
: base(message, httpOperationException)
{
HResult = errorCode;
HelpLink = helpLink;
Source = "Dataverse Server API";
foreach (var itm in data)
{
this.Data.Add(itm.Key, itm.Value);
}
}

/// <summary>
/// Creates a Dataverse Connection Exception from an httpOperationError
/// </summary>
/// <param name="httpOperationException"></param>
/// <returns></returns>
public static DataverseConnectionException GenerateClientConnectionException(HttpOperationException httpOperationException)
{
string errorDetailPrefixString = "@Microsoft.PowerApps.CDS.ErrorDetails.";
Dictionary<string, string> cdsErrorData = new Dictionary<string, string>();

JToken ErrorBlock = null;
try
{
if (!string.IsNullOrWhiteSpace(httpOperationException.Response.Content))
{
JObject contentBody = JObject.Parse(httpOperationException.Response.Content);
ErrorBlock = contentBody["error"];
}
}
catch { }

if (ErrorBlock != null)
{
string errorMessage = DataverseTraceLogger.GetFirstLineFromString(ErrorBlock["message"]?.ToString()).Trim();
var code = ErrorBlock["code"];
int HResult = code != null && !string.IsNullOrWhiteSpace(code.ToString()) ? Convert.ToInt32(code.ToString(), 16) : -1;

string HelpLink = ErrorBlock["@Microsoft.PowerApps.CDS.HelpLink"]?.ToString();

foreach (var node in ErrorBlock.ToArray())
{
if (node.Path.Contains(errorDetailPrefixString))
{
cdsErrorData.Add(node.Value<JProperty>().Name.ToString().Replace(errorDetailPrefixString, string.Empty), node.HasValues ? node.Value<JProperty>().Value.ToString() : string.Empty);
}
}
return new DataverseConnectionException(errorMessage, HResult, HelpLink, cdsErrorData, httpOperationException);
}
else
return new DataverseConnectionException("Server Error, no error report generated from server", -1, string.Empty, cdsErrorData, httpOperationException);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//using Microsoft.Rest;
using Microsoft.PowerPlatform.Dataverse.Client.Exceptions;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.PowerPlatform.Dataverse.Client.Utils
{
/// <summary>
/// Used to encompass a ServiceClient Operation Exception
/// </summary>
[Serializable]
public class DataverseOperationException : Exception
{
/// <summary>
/// Creates a CdsService Client Exception
/// </summary>
/// <param name="message">Error Message</param>
public DataverseOperationException(string message)
: base(message)
{
}

/// <summary>
/// Creates a CdsService Client Exception
/// </summary>
/// <param name="message">Error Message</param>
/// <param name="errorCode">Error code</param>
/// <param name="data">Data Properties</param>
/// <param name="helpLink">Help Link</param>
/// <param name="httpOperationException"></param>
public DataverseOperationException(string message, int errorCode, string helpLink, IDictionary<string, string> data, HttpOperationException httpOperationException = null)
: base(message, httpOperationException)
{
HResult = errorCode;
HelpLink = helpLink;
Source = "Dataverse Server API";
foreach (var itm in data)
{
this.Data.Add(itm.Key, itm.Value);
}
}

/// <summary>
/// Creates a CdsService Client Exception from a httpOperationResult.
/// </summary>
/// <param name="httpOperationException"></param>
public static DataverseOperationException GenerateClientOperationException(HttpOperationException httpOperationException)
{
string errorDetailPrefixString = "@Microsoft.PowerApps.CDS.ErrorDetails.";
Dictionary<string, string> cdsErrorData = new Dictionary<string, string>();

JToken ErrorBlock = null;
try
{
if (!string.IsNullOrWhiteSpace(httpOperationException.Response.Content))
{
JObject contentBody = JObject.Parse(httpOperationException.Response.Content);
ErrorBlock = contentBody["error"];
}
}
catch { }

if (ErrorBlock != null)
{
string errorMessage = DataverseTraceLogger.GetFirstLineFromString(ErrorBlock["message"]?.ToString()).Trim();
var code = ErrorBlock["code"];
int HResult = code != null && !string.IsNullOrWhiteSpace(code.ToString()) ? Convert.ToInt32(code.ToString(), 16) : -1;

string HelpLink = ErrorBlock["@Microsoft.PowerApps.CDS.HelpLink"]?.ToString();

foreach (var node in ErrorBlock.ToArray())
{
if (node.Path.Contains(errorDetailPrefixString))
{
cdsErrorData.Add(node.Value<JProperty>().Name.ToString().Replace(errorDetailPrefixString, string.Empty), node.HasValues ? node.Value<JProperty>().Value.ToString() : string.Empty);
}
}
return new DataverseOperationException(errorMessage, HResult, HelpLink, cdsErrorData, httpOperationException);
}
else
return new DataverseOperationException("Server Error, no error report generated from server", -1, string.Empty, cdsErrorData, httpOperationException);
}

/// <summary>
/// Creates a CdsService Client Exception
/// </summary>
/// <param name="message">Error Message</param>
/// <param name="innerException">Supporting Exception</param>
public DataverseOperationException(string message, Exception innerException)
: base(message, innerException)
{
}

}
}
Loading