Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
TourDataManager
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill
TourDataManager
Commits
13c40374
Commit
13c40374
authored
Oct 12, 2018
by
Kirill
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Файлы добавляются в БД
parent
f88a196a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
12 deletions
+29
-12
Db.cs
TourDataManager/Db.cs
+11
-2
File.cs
TourDataManager/Entities/File.cs
+4
-2
FetchTourContentUseCase.cs
TourDataManager/FetchTourContentUseCase.cs
+14
-8
No files found.
TourDataManager/Db.cs
View file @
13c40374
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
();
}
...
...
TourDataManager/Entities/File.cs
View file @
13c40374
using
SQLite.CodeFirst
;
namespace
TourDataManager.Entities
{
public
class
File
{
public
long
Tour
Id
{
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
;
}
...
...
TourDataManager/FetchTourContentUseCase.cs
View file @
13c40374
...
...
@@ -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
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment