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
9bb6cf19
Commit
9bb6cf19
authored
Oct 11, 2018
by
Kirill
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Отрабатываются ошибки при получении estates
parent
fbf2e42b
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
76 additions
and
8 deletions
+76
-8
Estate.cs
TourDataManager/Entities/Estate.cs
+5
-1
GetEstatesUseCase.cs
TourDataManager/GetEstatesUseCase.cs
+55
-3
TourDataManager.cs
TourDataManager/TourDataManager.cs
+5
-2
TourDataManager.csproj
TourDataManager/TourDataManager.csproj
+4
-0
packages.config
TourDataManager/packages.config
+1
-0
Program.cs
TourDataManagerConsoleApplication/Program.cs
+6
-2
No files found.
TourDataManager/Entities/Estate.cs
View file @
9bb6cf19
using
Newtonsoft.Json
;
using
Newtonsoft.Json.Serialization
;
namespace
TourDataManager.Entities
{
namespace
TourDataManager.Entities
{
public
class
Estate
{
public
class
Estate
{
...
@@ -7,7 +10,8 @@ namespace TourDataManager.Entities {
...
@@ -7,7 +10,8 @@ namespace TourDataManager.Entities {
public
string
Title
{
get
;
set
;
}
public
string
Title
{
get
;
set
;
}
public
int
TourCount
{
get
;
set
;
}
//cnt_tours
[
JsonProperty
(
"cnt_tours"
)]
public
int
TourCount
{
get
;
set
;
}
public
string
Preview
{
get
;
set
;
}
public
string
Preview
{
get
;
set
;
}
...
...
TourDataManager/GetEstatesUseCase.cs
View file @
9bb6cf19
using
System
;
using
System.Collections.Generic
;
using
System.Net.Http
;
using
System.Net.Http
;
using
System.Threading.Tasks
;
using
Newtonsoft.Json
;
using
Newtonsoft.Json.Converters
;
using
Newtonsoft.Json.Serialization
;
using
Ninject
;
using
Ninject
;
using
TourDataManager.Entities
;
namespace
TourDataManager
{
namespace
TourDataManager
{
public
class
GetEstatesUseCase
{
public
class
GetEstatesUseCase
{
...
@@ -7,10 +14,55 @@ namespace TourDataManager {
...
@@ -7,10 +14,55 @@ namespace TourDataManager {
[
Inject
]
[
Inject
]
public
HttpClient
httpClient
{
get
;
set
;
}
public
HttpClient
httpClient
{
get
;
set
;
}
public
async
void
GetEstates
(){
public
struct
BigantoErrorList
{
public
List
<
BigantoError
>
Errors
;
}
public
struct
BigantoError
{
public
int
Code
;
public
string
Message
;
public
override
string
ToString
(){
return
$"code=
{
Code
}
;message=
{
Message
}
"
;
}
}
public
class
BigantoErrorException
:
Exception
{
public
BigantoErrorList
ErrorsList
;
public
BigantoErrorException
(
BigantoErrorList
errors
){
ErrorsList
=
errors
;
}
}
/// <summary>
/// <exception cref="HttpRequestException">Если сервер даст дубу</exception>
/// <exception cref="BigantoErrorException">Если вместо массива эстейтов с сервера получены ошибки</exception>
/// <exception cref="JsonException">Если вместо массива эстейтов или ошибки пришло нечто иное</exception>
/// </summary>
public
async
Task
<
Estate
[
]>
GetEstates
(){
var
response
=
await
httpClient
.
GetAsync
(
"https://biganto.com/api-novus/estates.getList?client=desktopplayer&client_version=3.0&v=2.0"
);
var
response
=
await
httpClient
.
GetAsync
(
"https://biganto.com/api-novus/estates.getList?client=desktopplayer&client_version=3.0&v=2.0"
);
// throw HttpRequestException
var
content
=
await
response
.
Content
.
ReadAsStringAsync
();
var
content
=
await
response
.
Content
.
ReadAsStringAsync
();
Debug
.
Log
(
content
);
ErrorContext
error
=
null
;
var
errorHandlerSettings
=
new
JsonSerializerSettings
{
Error
=
(
sender
,
args
)
=>
{
error
=
args
.
ErrorContext
;
args
.
ErrorContext
.
Handled
=
true
;
}
};
var
estates
=
JsonConvert
.
DeserializeObject
<
Estate
[
]>
(
content
,
errorHandlerSettings
);
if
(
error
==
null
)
return
estates
;
error
=
null
;
// Вместо массиво эстейтов в ответе может содержаться json ошибки
// Предпринимается попытка десериализовать ошибки и выкинуть BigantoErrorException
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 @
9bb6cf19
using
System
;
using
System.Net.Http
;
using
System.Net.Http
;
using
System.Threading.Tasks
;
using
Ninject
;
using
Ninject
;
using
Ninject.Modules
;
using
Ninject.Modules
;
using
TourDataManager.Entities
;
namespace
TourDataManager
{
namespace
TourDataManager
{
...
@@ -23,8 +26,8 @@ namespace TourDataManager {
...
@@ -23,8 +26,8 @@ namespace TourDataManager {
});
});
}
}
public
void
GetEstates
(){
public
Task
<
Estate
[
]>
GetEstates
(){
Container
.
Get
<
GetEstatesUseCase
>().
GetEstates
();
return
Container
.
Get
<
GetEstatesUseCase
>().
GetEstates
();
}
}
}
}
...
...
TourDataManager/TourDataManager.csproj
View file @
9bb6cf19
...
@@ -38,6 +38,10 @@
...
@@ -38,6 +38,10 @@
<Private>
True
</Private>
<Private>
True
</Private>
</Reference>
</Reference>
<Reference
Include=
"mscorlib"
/>
<Reference
Include=
"mscorlib"
/>
<Reference
Include=
"Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed"
>
<HintPath>
..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll
</HintPath>
<Private>
True
</Private>
</Reference>
<Reference
Include=
"Ninject, Version=3.3.4.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7"
>
<Reference
Include=
"Ninject, Version=3.3.4.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7"
>
<HintPath>
..\packages\Ninject.3.3.4\lib\net45\Ninject.dll
</HintPath>
<HintPath>
..\packages\Ninject.3.3.4\lib\net45\Ninject.dll
</HintPath>
<Private>
True
</Private>
<Private>
True
</Private>
...
...
TourDataManager/packages.config
View file @
9bb6cf19
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
packages
>
<
packages
>
<
package
id
=
"EntityFramework"
version
=
"6.2.0"
targetFramework
=
"net45"
userInstalled
=
"true"
/>
<
package
id
=
"EntityFramework"
version
=
"6.2.0"
targetFramework
=
"net45"
userInstalled
=
"true"
/>
<
package
id
=
"Newtonsoft.Json"
version
=
"11.0.2"
targetFramework
=
"net472"
/>
<
package
id
=
"Ninject"
version
=
"3.3.4"
targetFramework
=
"net472"
/>
<
package
id
=
"Ninject"
version
=
"3.3.4"
targetFramework
=
"net472"
/>
<
package
id
=
"SQLite.CodeFirst"
version
=
"1.5.1.25"
targetFramework
=
"net472"
/>
<
package
id
=
"SQLite.CodeFirst"
version
=
"1.5.1.25"
targetFramework
=
"net472"
/>
<
package
id
=
"System.Data.SqlClient"
version
=
"4.5.1"
targetFramework
=
"net472"
/>
<
package
id
=
"System.Data.SqlClient"
version
=
"4.5.1"
targetFramework
=
"net472"
/>
...
...
TourDataManagerConsoleApplication/Program.cs
View file @
9bb6cf19
...
@@ -12,13 +12,17 @@ namespace TourDataManagerConsoleApplication {
...
@@ -12,13 +12,17 @@ namespace TourDataManagerConsoleApplication {
public
static
void
Main
(
string
[]
args
){
public
static
void
Main
(
string
[]
args
){
var
tourDataManager
=
new
TourDataManager
.
TourDataManager
(
PersistentPath
);
var
tourDataManager
=
new
TourDataManager
.
TourDataManager
(
PersistentPath
);
//
tourDataManager.Login(defaultLogin, defaultPassword);
tourDataManager
.
Login
(
defaultLogin
,
defaultPassword
);
//new Db();
//new Db();
tourDataManager
.
GetEstates
();
tourDataManager
.
GetEstates
().
ContinueWith
(
task
=>
{
var
est
=
task
.
Result
;
});
Console
.
Read
();
Console
.
Read
();
}
}
}
}
}
}
\ No newline at end of file
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