Skip to content

Commit 9862316

Browse files
committed
Import of automation code/logic/dialogs/etc from old repository
1 parent 80b63a8 commit 9862316

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+6628
-0
lines changed

src/Guidance.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# WebFormsToBlazorServer Guidance
2+
This guidance document provides an overview for how to understand the implementation of this command library.
3+
4+
To be updated

src/WebFormsToBlazorServer.sln

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30128.74
5+
MinimumVisualStudioVersion = 15.0.26124.0
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebFormsToBlazorServerCommands", "WebFormsToBlazorServerCommands\WebFormsToBlazorServerCommands.csproj", "{2B1CA33A-0E23-4ED6-97BE-67BFF5737A5A}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Debug|x64 = Debug|x64
12+
Debug|x86 = Debug|x86
13+
Release|Any CPU = Release|Any CPU
14+
Release|x64 = Release|x64
15+
Release|x86 = Release|x86
16+
EndGlobalSection
17+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18+
{2B1CA33A-0E23-4ED6-97BE-67BFF5737A5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19+
{2B1CA33A-0E23-4ED6-97BE-67BFF5737A5A}.Debug|Any CPU.Build.0 = Debug|Any CPU
20+
{2B1CA33A-0E23-4ED6-97BE-67BFF5737A5A}.Debug|x64.ActiveCfg = Debug|Any CPU
21+
{2B1CA33A-0E23-4ED6-97BE-67BFF5737A5A}.Debug|x64.Build.0 = Debug|Any CPU
22+
{2B1CA33A-0E23-4ED6-97BE-67BFF5737A5A}.Debug|x86.ActiveCfg = Debug|Any CPU
23+
{2B1CA33A-0E23-4ED6-97BE-67BFF5737A5A}.Debug|x86.Build.0 = Debug|Any CPU
24+
{2B1CA33A-0E23-4ED6-97BE-67BFF5737A5A}.Release|Any CPU.ActiveCfg = Release|Any CPU
25+
{2B1CA33A-0E23-4ED6-97BE-67BFF5737A5A}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{2B1CA33A-0E23-4ED6-97BE-67BFF5737A5A}.Release|x64.ActiveCfg = Release|Any CPU
27+
{2B1CA33A-0E23-4ED6-97BE-67BFF5737A5A}.Release|x64.Build.0 = Release|Any CPU
28+
{2B1CA33A-0E23-4ED6-97BE-67BFF5737A5A}.Release|x86.ActiveCfg = Release|Any CPU
29+
{2B1CA33A-0E23-4ED6-97BE-67BFF5737A5A}.Release|x86.Build.0 = Release|Any CPU
30+
EndGlobalSection
31+
GlobalSection(SolutionProperties) = preSolution
32+
HideSolutionNode = FALSE
33+
EndGlobalSection
34+
GlobalSection(ExtensibilityGlobals) = postSolution
35+
SolutionGuid = {608D67A6-252F-466D-A5BA-C9CE3310C604}
36+
EndGlobalSection
37+
EndGlobal
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using CodeFactory.Logging;
7+
using CodeFactory.VisualStudio;
8+
using CodeFactory.VisualStudio.SolutionExplorer;
9+
using CodeFactory.Formatting.CSharp;
10+
using WebFormsToBlazorServerCommands.Dialogs;
11+
using System.IO;
12+
13+
namespace WebFormsToBlazorServerCommands.Commands.Document
14+
{
15+
/// <summary>
16+
/// Code factory command for automation of a document when selected from a project in solution explorer.
17+
/// </summary>
18+
public class MigrateWebForm : ProjectDocumentCommandBase
19+
{
20+
private static readonly string commandTitle = "Migrate to Blazor";
21+
private static readonly string commandDescription = "Replace with description of what this command does";
22+
23+
#pragma warning disable CS1998
24+
25+
/// <inheritdoc />
26+
public MigrateWebForm(ILogger logger, IVsActions vsActions) : base(logger, vsActions, commandTitle, commandDescription)
27+
{
28+
//Intentionally blank
29+
}
30+
31+
#region Overrides of VsCommandBase<VsProjectDocument>
32+
33+
/// <summary>
34+
/// Validation logic that will determine if this command should be enabled for execution.
35+
/// </summary>
36+
/// <param name="result">The target model data that will be used to determine if this command should be enabled.</param>
37+
/// <returns>Boolean flag that will tell code factory to enable this command or disable it.</returns>
38+
public override async Task<bool> EnableCommandAsync(VsDocument result)
39+
{
40+
//Result that determines if the the command is enabled and visible in the context menu for execution.
41+
bool isEnabled = false;
42+
43+
try
44+
{
45+
isEnabled = result.Name.Contains("aspx");
46+
}
47+
catch (Exception unhandledError)
48+
{
49+
_logger.Error($"The following unhandled error occured while checking if the solution explorer project document command {commandTitle} is enabled. ",
50+
unhandledError);
51+
isEnabled = false;
52+
}
53+
54+
return isEnabled;
55+
}
56+
57+
/// <summary>
58+
/// Code factory framework calls this method when the command has been executed.
59+
/// </summary>
60+
/// <param name="result">The code factory model that has generated and provided to the command to process.</param>
61+
public override async Task ExecuteCommandAsync(VsDocument result)
62+
{
63+
try
64+
{
65+
//User Control to see the AngleSharp Nodes
66+
var migrateDialog = await VisualStudioActions.UserInterfaceActions.CreateVsUserControlAsync<MigrateWebFormDialog>();
67+
68+
//Get Project List
69+
var solution = await VisualStudioActions.SolutionActions.GetSolutionAsync();
70+
71+
//Set properties on the dialog
72+
var projects = await solution.GetProjectsAsync(false);
73+
migrateDialog.SolutionProjects = projects;
74+
migrateDialog.FormToMigrate = result;
75+
76+
//Show the dialog
77+
await VisualStudioActions.UserInterfaceActions.ShowDialogWindowAsync(migrateDialog);
78+
79+
}
80+
catch (Exception unhandledError)
81+
{
82+
_logger.Error($"The following unhandled error occured while executing the solution explorer project document command {commandTitle}. ",
83+
unhandledError);
84+
85+
}
86+
87+
}
88+
89+
90+
}
91+
92+
#endregion
93+
}
94+
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using CodeFactory.Logging;
7+
using CodeFactory.VisualStudio;
8+
using CodeFactory.VisualStudio.SolutionExplorer;
9+
using WebFormsToBlazorServerCommands.Dialogs;
10+
11+
namespace WebFormsToBlazorServerCommands.Commands.Project
12+
{
13+
/// <summary>
14+
/// Code factory command for automation of a project when selected from solution explorer.
15+
/// </summary>
16+
public class SetupBlazorProject : ProjectCommandBase
17+
{
18+
private static readonly string commandTitle = "Setup Blazor Project";
19+
private static readonly string commandDescription = "Will setup a blazor project with win form project data.";
20+
21+
#pragma warning disable CS1998
22+
23+
/// <inheritdoc />
24+
public SetupBlazorProject(ILogger logger, IVsActions vsActions) : base(logger, vsActions, commandTitle, commandDescription)
25+
{
26+
//Intentionally blank
27+
}
28+
#pragma warning disable CS1998
29+
#region Overrides of VsCommandBase<VsProject>
30+
31+
/// <summary>
32+
/// Validation logic that will determine if this command should be enabled for execution.
33+
/// </summary>
34+
/// <param name="result">The target model data that will be used to determine if this command should be enabled.</param>
35+
/// <returns>Boolean flag that will tell code factory to enable this command or disable it.</returns>
36+
public override async Task<bool> EnableCommandAsync(VsProject result)
37+
{
38+
//Result that determines if the the command is enabled and visible in the context menu for execution.
39+
bool isEnabled = false;
40+
41+
try
42+
{
43+
var children = await result.GetChildrenAsync(true);
44+
45+
if (children.Any(p => p.ModelType.Equals(VisualStudioModelType.ProjectFolder) && p.Name.Equals("Pages")))
46+
{
47+
isEnabled = true;
48+
}
49+
50+
}
51+
catch (Exception unhandledError)
52+
{
53+
_logger.Error($"The following unhandled error occured while checking if the solution explorer project command {commandTitle} is enabled. ",
54+
unhandledError);
55+
isEnabled = false;
56+
}
57+
58+
return isEnabled;
59+
}
60+
61+
/// <summary>
62+
/// Code factory framework calls this method when the command has been executed.
63+
/// </summary>
64+
/// <param name="result">The code factory model that has generated and provided to the command to process.</param>
65+
public override async Task ExecuteCommandAsync(VsProject result)
66+
{
67+
try
68+
{
69+
//Creating an instance of the setup blazor dialog class. This internally hooks it into the visual studio UI system.
70+
var migrateDialog = await VisualStudioActions.UserInterfaceActions.CreateVsUserControlAsync<SetupBlazorDialog>();
71+
72+
//Get Project List
73+
var solution = await VisualStudioActions.SolutionActions.GetSolutionAsync();
74+
75+
//Setting the list of solution projects into the dialog.
76+
migrateDialog.SolutionProjects = await solution.GetProjectsAsync(true);
77+
78+
//Showing the dialog
79+
await VisualStudioActions.UserInterfaceActions.ShowDialogWindowAsync(migrateDialog);
80+
}
81+
catch (Exception unhandledError)
82+
{
83+
_logger.Error($"The following unhandled error occured while executing the solution explorer project command {commandTitle}. ",
84+
unhandledError);
85+
86+
}
87+
}
88+
89+
#endregion
90+
}
91+
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
using System.Windows.Controls;
8+
using System.Windows.Media;
9+
using WebFormsToBlazorServerCommands.Migration;
10+
11+
namespace WebFormsToBlazorServerCommands.Dialogs
12+
{
13+
/// <summary>
14+
/// Extensions class that manages data to be used in the dialog.
15+
/// </summary>
16+
public static class DialogExtensions
17+
{
18+
/// <summary>
19+
/// Check a nullable bool for a value, will return false if the bool is null.
20+
/// </summary>
21+
/// <param name="source">Nullable bool to check</param>
22+
/// <returns>standard boolean result.</returns>
23+
public static bool GetResult(this bool? source)
24+
{
25+
return source.HasValue ? source.Value : false;
26+
}
27+
28+
/// <summary>
29+
/// Extension method used to help format labels that track migration status. Must be executed on the UI Thread.
30+
/// </summary>
31+
/// <param name="source">Label to be updated</param>
32+
/// <param name="status">Status type used for formatting.</param>
33+
public static void UpdateMigrationStatus(this TextBlock source, MigrationStatusEnum status)
34+
{
35+
switch (status)
36+
{
37+
case MigrationStatusEnum.Running:
38+
source.FontWeight = FontWeights.Bold;
39+
break;
40+
41+
case MigrationStatusEnum.Passed:
42+
source.FontWeight = FontWeights.ExtraBold;
43+
source.Foreground = Brushes.Green;
44+
break;
45+
46+
case MigrationStatusEnum.Failed:
47+
source.FontWeight = FontWeights.ExtraBold;
48+
source.Foreground = Brushes.Red;
49+
break;
50+
51+
default:
52+
break;
53+
}
54+
}
55+
56+
/// <summary>
57+
/// Gets a title assigned to each migration step.
58+
/// </summary>
59+
/// <param name="source">The migration step to be loaded.</param>
60+
/// <returns>The title.</returns>
61+
public static string GetName(this MigrationStepEnum source)
62+
{
63+
string name = null;
64+
65+
switch (source)
66+
{
67+
case MigrationStepEnum.Startup:
68+
name = "Startup";
69+
break;
70+
71+
case MigrationStepEnum.HttpModules:
72+
name = "Http Modules";
73+
break;
74+
75+
case MigrationStepEnum.StaticFiles:
76+
name = "Static Files";
77+
break;
78+
79+
case MigrationStepEnum.Bundling:
80+
name = "Bundling";
81+
break;
82+
83+
case MigrationStepEnum.AspxPages:
84+
name = "Aspx Pages";
85+
break;
86+
87+
case MigrationStepEnum.Config:
88+
name = "Configuration";
89+
break;
90+
91+
case MigrationStepEnum.AppLogic:
92+
name = "App Logic";
93+
break;
94+
95+
case MigrationStepEnum.MigrationProcess:
96+
name = "Migration Process";
97+
break;
98+
99+
}
100+
101+
return name;
102+
}
103+
104+
/// <summary>
105+
/// Gets a friendly string name for each message type.
106+
/// </summary>
107+
/// <param name="source">Message type to process.</param>
108+
/// <returns>The friendly name.</returns>
109+
public static string GetName(this MessageTypeEnum source)
110+
{
111+
string name = null;
112+
113+
switch (source)
114+
{
115+
case MessageTypeEnum.Information:
116+
name = "Information";
117+
break;
118+
119+
case MessageTypeEnum.Warning:
120+
name = "Warning";
121+
break;
122+
123+
case MessageTypeEnum.Error:
124+
name = "Error";
125+
break;
126+
}
127+
128+
return name;
129+
}
130+
}
131+
}

0 commit comments

Comments
 (0)