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
69743608
Commit
69743608
authored
Oct 15, 2018
by
Kirill
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Контент туров скачивается на диск
parent
f0633a9f
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
56 additions
and
46 deletions
+56
-46
ContentLoadingTask.cs
TourDataManager/ContentLoadingTask.cs
+41
-0
Db.cs
TourDataManager/Db.cs
+1
-0
FetchTourContentUseCase.cs
TourDataManager/FetchTourContentUseCase.cs
+2
-43
TourDataManager.cs
TourDataManager/TourDataManager.cs
+1
-1
TourDataManager.csproj
TourDataManager/TourDataManager.csproj
+1
-0
Program.cs
TourDataManagerConsoleApplication/Program.cs
+10
-2
No files found.
TourDataManager/ContentLoadingTask.cs
0 → 100644
View file @
69743608
using
System
;
using
System.IO
;
using
System.Net
;
using
System.Threading.Tasks
;
using
File
=
TourDataManager
.
Entities
.
File
;
namespace
TourDataManager
{
public
class
ContentLoadingTask
{
private
ITourFilesListFetcher
filesFetcher
;
private
long
tourId
;
public
ContentLoadingTask
(
long
tourId
,
ITourFilesListFetcher
filesFetcher
){
this
.
filesFetcher
=
filesFetcher
;
this
.
tourId
=
tourId
;
}
public
void
Run
(){
Debug
.
Log
(
$"ContentLoadingTask.Run()
{{
tourId
=
{
tourId
}
}}
"
);
var
files
=
filesFetcher
.
FetchFilesAsync
(
tourId
).
Result
;
var
webClient
=
new
WebClient
();
var
len
=
files
.
Length
;
var
count
=
0
;
foreach
(
var
file
in
files
){
Debug
.
Log
(
$"
{++
count
}
of
{
len
}
|
{
file
.
LocalUrl
}
"
);
var
dir
=
Path
.
GetDirectoryName
(
file
.
LocalUrl
);
if
(!
Directory
.
Exists
(
dir
))
Directory
.
CreateDirectory
(
dir
);
webClient
.
DownloadFile
(
new
Uri
(
file
.
Url
),
file
.
LocalUrl
);
}
}
}
}
\ No newline at end of file
TourDataManager/Db.cs
View file @
69743608
...
...
@@ -90,6 +90,7 @@ namespace TourDataManager {
}
public
void
InsertFiles
(
IEnumerable
<
File
>
files
){
Debug
.
Log
(
"Inserting Files list to database"
);
var
diff
=
files
.
Where
(
file
=>
!
context
.
Files
.
Any
(
file1
=>
file
.
Url
==
file1
.
Url
));
context
.
Files
.
AddRange
(
diff
);
context
.
SaveChanges
();
...
...
TourDataManager/FetchTourContentUseCase.cs
View file @
69743608
...
...
@@ -35,16 +35,14 @@ namespace TourDataManager {
/// <param name="tourId"></param>
/// <returns></returns>
public
async
Task
<
File
[
]>
FetchFilesAsync
(
long
tourId
){
Debug
.
Log
(
"Fetching Files list"
);
var
response
=
await
HttpClient
.
GetAsync
(
$"https://biganto.com/api-novus/tours.getFiles?client=desktopplayer&client_version=3.0&v=2.0&id=
{
tourId
}
"
);
var
content
=
await
response
.
Content
.
ReadAsStringAsync
();
var
fukin_dict_wrap
=
JsonConvert
.
DeserializeObject
<
Dictionary
<
string
,
File
[
]>
>(
content
);
var
files
=
fukin_dict_wrap
[
tourId
.
ToString
()];
var
regex
=
new
Regex
(
@"\/assets.+?(?=\?|$)"
);
var
regex
=
new
Regex
(
@"assets.+?(?=\?|$)"
);
// TODO Что если не сматчится?
foreach
(
var
file
in
files
){
// Id AutoIncrement
...
...
@@ -56,43 +54,4 @@ namespace TourDataManager {
return
files
;
}
}
public
class
ContentLoadingTask
{
private
ITourFilesListFetcher
filesFetcher
;
private
long
tourId
;
public
ContentLoadingTask
(
long
tourId
,
ITourFilesListFetcher
filesFetcher
){
this
.
filesFetcher
=
filesFetcher
;
this
.
tourId
=
tourId
;
}
public
async
Task
Run
(){
Debug
.
Log
(
$"ContentLoadingTask.Run()
{{
tourId
=
{
tourId
}
}}
"
);
var
files
=
await
filesFetcher
.
FetchFilesAsync
(
tourId
);
var
webClient
=
new
WebClient
();
async
void
Download
(
File
file
){
await
webClient
.
DownloadFileTaskAsync
(
new
Uri
(
file
.
LocalUrl
),
file
.
LocalUrl
);
}
await
Task
.
Factory
.
StartNew
(()
=>
{
// Parallel.ForEach(files, new ParallelOptions{MaxDegreeOfParallelism = 4}, Download);
});
foreach
(
var
file
in
files
){
Debug
.
Log
(
file
);
}
Debug
.
Log
(
"Done"
);
}
}
}
\ No newline at end of file
TourDataManager/TourDataManager.cs
View file @
69743608
...
...
@@ -15,7 +15,7 @@ namespace TourDataManager {
/// </summary>
public
class
TourDataManager
{
p
rivate
static
string
PersistentPath
;
p
ublic
static
volatile
string
PersistentPath
;
public
static
string
GetPathInPersistent
(
string
relative
){
return
Path
.
Combine
(
PersistentPath
,
relative
);
...
...
TourDataManager/TourDataManager.csproj
View file @
69743608
...
...
@@ -105,6 +105,7 @@
<ItemGroup>
<Compile
Include=
"Authenticator.cs"
/>
<Compile
Include=
"BigantoErrorException.cs"
/>
<Compile
Include=
"ContentLoadingTask.cs"
/>
<Compile
Include=
"CookieStorage.cs"
/>
<Compile
Include=
"Db.cs"
/>
<Compile
Include=
"Debug.cs"
/>
...
...
TourDataManagerConsoleApplication/Program.cs
View file @
69743608
using
System
;
using
System.IO
;
using
System.Net
;
using
System.Threading.Tasks
;
using
TourDataManager
;
using
TourDataManager.Entities
;
...
...
@@ -33,8 +35,14 @@ namespace TourDataManagerConsoleApplication {
}
System
.
Diagnostics
.
Debug
.
Assert
(
tours
!=
null
,
nameof
(
tours
)
+
" != null"
);
var
contentLoadingTask
=
plugin
.
DownloadTourContent
(
tours
[
0
].
Id
);
await
contentLoadingTask
.
Run
();
var
contentLoadingTask
=
plugin
.
DownloadTourContent
(
tours
[
2
].
Id
);
var
x
=
Task
.
Factory
.
StartNew
(()
=>
{
contentLoadingTask
.
Run
();
})
.
ContinueWith
(
task
=>
{
Debug
.
Log
(
"Done"
);
});
}
catch
(
Exception
e
){
Debug
.
Log
(
e
);
}
...
...
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