Skip to content

Commit

Permalink
chore: many small refatorings
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrybublik committed May 29, 2020
1 parent 30eaa52 commit a28168f
Show file tree
Hide file tree
Showing 16 changed files with 191 additions and 46 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,4 @@ MigrationBackup/
# Unclear
.DS_Store
/generated
/utils/ModifyTool/Properties/launchSettings.json
24 changes: 24 additions & 0 deletions devops/generate-devops-utils.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
REM Publish UninstallTemplate to \devops\utils folder

set utils=utils

if exist %utils% (
rmdir %utils% /s /q
)

if %ERRORLEVEL% NEQ 0 (
goto EXIT
)

cd ..\utils\UninstallTemplate

dotnet publish -c release -o ..\..\devops\%utils%

if %ERRORLEVEL% NEQ 0 (
goto EXIT
)

cd ..\..\devops

:EXIT
EXIT /B %ERRORLEVEL%
Binary file added devops/utils/JetBrains.Annotations.dll
Binary file not shown.
Binary file added devops/utils/System.CodeDom.dll
Binary file not shown.
Binary file added devops/utils/System.Management.dll
Binary file not shown.
106 changes: 105 additions & 1 deletion devops/utils/UninstallTemplate.deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,121 @@
"targets": {
".NETCoreApp,Version=v3.1": {
"UninstallTemplate/1.0.0": {
"dependencies": {
"JetBrains.Annotations": "2020.1.0",
"System.Management": "4.7.0"
},
"runtime": {
"UninstallTemplate.dll": {}
}
}
},
"JetBrains.Annotations/2020.1.0": {
"runtime": {
"lib/netstandard2.0/JetBrains.Annotations.dll": {
"assemblyVersion": "2020.1.0.0",
"fileVersion": "2020.1.0.0"
}
}
},
"Microsoft.NETCore.Platforms/3.1.0": {},
"Microsoft.Win32.Registry/4.7.0": {
"dependencies": {
"System.Security.AccessControl": "4.7.0",
"System.Security.Principal.Windows": "4.7.0"
}
},
"System.CodeDom/4.7.0": {
"runtime": {
"lib/netstandard2.0/System.CodeDom.dll": {
"assemblyVersion": "4.0.3.0",
"fileVersion": "4.700.19.56404"
}
}
},
"System.Management/4.7.0": {
"dependencies": {
"Microsoft.NETCore.Platforms": "3.1.0",
"Microsoft.Win32.Registry": "4.7.0",
"System.CodeDom": "4.7.0"
},
"runtime": {
"lib/netstandard2.0/System.Management.dll": {
"assemblyVersion": "4.0.1.0",
"fileVersion": "4.700.19.56404"
}
},
"runtimeTargets": {
"runtimes/win/lib/netcoreapp2.0/System.Management.dll": {
"rid": "win",
"assetType": "runtime",
"assemblyVersion": "4.0.1.0",
"fileVersion": "4.700.19.56404"
}
}
},
"System.Security.AccessControl/4.7.0": {
"dependencies": {
"Microsoft.NETCore.Platforms": "3.1.0",
"System.Security.Principal.Windows": "4.7.0"
}
},
"System.Security.Principal.Windows/4.7.0": {}
}
},
"libraries": {
"UninstallTemplate/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"JetBrains.Annotations/2020.1.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-kD9D2ey3DGeLbfIzS8PkwLFkcF5vCOLk2rdjgfSxTfpoyovl7gAyoS6yq6T77zo9QgJGaVJ7PO/cSgLopnKlzg==",
"path": "jetbrains.annotations/2020.1.0",
"hashPath": "jetbrains.annotations.2020.1.0.nupkg.sha512"
},
"Microsoft.NETCore.Platforms/3.1.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-z7aeg8oHln2CuNulfhiLYxCVMPEwBl3rzicjvIX+4sUuCwvXw5oXQEtbiU2c0z4qYL5L3Kmx0mMA/+t/SbY67w==",
"path": "microsoft.netcore.platforms/3.1.0",
"hashPath": "microsoft.netcore.platforms.3.1.0.nupkg.sha512"
},
"Microsoft.Win32.Registry/4.7.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-KSrRMb5vNi0CWSGG1++id2ZOs/1QhRqROt+qgbEAdQuGjGrFcl4AOl4/exGPUYz2wUnU42nvJqon1T3U0kPXLA==",
"path": "microsoft.win32.registry/4.7.0",
"hashPath": "microsoft.win32.registry.4.7.0.nupkg.sha512"
},
"System.CodeDom/4.7.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-Hs9pw/kmvH3lXaZ1LFKj3pLQsiGfj2xo3sxSzwiLlRL6UcMZUTeCfoJ9Udalvn3yq5dLlPEZzYegrTQ1/LhPOQ==",
"path": "system.codedom/4.7.0",
"hashPath": "system.codedom.4.7.0.nupkg.sha512"
},
"System.Management/4.7.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-IY+uuGhgzWiCg21i8IvQeY/Z7m1tX8VuPF+ludfn7iTCaccTtJo5HkjZbBEL8kbBubKhAKKtNXr7uMtmAc28Pw==",
"path": "system.management/4.7.0",
"hashPath": "system.management.4.7.0.nupkg.sha512"
},
"System.Security.AccessControl/4.7.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-JECvTt5aFF3WT3gHpfofL2MNNP6v84sxtXxpqhLBCcDRzqsPBmHhQ6shv4DwwN2tRlzsUxtb3G9M3763rbXKDg==",
"path": "system.security.accesscontrol/4.7.0",
"hashPath": "system.security.accesscontrol.4.7.0.nupkg.sha512"
},
"System.Security.Principal.Windows/4.7.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-ojD0PX0XhneCsUbAZVKdb7h/70vyYMDYs85lwEI+LngEONe/17A0cFaRFqZU+sOEidcVswYWikYOQ9PPfjlbtQ==",
"path": "system.security.principal.windows/4.7.0",
"hashPath": "system.security.principal.windows.4.7.0.nupkg.sha512"
}
}
}
Binary file modified devops/utils/UninstallTemplate.dll
Binary file not shown.
Binary file added devops/utils/UninstallTemplate.exe
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion specs/LogoFX.Cli.Dotnet.Specs.Steps/Consts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
{
internal static class Consts
{
public static int ProcessExecutionTimeout => 60000;
public static int ProcessExecutionTimeout => 40000;
}
}
47 changes: 24 additions & 23 deletions utils/ModifyTool/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ internal sealed class Engine
private const string MappingProfileFileName = "MappingProfile.cs";
private const string MappingProfileClassName = "MappingProfile";

private const string ModelSuffix = "Model";

private readonly string _solutionFolder;

public Engine(string solutionFolder)
Expand All @@ -29,7 +31,7 @@ public Engine(string solutionFolder)

private string GetProjectFolder()
{
return $"{_solutionFolder}.Model";
return $"{_solutionFolder}.{ModelSuffix}";
}

public void CreateMapping(string entityName)
Expand Down Expand Up @@ -148,9 +150,11 @@ public void RegisterMappers(string entityName)

private void ReplaceInFile(string filePath, string solutionName)
{
const string namespaceKey = "namespace";

var lines = File.ReadAllText(filePath);
var index1 = lines.IndexOf("namespace", StringComparison.Ordinal) + "namespace".Length;
var index2 = lines.IndexOf(".Model", index1, StringComparison.Ordinal);
var index1 = lines.IndexOf(namespaceKey, StringComparison.Ordinal) + namespaceKey.Length;
var index2 = lines.IndexOf($".{ModelSuffix}", index1, StringComparison.Ordinal);
var oldSolutionName = lines.Substring(index1, index2 - index1).Trim();
lines = lines.Replace(oldSolutionName, solutionName);
File.WriteAllText(filePath, lines);
Expand All @@ -176,29 +180,26 @@ private ExpressionStatementSyntax AddMapperRegistration(ExpressionStatementSynta
return statement;
}

private bool CheckExpression(CSharpSyntaxNode expression, NameSyntax name)
private static bool CheckExpression(CSharpSyntaxNode expression, SyntaxNode name)
{
if (expression is NameSyntax ns)
{
return SyntaxFactory.AreEquivalent(ns, name);
}

if (expression is ExpressionStatementSyntax ess)
{
return CheckExpression(ess.Expression, name);
}

if (expression is InvocationExpressionSyntax ies)
{
return CheckExpression(ies.Expression, name);
}

if (expression is MemberAccessExpressionSyntax maes)
while (true)
{
return CheckExpression(maes.Name, name) || CheckExpression(maes.Expression, name);
switch (expression)
{
case NameSyntax ns:
return SyntaxFactory.AreEquivalent(ns, name);
case ExpressionStatementSyntax ess:
expression = ess.Expression;
continue;
case InvocationExpressionSyntax ies:
expression = ies.Expression;
continue;
case MemberAccessExpressionSyntax maes:
return CheckExpression(maes.Name, name) || CheckExpression(maes.Expression, name);
default:
return false;
}
}

return false;
}

private bool CheckExpression(CSharpSyntaxNode expression, SyntaxToken name)
Expand Down
4 changes: 2 additions & 2 deletions utils/ModifyTool/ModifyTool.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand All @@ -15,7 +15,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.5.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.6.0" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 0 additions & 8 deletions utils/ModifyTool/Properties/launchSettings.json

This file was deleted.

31 changes: 21 additions & 10 deletions utils/UninstallTemplate/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using JetBrains.Annotations;
using LogoFX.Cli.Dotnet.Specs.Steps;
using LogoFX.Cli.Dotnet.Specs.Tests.Infra;

namespace UninstallTemplate
{
class Program
[UsedImplicitly]
internal sealed class Program
{
private enum TemplateNameKind
{
Expand All @@ -16,49 +20,56 @@ private enum TemplateNameKind
Directory
}

static int Main(string[] args)
private static class ReturnCode
{
public const int Successful = 0;
public const int IncorrectFunction = 1;
public const int Error = -1;
}

private static int Main(string[] args)
{
if (args.Length < 2)
{
ShowUsage();
return 1;
return ReturnCode.IncorrectFunction;
}

var kind = GetTemplateNameKind(args[0]);
if (kind == TemplateNameKind.None)
{
ShowUsage();
return 1;
return ReturnCode.IncorrectFunction;
}

var name = string.Join(' ', args.Skip(1));
var lines = LaunchApp("dotnet new -u");

if (lines == null)
{
return -1;
return ReturnCode.Error;
}

var uninstallString = FindUninstallString(lines, name, kind);

if (string.IsNullOrEmpty(uninstallString))
{
return 0;
return ReturnCode.Successful;
}

lines = LaunchApp(uninstallString);

if (lines == null)
{
return -1;
return ReturnCode.Error;
}

foreach (var line in lines)
{
Console.WriteLine(line);
}

return 0;
return ReturnCode.Successful;
}

private static int GetIndents(string line)
Expand Down Expand Up @@ -257,12 +268,12 @@ private static string[] LaunchApp(string appName, string[] args)

process.BeginErrorReadLine();

process.WaitForExit(30000);
process.WaitForExit(Consts.ProcessExecutionTimeout);

if (!process.HasExited)
{
isError = true;
process.Kill();
process.KillProcessAndChildren();
}

process.Close();
Expand Down
12 changes: 11 additions & 1 deletion utils/UninstallTemplate/UninstallTemplate.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand All @@ -10,4 +10,14 @@
<OutputPath>bin</OutputPath>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\..\specs\LogoFX.Cli.Dotnet.Specs.Steps\Consts.cs" Link="Consts.cs" />
<Compile Include="..\..\specs\LogoFX.Cli.Dotnet.Specs.Tests.Infra\ProcessExtensions.cs" Link="ProcessExtensions.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" />
<PackageReference Include="System.Management" Version="4.7.0" />
</ItemGroup>

</Project>
2 changes: 2 additions & 0 deletions utils/UninstallTemplate/UninstallTemplate.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=Consts/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

0 comments on commit a28168f

Please sign in to comment.