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