Skip to content

Commit

Permalink
Added WorkAsyncs
Browse files Browse the repository at this point in the history
  • Loading branch information
rappen committed Sep 10, 2021
1 parent 62a66ab commit 51acce4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 15 deletions.
64 changes: 49 additions & 15 deletions XRMTokensRun/XRMTR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public partial class XRMTR : PluginControlBase, IGitHubPlugin, IPayPalPlugin, IM

public string UserName => "rappen";

public string DonationDescription => "Donation to XRM Tokens Runner for XrmToolBox";
public string DonationDescription => "Donation to XRM Tokens Runners for XrmToolBox";

public string EmailAccount => "jonas@rappen.net";

Expand Down Expand Up @@ -147,12 +147,36 @@ private void btnGetRecord_Click(object sender, EventArgs e)
};
if (look.ShowDialog() == DialogResult.OK)
{
record.Record = Service.Retrieve(look.Record.LogicalName, look.Record.Id, new ColumnSet(true));
LoadRecord(look.Record.LogicalName, look.Record.Id);
}
Execute();
Enable(true);
}

private void LoadRecord(string entity, Guid id)
{
WorkAsync(new WorkAsyncInfo
{
Message = "Loading record...",
Work = (work, args) =>
{
args.Result = Service.Retrieve(entity, id, new ColumnSet(true));
},
PostWorkCallBack = (arg) =>
{
if (arg.Error != null)
{
MessageBox.Show(arg.Error.Message);
}
else if (arg.Result is Entity result)
{
record.Record = result;
Execute();
}
Enable(true);
}
});
}

private void Execute()
{
timer1.Stop();
Expand All @@ -161,16 +185,28 @@ private void Execute()
return;
}
SaveSettings();
try
{
lblError.Text = "";
txtTokensOut.Text = "";
txtTokensOut.Text = record.Record.Substitute(Service, txtTokensIn.Text);
}
catch (Exception ex)
lblError.Text = "";
txtTokensOut.Text = "";
WorkAsync(new WorkAsyncInfo
{
lblError.Text = ex.Message;
}
Message = "Calling Substitute",
Work = (work, arg) =>
{
arg.Result = record.Record.Substitute(Service, txtTokensIn.Text);
},
PostWorkCallBack = (arg) =>
{
if (arg.Error != null)
{
lblError.Text = arg.Error.Message;
}
else if (arg.Result is string result)
{
txtTokensOut.Text = result;
}

}
});
}

private void toolStripLabel1_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -295,9 +331,7 @@ public void OnIncomingMessage(MessageBusEventArgs message)
{
SetBackTag(message.SourcePlugin);
cmbTable.SetSelected(entity);
record.LogicalName = entity;
record.Id = id;
Enable(true);
LoadRecord(entity, id);
}
}

Expand Down
1 change: 1 addition & 0 deletions XRMTokensRun/XRMTR.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 51acce4

Please sign in to comment.