forked from kendarorg/RepositoryCache
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustom_Load.cs
More file actions
52 lines (48 loc) · 1.71 KB
/
Custom_Load.cs
File metadata and controls
52 lines (48 loc) · 1.71 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
using MultiRepositories.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MultiRepositories;
using Nuget.Services;
using MultiRepositories.Repositories;
using System.IO;
namespace Nuget.Controllers
{
public class Custom_Load:RestAPI
{
private IRepositoryEntitiesRepository _repositoryEntitiesRepository;
private IInsertNugetService _insertNugetService;
public Custom_Load(IInsertNugetService insertNugetService, IRepositoryEntitiesRepository repositoryEntitiesRepository, params string[] paths)
: base(null, paths)
{
_repositoryEntitiesRepository = repositoryEntitiesRepository;
_insertNugetService = insertNugetService;
SetHandler(Handler);
}
private SerializableResponse Handler(SerializableRequest localRequest)
{
var result = new List<string>();
var repo = _repositoryEntitiesRepository.GetByName(localRequest.PathParams["repo"]);
var dir = localRequest.QueryParams["dir"];
if (!Directory.Exists(dir))
{
throw new Exception();
}
foreach(var file in Directory.GetFiles(dir, "*.nupkg"))
{
try
{
_insertNugetService.Insert(repo.Id, null, File.ReadAllBytes(file));
result.Add("Loaded " + Path.GetFileNameWithoutExtension(file));
}
catch
{
result.Add("Error " + Path.GetFileNameWithoutExtension(file));
}
}
return JsonResponse(result);
}
}
}