Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit e55d143

Browse files
committed
add migration
1 parent da536c8 commit e55d143

File tree

13 files changed

+138
-24
lines changed

13 files changed

+138
-24
lines changed

HttpReports.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HttpReports.Transport.Grpc"
6565
EndProject
6666
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HttpReports.Collector.Grpc", "src\HttpReports.Collector.Grpc\HttpReports.Collector.Grpc.csproj", "{F8BC75E3-675C-442A-A653-8331B7357A20}"
6767
EndProject
68-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpReports.Collector.Demo", "example\HttpReports.Collector.Demo\HttpReports.Collector.Demo.csproj", "{7E1A2668-F5FA-44A4-851E-29CB18D3F279}"
68+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HttpReports.Collector.Demo", "example\HttpReports.Collector.Demo\HttpReports.Collector.Demo.csproj", "{7E1A2668-F5FA-44A4-851E-29CB18D3F279}"
6969
EndProject
7070
Global
7171
GlobalSection(SolutionConfigurationPlatforms) = preSolution

example/HttpReports.Demo/Controllers/WeatherForecastController.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ public class WeatherForecastController : ControllerBase
2020

2121
public WeatherForecastController(ILogger<WeatherForecastController> logger)
2222
{
23-
_logger = logger;
23+
_logger = logger;
2424
}
2525

26-
[HttpGet]
27-
public IEnumerable<WeatherForecast> Get()
26+
[HttpPost]
27+
public IEnumerable<WeatherForecast> Get(WeatherForecast weather)
2828
{
2929
var rng = new Random();
3030
return Enumerable.Range(1, 5).Select(index => new WeatherForecast

example/HttpReports.Demo/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
2020
Host.CreateDefaultBuilder(args)
2121
.ConfigureWebHostDefaults(webBuilder =>
2222
{
23-
webBuilder.UseStartup<Startup>();
23+
webBuilder.UseStartup<Startup>().UseUrls("http://localhost:5010");
2424
});
2525
}
2626
}

example/HttpReports.Demo/Startup.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public Startup(IConfiguration configuration)
2020

2121
public void ConfigureServices(IServiceCollection services)
2222
{
23-
//services.AddHttpReports().AddHttpTransport();
23+
services.AddHttpReports().AddHttpTransport();
2424

25-
services.AddHttpReportsDashboard().AddMySqlStorage();
25+
services.AddHttpReportsDashboard().AddPostgreSQLStorage();
2626

2727
services.AddControllers();
2828
services.AddSwaggerGen(c =>
@@ -35,7 +35,7 @@ public void ConfigureServices(IServiceCollection services)
3535

3636
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
3737
{
38-
//app.UseHttpReports();
38+
app.UseHttpReports();
3939
//app.UseMiddleware<ErrorMiddleware>();
4040

4141
app.UseHttpReportsDashboard();

example/HttpReports.Demo/appsettings.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"Logging": {
33
"LogLevel": {
4-
"Default": "Information",
5-
"Microsoft": "Warning",
6-
"Microsoft.Hosting.Lifetime": "Information"
4+
"Default": "Error",
5+
"Microsoft": "Error",
6+
"Microsoft.Hosting.Lifetime": "Error"
77
}
88
},
99
"HttpReports": {
@@ -16,7 +16,7 @@
1616
"Service": "User",
1717
"Switch": true,
1818
"MaxBytes": 20000,
19-
"RequestFilter": [ "/api/Health/*" ],
19+
"RequestFilter": [ "/api/Health/*","/HttpReports*"],
2020
"WithRequest": true,
2121
"WithResponse": true,
2222
"WithCookie": true,
@@ -26,9 +26,9 @@
2626
"QueryCount":6,
2727
"ExpireDay": 3,
2828
"Storage": {
29-
"ConnectionString": "DataBase=HttpReports;Data Source=localhost;User Id=root;Password=123456;",
29+
//"ConnectionString": "DataBase=HttpReports;Data Source=localhost;User Id=root;Password=123456;",
3030
//"ConnectionString": "Max Pool Size = 512;server=.;uid=sa;pwd=123456;database=HttpReports;Connection Timeout=900;",
31-
//"ConnectionString": "Host=localhost;Port=5432;Username=postgres;Password=123456;Database=HttpReports;",
31+
"ConnectionString": "Host=127.0.0.1;Port=5432;Username=postgres;Password=123456;Database=HttpReports;",
3232
"DeferSecond": 10,
3333
"DeferThreshold": 1
3434
},

src/HttpReports.Core/BasicConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static class BasicConfig
7171

7272
public const string Language = "Language";
7373

74-
public const string DefaultLanguage = "en-us";
74+
public const string DefaultLanguage = "zh-cn";
7575

7676
public const string StaticFilesRoot = "HttpReports.Dashboard";
7777

src/HttpReports.Dashboard.UI/src/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Vue.use(VueResource)
3333
Vue.use(VueParticles)
3434

3535
const i18n = new VueI18n({
36-
locale: basic.isEmpty(localStorage.getItem("locale")) ? 'en-us': localStorage.getItem("locale"),
36+
locale: basic.isEmpty(localStorage.getItem("locale")) ? 'zh-cn': localStorage.getItem("locale"),
3737
messages: {
3838
'en-us': Object.assign(require("../static/lang/en-us.json"), enLocale),
3939
'zh-cn': Object.assign(require("../static/lang/zh-cn.json"), zhLocale),

src/HttpReports.Dashboard.UI/src/view/Index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ export default {
630630
.catch((_) => {});
631631
},
632632
changeLanguage(type) {
633+
633634
this.$i18n.locale = type;
634635
635636
localStorage.setItem("locale", type);
@@ -642,8 +643,7 @@ export default {
642643
//this.$message({ message: "Switch: " + type, type: "success" });
643644
644645
this.$http.get(`/static/lang/${type}.json`).then((res) => {
645-
this.$store.commit("set_lang", res.body);
646-
646+
this.$store.commit("set_lang", res.body);
647647
window.location.reload();
648648
});
649649
});

src/HttpReports.Dashboard/DashboardOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class DashboardOptions : IOptions<DashboardOptions>
1414

1515
public int QueryCount { get; set; } = 6;
1616

17-
public bool Migrate { get; set; } = true;
17+
public bool Migration { get; set; } = true;
1818

1919
public HealthCheckOptions Check { get; set; } = new HealthCheckOptions();
2020

src/HttpReports.Dashboard/DependencyInjectionExtensions.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,21 +117,34 @@ public static IApplicationBuilder UseHttpReportsDashboard(this IApplicationBuild
117117

118118
var storage = app.ApplicationServices.GetRequiredService<IHttpReportsStorage>() ?? throw new ArgumentNullException("Storage Not Found");
119119

120-
storage.InitAsync().Wait();
120+
if (options.Value.Migration) storage.InitAsync().Wait();
121121

122122
app.ApplicationServices.GetService<IScheduleService>().InitAsync().Wait();
123123

124124
var localizeService = app.ApplicationServices.GetRequiredService<ILocalizeService>() ?? throw new ArgumentNullException("localizeService Not Found");
125125

126-
if (options.Value.Migrate) localizeService.InitAsync().Wait();
126+
localizeService.InitAsync().Wait();
127127

128128
app.UseHttpCollector();
129129

130130
app.UseMiddleware<DashboardMiddleware>();
131131

132132
return app;
133+
}
134+
135+
136+
public static IApplicationBuilder UseHttpReportsMigration(this IApplicationBuilder app)
137+
{
138+
ServiceContainer.provider = app.ApplicationServices.GetRequiredService<IServiceProvider>() ?? throw new ArgumentNullException("ServiceProvider Init Failed");
139+
140+
var storage = app.ApplicationServices.GetRequiredService<IHttpReportsStorage>() ?? throw new ArgumentNullException("Storage Not Found");
141+
142+
storage.PrintSQLAsync().Wait();
143+
144+
return app;
145+
133146
}
134-
147+
135148

136149
private static IServiceCollection AddHandleService(this IServiceCollection services)
137150
{

0 commit comments

Comments
 (0)