Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
91 lines (78 loc) · 2.94 KB
/
Copy pathProgram.cs
File metadata and controls
91 lines (78 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using Microsoft.EntityFrameworkCore;
using Search_Engine.Models;
using Search_Engine.Repositories;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddScoped<ISearchEngineRepository, SearchEngineRepository>();
builder.Services.AddDbContext<AppDbContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddScoped<ISearchEngineRepository, SearchEngineRepository>();
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowAll", policy =>
policy.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod());
});
var app = builder.Build();
// Automatically apply migrations at startup
using (var scope = app.Services.CreateScope())
{
// var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
// db.Database.Migrate();
// if (!db.UrlInfos.Any() && !db.WordInfos.Any())
// {
// var urlInfoPath = Environment.GetEnvironmentVariable("/Users/macbook/Desktop/UrlInfos.csv");
// var wordInfoPath = Environment.GetEnvironmentVariable("/Users/macbook/Desktop/WordInfos.csv");
// if (!string.IsNullOrEmpty(urlInfoPath) && File.Exists(urlInfoPath))
// {
// var urlLines = File.ReadAllLines(urlInfoPath);
// foreach (var line in urlLines)
// {
// var parts = line.Split(',');
// if (parts.Length >= 2)
// {
// db.UrlInfos.Add(new UrlInfo
// {
// URL_Num = int.Parse(parts[0].Trim()),
// URL = parts[1].Trim()
// });
// }
// }
// }
// if (!string.IsNullOrEmpty(wordInfoPath) && File.Exists(wordInfoPath))
// {
// var wordLines = File.ReadAllLines(wordInfoPath);
// foreach (var line in wordLines)
// {
// var parts = line.Split(',');
// if (parts.Length >= 4)
// {
// db.WordInfos.Add(new WordInfo
// {
// Word = parts[0].Trim(),
// URL_Num = int.Parse(parts[1].Trim()),
// Count = int.Parse(parts[2].Trim()),
// PageRank = double.Parse(parts[3].Trim(), System.Globalization.CultureInfo.InvariantCulture)
// });
// }
// }
// }
// db.SaveChanges();
// }
}
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
app.UseCors("AllowAll");
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();