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
e1994cb2
Commit
e1994cb2
authored
Oct 12, 2018
by
Kirill
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Фетчатся и выводятся в лог TourPreview объекты
parent
3a4c4875
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
86 additions
and
22 deletions
+86
-22
Db.cs
TourDataManager/Db.cs
+2
-2
Tour.cs
TourDataManager/Entities/Tour.cs
+4
-1
FetchEstatesUseCase.cs
TourDataManager/FetchEstatesUseCase.cs
+2
-2
FetchTourPreviewsUseCase.cs
TourDataManager/FetchTourPreviewsUseCase.cs
+44
-0
TourDataManager.cs
TourDataManager/TourDataManager.cs
+12
-10
TourDataManager.csproj
TourDataManager/TourDataManager.csproj
+1
-0
Program.cs
TourDataManagerConsoleApplication/Program.cs
+21
-7
No files found.
TourDataManager/Db.cs
View file @
e1994cb2
...
...
@@ -4,6 +4,7 @@ using System.ComponentModel.DataAnnotations.Schema;
using
System.Data.Common
;
using
System.Data.Entity
;
using
System.Data.Entity.Core.Common
;
using
System.Data.Entity.Migrations
;
using
System.Data.SQLite
;
using
System.Data.SQLite.EF6
;
using
System.Linq
;
...
...
@@ -68,9 +69,8 @@ namespace TourDataManager {
}
public
void
InsertEstates
(
Estate
[]
estates
){
//context.Estates.AddRange(estates);
foreach
(
var
estate
in
estates
){
context
.
Estates
.
Add
(
estate
);
context
.
Estates
.
Add
OrUpdate
(
estate
);
}
foreach
(
var
contextEstate
in
context
.
Estates
){
Debug
.
Log
(
contextEstate
.
Id
);
...
...
TourDataManager/Entities/Tour.cs
View file @
e1994cb2
...
...
@@ -9,7 +9,6 @@ namespace TourDataManager.Entities {
public
string
Screen
{
get
;
set
;
}
public
int
EstateId
{
get
;
set
;
}
public
string
Created
{
get
;
set
;
}
...
...
@@ -20,5 +19,9 @@ namespace TourDataManager.Entities {
/// Состояние тура
public
int
State
{
get
;
set
;
}
public
long
EstateId
{
get
;
set
;
}
public
override
string
ToString
(){
return
$"Tour :
{
Id
}
|
{
Title
}
|
{
EstateId
}
"
;
}
}
}
\ No newline at end of file
TourDataManager/FetchEstatesUseCase.cs
View file @
e1994cb2
...
...
@@ -12,7 +12,7 @@ namespace TourDataManager {
[
Inject
]
public
HttpClient
HttpClient
{
get
;
set
;
}
[
Inject
]
public
Db
Database
{
get
;
set
;
}
public
Task
<
Estate
[
]>
FetchEstatesFromDb
(){
public
Task
<
Estate
[
]>
FetchEstatesFromDb
Async
(){
return
Database
.
GetEstatesAsync
();
}
...
...
@@ -21,7 +21,7 @@ namespace TourDataManager {
/// <exception cref="BigantoErrorException">Если вместо массива эстейтов с сервера получены ошибки</exception>
/// <exception cref="JsonException">Если вместо массива эстейтов или ошибки пришло нечто иное</exception>
/// </summary>
public
async
Task
<
Estate
[
]>
FetchEstatesFromServer
(){
public
async
Task
<
Estate
[
]>
FetchEstatesFromServer
Async
(){
var
response
=
await
HttpClient
.
GetAsync
(
"https://biganto.com/api-novus/estates.getList?client=desktopplayer&client_version=3.0&v=2.0"
);
// throw HttpRequestException
...
...
TourDataManager/FetchTourPreviewsUseCase.cs
0 → 100644
View file @
e1994cb2
using
System
;
using
System.Net.Http
;
using
System.Threading.Tasks
;
using
Newtonsoft.Json
;
using
Newtonsoft.Json.Serialization
;
using
Ninject
;
using
TourDataManager.Entities
;
namespace
TourDataManager
{
public
class
FetchTourPreviewsUseCase
{
[
Inject
]
public
HttpClient
HttpClient
{
get
;
set
;
}
public
async
Task
<
Tour
[
]>
FetchTourFromServerAsync
(
long
estateId
){
var
response
=
await
HttpClient
.
GetAsync
(
$"https://biganto.com/api-novus/tours.getList?client=desktopplayer&client_version=3.0&v=2.0&estate_id=
{
estateId
}
"
);
// throw HttpRequestException
var
content
=
await
response
.
Content
.
ReadAsStringAsync
();
// TODO Это в буквальнос смысле копипаста с FetchEstatesUseCase.FetchEstatesFromServerAsync
ErrorContext
error
=
null
;
var
errorHandlerSettings
=
new
JsonSerializerSettings
{
Error
=
(
sender
,
args
)
=>
{
error
=
args
.
ErrorContext
;
args
.
ErrorContext
.
Handled
=
true
;
}
};
var
tours
=
JsonConvert
.
DeserializeObject
<
Tour
[
]>
(
content
,
errorHandlerSettings
);
if
(
error
==
null
){
// Т.к из json нам не приходит estateId, а мы и так по контексту его знаем, то вбиваем так.
// Теперь и база будет знать.
foreach
(
var
tour
in
tours
){
tour
.
EstateId
=
estateId
;}
return
tours
;
}
error
=
null
;
var
exceptionList
=
JsonConvert
.
DeserializeObject
<
BigantoErrorList
>(
content
,
errorHandlerSettings
);
if
(
error
==
null
)
throw
new
BigantoErrorException
(
exceptionList
);
throw
new
JsonException
(
"Something goes wrong"
,
error
.
Error
);
}
}
}
\ No newline at end of file
TourDataManager/TourDataManager.cs
View file @
e1994cb2
...
...
@@ -15,7 +15,8 @@ namespace TourDataManager {
public
class
TourDataManager
{
public
FetchEstatesUseCase
fetch
{
get
;
set
;
}
public
FetchEstatesUseCase
estatesfetch
{
get
;
set
;
}
public
FetchTourPreviewsUseCase
tourpreviewsfetch
{
get
;
set
;
}
public
Db
database
{
get
;
set
;
}
private
string
persistentPath
;
...
...
@@ -27,7 +28,8 @@ namespace TourDataManager {
Container
=
new
StandardKernel
(
new
MyModule
(
persistentPath
));
fetch
=
Container
.
Get
<
FetchEstatesUseCase
>();
estatesfetch
=
Container
.
Get
<
FetchEstatesUseCase
>();
tourpreviewsfetch
=
Container
.
Get
<
FetchTourPreviewsUseCase
>();
database
=
Container
.
Get
<
Db
>();
}
...
...
@@ -41,14 +43,14 @@ namespace TourDataManager {
}
public
async
Task
<
Estate
[
]>
DownloadEstates
(){
try
{
var
estates
=
await
fetch
.
FetchEstatesFromServer
();
var
estates
=
await
estatesfetch
.
FetchEstatesFromServerAsync
();
database
.
InsertEstates
(
estates
);
return
estates
;
}
catch
(
Exception
){
Debug
.
Log
(
"Не удалось загрузить эстейты"
);
return
null
;
}
public
async
Task
<
Tour
[
]>
DownloadTourPreviews
(
long
estateId
){
var
tours
=
await
tourpreviewsfetch
.
FetchTourFromServerAsync
(
estateId
);
return
tours
;
}
}
...
...
TourDataManager/TourDataManager.csproj
View file @
e1994cb2
...
...
@@ -111,6 +111,7 @@
<Compile
Include=
"Entities\Estate.cs"
/>
<Compile
Include=
"Entities\Tour.cs"
/>
<Compile
Include=
"FetchEstatesUseCase.cs"
/>
<Compile
Include=
"FetchTourPreviewsUseCase.cs"
/>
<Compile
Include=
"IAuthenticator.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"TourDataManager.cs"
/>
...
...
TourDataManagerConsoleApplication/Program.cs
View file @
e1994cb2
using
System
;
using
System.Threading.Tasks
;
using
TourDataManager
;
using
TourDataManager.Entities
;
namespace
TourDataManagerConsoleApplication
{
internal
class
Program
{
...
...
@@ -12,16 +14,28 @@ namespace TourDataManagerConsoleApplication {
public
static
void
Main
(
string
[]
args
){
var
tourDataManager
=
new
TourDataManager
.
TourDataManager
(
PersistentPath
);
tourDataManager
.
Login
(
defaultLogin
,
defaultPassword
);
//tourDataManager.Login(defaultLogin, defaultPassword);
AsyncMethod
(
tourDataManager
);
//new Db();
Console
.
Read
();
}
tourDataManager
.
DownloadEstates
().
ContinueWith
(
task
=>
{
foreach
(
var
estate
in
task
.
Result
){
public
static
async
void
AsyncMethod
(
TourDataManager
.
TourDataManager
plugin
){
try
{
var
estates
=
await
plugin
.
DownloadEstates
();
foreach
(
var
estate
in
estates
){
Debug
.
Log
(
estate
);
var
tours
=
await
plugin
.
DownloadTourPreviews
(
estate
.
Id
);
foreach
(
var
tour
in
tours
){
Debug
.
Log
(
tour
);
}
});
Console
.
Read
();
}
}
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