Skip to content

Commit 72c50fb

Browse files
committed
Added Upgrade project, work in progress
1 parent c513b9b commit 72c50fb

File tree

5 files changed

+159
-2
lines changed

5 files changed

+159
-2
lines changed

Blogifier.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{BE5E262F
4141
build\build.ps1 = build\build.ps1
4242
EndProjectSection
4343
EndProject
44+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Upgrade", "src\Upgrade\Upgrade.csproj", "{CECA836F-2FFA-47DA-B846-8F44C2A4B783}"
45+
EndProject
4446
Global
4547
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4648
Debug|Any CPU = Debug|Any CPU
@@ -63,6 +65,10 @@ Global
6365
{1CBAC56F-3CFB-497A-86B0-9F49CCFC78DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
6466
{1CBAC56F-3CFB-497A-86B0-9F49CCFC78DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
6567
{1CBAC56F-3CFB-497A-86B0-9F49CCFC78DB}.Release|Any CPU.Build.0 = Release|Any CPU
68+
{CECA836F-2FFA-47DA-B846-8F44C2A4B783}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
69+
{CECA836F-2FFA-47DA-B846-8F44C2A4B783}.Debug|Any CPU.Build.0 = Debug|Any CPU
70+
{CECA836F-2FFA-47DA-B846-8F44C2A4B783}.Release|Any CPU.ActiveCfg = Release|Any CPU
71+
{CECA836F-2FFA-47DA-B846-8F44C2A4B783}.Release|Any CPU.Build.0 = Release|Any CPU
6672
EndGlobalSection
6773
GlobalSection(SolutionProperties) = preSolution
6874
HideSolutionNode = FALSE
@@ -72,6 +78,7 @@ Global
7278
{88490336-DB30-4F9D-B737-3CA993F4EDC0} = {39614650-0D6E-4502-B87D-184366060F59}
7379
{920B80AA-983C-46ED-8A19-8DC43C839237} = {39614650-0D6E-4502-B87D-184366060F59}
7480
{1CBAC56F-3CFB-497A-86B0-9F49CCFC78DB} = {57BDF133-7290-40EA-8503-1BFCBBEEBB3A}
81+
{CECA836F-2FFA-47DA-B846-8F44C2A4B783} = {39614650-0D6E-4502-B87D-184366060F59}
7582
EndGlobalSection
7683
GlobalSection(ExtensibilityGlobals) = postSolution
7784
SolutionGuid = {D601BCCC-A1D9-415B-94B5-B3C0EF4AAF0B}

src/App/Pages/Admin/Upgrade/Index.cshtml.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.AspNetCore.Hosting;
2+
using System;
23
using System.Diagnostics;
34

45
namespace App.Pages.Admin.Upgrade
@@ -31,12 +32,18 @@ public void OnPost()
3132
// start upgrade process
3233
//Process p = new Process();
3334
//p.StartInfo.FileName = "dotnet";
34-
//p.StartInfo.Arguments = "upgrade.dll";
35+
//p.StartInfo.Arguments = "Upgrade.dll";
3536
//p.StartInfo.UseShellExecute = false;
3637
//p.StartInfo.CreateNoWindow = false;
37-
3838
//p.Start();
39+
3940
ApplicationLifetime.StopApplication();
41+
42+
//Program.Main(null);
43+
44+
//Process.GetCurrentProcess().Kill();
45+
//Environment.Exit(0);
46+
//Program.Shutdown();
4047
}
4148
}
4249
}

src/App/Program.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
using Microsoft.EntityFrameworkCore;
88
using Microsoft.Extensions.DependencyInjection;
99
using System.Linq;
10+
using System.Threading;
1011

1112
namespace App
1213
{
1314
public class Program
1415
{
16+
private static CancellationTokenSource cancelTokenSource = new CancellationTokenSource();
17+
1518
public static void Main(string[] args)
1619
{
1720
var host = CreateWebHostBuilder(args).Build();
@@ -52,5 +55,10 @@ public static void Main(string[] args)
5255

5356
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
5457
WebHost.CreateDefaultBuilder(args).UseStartup<Startup>();
58+
59+
public static void Shutdown()
60+
{
61+
cancelTokenSource.Cancel();
62+
}
5563
}
5664
}

src/Upgrade/Program.cs

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.IO;
5+
using System.Reflection;
6+
7+
namespace Upgrade
8+
{
9+
class Program
10+
{
11+
static string _appDir = "";
12+
static string _upgDir = "";
13+
static string _slash = Path.DirectorySeparatorChar.ToString();
14+
static List<string> _items;
15+
16+
static void Main(string[] args)
17+
{
18+
_appDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
19+
_upgDir = $"{_appDir}{_slash}upgrade";
20+
_items = new List<string>();
21+
22+
_items.Add($"STARTING UPGRADE IN: {_appDir}");
23+
24+
// wait for web app to stop
25+
System.Threading.Thread.Sleep(3000);
26+
27+
var files = Directory.GetFiles(_appDir);
28+
29+
foreach (var file in GetCoreFiles())
30+
{
31+
ReplaceFile(file);
32+
}
33+
34+
ReplaceFolder($"wwwroot{_slash}admin");
35+
ReplaceFolder($"wwwroot{_slash}lib");
36+
37+
using (StreamWriter writer = new StreamWriter("upgrade.log"))
38+
{
39+
foreach (var item in _items)
40+
{
41+
writer.WriteLine(item);
42+
}
43+
}
44+
45+
Process p = new Process();
46+
p.StartInfo.FileName = "dotnet";
47+
p.StartInfo.Arguments = "App.dll";
48+
p.StartInfo.UseShellExecute = false;
49+
p.StartInfo.CreateNoWindow = false;
50+
p.Start();
51+
}
52+
53+
static void ReplaceFile(string file)
54+
{
55+
string oldFile = $"{_appDir}{_slash}{file}";
56+
string newFile = $"{_upgDir}{_slash}{file}";
57+
try
58+
{
59+
if (File.Exists(oldFile))
60+
File.Delete(oldFile);
61+
62+
File.Copy(newFile, oldFile);
63+
_items.Add($"Replacing {oldFile} with {newFile}");
64+
}
65+
catch (Exception fe)
66+
{
67+
_items.Add($"Error replacing {oldFile}: {fe.Message}");
68+
}
69+
}
70+
71+
static void ReplaceFolder(string folder)
72+
{
73+
string oldFolder = $"{_appDir}{_slash}{folder}";
74+
string newFolder = $"{_upgDir}{_slash}{folder}";
75+
try
76+
{
77+
if (Directory.Exists(oldFolder))
78+
Directory.Delete(oldFolder, true);
79+
80+
Directory.Move(newFolder, oldFolder);
81+
_items.Add($"Replacing {oldFolder} with {newFolder}");
82+
}
83+
catch (Exception fe)
84+
{
85+
_items.Add($"Error replacing {oldFolder}: {fe.Message}");
86+
}
87+
}
88+
89+
static string NameFromPath(string path)
90+
{
91+
int x = path.LastIndexOf(_slash);
92+
string name = path.Substring(x);
93+
return name;
94+
}
95+
96+
static List<string> GetCoreFiles()
97+
{
98+
return new List<string>
99+
{
100+
"App.deps.json",
101+
"App.dll",
102+
"App.pdb",
103+
"App.PrecompiledViews.dll",
104+
"App.PrecompiledViews.pdb",
105+
"App.runtimeconfig.json",
106+
"Common.dll",
107+
"Core.dll",
108+
"Core.pdb",
109+
"HtmlAgilityPack.dll",
110+
"Markdig.dll",
111+
"Microsoft.Data.Sqlite.dll",
112+
"Microsoft.EntityFrameworkCore.Sqlite.dll",
113+
"Microsoft.SyndicationFeed.ReaderWriter.dll",
114+
"ReverseMarkdown.dll",
115+
"Serilog.dll",
116+
"Serilog.Extensions.Logging.dll",
117+
"Serilog.Sinks.File.dll",
118+
"Serilog.Sinks.RollingFile.dll",
119+
"SQLitePCLRaw.batteries_green.dll",
120+
"SQLitePCLRaw.batteries_v2.dll",
121+
"SQLitePCLRaw.core.dll",
122+
"SQLitePCLRaw.provider.e_sqlite3.dll",
123+
"System.Xml.XPath.XmlDocument.dll"
124+
};
125+
}
126+
}
127+
}

src/Upgrade/Upgrade.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.1</TargetFramework>
6+
</PropertyGroup>
7+
8+
</Project>

0 commit comments

Comments
 (0)