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
f88a196a
Commit
f88a196a
authored
Oct 12, 2018
by
Kirill
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Список ассетов тура выводится в лог
parent
eec4d977
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
127 additions
and
13 deletions
+127
-13
File.cs
TourDataManager/Entities/File.cs
+10
-0
FetchTourContentUseCase.cs
TourDataManager/FetchTourContentUseCase.cs
+92
-0
TourDataManager.cs
TourDataManager/TourDataManager.cs
+15
-9
TourDataManager.csproj
TourDataManager/TourDataManager.csproj
+2
-0
Program.cs
TourDataManagerConsoleApplication/Program.cs
+8
-4
No files found.
TourDataManager/Entities/File.cs
0 → 100644
View file @
f88a196a
namespace
TourDataManager.Entities
{
public
class
File
{
public
long
TourId
{
get
;
set
;
}
public
string
Url
{
get
;
set
;
}
public
int
Size
{
get
;
set
;
}
public
string
LocalUrl
{
get
;
set
;
}
public
override
string
ToString
(){
return
$"
{
Size
}
|
{
Url
}
"
;
}
}
}
\ No newline at end of file
TourDataManager/FetchTourContentUseCase.cs
0 → 100644
View file @
f88a196a
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Net
;
using
System.Net.Http
;
using
System.Runtime.CompilerServices
;
using
System.Text.RegularExpressions
;
using
System.Threading.Tasks
;
using
Newtonsoft.Json
;
using
Newtonsoft.Json.Serialization
;
using
Ninject
;
using
TourDataManager.Entities
;
namespace
TourDataManager
{
public
interface
ITourFilesListFetcher
{
Task
<
File
[
]>
FetchFilesAsync
(
long
tourId
);
}
public
class
FetchTourContentUseCase
:
ITourFilesListFetcher
{
[
Inject
]
public
HttpClient
HttpClient
{
get
;
set
;
}
public
ContentLoadingTask
FetchTourContentFromServerAsync
(
long
tourId
){
Debug
.
Log
(
$"ContentLoadingTask queued for tour
{
tourId
}
"
);
var
contentLoadingTask
=
new
ContentLoadingTask
(
tourId
,
this
);
// add to queue
return
contentLoadingTask
;
}
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
}
"
);
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.+?(?=\?|$)"
);
foreach
(
var
file
in
files
){
file
.
TourId
=
tourId
;
file
.
LocalUrl
=
TourDataManager
.
GetPathInPersistent
(
regex
.
Match
(
file
.
Url
).
Value
);
}
return
files
;
}
}
public
class
ContentLoadingTask
{
private
string
PersistentPath
;
private
ITourFilesListFetcher
filesFetcher
;
private
long
tourId
;
public
ContentLoadingTask
(
long
tourId
,
ITourFilesListFetcher
filesFetcher
){
this
.
filesFetcher
=
filesFetcher
;
this
.
tourId
=
tourId
;
}
public
async
Task
Run
(){
var
files
=
await
filesFetcher
.
FetchFilesAsync
(
tourId
);
// add to db
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 @
f88a196a
using
System
;
using
System
;
using
System.Data.Entity
;
using
System.Data.Entity
;
using
System.IO
;
using
System.Net.Http
;
using
System.Net.Http
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
Ninject
;
using
Ninject
;
...
@@ -14,18 +15,22 @@ namespace TourDataManager {
...
@@ -14,18 +15,22 @@ namespace TourDataManager {
/// </summary>
/// </summary>
public
class
TourDataManager
{
public
class
TourDataManager
{
private
static
string
PersistentPath
;
public
static
string
GetPathInPersistent
(
string
relative
){
return
Path
.
Combine
(
PersistentPath
,
relative
);
}
public
FetchEstatesUseCase
estatesfetch
{
get
;
set
;
}
public
FetchEstatesUseCase
estatesfetch
{
get
;
set
;
}
public
FetchTourPreviewsUseCase
tourpreviewsfetch
{
get
;
set
;
}
public
FetchTourPreviewsUseCase
tourpreviewsfetch
{
get
;
set
;
}
public
Db
database
{
get
;
set
;
}
public
Db
database
{
get
;
set
;
}
private
string
persistentPath
;
private
IKernel
Container
;
private
IKernel
Container
;
public
TourDataManager
(
string
persistentPath
){
public
TourDataManager
(
string
persistentPath
){
this
.
p
ersistentPath
=
persistentPath
;
P
ersistentPath
=
persistentPath
;
Container
=
new
StandardKernel
(
new
MyModule
(
persistentPath
));
Container
=
new
StandardKernel
(
new
MyModule
());
estatesfetch
=
Container
.
Get
<
FetchEstatesUseCase
>();
estatesfetch
=
Container
.
Get
<
FetchEstatesUseCase
>();
...
@@ -53,18 +58,17 @@ namespace TourDataManager {
...
@@ -53,18 +58,17 @@ namespace TourDataManager {
database
.
InsertTours
(
tours
);
database
.
InsertTours
(
tours
);
return
tours
;
return
tours
;
}
}
public
ContentLoadingTask
DownloadTourContent
(
long
tourId
){
return
Container
.
Get
<
FetchTourContentUseCase
>().
FetchTourContentFromServerAsync
(
tourId
);
}
}
}
public
class
MyModule
:
NinjectModule
{
public
class
MyModule
:
NinjectModule
{
private
readonly
string
persistentPath
;
public
MyModule
(
string
persistentPath
){
this
.
persistentPath
=
persistentPath
;
}
public
override
void
Load
(){
public
override
void
Load
(){
var
cookieStorage
=
new
CookieStorage
(
persistentPath
+
"\\cookie.storage"
);
var
cookieStorage
=
new
CookieStorage
(
TourDataManager
.
GetPathInPersistent
(
"cookie.storage"
)
);
var
httpClientHandler
=
new
HttpClientHandler
();
var
httpClientHandler
=
new
HttpClientHandler
();
//CookieContainer сам запоминает полученные из ответа куки
//CookieContainer сам запоминает полученные из ответа куки
httpClientHandler
.
CookieContainer
=
cookieStorage
.
Get
();
httpClientHandler
.
CookieContainer
=
cookieStorage
.
Get
();
...
@@ -76,6 +80,8 @@ namespace TourDataManager {
...
@@ -76,6 +80,8 @@ namespace TourDataManager {
Bind
<
HttpClient
>().
ToConstant
(
httpClient
).
InSingletonScope
();
Bind
<
HttpClient
>().
ToConstant
(
httpClient
).
InSingletonScope
();
Bind
<
IAuthenticator
>().
To
<
Authenticator
>().
InSingletonScope
();
Bind
<
IAuthenticator
>().
To
<
Authenticator
>().
InSingletonScope
();
Bind
<
FetchEstatesUseCase
>().
ToSelf
().
InSingletonScope
();
Bind
<
FetchEstatesUseCase
>().
ToSelf
().
InSingletonScope
();
Bind
<
FetchTourPreviewsUseCase
>().
ToSelf
().
InSingletonScope
();
Bind
<
FetchTourContentUseCase
>().
ToSelf
().
InSingletonScope
();
Bind
<
Db
>().
ToSelf
().
InSingletonScope
();
Bind
<
Db
>().
ToSelf
().
InSingletonScope
();
}
}
...
...
TourDataManager/TourDataManager.csproj
View file @
f88a196a
...
@@ -109,8 +109,10 @@
...
@@ -109,8 +109,10 @@
<Compile
Include=
"Db.cs"
/>
<Compile
Include=
"Db.cs"
/>
<Compile
Include=
"Debug.cs"
/>
<Compile
Include=
"Debug.cs"
/>
<Compile
Include=
"Entities\Estate.cs"
/>
<Compile
Include=
"Entities\Estate.cs"
/>
<Compile
Include=
"Entities\File.cs"
/>
<Compile
Include=
"Entities\Tour.cs"
/>
<Compile
Include=
"Entities\Tour.cs"
/>
<Compile
Include=
"FetchEstatesUseCase.cs"
/>
<Compile
Include=
"FetchEstatesUseCase.cs"
/>
<Compile
Include=
"FetchTourContentUseCase.cs"
/>
<Compile
Include=
"FetchTourPreviewsUseCase.cs"
/>
<Compile
Include=
"FetchTourPreviewsUseCase.cs"
/>
<Compile
Include=
"IAuthenticator.cs"
/>
<Compile
Include=
"IAuthenticator.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
...
...
TourDataManagerConsoleApplication/Program.cs
View file @
f88a196a
...
@@ -22,20 +22,24 @@ namespace TourDataManagerConsoleApplication {
...
@@ -22,20 +22,24 @@ namespace TourDataManagerConsoleApplication {
public
static
async
void
AsyncMethod
(
TourDataManager
.
TourDataManager
plugin
){
public
static
async
void
AsyncMethod
(
TourDataManager
.
TourDataManager
plugin
){
try
{
try
{
var
estates
=
await
plugin
.
DownloadEstates
();
var
estates
=
await
plugin
.
DownloadEstates
();
Tour
[]
tours
=
null
;
foreach
(
var
estate
in
estates
){
foreach
(
var
estate
in
estates
){
Debug
.
Log
(
estate
);
Debug
.
Log
(
estate
);
var
tours
=
await
plugin
.
DownloadTourPreviews
(
estate
.
Id
);
tours
=
await
plugin
.
DownloadTourPreviews
(
estate
.
Id
);
foreach
(
var
tour
in
tours
){
foreach
(
var
tour
in
tours
){
Debug
.
Log
(
tour
);
Debug
.
Log
(
tour
);
}
}
}
}
System
.
Diagnostics
.
Debug
.
Assert
(
tours
!=
null
,
nameof
(
tours
)
+
" != null"
);
var
contentLoadingTask
=
plugin
.
DownloadTourContent
(
tours
[
0
].
Id
);
await
contentLoadingTask
.
Run
();
}
catch
(
Exception
e
){
}
catch
(
Exception
e
){
Debug
.
Log
(
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