Skip to content

Commit 9a1d80f

Browse files
committed
Using XmlAtomicStore plus newest Supporting
1 parent 77700b3 commit 9a1d80f

File tree

5 files changed

+37
-52
lines changed

5 files changed

+37
-52
lines changed

FetchXmlBuilder/Converters/LCG/ConfigurationUtils.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
using McTools.Xrm.Connection;
1+
using Rappen.XTB.Helpers;
22
using System.IO;
33

4-
namespace Rappen.XTB.Helper
4+
namespace Rappen.XTB.Helpers
55
{
66
public static class ConfigurationUtils
77
{
8-
public static T GetEmbeddedConfiguration<T>(string filename, string begintoken, string endtoken)
8+
public static T GetEmbeddedConfiguration<T>(string filename, string begintoken, string endtoken) where T : new()
99
{
1010
var csfile = File.ReadAllText(filename);
1111
var configstr = csfile.GetTextBetween(begintoken, endtoken, false);
@@ -19,7 +19,7 @@ public static T GetEmbeddedConfiguration<T>(string filename, string begintoken,
1919
{
2020
throw new FileLoadException($"Could not find {configname} XML in file.", filename);
2121
}
22-
var inlinesettings = (T)XmlSerializerHelper.Deserialize(configstr, typeof(T));
22+
var inlinesettings = XmlAtomicStore.Deserialize<T>(configstr);
2323
return inlinesettings;
2424
}
2525

@@ -48,4 +48,4 @@ private static string GetTextBetween(this string text, string begin, string end,
4848
return text;
4949
}
5050
}
51-
}
51+
}

FetchXmlBuilder/DockControls/AiChatControl.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ namespace Rappen.XTB.FetchXmlBuilder.DockControls
2222
{
2323
public partial class AiChatControl : WeifenLuo.WinFormsUI.Docking.DockContent
2424
{
25+
private const string GeneralSettingsURL = "https://rappen.github.io/Tools/";
26+
private const string AiUsersFileName = "Rappen.XTB.AI.Settings.xml";
27+
2528
private FetchXmlBuilder fxb;
2629
private AIAppInsights ai;
2730
private ChatMessageHistory chatHistory;
@@ -185,9 +188,7 @@ internal static bool IsFreeAiUser(PluginControlBase tool)
185188
{
186189
if (freeusers == null)
187190
{
188-
freeusers = new Uri("https://rappen.github.io/Tools/Rappen.XTB.AI.Users.xml")
189-
.DownloadXml(new List<AiUser>())
190-
.ToList();
191+
freeusers = XmlAtomicStore.DownloadXml<List<AiUser>>(GeneralSettingsURL, AiUsersFileName, Paths.SettingsPath);
191192
}
192193
return freeusers?.Any(u =>
193194
u.ToolName == tool.ToolName &&
@@ -507,7 +508,7 @@ private void PopupMessageIfRelevant()
507508
{
508509
if (MessageBoxEx.Show(fxb, message, title, MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
509510
{
510-
Supporting.ShowIf(fxb, true, false, fxb.ai2);
511+
Supporting.ShowIf(fxb, ShowItFrom.Button, true, false, fxb.ai2, sync: true);
511512
}
512513
}
513514
else if (!string.IsNullOrWhiteSpace(popup.HelpUrl))
@@ -684,7 +685,7 @@ private void mnuSettings_Click(object sender, EventArgs e)
684685

685686
private void mnuSupporting_Click(object sender, EventArgs e)
686687
{
687-
Supporting.ShowIf(fxb, true, false, fxb.ai2);
688+
Supporting.ShowIf(fxb, ShowItFrom.Button, true, false, fxb.ai2, sync: true);
688689
}
689690

690691
private void mnuDocs_Click(object sender, EventArgs e)

FetchXmlBuilder/FetchXmlBuilder.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Cinteros.Xrm.FetchXmlBuilder.Properties;
22
using McTools.Xrm.Connection;
3+
using Microsoft.Toolkit.Uwp.Notifications;
34
using Rappen.XRM.Helpers.Extensions;
45
using Rappen.XRM.Helpers.FetchXML;
56
using Rappen.XTB.FetchXmlBuilder.Builder;
@@ -256,6 +257,15 @@ public override void ClosingPlugin(PluginCloseInfo info)
256257
LogUse("Close", ai2: true);
257258
}
258259

260+
public override void HandleToastActivation(ToastNotificationActivatedEventArgsCompat args)
261+
{
262+
if (Supporting.HandleToastActivation(this, args, ai2))
263+
{
264+
return;
265+
}
266+
base.HandleToastActivation(args);
267+
}
268+
259269
public void ApplyState(object state)
260270
{
261271
if (state is string fetch && fetch.ToLowerInvariant().StartsWith("<fetch"))
@@ -592,7 +602,7 @@ private void FetchXmlBuilder_Load(object sender, EventArgs e)
592602
}
593603
else
594604
{
595-
Supporting.ShowIf(this, false, true, ai2);
605+
Supporting.ShowIf(this, ShowItFrom.Open, false, true, ai2);
596606
}
597607
if (Supporting.IsEnabled(this))
598608
{
@@ -894,7 +904,7 @@ private void tsmiRepoExport_Click(object sender, EventArgs e)
894904
};
895905
if (sfd.ShowDialog() == DialogResult.OK)
896906
{
897-
XmlSerializerHelper.SerializeToFile(repository, sfd.FileName);
907+
XmlAtomicStore.Serialize(repository, sfd.FileName);
898908
MessageBox.Show($"The entire repository has been saved to file\n{sfd.FileName}", "Export repository", MessageBoxButtons.OK, MessageBoxIcon.Information);
899909
}
900910
}
@@ -911,9 +921,7 @@ private void tsmiRepoImport_Click(object sender, EventArgs e)
911921
{
912922
try
913923
{
914-
var document = new XmlDocument();
915-
document.Load(ofd.FileName);
916-
var repo = (QueryRepository)XmlSerializerHelper.Deserialize(document.OuterXml, typeof(QueryRepository));
924+
var repo = XmlAtomicStore.Deserialize<QueryRepository>(ofd.FileName);
917925
var reponame = Path.ChangeExtension(Path.GetFileName(ofd.FileName), "").Trim('.');
918926
if (MessageBox.Show($"Confirm importing {repo.Queries.Count} queries into repository folder \"{reponame}\".", "Confirm", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
919927
{
@@ -969,7 +977,7 @@ private void tsbShare_Click(object sender, EventArgs e)
969977

970978
private void tsbSupporting_Click(object sender, EventArgs e)
971979
{
972-
Supporting.ShowIf(this, true, false, ai2);
980+
Supporting.ShowIf(this, ShowItFrom.Button, true, false, ai2, sync: true);
973981
}
974982

975983
private void reloadBySolutionToolStripMenuItem_Click(object sender, EventArgs e)

FetchXmlBuilder/Forms/CSharpCodeGeneratedLCGSettings.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
using McTools.Xrm.Connection;
2-
using Rappen.XTB.Helper;
1+
using Rappen.XTB.Helpers;
32
using Rappen.XTB.LCG;
43
using System;
54
using System.IO;
65
using System.Windows.Forms;
7-
using System.Xml;
86

97
namespace Rappen.XTB.FetchXmlBuilder.Forms
108
{
@@ -83,13 +81,11 @@ private void btnOpenFile_Click(object sender, EventArgs e)
8381
var lcgsettings = new LCG.Settings();
8482
if (type == ".cs")
8583
{
86-
lcgsettings = ConfigurationUtils.GetEmbeddedConfiguration<LCG.Settings>(ofd.FileName, lcgsettings.commonsettings.InlineConfigBegin, lcgsettings.commonsettings.InlineConfigEnd);
84+
lcgsettings = ConfigurationUtils.GetEmbeddedConfiguration<LCG.Settings>(ofd.FileName, lcgsettings.commonsettings.InlineConfigBegin, lcgsettings.commonsettings.InlineConfigEnd) ?? new LCG.Settings();
8785
}
8886
else if (type == ".xml")
8987
{
90-
var document = new XmlDocument();
91-
document.Load(ofd.FileName);
92-
lcgsettings = (LCG.Settings)XmlSerializerHelper.Deserialize(document.OuterXml, typeof(LCG.Settings));
88+
lcgsettings = XmlAtomicStore.Deserialize<LCG.Settings>(File.ReadAllText(ofd.FileName));
9389
}
9490
lcgsettings.SourceFile = ofd.FileName;
9591
SetSettings(lcgsettings);

FetchXmlBuilder/Settings/OnlineSettings.cs

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
using Rappen.AI.WinForm;
22
using Rappen.XTB.Helpers;
3-
using System;
43
using System.Collections.Generic;
54
using System.Drawing;
65
using System.IO;
76
using System.Windows.Forms;
87
using XrmToolBox.Extensibility;
9-
using XrmToolBox.ToolLibrary.AppCode;
108

119
namespace Rappen.XTB.FXB.Settings
1210
{
1311
public class OnlineSettings
1412
{
1513
private const string FileName = "Rappen.XTB.FXB.Settings.xml";
16-
private static readonly Uri ToolSettingsURLPath = new Uri("https://rappen.github.io/Tools/");
14+
private static readonly string ToolSettingsURLPath = "https://rappen.github.io/Tools/";
1715
private static OnlineSettings instance;
1816

1917
public int SettingsVersion = 1;
@@ -22,7 +20,7 @@ public class OnlineSettings
2220
public AiSupport AiSupport = new AiSupport();
2321
public ToolColors Colors = new ToolColors();
2422

25-
private OnlineSettings()
23+
public OnlineSettings()
2624
{ }
2725

2826
public static OnlineSettings Instance
@@ -32,39 +30,21 @@ public static OnlineSettings Instance
3230
if (instance == null)
3331
{
3432
#if DEBUG
35-
instance = Load<OnlineSettings>(FileName) ?? new OnlineSettings();
36-
//instance.Save();
37-
#else
38-
instance = new Uri(ToolSettingsURLPath, FileName).DownloadXml<OnlineSettings>() ?? new OnlineSettings();
33+
var path = Path.Combine(Paths.SettingsPath, FileName);
34+
if (!File.Exists(path))
35+
{
36+
MessageBoxEx.Show($"DEBUG MODE:\n\nSettings file '{path}' not found. Now it's created by default.\nIt can be found here:\n{ToolSettingsURLPath}{FileName}");
37+
}
3938
#endif
39+
instance = XmlAtomicStore.DownloadXml<OnlineSettings>(ToolSettingsURLPath, FileName, Paths.SettingsPath);
4040
}
4141
return instance;
4242
}
4343
}
4444

4545
public static void Reset() => instance = null;
4646

47-
private static T Load<T>(string filename)
48-
{
49-
var path = Path.Combine(Paths.SettingsPath, FileName);
50-
if (!File.Exists(path))
51-
{
52-
MessageBoxEx.Show($"DEBUG MODE:\n\nSettings file '{path}' not found. Now it's created by default.\nIt can be found here:\n{ToolSettingsURLPath}{FileName}");
53-
return default(T);
54-
}
55-
var file = File.ReadAllText(path);
56-
return (T)XmlSerializerHelper.Deserialize(file, typeof(T));
57-
}
58-
59-
public void Save()
60-
{
61-
if (!Directory.Exists(Paths.SettingsPath))
62-
{
63-
Directory.CreateDirectory(Paths.SettingsPath);
64-
}
65-
var path = Path.Combine(Paths.SettingsPath, FileName);
66-
XmlSerializerHelper.SerializeToFile(this, path);
67-
}
47+
public void Save() => XmlAtomicStore.Serialize(this, Path.Combine(Paths.SettingsPath, FileName));
6848
}
6949

7050
public class ToolColors

0 commit comments

Comments
 (0)