Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Revert "Switch to using System.Text.Json instead of Newtonsoft to improve performance." #784

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ namespace Diagnostics.DataProviders
{
public class KustoQuery
{
public string Text { get; set; }
public string Url { get; set; }
public string KustoDesktopUrl { get; set; }
public string OperationName { get; set; }
public string Text;
public string Url;
public string KustoDesktopUrl;
public string OperationName;
}

public class KustoDataProvider : DiagnosticDataProvider, IKustoDataProvider
Expand Down
5 changes: 3 additions & 2 deletions src/Diagnostics.DataProviders/HealthCheckResult.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Diagnostics.DataProviders
{
Expand All @@ -14,7 +15,7 @@ public enum HealthStatus
/// </summary>
public sealed class HealthCheckResult
{
[JsonConverter(typeof(JsonStringEnumConverter))]
[JsonConverter(typeof(StringEnumConverter))]
public HealthStatus Status { get; private set; }
public string Name { get; private set; }
public string Description { get; private set; }
Expand Down
4 changes: 2 additions & 2 deletions src/Diagnostics.DataProviders/KustoSDKClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,9 @@ private void LogKustoQuery(string query, string cluster, string operationName, S
if (dataSet != null && dataSet.Tables != null && dataSet.Tables.Count >= 4)
{
var statisticsTable = dataSet.Tables[dataSet.Tables.Count - 2].ToDataTableResponseObject();
if (statisticsTable.Rows.Length >= 2 && statisticsTable.Rows[1].Length >= 5)
if (statisticsTable.Rows.GetLength(0) >= 2 && statisticsTable.Rows.GetLength(1) >= 5)
{
stats = statisticsTable.Rows[1][4];
stats = statisticsTable.Rows[1, 4];
}
}

Expand Down
32 changes: 5 additions & 27 deletions src/Diagnostics.ModelsAndUtils/Attributes/Definition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
// </copyright>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text.Json.Serialization;
using Diagnostics.ModelsAndUtils.Models;
using Newtonsoft.Json;

namespace Diagnostics.ModelsAndUtils.Attributes
{
Expand Down Expand Up @@ -57,38 +56,17 @@ public Definition()

/// <summary>
/// List of Support Topics for which this detector is enabled.
/// Mark it as JsonIgnore because the SupportTopic class is deriving
/// from Attribute and attributes are not serialized by System.Text.Json
/// </summary>
[JsonIgnore]
public IEnumerable<SupportTopic> SupportTopicList { get; set; }

/// <summary>
/// Property created only for Json Serialization as Attributes
/// are not serialized today properly by System.Text.Json
/// https://github.com/dotnet/runtime/issues/58947
/// </summary>
[DataMember]
[JsonPropertyName("supportTopicList")]
public IEnumerable<SupportTopicSTJCompat> SupportTopicListSTJCompat
{
get
{
if (SupportTopicList == null)
{
return null;
}

return SupportTopicList
.Where(st => st != null)
.Select(x => new SupportTopicSTJCompat(x));
}
}
public IEnumerable<SupportTopic> SupportTopicList { get; set; }

[JsonIgnore]
public string AnalysisType { get; set; } = string.Empty;

[JsonIgnore]
private Guid instanceGUID;

[JsonIgnore]
public override object TypeId { get { return (object)instanceGUID; } }

/// <summary>
Expand Down
30 changes: 0 additions & 30 deletions src/Diagnostics.ModelsAndUtils/Attributes/SupportTopic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,4 @@ public bool Equals(SupportTopic other)
return (this.Id == other.Id && this.PesId == other.PesId);
}
}

/// <summary>
/// Class created just for Json Serialization as Attributes
/// are not serialized properly to Json using System.Text.Json
/// https://github.com/dotnet/runtime/issues/58947
/// </summary>
public class SupportTopicSTJCompat
{
/// <summary>
/// Support Topic Id
/// </summary>
/// See <see href="http://aka.ms/selfhelppreview"/>
public string Id { get; set; }

/// <summary>
/// Unique resource Id.
/// </summary>
public string PesId { get; set; }

public SupportTopicSTJCompat(SupportTopic st)
{
if (st == null)
{
throw new ArgumentNullException(nameof(st));
}

this.Id = st.Id;
this.PesId = st.Id;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Diagnostics.ModelsAndUtils.Models
{
public class DataProviderMetadata
{
public string ProviderName { get; set; }
public string ProviderName;
public List<KeyValuePair<string, object>> PropertyBag { get; }

public DataProviderMetadata()
Expand Down
15 changes: 9 additions & 6 deletions src/Diagnostics.ModelsAndUtils/Models/DataTableResponseObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class DataTableResponseObject

public IEnumerable<DataTableResponseColumn> Columns { get; set; }

public dynamic[][] Rows { get; set; }
public dynamic[,] Rows { get; set; }
}

public class DataTableResponseColumn
Expand All @@ -41,7 +41,7 @@ public class AppInsightsDataTableResponseObject
{
public string Name { get; set; }
public IEnumerable<AppInsightsDataTableResponseColumn> Columns { get; set; }
public dynamic[][] Rows { get; set; }
public dynamic[,] Rows { get; set; }
}

public class AppInsightsDataTableResponseColumn
Expand All @@ -68,7 +68,7 @@ public static DataTable ToDataTable(this DataTableResponseObject dataTableRespon
var row = dataTable.NewRow();
for (int j = 0; j < dataTable.Columns.Count; j++)
{
row[j] = dataTableResponse.Rows[i][j] ?? DBNull.Value;
row[j] = dataTableResponse.Rows[i, j] ?? DBNull.Value;
}

dataTable.Rows.Add(row);
Expand All @@ -92,7 +92,7 @@ public static DataTable ToAppInsightsDataTable(this AppInsightsDataTableResponse
var row = dataTable.NewRow();
for (int j = 0; j < dataTable.Columns.Count; j++)
{
row[j] = MaskPII(appInsightsDataTableResponse.Rows[i][j]) ?? DBNull.Value;
row[j] = MaskPII(appInsightsDataTableResponse.Rows[i, j]) ?? DBNull.Value;
}

dataTable.Rows.Add(row);
Expand Down Expand Up @@ -125,11 +125,14 @@ public static DataTableResponseObject ToDataTableResponseObject(this DataTable t
columns.Add(new DataTableResponseColumn() { ColumnName = col.ColumnName, DataType = col.DataType.ToString().Replace("System.", "") });
}

var rows = new dynamic[table.Rows.Count][];
var rows = new dynamic[table.Rows.Count, table.Columns.Count];

for (int i = 0; i < table.Rows.Count; i++)
{
rows[i] = table.Rows[i].ItemArray;
for (int j = 0; j < table.Columns.Count; j++)
{
rows[i, j] = table.Rows[i][j] == DBNull.Value ? null : table.Rows[i][j];
}
}

dataTableResponseObject.Columns = columns;
Expand Down
6 changes: 3 additions & 3 deletions src/Diagnostics.ModelsAndUtils/Models/DetectorType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.
// </copyright>


using System.Text.Json.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Diagnostics.ModelsAndUtils.Models
{
/// <summary>
/// Defines whether the Detector is of type Analysis or not.
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter))]
[JsonConverter(typeof(StringEnumConverter))]
public enum DetectorType
{
/// <summary>
Expand Down
1 change: 0 additions & 1 deletion src/Diagnostics.ModelsAndUtils/Models/Response.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text.Json.Serialization;
using Diagnostics.ModelsAndUtils.Attributes;
using Diagnostics.ModelsAndUtils.Models.ResponseExtensions;

Expand Down
18 changes: 9 additions & 9 deletions src/Diagnostics.ModelsAndUtils/Models/ResponseExtensions/Card.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.Data;
using System.Text.Json;
using System.Text.Json.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Diagnostics.ModelsAndUtils.Models.ResponseExtensions
{
Expand All @@ -16,12 +16,12 @@ public class Card
/// <summary>
/// Title of the Card
/// </summary>
public string Title { get; set; }
public string Title;

/// <summary>
/// A list of descriptions for this card
/// </summary>
public List<string> Descriptions { get; set; }
public List<string> Descriptions;

/// <summary>
/// Specify and icon from the font-awesome collection (for e.g. fa-circle)
Expand All @@ -31,13 +31,13 @@ public class Card
/// <summary>
/// Specify the action type for this card
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter))]
public CardActionType ActionType { get; set; }
[JsonConverter(typeof(StringEnumConverter))]
public CardActionType ActionType;

/// <summary>
/// Specify the action value for the card (will be detectorId for detectors)
/// </summary>
public string ActionValue { get; set; }
public string ActionValue;

/// <summary>
/// Creates an instance of Card class.
Expand Down Expand Up @@ -105,8 +105,8 @@ public static DiagnosticData AddCards(this Response response, List<Card> cards)
table.Rows.Add(new object[] {
card.Title,
card.Icon,
JsonSerializer.Serialize(card.Descriptions),
JsonSerializer.Serialize(card.ActionType),
JsonConvert.SerializeObject(card.Descriptions),
JsonConvert.SerializeObject(card.ActionType),
card.ActionValue
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public class DownTime
/// <summary>
/// Represents the start time for the downtime period
/// </summary>
public DateTime StartTime { get; set; } = DateTime.SpecifyKind(DateTime.MinValue, DateTimeKind.Utc);
public DateTime StartTime { get; set; } = DateTime.MinValue;

/// <summary>
/// The end time for the downtime period
/// </summary>
public DateTime EndTime { get; set; } = DateTime.SpecifyKind(DateTime.MinValue, DateTimeKind.Utc);
public DateTime EndTime { get; set; } = DateTime.MinValue;

/// <summary>
/// A optional label that if specified can be used to render a label or span in downtime analysis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Diagnostics.ModelsAndUtils.Models.ResponseExtensions
{
Expand All @@ -25,7 +25,7 @@ public Guage(InsightStatus status, double percentFilled, string displayValue, st
/// <summary>
/// Insight Level for the Guage. Decides the color of the Guage. Red for Critical, Orange for Warning, Green for Success and Blue for Info & None.
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter))]
[JsonConverter(typeof(StringEnumConverter))]
public InsightStatus Status { get; set; }

private double _percentFilled;
Expand Down Expand Up @@ -61,7 +61,7 @@ public double PercentFilled
/// <summary>
/// Size of the Guage. Can be either Small, Medium or Large
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter))]
[JsonConverter(typeof(StringEnumConverter))]
public GuageSize Size { get; set; }

/// <summary>
Expand Down Expand Up @@ -159,8 +159,8 @@ public static DiagnosticData AddGuages(this Response response, List<Guage> guage
foreach (Guage g in guages)
{
table.Rows.Add(
JsonSerializer.Serialize(renderDirection),
JsonSerializer.Serialize(g.Size),
JsonConvert.SerializeObject(renderDirection),
JsonConvert.SerializeObject(g.Size),
g.Status,
g.PercentFilled,
g.DisplayValue,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Diagnostics.ModelsAndUtils.ScriptUtilities;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Diagnostics.ModelsAndUtils.Models.ResponseExtensions
{
Expand All @@ -24,7 +25,7 @@ public class Solution
/// <summary>
/// Denotes which action will be performed, such as calling an ARM API or navigating to a Portal Blade.
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter))]
[JsonConverter(typeof(StringEnumConverter))]
public ActionType Action { get; set; }

/// <summary>
Expand Down Expand Up @@ -121,10 +122,10 @@ public class SolutionButtonOption
{
public string Label { get; set; }

[JsonConverter(typeof(JsonStringEnumConverter))]
[JsonConverter(typeof(StringEnumConverter))]
public SolutionButtonType Type { get; set; } = SolutionButtonType.Button;

[JsonConverter(typeof(JsonStringEnumConverter))]
[JsonConverter(typeof(StringEnumConverter))]
public SolutionButtonPosition Position { get; set; } = SolutionButtonPosition.Bottom;

public SolutionButtonOption(string label, SolutionButtonType type = SolutionButtonType.Button, SolutionButtonPosition position = SolutionButtonPosition.Bottom)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text.Json.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Diagnostics.ModelsAndUtils.Models.ResponseExtensions
{
Expand Down Expand Up @@ -43,7 +44,7 @@ public class SummaryCard
/// <summary>
/// Spicfy the status(Critical,Warning,Info,Success,None) shown as icon in middle left card
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter))]
[JsonConverter(typeof(StringEnumConverter))]
public SummaryCardStatus Status { set; get; }

/// <summary>
Expand All @@ -54,7 +55,7 @@ public class SummaryCard
/// <summary>
/// Spicfy the Action Type(Detector,Tool)
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter))]
[JsonConverter(typeof(StringEnumConverter))]
public SummaryCardActionType OnClickActionType { set; get; }

/// <summary>
Expand Down
Loading