Skip to content

Commit

Permalink
Added scrollbar for small screens
Browse files Browse the repository at this point in the history
  • Loading branch information
BetimBeja committed Feb 4, 2022
1 parent dc38dc8 commit 529231a
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AlbanianXrm.XrmToolBox.Shared" Version="1.2021.4.5" />
<PackageReference Include="NuGet.Protocol" Version="5.9.0" />
<PackageReference Include="XrmToolBoxPackage" Version="1.2021.02.45" />
<PackageReference Include="AlbanianXrm.XrmToolBox.Shared" Version="1.2021.6.1" />
<PackageReference Include="NuGet.Protocol" Version="5.9.1" />
<PackageReference Include="XrmToolBoxPackage" Version="1.2021.12.53" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\DataPlatformErrorCodes.Designer.cs">
Expand Down
34 changes: 16 additions & 18 deletions AlbanianXrm.SolutionPackager.Tool/CoreToolsDownloader.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using AlbanianXrm.SolutionPackager.Properties;
using AlbanianXrm.XrmToolBox.Shared;
using AlbanianXrm.BackgroundWorker;
using AlbanianXrm.SolutionPackager.Properties;
using AlbanianXrm.XrmToolBox.Shared.Extensions;
using NuGet.Common;
using NuGet.Packaging;
using NuGet.Protocol;
Expand All @@ -8,7 +9,6 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
Expand All @@ -19,11 +19,11 @@ internal class CoreToolsDownloader
{
public const string coreToolsId = "Microsoft.CrmSdk.CoreTools";
public const string solutionPackagerName = "SolutionPackager.exe";
private readonly BackgroundWorkHandler backgroundWorkHandler;
private readonly AlBackgroundWorkHandler backgroundWorkHandler;
private readonly SolutionPackagerControl solutionPackagerControl;
private readonly ToolViewModel toolViewModel;

public CoreToolsDownloader(BackgroundWorkHandler backgroundWorkHandler, SolutionPackagerControl solutionPackagerControl, ToolViewModel toolViewModel)
public CoreToolsDownloader(AlBackgroundWorkHandler backgroundWorkHandler, SolutionPackagerControl solutionPackagerControl, ToolViewModel toolViewModel)
{
this.backgroundWorkHandler = backgroundWorkHandler ?? throw new ArgumentNullException(nameof(backgroundWorkHandler));
this.solutionPackagerControl = solutionPackagerControl ?? throw new ArgumentNullException(nameof(solutionPackagerControl));
Expand All @@ -32,12 +32,10 @@ public CoreToolsDownloader(BackgroundWorkHandler backgroundWorkHandler, Solution

public void DownloadCoreTools(string nuGetFeed)
{
backgroundWorkHandler.EnqueueAsyncWork(
Resources.DOWNLOADING_CORE_TOOLS,
DownloadCoreToolsAsync,
nuGetFeed,
DownloadCoreToolsCompleted
);
backgroundWorkHandler.EnqueueBackgroundWork(
AlBackgroundWorkerFactory.NewAsyncWorker(DownloadCoreToolsAsync, nuGetFeed, DownloadCoreToolsCompleted)
.WithViewModel(toolViewModel)
.WithMessage(solutionPackagerControl, Resources.DOWNLOADING_CORE_TOOLS));
}

public static Version GetSolutionPackagerVersion()
Expand Down Expand Up @@ -79,7 +77,7 @@ public async Task<object> DownloadCoreToolsAsync(string nugetSource)

var metadata = (await packageSearch.SearchAsync(coreToolsId, new SearchFilter(false, SearchFilterType.IsLatestVersion), 0, 1, logger, cancellationToken)).FirstOrDefault();
var version = (await metadata.GetVersionsAsync()).Max(v => v.Version);
System.Diagnostics.Debug.WriteLine($"Version {version}");

using (MemoryStream packageStream = new MemoryStream())
{
if (!await findPackageById.CopyNupkgToStreamAsync(
Expand Down Expand Up @@ -112,18 +110,18 @@ public async Task<object> DownloadCoreToolsAsync(string nugetSource)
return GetSolutionPackagerVersion(dir);
}

private void DownloadCoreToolsCompleted(BackgroundWorkResult<string, object> args)
private void DownloadCoreToolsCompleted(string source, object value, Exception exception)
{
if (args.Exception != null)
if (exception != null)
{
solutionPackagerControl.WriteErrorLog("The following error occured while downloading core tools: \r\n{0}", args.Exception);
MessageBox.Show(args.Exception.Message, Resources.MBOX_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
solutionPackagerControl.WriteErrorLog("The following error occured while downloading core tools: \r\n{0}", exception);
MessageBox.Show(exception.Message, Resources.MBOX_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (args.Value is string errorMessage)
else if (value is string errorMessage)
{
MessageBox.Show(errorMessage, Resources.MBOX_INFORMATION, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if (args.Value is Version version)
else if (value is Version version)
{
toolViewModel.SolutionPackagerVersion = version.ToString();
}
Expand Down
50 changes: 24 additions & 26 deletions AlbanianXrm.SolutionPackager.Tool/CrmSolutionDownloader.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using AlbanianXrm.SolutionPackager.Models;
using AlbanianXrm.BackgroundWorker;
using AlbanianXrm.SolutionPackager.Models;
using AlbanianXrm.SolutionPackager.Properties;
using AlbanianXrm.XrmToolBox.Shared;
using AlbanianXrm.XrmToolBox.Shared.Extensions;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
Expand All @@ -16,11 +17,11 @@ namespace AlbanianXrm.SolutionPackager
internal class CrmSolutionDownloader
{
private readonly SolutionPackagerControl solutionPackagerControl;
private readonly BackgroundWorkHandler asyncWorkQueue;
private readonly AlBackgroundWorkHandler asyncWorkQueue;
private readonly SolutionPackagerCaller solutionPackagerCaller;
private readonly ComboBox cmbCrmSolutions;

public CrmSolutionDownloader(SolutionPackagerControl solutionPackagerControl, BackgroundWorkHandler asyncWorkQueue, SolutionPackagerCaller solutionPackagerCaller, ComboBox cmbCrmSolutions)
public CrmSolutionDownloader(SolutionPackagerControl solutionPackagerControl, AlBackgroundWorkHandler asyncWorkQueue, SolutionPackagerCaller solutionPackagerCaller, ComboBox cmbCrmSolutions)
{
this.solutionPackagerControl = solutionPackagerControl ?? throw new ArgumentNullException(nameof(solutionPackagerControl));
this.asyncWorkQueue = asyncWorkQueue ?? throw new ArgumentNullException(nameof(asyncWorkQueue));
Expand All @@ -30,12 +31,10 @@ public CrmSolutionDownloader(SolutionPackagerControl solutionPackagerControl, Ba

public void DownloadSolution(Parameters @params)
{
asyncWorkQueue.EnqueueWork(
string.Format(CultureInfo.InvariantCulture, Resources.DOWNLOADING_SOLUTION, @params.Solution.FriendlyName),
DownloadSolutionInner,
@params,
DownloadSolutionCompleted
);
asyncWorkQueue.EnqueueBackgroundWork(
AlBackgroundWorkerFactory.NewWorker(DownloadSolutionInner, @params, DownloadSolutionCompleted)
.WithViewModel(solutionPackagerControl.toolViewModel)
.WithMessage(solutionPackagerControl, string.Format(CultureInfo.InvariantCulture, Resources.DOWNLOADING_SOLUTION, @params.Solution.FriendlyName)));
}

private SolutionPackagerCaller.Parameters DownloadSolutionInner(Parameters @params)
Expand Down Expand Up @@ -73,31 +72,30 @@ private SolutionPackagerCaller.Parameters DownloadSolutionInner(Parameters @para
return @params.SolutionPackagerParameters;
}

private void DownloadSolutionCompleted(BackgroundWorkResult<Parameters, SolutionPackagerCaller.Parameters> args)
private void DownloadSolutionCompleted(Parameters args, SolutionPackagerCaller.Parameters value, Exception exception)
{
if (args.Exception is FaultException<OrganizationServiceFault> crmError)
if (exception is FaultException<OrganizationServiceFault> crmError)
{
solutionPackagerControl.WriteErrorLog("The following error occurred while downloading the solution:\r\n{0}", crmError);
MessageBox.Show(crmError.Message, Resources.MBOX_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (args.Exception != null)
else if (exception != null)
{
solutionPackagerControl.WriteErrorLog("The following error occurred while downloading the solution:\r\n{0}", args.Exception);
MessageBox.Show(args.Exception.Message, Resources.MBOX_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
solutionPackagerControl.WriteErrorLog("The following error occurred while downloading the solution:\r\n{0}", exception);
MessageBox.Show(exception.Message, Resources.MBOX_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
solutionPackagerCaller.ManageSolution(args.Value);
solutionPackagerCaller.ManageSolution(value);
}
}

public void RefreshSolutionList()
{
asyncWorkQueue.EnqueueWork(
Resources.REFRESHING_SOLUTION_LIST,
RefreshSolutionListInner,
RefreshSolutionListCompleted
);
asyncWorkQueue.EnqueueBackgroundWork(
AlBackgroundWorkerFactory.NewWorker(RefreshSolutionListInner, RefreshSolutionListCompleted)
.WithViewModel(solutionPackagerControl.toolViewModel)
.WithMessage(solutionPackagerControl, Resources.REFRESHING_SOLUTION_LIST));
}

private object[] RefreshSolutionListInner()
Expand All @@ -111,18 +109,18 @@ private object[] RefreshSolutionListInner()
return solutionPackagerControl.Service.RetrieveMultiple(query).Entities.Select(solution => solution.ToEntity<Solution>()).ToArray<object>();
}

private void RefreshSolutionListCompleted(BackgroundWorkResult<object[]> args)
private void RefreshSolutionListCompleted(object[] value, Exception exception)
{
if (args.Exception != null)
if (exception != null)
{
solutionPackagerControl.WriteErrorLog("The following error occurred while refreshing the solution list:\r\n{0}", args.Exception);
MessageBox.Show(args.Exception.Message, Resources.MBOX_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
solutionPackagerControl.WriteErrorLog("The following error occurred while refreshing the solution list:\r\n{0}", exception);
MessageBox.Show(exception.Message, Resources.MBOX_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
cmbCrmSolutions.BeginUpdate();
cmbCrmSolutions.Items.Clear();
cmbCrmSolutions.Items.AddRange(args.Value);
cmbCrmSolutions.Items.AddRange(value);
cmbCrmSolutions.EndUpdate();
}
}
Expand Down
30 changes: 15 additions & 15 deletions AlbanianXrm.SolutionPackager.Tool/CrmSolutionImporter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using AlbanianXrm.SolutionPackager.Properties;
using AlbanianXrm.BackgroundWorker;
using AlbanianXrm.SolutionPackager.Properties;
using AlbanianXrm.XrmToolBox.Shared;
using AlbanianXrm.XrmToolBox.Shared.Extensions;
using Microsoft.Xrm.Sdk.Messages;
using System;
using System.Globalization;
Expand All @@ -11,11 +13,11 @@ namespace AlbanianXrm.SolutionPackager
internal class CrmSolutionImporter
{
private readonly SolutionPackagerControl solutionPackagerControl;
private readonly BackgroundWorkHandler asyncWorkQueue;
private readonly AlBackgroundWorkHandler asyncWorkQueue;
private readonly ToolViewModel toolViewModel;
private SolutionImportStatus solutionImportStatus;

public CrmSolutionImporter(SolutionPackagerControl solutionPackagerControl, BackgroundWorkHandler asyncWorkQueue, ToolViewModel pluginViewModel)
public CrmSolutionImporter(SolutionPackagerControl solutionPackagerControl, AlBackgroundWorkHandler asyncWorkQueue, ToolViewModel pluginViewModel)
{
this.solutionPackagerControl = solutionPackagerControl;
this.asyncWorkQueue = asyncWorkQueue;
Expand All @@ -30,12 +32,10 @@ public void ImportSolution(Parameters @params)
fileInfo = new FileInfo(fileInfo.FullName.Substring(0, fileInfo.FullName.Length - fileInfo.Extension.Length) + "_managed" + fileInfo.Extension);
@params.CustomizationFile = fileInfo.FullName;
}
asyncWorkQueue.EnqueueWork(
string.Format(CultureInfo.InvariantCulture, Resources.IMPORT_SOLUTION, fileInfo.Name),
ImportSolutionInner,
@params,
ImportSolutionStarted
);
asyncWorkQueue.EnqueueBackgroundWork(
AlBackgroundWorkerFactory.NewWorker(ImportSolutionInner, @params, ImportSolutionStarted)
.WithViewModel(toolViewModel)
.WithMessage(solutionPackagerControl, string.Format(CultureInfo.InvariantCulture, Resources.IMPORT_SOLUTION, fileInfo.Name)));
}

private Models.ImportSolutionRequest ImportSolutionInner(Parameters @params)
Expand All @@ -53,23 +53,23 @@ private Models.ImportSolutionRequest ImportSolutionInner(Parameters @params)
CustomizationFile = File.ReadAllBytes(@params.CustomizationFile)
}
};
return new Models.ImportSolutionRequest()
return new Models.ImportSolutionRequest()
{
ImportJobId = importJobId,
ExecuteAsyncResponse = solutionPackagerControl.Service.Execute(importSolutionRequest) as ExecuteAsyncResponse
};
}

private void ImportSolutionStarted(BackgroundWorkResult<Parameters, Models.ImportSolutionRequest> args)
private void ImportSolutionStarted(Parameters @params, Models.ImportSolutionRequest value, Exception exception)
{
if (args.Exception != null)
if (exception != null)
{
solutionPackagerControl.WriteErrorLog("The following error occurred while importing the solution:\r\n{0}", args.Exception);
MessageBox.Show(args.Exception.Message, Resources.MBOX_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
solutionPackagerControl.WriteErrorLog("The following error occurred while importing the solution:\r\n{0}", exception);
MessageBox.Show(exception.Message, Resources.MBOX_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}

solutionImportStatus = new SolutionImportStatus(args.Value.ExecuteAsyncResponse.AsyncJobId, args.Value.ImportJobId, solutionPackagerControl, toolViewModel);
solutionImportStatus = new SolutionImportStatus(value.ExecuteAsyncResponse.AsyncJobId, value.ImportJobId, solutionPackagerControl, toolViewModel);
solutionImportStatus.Show(solutionPackagerControl);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using AlbanianXrm.XrmToolBox.Shared;
using AlbanianXrm.BackgroundWorker;
using System.Windows.Forms;

namespace AlbanianXrm.SolutionPackager.Interfaces
{
interface IMyToolFactory
{
ToolViewModel NewToolViewModel();
BackgroundWorkHandler BackgroundWorkHandler();
AlBackgroundWorkHandler BackgroundWorkHandler();
CoreToolsDownloader NewCoreToolsDownloader();
CrmSolutionImporter NewCrmSolutionImporter();
SolutionPackagerCaller NewSolutionPackagerCaller(RichTextBox txtOutput, CrmSolutionImporter crmSolutionImporter);
Expand Down
9 changes: 5 additions & 4 deletions AlbanianXrm.SolutionPackager.Tool/MyToolFactory.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AlbanianXrm.SolutionPackager.Interfaces;
using AlbanianXrm.BackgroundWorker;
using AlbanianXrm.SolutionPackager.Interfaces;
using AlbanianXrm.XrmToolBox.Shared;
using System.Windows.Forms;

Expand All @@ -8,21 +9,21 @@ internal class MyToolFactory : IMyToolFactory
{
private readonly SolutionPackagerControl solutionPackagerControl;
private readonly ToolViewModel toolViewModel;
private readonly BackgroundWorkHandler backgroundWorkHandler;
private readonly AlBackgroundWorkHandler backgroundWorkHandler;

private MyToolFactory(SolutionPackagerControl solutionPackagerControl)
{
this.solutionPackagerControl = solutionPackagerControl;
this.toolViewModel = new ToolViewModel();
this.backgroundWorkHandler = new BackgroundWorkHandler(solutionPackagerControl, toolViewModel);
this.backgroundWorkHandler = new AlBackgroundWorkHandler();
}

public static IMyToolFactory GetMyToolFactory(SolutionPackagerControl solutionPackagerControl)
{
return new MyToolFactory(solutionPackagerControl);
}

public BackgroundWorkHandler BackgroundWorkHandler()
public AlBackgroundWorkHandler BackgroundWorkHandler()
{
return backgroundWorkHandler;
}
Expand Down
Loading

0 comments on commit 529231a

Please sign in to comment.