Skip to content

Commit 02bfe18

Browse files
authored
Merge pull request #476 from microsoft/release/update/241106075553
Update for .net 8 swing release. Remove of Microsoft.Rest.Client Dependnacy
2 parents be9ee13 + c16a939 commit 02bfe18

21 files changed

+810
-53
lines changed

src/Build.Common.core.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
</PropertyGroup>
66

77
<PropertyGroup Condition="'$(ProjectSpecificFx)' == ''">
8-
<TargetFrameworks>net462;net472;net48;netstandard2.0;net6.0</TargetFrameworks>
8+
<TargetFrameworks>net462;net472;net48;netstandard2.0;net6.0;net8.0</TargetFrameworks>
99
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
10+
<NoWarn>NU5104</NoWarn>
1011
</PropertyGroup>
1112

1213
<PropertyGroup>

src/GeneralTools/DataverseClient/Client/ConnectionService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
using Microsoft.PowerPlatform.Dataverse.Client.Auth.TokenCache;
1010
using Microsoft.PowerPlatform.Dataverse.Client.Connector;
1111
using Microsoft.PowerPlatform.Dataverse.Client.Connector.OnPremises;
12+
using Microsoft.PowerPlatform.Dataverse.Client.Exceptions;
13+
using Microsoft.PowerPlatform.Dataverse.Client.HttpUtils;
1214
using Microsoft.PowerPlatform.Dataverse.Client.InternalExtensions;
1315
using Microsoft.PowerPlatform.Dataverse.Client.Model;
1416
using Microsoft.PowerPlatform.Dataverse.Client.Utils;
15-
using Microsoft.Rest;
1617
using Microsoft.Xrm.Sdk;
1718
using Microsoft.Xrm.Sdk.Discovery;
1819
using Microsoft.Xrm.Sdk.Messages;

src/GeneralTools/DataverseClient/Client/DataverseTraceLogger.cs

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Microsoft.Extensions.Logging;
22
using Microsoft.PowerPlatform.Dataverse.Client.Utils;
3-
using Microsoft.Rest;
43
using Microsoft.Xrm.Sdk;
54
using Newtonsoft.Json.Linq;
65
using System;
@@ -12,6 +11,7 @@
1211
using System.ServiceModel;
1312
using System.Linq;
1413
using System.Text;
14+
using Microsoft.PowerPlatform.Dataverse.Client.Exceptions;
1515

1616
namespace Microsoft.PowerPlatform.Dataverse.Client
1717
{
@@ -21,9 +21,6 @@ namespace Microsoft.PowerPlatform.Dataverse.Client
2121
[LocalizableAttribute(false)]
2222
internal sealed class DataverseTraceLogger : TraceLoggerBase
2323
{
24-
// Internal connection of exceptions since last clear.
25-
private List<Exception> _ActiveExceptionsList;
26-
2724
internal ILogger _logger;
2825

2926
#region Properties
@@ -79,16 +76,13 @@ public DataverseTraceLogger(string traceSourceName = "")
7976
TraceSourceName = traceSourceName;
8077
}
8178

82-
_ActiveExceptionsList = new List<Exception>();
83-
8479
base.Initialize();
8580
}
8681

8782
public DataverseTraceLogger(ILogger logger)
8883
{
8984
_logger = logger;
9085
TraceSourceName = DefaultTraceSourceName;
91-
_ActiveExceptionsList = new List<Exception>();
9286
base.Initialize();
9387
}
9488

@@ -98,7 +92,6 @@ public override void ResetLastError()
9892
if (base.LastError.Length > 0)
9993
base.LastError = base.LastError.Remove(0, LastError.Length - 1);
10094
LastException = null;
101-
_ActiveExceptionsList.Clear();
10295
}
10396

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

154-
StringBuilder detailedDump = new StringBuilder();
155-
StringBuilder lastMessage = new StringBuilder();
147+
StringBuilder detailedDump = new StringBuilder(4096);
148+
StringBuilder lastMessage = new StringBuilder(2048);
156149

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

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

163155
TraceEvent(eventType, (int)eventType, detailedDump.ToString(), exception);
164156
if (eventType == TraceEventType.Error)
165157
{
166158
base.LastError += lastMessage.ToString();
167-
if (!(exception != null && _ActiveExceptionsList.Contains(exception))) // Skip this line if its already been done.
159+
// check and or alter the exception is its and HTTPOperationExecption.
160+
if (exception is HttpOperationException httpOperationException)
168161
{
169-
// check and or alter the exception is its and HTTPOperationExecption.
170-
if (exception is HttpOperationException httpOperationException)
162+
string errorMessage = "Not Provided";
163+
if (!string.IsNullOrWhiteSpace(httpOperationException.Response.Content))
171164
{
172-
string errorMessage = "Not Provided";
173-
if (!string.IsNullOrWhiteSpace(httpOperationException.Response.Content))
174-
{
175-
JObject contentBody = JObject.Parse(httpOperationException.Response.Content);
176-
errorMessage = string.IsNullOrEmpty(contentBody["error"]["message"]?.ToString()) ? "Not Provided" : GetFirstLineFromString(contentBody["error"]["message"]?.ToString()).Trim();
177-
}
178-
179-
Utils.DataverseOperationException webApiExcept = new Utils.DataverseOperationException(errorMessage, httpOperationException);
180-
LastException = webApiExcept;
165+
JObject contentBody = JObject.Parse(httpOperationException.Response.Content);
166+
errorMessage = string.IsNullOrEmpty(contentBody["error"]["message"]?.ToString()) ? "Not Provided" : GetFirstLineFromString(contentBody["error"]["message"]?.ToString()).Trim();
181167
}
182-
else
183-
LastException = exception;
168+
169+
Utils.DataverseOperationException webApiExcept = new Utils.DataverseOperationException(errorMessage, httpOperationException);
170+
LastException = webApiExcept;
184171
}
172+
else
173+
LastException = exception;
185174
}
186-
_ActiveExceptionsList.Add(exception);
187175

188176
detailedDump.Clear();
189177
lastMessage.Clear();
@@ -196,18 +184,13 @@ public override void Log(string message, TraceEventType eventType, Exception exc
196184
/// <param name="exception"></param>
197185
public override void Log(Exception exception)
198186
{
199-
if (exception != null && _ActiveExceptionsList.Contains(exception))
200-
return; // already logged this one .
201-
202-
StringBuilder detailedDump = new StringBuilder();
203-
StringBuilder lastMessage = new StringBuilder();
187+
StringBuilder detailedDump = new StringBuilder(4096);
188+
StringBuilder lastMessage = new StringBuilder(2048);
204189
GetExceptionDetail(exception, detailedDump, 0, lastMessage);
205190
TraceEvent(TraceEventType.Error, (int)TraceEventType.Error, detailedDump.ToString(), exception);
206191
base.LastError += lastMessage.ToString();
207192
LastException = exception;
208193

209-
_ActiveExceptionsList.Add(exception);
210-
211194
detailedDump.Clear();
212195
lastMessage.Clear();
213196
}
@@ -594,7 +577,7 @@ private static string GenerateOrgErrorDetailsInfo(ErrorDetailCollection errorDet
594577
{
595578
if (errorDetails != null && errorDetails.Count > 0)
596579
{
597-
StringBuilder sw = new StringBuilder();
580+
StringBuilder sw = new StringBuilder(2048);
598581
sw.AppendLine("Error Details\t:");
599582
foreach (var itm in errorDetails)
600583
{
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
//using Microsoft.Rest;
2+
using Microsoft.PowerPlatform.Dataverse.Client.Exceptions;
3+
using Newtonsoft.Json.Linq;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Runtime.Serialization;
8+
9+
namespace Microsoft.PowerPlatform.Dataverse.Client.Utils
10+
{
11+
/// <summary>
12+
/// Used to encompass a ServiceClient Connection Centric exceptions
13+
/// </summary>
14+
[Serializable]
15+
public class DataverseConnectionException : Exception
16+
{
17+
/// <summary>
18+
/// Creates a dataverse connection Exception
19+
/// </summary>
20+
/// <param name="message">Error Message</param>
21+
public DataverseConnectionException(string message)
22+
: base(message)
23+
{
24+
}
25+
26+
/// <summary>
27+
/// Creates a dataverse connection Exception
28+
/// </summary>
29+
/// <param name="message">Error Message</param>
30+
/// <param name="innerException">Supporting Exception</param>
31+
public DataverseConnectionException(string message, Exception innerException)
32+
: base(message, innerException)
33+
{
34+
this.HResult = innerException.HResult;
35+
}
36+
37+
/// <summary>
38+
/// Creates a dataverse connection Exception
39+
/// </summary>
40+
/// <param name="message">Error Message</param>
41+
/// <param name="errorCode">Error code</param>
42+
/// <param name="data">Data Properties</param>
43+
/// <param name="helpLink">Help Link</param>
44+
/// <param name="httpOperationException"></param>
45+
public DataverseConnectionException(string message, int errorCode, string helpLink, IDictionary<string, string> data, HttpOperationException httpOperationException = null)
46+
: base(message, httpOperationException)
47+
{
48+
HResult = errorCode;
49+
HelpLink = helpLink;
50+
Source = "Dataverse Server API";
51+
foreach (var itm in data)
52+
{
53+
this.Data.Add(itm.Key, itm.Value);
54+
}
55+
}
56+
57+
/// <summary>
58+
/// Creates a Dataverse Connection Exception from an httpOperationError
59+
/// </summary>
60+
/// <param name="httpOperationException"></param>
61+
/// <returns></returns>
62+
public static DataverseConnectionException GenerateClientConnectionException(HttpOperationException httpOperationException)
63+
{
64+
string errorDetailPrefixString = "@Microsoft.PowerApps.CDS.ErrorDetails.";
65+
Dictionary<string, string> cdsErrorData = new Dictionary<string, string>();
66+
67+
JToken ErrorBlock = null;
68+
try
69+
{
70+
if (!string.IsNullOrWhiteSpace(httpOperationException.Response.Content))
71+
{
72+
JObject contentBody = JObject.Parse(httpOperationException.Response.Content);
73+
ErrorBlock = contentBody["error"];
74+
}
75+
}
76+
catch { }
77+
78+
if (ErrorBlock != null)
79+
{
80+
string errorMessage = DataverseTraceLogger.GetFirstLineFromString(ErrorBlock["message"]?.ToString()).Trim();
81+
var code = ErrorBlock["code"];
82+
int HResult = code != null && !string.IsNullOrWhiteSpace(code.ToString()) ? Convert.ToInt32(code.ToString(), 16) : -1;
83+
84+
string HelpLink = ErrorBlock["@Microsoft.PowerApps.CDS.HelpLink"]?.ToString();
85+
86+
foreach (var node in ErrorBlock.ToArray())
87+
{
88+
if (node.Path.Contains(errorDetailPrefixString))
89+
{
90+
cdsErrorData.Add(node.Value<JProperty>().Name.ToString().Replace(errorDetailPrefixString, string.Empty), node.HasValues ? node.Value<JProperty>().Value.ToString() : string.Empty);
91+
}
92+
}
93+
return new DataverseConnectionException(errorMessage, HResult, HelpLink, cdsErrorData, httpOperationException);
94+
}
95+
else
96+
return new DataverseConnectionException("Server Error, no error report generated from server", -1, string.Empty, cdsErrorData, httpOperationException);
97+
}
98+
}
99+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
//using Microsoft.Rest;
2+
using Microsoft.PowerPlatform.Dataverse.Client.Exceptions;
3+
using Newtonsoft.Json.Linq;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Runtime.Serialization;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
11+
namespace Microsoft.PowerPlatform.Dataverse.Client.Utils
12+
{
13+
/// <summary>
14+
/// Used to encompass a ServiceClient Operation Exception
15+
/// </summary>
16+
[Serializable]
17+
public class DataverseOperationException : Exception
18+
{
19+
/// <summary>
20+
/// Creates a CdsService Client Exception
21+
/// </summary>
22+
/// <param name="message">Error Message</param>
23+
public DataverseOperationException(string message)
24+
: base(message)
25+
{
26+
}
27+
28+
/// <summary>
29+
/// Creates a CdsService Client Exception
30+
/// </summary>
31+
/// <param name="message">Error Message</param>
32+
/// <param name="errorCode">Error code</param>
33+
/// <param name="data">Data Properties</param>
34+
/// <param name="helpLink">Help Link</param>
35+
/// <param name="httpOperationException"></param>
36+
public DataverseOperationException(string message, int errorCode, string helpLink, IDictionary<string, string> data, HttpOperationException httpOperationException = null)
37+
: base(message, httpOperationException)
38+
{
39+
HResult = errorCode;
40+
HelpLink = helpLink;
41+
Source = "Dataverse Server API";
42+
foreach (var itm in data)
43+
{
44+
this.Data.Add(itm.Key, itm.Value);
45+
}
46+
}
47+
48+
/// <summary>
49+
/// Creates a CdsService Client Exception from a httpOperationResult.
50+
/// </summary>
51+
/// <param name="httpOperationException"></param>
52+
public static DataverseOperationException GenerateClientOperationException(HttpOperationException httpOperationException)
53+
{
54+
string errorDetailPrefixString = "@Microsoft.PowerApps.CDS.ErrorDetails.";
55+
Dictionary<string, string> cdsErrorData = new Dictionary<string, string>();
56+
57+
JToken ErrorBlock = null;
58+
try
59+
{
60+
if (!string.IsNullOrWhiteSpace(httpOperationException.Response.Content))
61+
{
62+
JObject contentBody = JObject.Parse(httpOperationException.Response.Content);
63+
ErrorBlock = contentBody["error"];
64+
}
65+
}
66+
catch { }
67+
68+
if (ErrorBlock != null)
69+
{
70+
string errorMessage = DataverseTraceLogger.GetFirstLineFromString(ErrorBlock["message"]?.ToString()).Trim();
71+
var code = ErrorBlock["code"];
72+
int HResult = code != null && !string.IsNullOrWhiteSpace(code.ToString()) ? Convert.ToInt32(code.ToString(), 16) : -1;
73+
74+
string HelpLink = ErrorBlock["@Microsoft.PowerApps.CDS.HelpLink"]?.ToString();
75+
76+
foreach (var node in ErrorBlock.ToArray())
77+
{
78+
if (node.Path.Contains(errorDetailPrefixString))
79+
{
80+
cdsErrorData.Add(node.Value<JProperty>().Name.ToString().Replace(errorDetailPrefixString, string.Empty), node.HasValues ? node.Value<JProperty>().Value.ToString() : string.Empty);
81+
}
82+
}
83+
return new DataverseOperationException(errorMessage, HResult, HelpLink, cdsErrorData, httpOperationException);
84+
}
85+
else
86+
return new DataverseOperationException("Server Error, no error report generated from server", -1, string.Empty, cdsErrorData, httpOperationException);
87+
}
88+
89+
/// <summary>
90+
/// Creates a CdsService Client Exception
91+
/// </summary>
92+
/// <param name="message">Error Message</param>
93+
/// <param name="innerException">Supporting Exception</param>
94+
public DataverseOperationException(string message, Exception innerException)
95+
: base(message, innerException)
96+
{
97+
}
98+
99+
}
100+
}

0 commit comments

Comments
 (0)