Skip to content

Commit

Permalink
Small fixes for FetchXML code type
Browse files Browse the repository at this point in the history
  • Loading branch information
rappen committed Dec 11, 2022
1 parent d83aae8 commit fbd37a5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
31 changes: 17 additions & 14 deletions FetchXmlBuilder/Converters/CSharpCodeGeneratorFetchXML.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using Rappen.XTB.FetchXmlBuilder.Settings;
using System.Collections.Generic;
using System.Linq;
using System.Security;
using System.Text;
Expand All @@ -8,28 +9,30 @@ namespace Rappen.XTB.FetchXmlBuilder.Converters
{
public class CSharpCodeGeneratorFetchXML
{
public static string GetCSharpFetchXMLCode(string fetchXml)
public static string GetCSharpFetchXMLCode(string fetchXml, CodeGenerators codesettings)
{
var data = new Dictionary<string, string>();
var xml = new XmlDocument();
xml.LoadXml(fetchXml);

var conditionAttributes = xml.SelectNodes("//condition/@value");

foreach (XmlAttribute attribute in conditionAttributes)
if (codesettings.FilterVariables)
{
var value = AddData(attribute.OwnerElement.GetAttribute("attribute"), attribute.Value, data);
attribute.Value = $"{{{value}}}";
}
var conditionAttributes = xml.SelectNodes("//condition/@value");

var conditionValues = xml.SelectNodes("//condition/value");
foreach (XmlAttribute attribute in conditionAttributes)
{
var value = AddData(attribute.OwnerElement.GetAttribute("attribute"), attribute.Value, data);
attribute.Value = $"{{{value}}}";
}

foreach (XmlElement val in conditionValues)
{
var value = AddData(((XmlElement)val.ParentNode).GetAttribute("attribute"), val.InnerText.Trim(), data);
val.InnerText = $"{{{value}}}";
}
var conditionValues = xml.SelectNodes("//condition/value");

foreach (XmlElement val in conditionValues)
{
var value = AddData(((XmlElement)val.ParentNode).GetAttribute("attribute"), val.InnerText.Trim(), data);
val.InnerText = $"{{{value}}}";
}
}
var cs = "";

if (data.Count > 0)
Expand Down
9 changes: 9 additions & 0 deletions FetchXmlBuilder/DockControls/XmlContentControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,15 @@ private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs
private void cmbQExStyle_SelectedIndexChanged(object sender, EventArgs e)
{
fxb.settings.CodeGenerators.QExStyle = (cmbQExStyle.SelectedItem is QExStyle style) ? style.Tag : QExStyleEnum.QueryExpression;
rbQExObjectinitializer.Enabled = fxb.settings.CodeGenerators.QExStyle != QExStyleEnum.FetchXML;
cmbQExFlavor.Enabled = fxb.settings.CodeGenerators.QExStyle != QExStyleEnum.FetchXML;
chkQExComments.Enabled = fxb.settings.CodeGenerators.QExStyle != QExStyleEnum.FetchXML;
if (fxb.settings.CodeGenerators.QExStyle == QExStyleEnum.FetchXML)
{
rbQExLineByLine.Checked = true;
cmbQExFlavor.SelectedIndex = -1;
chkQExComments.Checked = false;
}
fxb.UpdateLiveXML();
}

Expand Down
2 changes: 1 addition & 1 deletion FetchXmlBuilder/FetchXmlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ private string GetQueryExpressionCode()
{
case QExStyleEnum.FetchXML:
var fetch = dockControlBuilder.GetFetchString(true, false);
return CSharpCodeGeneratorFetchXML.GetCSharpFetchXMLCode(fetch);
return CSharpCodeGeneratorFetchXML.GetCSharpFetchXMLCode(fetch, settings.CodeGenerators);

case QExStyleEnum.QueryExpression:
case QExStyleEnum.OrganizationServiceContext:
Expand Down

0 comments on commit fbd37a5

Please sign in to comment.