Skip to content

Commit

Permalink
Using new extension method string.ToXml everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
rappen committed Aug 16, 2023
1 parent 5eb779a commit 0d107f4
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 49 deletions.
9 changes: 3 additions & 6 deletions FetchXmlBuilder/AppCode/QueryInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Rappen.XRM.Helpers.Extensions;
using Rappen.XRM.Helpers.FetchXML;
using System;
using System.Xml;
Expand Down Expand Up @@ -27,9 +28,7 @@ public QueryBase Query
query = value;
if (query is FetchExpression fetch)
{
var fetchdoc = new XmlDocument();
fetchdoc.LoadXml(fetch.Query);
if (fetchdoc.SelectSingleNode("fetch") is XmlElement fetchnode)
if (fetch.Query.ToXml().SelectSingleNode("fetch") is XmlElement fetchnode)
{
PageSize = Math.Min(fetchnode.AttributeInt("count") ?? 5000, 5000);
PageNo = fetchnode.AttributeInt("page") ?? 1;
Expand All @@ -46,9 +45,7 @@ public EntityCollection Results
result = value;
if (!string.IsNullOrEmpty(result.PagingCookie))
{
var cookdoc = new XmlDocument();
cookdoc.LoadXml(result.PagingCookie);
if (cookdoc.SelectSingleNode("cookie") is XmlElement cookie &&
if (result.PagingCookie.ToXml().SelectSingleNode("cookie") is XmlElement cookie &&
cookie.AttributeInt("page") is int page)
{
PageNo = page;
Expand Down
10 changes: 3 additions & 7 deletions FetchXmlBuilder/Builder/TreeNodeHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Rappen.XRM.Helpers.FetchXML;
using Rappen.XRM.Helpers.Extensions;
using Rappen.XRM.Helpers.FetchXML;
using Rappen.XTB.FetchXmlBuilder.DockControls;
using Rappen.XTB.FetchXmlBuilder.Settings;
using System.Collections.Generic;
Expand Down Expand Up @@ -544,12 +545,7 @@ internal static TreeNode AddChildNode(TreeNode parentNode, string name, FetchXml
return childNode;
}

internal static bool IsFetchAggregate(string fetch)
{
var xml = new XmlDocument();
xml.LoadXml(fetch);
return IsFetchAggregate(xml);
}
internal static bool IsFetchAggregate(string fetch) => IsFetchAggregate(fetch.ToXml());

private static bool IsFetchAggregate(XmlDocument xml)
{
Expand Down
6 changes: 3 additions & 3 deletions FetchXmlBuilder/Converters/CSharpCodeGeneratorFetchXML.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Rappen.XTB.FetchXmlBuilder.Settings;
using Rappen.XRM.Helpers.Extensions;
using Rappen.XTB.FetchXmlBuilder.Settings;
using System.Collections.Generic;
using System.Linq;
using System.Security;
Expand All @@ -12,8 +13,7 @@ public class CSharpCodeGeneratorFetchXML
public static string GetCSharpFetchXMLCode(string fetchXml, CodeGenerators codesettings)
{
var data = new Dictionary<string, string>();
var xml = new XmlDocument();
xml.LoadXml(fetchXml);
var xml = fetchXml.ToXml();

if (codesettings.FilterVariables)
{
Expand Down
5 changes: 2 additions & 3 deletions FetchXmlBuilder/Converters/JavascriptCodeGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using Rappen.XRM.Helpers.Extensions;
using System.Collections.Generic;
using System.Linq;
using System.Security;
Expand All @@ -12,10 +13,8 @@ public static string GetJavascriptCode(string fetchXml)
{
var data = new Dictionary<string, string>();
var lines = new List<string>();
var xml = new XmlDocument();
xml.LoadXml(fetchXml);

Convert(xml.DocumentElement, 0, lines, data);
Convert(fetchXml.ToXml().DocumentElement, 0, lines, data);

var js = "";

Expand Down
4 changes: 2 additions & 2 deletions FetchXmlBuilder/DockControls/ResultGrid.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Metadata;
using Microsoft.Xrm.Sdk.Query;
using Rappen.XRM.Helpers.Extensions;
using Rappen.XTB.FetchXmlBuilder.AppCode;
using Rappen.XTB.FetchXmlBuilder.Extensions;
using Rappen.XTB.FetchXmlBuilder.Views;
Expand Down Expand Up @@ -352,8 +353,7 @@ private void RetrievePageNo(int page)
{
if (queryinfo.Query is FetchExpression fetchexpr)
{
var fetchdoc = new XmlDocument();
fetchdoc.LoadXml(fetchexpr.Query);
var fetchdoc = fetchexpr.Query.ToXml();
var fetchnode = fetchdoc.SelectSingleNode("fetch") as XmlElement;
fetchnode.SetAttribute("page", page.ToString());
form.FetchResults(fetchdoc.OuterXml);
Expand Down
6 changes: 2 additions & 4 deletions FetchXmlBuilder/DockControls/XmlContentControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ internal void SetFormat(SaveFormat saveFormat)

internal static string GetFetchMini(string fetchxml, char quotationchar = '\'', bool removecomments = true)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(fetchxml);
XmlDocument doc = fetchxml.ToXml();
var comments = doc.SelectNodes("//comment()");
if (comments.Count > 0 && removecomments)
{
Expand Down Expand Up @@ -809,8 +808,7 @@ private void UpdateQueryBuild(string action, bool live)
{
try
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(txtXML.Text);
XmlDocument doc = txtXML.Text.ToXml();
if (doc.OuterXml != liveUpdateXml)
{
switch (contenttype)
Expand Down
5 changes: 2 additions & 3 deletions FetchXmlBuilder/Extensions/ServiceExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using System.Xml;
using Rappen.XRM.Helpers.Extensions;

namespace Rappen.XTB.FetchXmlBuilder.Extensions
{
Expand All @@ -21,8 +21,7 @@ public static string QueryExpressionToFetchXml(this IOrganizationService organiz
Query = query
};
QueryExpressionToFetchXmlResponse response = (QueryExpressionToFetchXmlResponse)organizationService.Execute(request);
var doc = new XmlDocument();
doc.LoadXml(response.FetchXml);
var doc = response.FetchXml.ToXml();
var fetchnode = doc.SelectSingleNode("fetch");
if (fetchnode != null && fetchnode.Attributes["useraworderby"] != null)
{
Expand Down
11 changes: 3 additions & 8 deletions FetchXmlBuilder/FXBQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,7 @@ internal void StringQueryExpressionToFetchXml(string query, QExStyleEnum style)
}
else if (completedargs.Result is string)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(completedargs.Result.ToString());
dockControlBuilder.Init(doc.OuterXml, null, $"parse {style}", true);
dockControlBuilder.Init(completedargs.Result.ToString().ToXml().OuterXml, null, $"parse {style}", true);
}
working = false;
}
Expand Down Expand Up @@ -262,9 +260,7 @@ private void ExecuteFetch(string fetch)
}
else if (completedargs.Result is string)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(completedargs.Result.ToString());
ShowResultControl(doc.OuterXml, ContentType.FetchXML_Result, SaveFormat.XML, settings.DockStates.FetchResult);
ShowResultControl(completedargs.Result.ToString().ToXml().OuterXml, ContentType.FetchXML_Result, SaveFormat.XML, settings.DockStates.FetchResult);
}
}
});
Expand Down Expand Up @@ -328,8 +324,7 @@ private void RetrieveMultiple(string fetch)
}
else if (query is FetchExpression fex && fex.Query is string pagefetch)
{
var pagedoc = new XmlDocument();
pagedoc.LoadXml(pagefetch);
var pagedoc = pagefetch.ToXml();
if (pagedoc.SelectSingleNode("fetch") is XmlElement fetchnode)
{
if (!int.TryParse(fetchnode.GetAttribute("page"), out int pageno))
Expand Down
9 changes: 3 additions & 6 deletions FetchXmlBuilder/Forms/SelectAttributesDialog.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Metadata;
using Microsoft.Xrm.Sdk.Query;
using Rappen.XRM.Helpers.Extensions;
using Rappen.XTB.FetchXmlBuilder.Extensions;
using Rappen.XTB.XmlEditorUtils;
using System;
Expand Down Expand Up @@ -193,9 +194,7 @@ private void SetViewColumns(EntityCollection views)
foreach (var view in views.Entities)
{
var layout = view.GetAttributeValue<string>("layoutxml");
var layoutdoc = new XmlDocument();
layoutdoc.LoadXml(layout);
if (layoutdoc.SelectSingleNode("grid") is XmlElement grid &&
if (layout.ToXml().SelectSingleNode("grid") is XmlElement grid &&
grid.SelectSingleNode("row") is XmlElement row)
{
viewcolumns.AddRange(row.ChildNodes
Expand All @@ -213,9 +212,7 @@ private void SetFormColumns(EntityCollection forms)
foreach (var form in forms.Entities)
{
var formxml = form.GetAttributeValue<string>("formxml");
var formdoc = new XmlDocument();
formdoc.LoadXml(formxml);
var nodes = formdoc.ChildNodes;
var nodes = formxml.ToXml().ChildNodes;
foreach (XmlNode node in nodes)
{
formcolumns.AddRange(FindCellControlFields(node));
Expand Down
10 changes: 4 additions & 6 deletions FetchXmlBuilder/Views/LayoutXML.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Rappen.XTB.FetchXmlBuilder.Builder;
using Microsoft.Xrm.Sdk.Metadata;
using Rappen.XRM.Helpers.Extensions;
using Rappen.XTB.FetchXmlBuilder.Builder;
using Rappen.XTB.FetchXmlBuilder.Extensions;
using Microsoft.Xrm.Sdk.Metadata;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
Expand Down Expand Up @@ -58,9 +58,7 @@ public LayoutXML(string layoutxmlstr, FetchXmlBuilder fxb)
if (!string.IsNullOrEmpty(layoutxmlstr))
{
createdfromaview = fxb.View != null;
var doc = new XmlDocument();
doc.LoadXml(layoutxmlstr);
if (doc.SelectSingleNode("grid") is XmlElement grid)
if (layoutxmlstr.ToXml().SelectSingleNode("grid") is XmlElement grid)
{
if (int.TryParse(grid.AttributeValue("object"), out int entityid))
{
Expand Down

0 comments on commit 0d107f4

Please sign in to comment.