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
8add35b7
Commit
8add35b7
authored
6 years ago
by
Kirill
Browse files
Options
Browse Files
Download
Plain Diff
Подключен декодер Json
parents
6c89ad6c
9bb6cf19
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
97 additions
and
5 deletions
+97
-5
Estate.cs
TourDataManager/Entities/Estate.cs
+5
-1
GetEstatesUseCase.cs
TourDataManager/GetEstatesUseCase.cs
+68
-0
TourDataManager.cs
TourDataManager/TourDataManager.cs
+9
-1
TourDataManager.csproj
TourDataManager/TourDataManager.csproj
+5
-0
packages.config
TourDataManager/packages.config
+1
-0
Program.cs
TourDataManagerConsoleApplication/Program.cs
+9
-3
No files found.
TourDataManager/Entities/Estate.cs
View file @
8add35b7
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
;
}
...
...
This diff is collapsed.
Click to expand it.
TourDataManager/GetEstatesUseCase.cs
0 → 100644
View file @
8add35b7
using
System
;
using
System.Collections.Generic
;
using
System.Net.Http
;
using
System.Threading.Tasks
;
using
Newtonsoft.Json
;
using
Newtonsoft.Json.Converters
;
using
Newtonsoft.Json.Serialization
;
using
Ninject
;
using
TourDataManager.Entities
;
namespace
TourDataManager
{
public
class
GetEstatesUseCase
{
[
Inject
]
public
HttpClient
httpClient
{
get
;
set
;
}
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"
);
// throw HttpRequestException
var
content
=
await
response
.
Content
.
ReadAsStringAsync
();
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
This diff is collapsed.
Click to expand it.
TourDataManager/TourDataManager.cs
View file @
8add35b7
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
{
...
@@ -22,6 +25,10 @@ namespace TourDataManager {
...
@@ -22,6 +25,10 @@ namespace TourDataManager {
cookiestor
.
Save
();
cookiestor
.
Save
();
});
});
}
}
public
Task
<
Estate
[
]>
GetEstates
(){
return
Container
.
Get
<
GetEstatesUseCase
>().
GetEstates
();
}
}
}
public
class
MyModule
:
NinjectModule
{
public
class
MyModule
:
NinjectModule
{
...
@@ -44,7 +51,8 @@ namespace TourDataManager {
...
@@ -44,7 +51,8 @@ namespace TourDataManager {
Bind
<
HttpClientHandler
>().
ToConstant
(
httpClientHandler
).
InSingletonScope
();
Bind
<
HttpClientHandler
>().
ToConstant
(
httpClientHandler
).
InSingletonScope
();
Bind
<
HttpClient
>().
ToConstant
(
httpClient
).
InSingletonScope
();
Bind
<
HttpClient
>().
ToConstant
(
httpClient
).
InSingletonScope
();
Bind
<
IAuthenticator
>().
To
<
Authenticator
>().
InSingletonScope
();
Bind
<
IAuthenticator
>().
To
<
Authenticator
>().
InSingletonScope
();
Bind
<
GetEstatesUseCase
>().
ToSelf
().
InSingletonScope
();
}
}
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
TourDataManager/TourDataManager.csproj
View file @
8add35b7
...
@@ -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>
...
@@ -105,6 +109,7 @@
...
@@ -105,6 +109,7 @@
<Compile
Include=
"Debug.cs"
/>
<Compile
Include=
"Debug.cs"
/>
<Compile
Include=
"Entities\Estate.cs"
/>
<Compile
Include=
"Entities\Estate.cs"
/>
<Compile
Include=
"Entities\Tour.cs"
/>
<Compile
Include=
"Entities\Tour.cs"
/>
<Compile
Include=
"GetEstatesUseCase.cs"
/>
<Compile
Include=
"IAuthenticator.cs"
/>
<Compile
Include=
"IAuthenticator.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"TourDataManager.cs"
/>
<Compile
Include=
"TourDataManager.cs"
/>
...
...
This diff is collapsed.
Click to expand it.
TourDataManager/packages.config
View file @
8add35b7
<?
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"
/>
...
...
This diff is collapsed.
Click to expand it.
TourDataManagerConsoleApplication/Program.cs
View file @
8add35b7
...
@@ -11,12 +11,18 @@ namespace TourDataManagerConsoleApplication {
...
@@ -11,12 +11,18 @@ 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
().
ContinueWith
(
task
=>
{
var
est
=
task
.
Result
;
});
Console
.
Read
();
Console
.
Read
();
}
}
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
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