Skip to content

Commit

Permalink
🔧 Fixed import solution UI
Browse files Browse the repository at this point in the history
  • Loading branch information
BetimBeja committed Jan 14, 2021
1 parent 4cd12f5 commit 418130c
Show file tree
Hide file tree
Showing 9 changed files with 2,031 additions and 1,904 deletions.
7 changes: 2 additions & 5 deletions AlbanianXrm.SolutionPackager.Tool/CrmSolutionImporter.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using AlbanianXrm.SolutionPackager.Models;
using AlbanianXrm.SolutionPackager.Properties;
using Microsoft.Crm.Sdk.Messages;
using AlbanianXrm.SolutionPackager.Properties;
using Microsoft.Xrm.Sdk.Messages;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Windows.Forms;
Expand Down Expand Up @@ -78,7 +75,7 @@ private void ImportSolutionStarted(RunWorkerCompletedEventArgs args)

var importSolution = args.Result as Models.ImportSolutionRequest;

solutionImportStatus = new SolutionImportStatus(importSolution.ExecuteAsyncResponse.AsyncJobId, importSolution.ImportJobId, pluginViewModel);
solutionImportStatus = new SolutionImportStatus(importSolution.ExecuteAsyncResponse.AsyncJobId, importSolution.ImportJobId, solutionPackagerControl);
solutionImportStatus.Show(solutionPackagerControl);
}

Expand Down

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

3 changes: 3 additions & 0 deletions AlbanianXrm.SolutionPackager.Tool/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@
<data name="PROGRAM_OUTPUT" xml:space="preserve">
<value>Program output</value>
</data>
<data name="PROGRESS_X_PERCENT" xml:space="preserve">
<value>Progress {0}%</value>
</data>
<data name="QUESTION" xml:space="preserve">
<value>Question</value>
</data>
Expand Down
64 changes: 59 additions & 5 deletions AlbanianXrm.SolutionPackager.Tool/SolutionImportStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,29 @@

namespace AlbanianXrm.SolutionPackager
{
public partial class SolutionImportStatus : Form
internal partial class SolutionImportStatus : Form
{
private readonly Guid asyncJobId;
private readonly Guid importJobId;
private readonly SolutionPackagerControl solutionPackagerControl;
private string errorDetails;

public IOrganizationService OrganizationService { get; set; }

public SolutionImportStatus(Guid asyncJobId, Guid importJobId, PluginViewModel pluginViewModel)
internal SolutionImportStatus(Guid asyncJobId, Guid importJobId, SolutionPackagerControl solutionPackagerControl)
{
InitializeComponent();
this.asyncJobId = asyncJobId;
this.importJobId = importJobId;
this.solutionPackagerControl = solutionPackagerControl;
this.timer.Tick += new EventHandler(Timer_Tick);
this.backgroundWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(WorkAsync);
this.backgroundWorkerCancel.DoWork += new System.ComponentModel.DoWorkEventHandler(WorkAsyncCancel);
this.backgroundWorker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(WorkAsyncEnded);
this.Bind(t => t.OrganizationService, pluginViewModel, s => s.OrganizationService, formattingEnabled: true);
this.backgroundWorkerCancel.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(WorkAsyncCancelEnded);
this.Bind(t => t.OrganizationService, solutionPackagerControl.pluginViewModel, s => s.OrganizationService, formattingEnabled: true);
this.timer.Start();
}
}

private void Timer_Tick(object sender, EventArgs e)
{
Expand Down Expand Up @@ -78,6 +82,14 @@ private void WorkAsync(object sender, System.ComponentModel.DoWorkEventArgs args

private void WorkAsyncEnded(object sender, System.ComponentModel.RunWorkerCompletedEventArgs args)
{
if (args.Error != null)
{
solutionPackagerControl.WriteErrorLog("The following error occurred while checking the solution import status:\r\n{0}", args.Error);
MessageBox.Show(args.Error.Message, Resources.MBOX_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
timer.Start();
return;
}

if (!(args.Result is ImportSolutionStatus result))
{
timer.Start();
Expand Down Expand Up @@ -113,16 +125,20 @@ private void WorkAsyncEnded(object sender, System.ComponentModel.RunWorkerComple
if (asyncOperation.ErrorCode.HasValue)
{
errorDetails = asyncOperation.Message;
btnCancelImport.Visible = false;
tlpContainer.SetRow(btnCancelImport, 8);
tlpContainer.SetRow(btnCopyMessage, 7);
btnCopyMessage.Visible = true;
lblJobStatus.ForeColor = Color.Red;
}

if (importJob != null)
{
progressBar.Value = importJob.Progress.HasValue ? (int)importJob.Progress : 0;
toolTip.SetToolTip(progressBar, string.Format(Resources.PROGRESS_X_PERCENT, progressBar.Value));
lblSolutionName.Text = importJob.SolutionName;
}


if (asyncOperation.StatusCode != AsyncOperation.OptionSets.StatusCode.Canceled &&
asyncOperation.StatusCode != AsyncOperation.OptionSets.StatusCode.Failed &&
Expand All @@ -132,17 +148,55 @@ private void WorkAsyncEnded(object sender, System.ComponentModel.RunWorkerComple
}
}

private void WorkAsyncCancel(object sender, System.ComponentModel.DoWorkEventArgs args)
{
var service = OrganizationService;
if (service == null)
{
return;
}

var asyncOperation = new AsyncOperation()
{
Id = asyncJobId,
StateCode = AsyncOperation.OptionSets.StateCode.Completed,
StatusCode = AsyncOperation.OptionSets.StatusCode.Canceling
};

service.Update(asyncOperation);
}

private void WorkAsyncCancelEnded(object sender, System.ComponentModel.RunWorkerCompletedEventArgs args)
{
if (args.Error != null)
{
solutionPackagerControl.WriteErrorLog("The following error occurred while canceling the solution import:\r\n{0}", args.Error);
MessageBox.Show(args.Error.Message, Resources.MBOX_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
timer.Stop();
timer.Dispose();
backgroundWorker.Dispose();
backgroundWorkerCancel.Dispose();
}

private void BtnCopyMessage_Click(object sender, EventArgs e)
{
Clipboard.SetText(errorDetails);
}

private void BtnCancelImport_Click(object sender, EventArgs e)
{
if (!btnCancelImport.Enabled)
{
return;
}
btnCancelImport.Enabled = false;
backgroundWorkerCancel.RunWorkerAsync();
}
}
}
39 changes: 23 additions & 16 deletions AlbanianXrm.SolutionPackager.Tool/SolutionImportStatus.designer.cs

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

Loading

0 comments on commit 418130c

Please sign in to comment.