Skip to content

Commit 38a9c31

Browse files
Merge branch 'beta' of https://github.com/genexuslabs/DotNetClasses into beta
2 parents df86506 + c370028 commit 38a9c31

File tree

12 files changed

+433
-15
lines changed

12 files changed

+433
-15
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
using System;
2+
using System.Diagnostics;
3+
using OpenTelemetry.Trace;
4+
5+
namespace GxClasses.Diagnostics.Opentelemetry
6+
{
7+
public class OtelSpan
8+
{
9+
private Activity _activity;
10+
public string Id
11+
{ get => _activity?.Id; }
12+
13+
public bool IsAllDataRequested
14+
{
15+
get
16+
{
17+
if (_activity != null)
18+
return _activity.IsAllDataRequested;
19+
return false;
20+
}
21+
}
22+
23+
public bool IsStopped
24+
{ get
25+
{
26+
if (_activity != null )
27+
return _activity.IsStopped;
28+
return false;
29+
}
30+
}
31+
32+
public SpanKind Kind
33+
{ get => (SpanKind)_activity?.Kind; }
34+
35+
public string ParentId
36+
{ get => _activity?.ParentId; }
37+
38+
public string ParentSpanId
39+
{ get => _activity?.ParentSpanId.ToString(); }
40+
41+
public string TraceId
42+
{ get => _activity?.TraceId.ToString(); }
43+
44+
public SpanStatusCode Status
45+
{ get => (SpanStatusCode)_activity?.Status; }
46+
47+
public enum SpanStatusCode
48+
{
49+
Unset,
50+
Ok,
51+
Error
52+
}
53+
54+
internal OtelSpan(Activity activity)
55+
{
56+
_activity = activity;
57+
}
58+
59+
public void Start()
60+
{
61+
_activity?.Start();
62+
}
63+
64+
public void Stop()
65+
{
66+
_activity?.Stop();
67+
}
68+
public void RecordException(string message)
69+
{
70+
_activity.RecordException(new Exception(message));
71+
}
72+
73+
public void SetTag(string property, string value)
74+
{
75+
_activity.SetTag(property, value);
76+
}
77+
public string GetTagItem(string property)
78+
{
79+
return _activity.GetTagItem(property).ToString();
80+
}
81+
public void AddBaggage(string property, string value)
82+
{
83+
_activity.AddBaggage(property, value);
84+
}
85+
public string GetBaggageItem(string property)
86+
{
87+
return _activity.GetBaggageItem(property).ToString();
88+
}
89+
public void SetStatus(SpanStatusCode spanStatusCode, string message)
90+
{
91+
_activity.SetStatus((ActivityStatusCode)spanStatusCode, message);
92+
}
93+
94+
public SpanStatusCode GetStatus()
95+
{
96+
return (SpanStatusCode)_activity.GetStatus().StatusCode;
97+
}
98+
99+
//ToDO
100+
//public void AddEvent()
101+
//{
102+
103+
//}
104+
105+
}
106+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Diagnostics;
2+
using GeneXus.Application;
3+
using GeneXus.Attributes;
4+
5+
namespace GxClasses.Diagnostics.Opentelemetry
6+
{
7+
[GXApi]
8+
public class OtelTracer
9+
{
10+
public enum SpanKind
11+
{
12+
Client,
13+
Consumer,
14+
Internal,
15+
Producer,
16+
Server
17+
}
18+
19+
public static OtelSpan CreateSpan(string name, SpanKind kind)
20+
{
21+
Activity activity = GXBaseObject.ActivitySource.StartActivity(name, (ActivityKind)kind);
22+
return new OtelSpan(activity);
23+
}
24+
25+
public static OtelSpan GetCurrent()
26+
{
27+
return new OtelSpan(Activity.Current);
28+
}
29+
30+
public static bool HasListeners()
31+
{
32+
return GXBaseObject.ActivitySource.HasListeners();
33+
}
34+
}
35+
}

dotnet/src/dotnetcore/GxClasses/Domain/JArray.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ namespace GeneXus.Application
4343
/// </remarks>
4444

4545
[ Serializable ]
46-
internal class JArray : CollectionBase
47-
{
46+
internal class JArray : CollectionBase, IJayrockCompatible
47+
{
4848
public JArray() {}
4949

5050
public JArray(IEnumerable collection)
@@ -187,7 +187,7 @@ protected override void OnValidate(object value)
187187

188188
public override string ToString()
189189
{
190-
return JSONHelper.WriteJSON(this);
190+
return TextJsonSerializer.SerializeToJayrockCompatibleJson(this);
191191
}
192192

193193

dotnet/src/dotnetcore/GxClasses/Domain/JNull.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,15 @@ namespace GeneXus.Application
3030

3131
/// <summary>
3232
/// Represent the one and only representation of the "null" value in JSON.
33-
/// </summary>
33+
/// </summary>
3434

35-
[ Serializable ]
36-
internal sealed class JNull
37-
{
35+
internal interface IJayrockCompatible
36+
{
37+
38+
}
39+
[ Serializable ]
40+
internal sealed class JNull : IJayrockCompatible
41+
{
3842
public static readonly JNull Value = new JNull();
3943

4044
public override string ToString()

dotnet/src/dotnetcore/GxClasses/Domain/JObject.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ namespace GeneXus.Application
1616
/// an instance is rendered as text.</para>
1717

1818
[ Serializable ]
19-
internal class JObject : OrderedDictionary
20-
{
19+
internal class JObject : OrderedDictionary, IJayrockCompatible
20+
{
2121
public JObject() {}
2222

2323
/// <summary>
@@ -115,7 +115,7 @@ public virtual ICollection Names
115115

116116
public override string ToString()
117117
{
118-
return JSONHelper.WriteJSON(this);
118+
return TextJsonSerializer.SerializeToJayrockCompatibleJson(this);
119119
}
120120

121121

dotnet/src/dotnetcore/GxClasses/GxClasses.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@
120120
</ItemGroup>
121121

122122
<ItemGroup>
123-
<Folder Include="Diagnostics\" />
124123
<Folder Include="Helpers\Cryptography\Hashing\" />
125124
<Folder Include="Domain\SD\" />
126125
<Folder Include="Attributes\" />

dotnet/src/dotnetcore/GxClasses/Helpers/GXGeographyCore.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections;
33
using System.Globalization;
44
using System.Runtime.Serialization;
5+
using System.Text.Json.Serialization;
56
#if NETCORE
67
using GeneXus.Application;
78
#else
@@ -206,6 +207,7 @@ internal static object STRingN(object instance, int i)
206207
[KnownType(typeof(System.Double[]))]
207208
[KnownType(typeof(System.Collections.ArrayList))]
208209
[DataContract]
210+
[JsonConverter(typeof(CustomGeospatialConverter))]
209211
public class Geospatial : IGeographicNative
210212
{
211213
static readonly IGXLogger log = GXLoggerFactory.GetLogger<GeneXus.Utils.Geospatial>();

dotnet/src/dotnetframework/GxClasses/Helpers/JSONHelper.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,22 @@ public override void Write(Utf8JsonWriter writer, object value, JsonSerializerOp
6565
throw new NotImplementedException();
6666
}
6767
}
68+
internal class CustomGeospatialConverter : JsonConverter<Geospatial>
69+
{
70+
public override Geospatial Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) =>
71+
throw new NotImplementedException("Deserialization is not supported.");
72+
73+
public override void Write(Utf8JsonWriter writer, Geospatial value, JsonSerializerOptions options)
74+
{
75+
string stringValue = value?.ToString();
76+
JsonSerializer.Serialize(writer, stringValue, options);
77+
}
78+
}
6879
internal class CustomDateTimeConverter : JsonConverter<DateTime>
6980
{
7081
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
7182
{
72-
throw new NotImplementedException();
83+
throw new NotImplementedException("Deserialization is not supported.");
7384
}
7485

7586
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
@@ -91,11 +102,20 @@ internal override T ReadJSON<T>(string json)
91102
return JsonSerializer.Deserialize<T>(json, opts);
92103
}
93104
internal override string WriteJSON<T>(T kbObject)
105+
{
106+
if (kbObject != null)
107+
{
108+
return kbObject.ToString();
109+
}
110+
return null;
111+
}
112+
internal static string SerializeToJayrockCompatibleJson<T>(T value) where T : IJayrockCompatible
94113
{
95114
JsonSerializerOptions opts = new JsonSerializerOptions();
96115
opts.Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping;
97116
opts.Converters.Add(new CustomDateTimeConverter());
98-
return JsonSerializer.Serialize<T>(kbObject, opts);
117+
opts.NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals;
118+
return JsonSerializer.Serialize(value, opts);
99119
}
100120
}
101121
#else

dotnet/src/dotnetframework/GxClasses/Reorg/GXReorg.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ protected virtual void ExecutePrivate()
5858
{
5959

6060
}
61-
public IGxContext context
61+
protected virtual void ExecuteImpl()
62+
{
63+
ExecutePrivate();
64+
}
65+
public IGxContext context
6266
{
6367
get { return _Context; }
6468
set { _Context = value; }

dotnet/test/DotNetCoreUnitTest/StringUtil/JsonUtilTest.cs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using GeneXus.Application;
55
using GeneXus.Utils;
66
using System.ServiceModel;
7+
using GeneXus.Programs;
78
#if !NETCORE
89
using Jayrock.Json;
910
#endif
@@ -13,6 +14,41 @@ namespace xUnitTesting
1314
{
1415
public class JsonUtilTest
1516
{
17+
[Fact]
18+
public void PropertiesSerialization()
19+
{
20+
GXProperties AV9properties = new GXProperties();
21+
string url = "http://localhost/OuvidoriaOuvidoriaAndroidHomologa/login.aspx?pmsa";
22+
string user = "mpsa";
23+
string AV8json = "{\"Url\" : \""+ url + "\",\"User\" : \"" + user + "\"}";
24+
AV9properties.FromJSonString(AV8json, null);
25+
GxKeyValuePair AV10property = AV9properties.GetFirst();
26+
Assert.Equal("Url", AV10property.Key);
27+
Assert.Equal(url, AV10property.Value);
28+
AV10property = AV9properties.GetNext();
29+
Assert.Equal("User", AV10property.Key);
30+
Assert.Equal(user, AV10property.Value);
31+
32+
}
33+
[Fact]
34+
public void StringSerialization()
35+
{
36+
string result = JSONHelper.WriteJSON<dynamic>("myvalue");
37+
Assert.Equal("myvalue", result);
38+
39+
}
40+
[Fact]
41+
public void SerializationFloatingNumbers()
42+
{
43+
SdtSDTGeneric genericSdt = new SdtSDTGeneric();
44+
genericSdt.gxTpr_Itemnum = 1;
45+
genericSdt.gxTpr_Itemchar = "Caso Base";
46+
genericSdt.gxTpr_Itemgeopoint = new Geospatial("POINT(-56.248367 -34.873821)");
47+
genericSdt.gxTpr_Itemgeography = new Geospatial("-34.873821, -56.248367");
48+
string json = genericSdt.ToJSonString();
49+
string expectedJson = "{\"ItemNum\":1,\"ItemChar\":\"Caso Base\",\"ItemGeoPoint\":\"POINT (-56.248367 -34.873821)\",\"ItemGeography\":\"\",\"ItemGEolocation\":\"\"}";
50+
Assert.Equal(expectedJson, json);
51+
}
1652
[Fact]
1753
public void DeserializationInvalidJsonNoDuplicateError()
1854
{
@@ -80,7 +116,7 @@ public void DeserializationWithNumbers()
80116
}
81117

82118
[Fact]
83-
public void SerializationWithBigDecimalsTest_Issue70446()
119+
public void DeserializationWithBigDecimalsTest_Issue70446()
84120
{
85121
decimal expectedBigdecimal = 53903859.09090909M;
86122
GxContext context = new GxContext();
@@ -92,6 +128,20 @@ public void SerializationWithBigDecimalsTest_Issue70446()
92128
Assert.Equal("um", sdt.gxTpr_Testename);
93129
}
94130
[Fact]
131+
public void SerializationWithBigDecimalsTest_Issue70446()
132+
{
133+
decimal expectedBigdecimal = 53903859.09090909M;
134+
GxContext context = new GxContext();
135+
SdtSDTteste sdt = new SdtSDTteste(context);
136+
sdt.gxTpr_Testeid = 1;
137+
sdt.gxTpr_Testename = "um";
138+
sdt.gxTpr_Testenumero = expectedBigdecimal;
139+
140+
string expectedJson = "{\"testeID\":1,\"testeName\":\"um\",\"testeNumero\":\"53903859.09090909\"}";
141+
string json = sdt.ToJSonString();
142+
Assert.Equal(expectedJson, json);
143+
}
144+
[Fact]
95145
public void SerializationWithSpecialCharacters_Issue69271()
96146
{
97147
string specialCharacters = $"1:{StringUtil.Chr(30)}:1-2:{StringUtil.Chr(29)}:2";

0 commit comments

Comments
 (0)