Skip to content

Commit

Permalink
Remembering record used last time
Browse files Browse the repository at this point in the history
  • Loading branch information
rappen committed Nov 4, 2022
1 parent fa2f9e6 commit 5d9bf61
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions XRMTokensRun/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace XRMTokensRun
public class Settings
{
public string Table { get; set; }
public List<KeyValuePair> RecordId { get; set; }
public List<KeyValuePair> Token { get; set; } = new List<KeyValuePair>();
}

Expand Down
21 changes: 19 additions & 2 deletions XRMTokensRun/XRMTR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Rappen.XRM.Helpers.Extensions;
using Rappen.XTB.Helpers.Controls;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -136,7 +137,7 @@ private void LoadEntitiesEtc()

private void LoadSetting()
{
if (settings == null && !SettingsManager.Instance.TryLoad(GetType(), out settings))
if (settings == null && !SettingsManager.Instance.TryLoad(GetType(), out settings, ConnectionDetail?.ConnectionName))
{
settings = new Settings();
}
Expand All @@ -148,7 +149,17 @@ private void SaveSettings()
{
settings = new Settings();
}
settings.RecordId = settings.RecordId ?? new List<KeyValuePair>();
settings.Token = settings.Token ?? new List<KeyValuePair>();
settings.Table = cmbTable.SelectedEntity?.LogicalName;
if (settings.RecordId?.FirstOrDefault(t => t.key == settings.Table) is KeyValuePair id)
{
id.value = record.Id.ToString();
}
else
{
settings.RecordId.Add(new KeyValuePair { key = settings.Table, value = record.Id.ToString() });
}
if (settings.Token?.FirstOrDefault(t => t.key == settings.Table) is KeyValuePair token)
{
token.value = txtTokensIn.Text;
Expand All @@ -157,7 +168,7 @@ private void SaveSettings()
{
settings.Token.Add(new KeyValuePair { key = settings.Table, value = txtTokensIn.Text });
}
SettingsManager.Instance.Save(GetType(), settings);
SettingsManager.Instance.Save(GetType(), settings, ConnectionDetail?.ConnectionName);
}

private void Enable(bool on)
Expand All @@ -182,6 +193,12 @@ private void cmbTable_SelectedIndexChanged(object sender, EventArgs e)
record.Record = null;
if (entity != null && settings != null)
{
if (settings.RecordId?.FirstOrDefault(r => r.key == entity.LogicalName) is KeyValuePair strid &&
Guid.TryParse(strid.value, out Guid id) &&
!id.Equals(Guid.Empty))
{
LoadRecord(new EntityReference(entity.LogicalName, id));
}
var token = settings.Token?.FirstOrDefault(t => t.key == entity.LogicalName)?.value;
txtTokensIn.Lines = token?.Split('\n');
}
Expand Down

0 comments on commit 5d9bf61

Please sign in to comment.