Commit 13c40374 authored by Kirill's avatar Kirill

Файлы добавляются в БД

parent f88a196a
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Common;
......@@ -49,6 +50,7 @@ namespace TourDataManager {
public DbSet<Estate> Estates{ get; set; }
public DbSet<Tour> Tours{ get; set; }
public DbSet<File> Files{ get; set; }
......@@ -71,14 +73,14 @@ namespace TourDataManager {
return context.Estates.ToArrayAsync();
}
public void InsertEstates(Estate[] estates){
public void InsertEstates(IEnumerable<Estate> estates){
foreach (var estate in estates){
context.Estates.AddOrUpdate(estate);
}
context.SaveChanges();
}
public void InsertTours(Tour[] tours){
public void InsertTours(IEnumerable<Tour> tours){
foreach (var tour in tours){
context.Tours.AddOrUpdate(tour);
}
......@@ -86,6 +88,13 @@ namespace TourDataManager {
}
public void InsertFiles(IEnumerable<File> files){
foreach (var file in files){
context.Files.AddOrUpdate(file);
}
context.SaveChanges();
}
public void Dispose(){
connection?.Dispose();
}
......
using SQLite.CodeFirst;
namespace TourDataManager.Entities {
public class File {
public long TourId{ get; set; }
public string Url{ get; set; }
public long Id{ get; set; }
[Unique] public string Url{ get; set; }
public int Size{ get; set; }
public string LocalUrl{ get; set; }
......
......@@ -20,6 +20,7 @@ namespace TourDataManager {
public class FetchTourContentUseCase : ITourFilesListFetcher{
[Inject] public HttpClient HttpClient{ get; set; }
[Inject] public Db Database{ get; set; }
public ContentLoadingTask FetchTourContentFromServerAsync(long tourId){
Debug.Log($"ContentLoadingTask queued for tour {tourId}");
......@@ -28,6 +29,11 @@ namespace TourDataManager {
return contentLoadingTask;
}
/// <summary>
/// Получить список файлов
/// </summary>
/// <param name="tourId"></param>
/// <returns></returns>
public async Task<File[]> FetchFilesAsync(long tourId){
var response = await HttpClient.GetAsync(
$"https://biganto.com/api-novus/tours.getFiles?client=desktopplayer&client_version=3.0&v=2.0&id={tourId}");
......@@ -39,20 +45,20 @@ namespace TourDataManager {
var regex = new Regex(@"\/assets.+?(?=\?|$)");
// TODO Что если не сматчится?
foreach (var file in files){
file.TourId = tourId;
file.LocalUrl = TourDataManager.GetPathInPersistent(regex.Match(file.Url).Value);
// Id AutoIncrement
var val = regex.Match(file.Url).Value;
System.Diagnostics.Debug.Assert(!string.IsNullOrEmpty(val));
file.LocalUrl = TourDataManager.GetPathInPersistent(val);
}
Database.InsertFiles(files);
return files;
}
}
public class ContentLoadingTask {
private string PersistentPath;
private ITourFilesListFetcher filesFetcher;
private long tourId;
......@@ -63,9 +69,9 @@ namespace TourDataManager {
public async Task Run(){
Debug.Log($"ContentLoadingTask.Run(){{ tourId = {tourId} }}");
var files = await filesFetcher.FetchFilesAsync(tourId);
// add to db
var webClient = new WebClient();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment