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
419ec5b0
Commit
419ec5b0
authored
Oct 15, 2018
by
Kirill
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Немного элементов управления через консоль и рефакторинга
parent
69743608
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
99 additions
and
22 deletions
+99
-22
Authenticator.cs
TourDataManager/Authenticator.cs
+8
-4
Debug.cs
TourDataManager/Debug.cs
+6
-0
IAuthenticator.cs
TourDataManager/IAuthenticator.cs
+3
-1
TourDataManager.cs
TourDataManager/TourDataManager.cs
+25
-13
Program.cs
TourDataManagerConsoleApplication/Program.cs
+57
-4
No files found.
TourDataManager/Authenticator.cs
View file @
419ec5b0
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Net.Http
;
using
System.Net.Http
;
using
System.Threading.Tasks
;
using
Ninject
;
using
Ninject
;
namespace
TourDataManager
{
namespace
TourDataManager
{
...
@@ -9,19 +10,22 @@ namespace TourDataManager {
...
@@ -9,19 +10,22 @@ namespace TourDataManager {
[
Inject
]
public
HttpClient
HttpClient
{
get
;
set
;
}
[
Inject
]
public
HttpClient
HttpClient
{
get
;
set
;
}
public
async
void
Login
(
string
email
,
string
password
,
Action
<
bool
,
string
>
continuation
=
null
){
public
(
bool
,
string
)
Login
(
string
email
,
string
password
){
return
LoginAsync
(
email
,
password
).
Result
;
}
public
async
Task
<(
bool
,
string
)>
LoginAsync
(
string
email
,
string
password
){
var
x
=
await
HttpClient
.
PostAsync
(
authUri
,
var
x
=
await
HttpClient
.
PostAsync
(
authUri
,
new
FormUrlEncodedContent
(
new
[]{
new
FormUrlEncodedContent
(
new
[]{
new
KeyValuePair
<
string
,
string
>(
"email"
,
email
),
new
KeyValuePair
<
string
,
string
>(
"email"
,
email
),
new
KeyValuePair
<
string
,
string
>(
"password"
,
password
)
new
KeyValuePair
<
string
,
string
>(
"password"
,
password
)
}));
}));
var
content
=
await
x
.
Content
.
ReadAsStringAsync
();
var
content
=
await
x
.
Content
.
ReadAsStringAsync
();
return
(
x
.
IsSuccessStatusCode
,
content
);
continuation
?.
Invoke
(
x
.
IsSuccessStatusCode
,
content
);
}
}
public
void
Logout
(){
public
void
Logout
(){
throw
new
NotImplementedException
();
}
}
}
}
}
}
\ No newline at end of file
TourDataManager/Debug.cs
View file @
419ec5b0
...
@@ -12,5 +12,11 @@ namespace TourDataManager {
...
@@ -12,5 +12,11 @@ namespace TourDataManager {
Console
.
WriteLine
(
msg
);
Console
.
WriteLine
(
msg
);
Console
.
ResetColor
();
Console
.
ResetColor
();
}
}
public
static
char
ReadKey
(){
var
ch
=
Console
.
ReadKey
().
KeyChar
;
Console
.
WriteLine
();
return
ch
;
}
}
}
}
}
\ No newline at end of file
TourDataManager/IAuthenticator.cs
View file @
419ec5b0
using
System
;
using
System
;
using
System.Threading.Tasks
;
namespace
TourDataManager
{
namespace
TourDataManager
{
public
interface
IAuthenticator
{
public
interface
IAuthenticator
{
void
Login
(
string
email
,
string
password
,
Action
<
bool
,
string
>
continuation
=
null
);
(
bool
,
string
)
Login
(
string
email
,
string
password
);
Task
<(
bool
,
string
)>
LoginAsync
(
string
email
,
string
password
);
void
Logout
();
void
Logout
();
}
}
}
}
\ No newline at end of file
TourDataManager/TourDataManager.cs
View file @
419ec5b0
...
@@ -13,7 +13,7 @@ namespace TourDataManager {
...
@@ -13,7 +13,7 @@ namespace TourDataManager {
/// <summary>
/// <summary>
/// Фасад для всего плагина
/// Фасад для всего плагина
/// </summary>
/// </summary>
public
class
TourDataManager
{
public
class
TourDataManager
:
IAuthenticator
{
public
static
volatile
string
PersistentPath
;
public
static
volatile
string
PersistentPath
;
...
@@ -21,9 +21,9 @@ namespace TourDataManager {
...
@@ -21,9 +21,9 @@ namespace TourDataManager {
return
Path
.
Combine
(
PersistentPath
,
relative
);
return
Path
.
Combine
(
PersistentPath
,
relative
);
}
}
p
ublic
FetchEstatesUseCase
estatesfetch
{
get
;
set
;
}
p
rivate
FetchEstatesUseCase
estatesfetch
{
get
;
set
;
}
p
ublic
FetchTourPreviewsUseCase
tourpreviewsfetch
{
get
;
set
;
}
p
rivate
FetchTourPreviewsUseCase
tourpreviewsfetch
{
get
;
set
;
}
p
ublic
Db
database
{
get
;
set
;
}
p
rivate
Db
database
{
get
;
set
;
}
private
IKernel
Container
;
private
IKernel
Container
;
...
@@ -38,22 +38,27 @@ namespace TourDataManager {
...
@@ -38,22 +38,27 @@ namespace TourDataManager {
database
=
Container
.
Get
<
Db
>();
database
=
Container
.
Get
<
Db
>();
}
}
public
void
Login
(
string
email
,
string
password
){
public
async
Task
<(
bool
,
string
)>
LoginAsync
(
string
email
,
string
password
){
Container
.
Get
<
IAuthenticator
>().
Login
(
email
,
password
,
(
b
,
s
)
=>
{
var
result
=
await
Container
.
Get
<
IAuthenticator
>().
LoginAsync
(
email
,
password
);
if
(
result
.
Item1
)
SaveCookie
();
return
result
;
}
private
void
SaveCookie
(){
var
cookiestor
=
Container
.
Get
<
CookieStorage
>();
var
cookiestor
=
Container
.
Get
<
CookieStorage
>();
Debug
.
Log
(
$"Authorization :
{
s
}
"
);
Debug
.
Log
(
$"Cookie saved. Current count :
{
cookiestor
.
Get
().
Count
}
"
);
Debug
.
Log
(
$"Cookie count in storage :
{
cookiestor
.
Get
().
Count
}
"
);
cookiestor
.
Save
();
cookiestor
.
Save
();
});
}
}
public
async
Task
<
Estate
[
]>
DownloadEstates
(){
public
void
Logout
(){
throw
new
NotImplementedException
();
}
public
async
Task
<
Estate
[
]>
FetchEstatesAsync
(){
var
estates
=
await
estatesfetch
.
FetchEstatesFromServerAsync
();
var
estates
=
await
estatesfetch
.
FetchEstatesFromServerAsync
();
database
.
InsertEstates
(
estates
);
database
.
InsertEstates
(
estates
);
return
estates
;
return
estates
;
}
}
public
async
Task
<
Tour
[
]>
DownloadTourPreviews
(
long
estateId
){
public
async
Task
<
Tour
[
]>
FetchTourPreviewsAsync
(
long
estateId
){
var
tours
=
await
tourpreviewsfetch
.
FetchTourFromServerAsync
(
estateId
);
var
tours
=
await
tourpreviewsfetch
.
FetchTourFromServerAsync
(
estateId
);
database
.
InsertTours
(
tours
);
database
.
InsertTours
(
tours
);
return
tours
;
return
tours
;
...
@@ -62,6 +67,13 @@ namespace TourDataManager {
...
@@ -62,6 +67,13 @@ namespace TourDataManager {
public
ContentLoadingTask
DownloadTourContent
(
long
tourId
){
public
ContentLoadingTask
DownloadTourContent
(
long
tourId
){
return
Container
.
Get
<
FetchTourContentUseCase
>().
FetchTourContentFromServerAsync
(
tourId
);
return
Container
.
Get
<
FetchTourContentUseCase
>().
FetchTourContentFromServerAsync
(
tourId
);
}
}
public
(
bool
,
string
)
Login
(
string
email
,
string
password
){
return
LoginAsync
(
email
,
password
).
Result
;
}
}
}
public
class
MyModule
:
NinjectModule
{
public
class
MyModule
:
NinjectModule
{
...
...
TourDataManagerConsoleApplication/Program.cs
View file @
419ec5b0
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
using
System.IO
;
using
System.IO
;
using
System.Net
;
using
System.Net
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
Ninject.Activation.Strategies
;
using
TourDataManager
;
using
TourDataManager
;
using
TourDataManager.Entities
;
using
TourDataManager.Entities
;
...
@@ -13,22 +14,74 @@ namespace TourDataManagerConsoleApplication {
...
@@ -13,22 +14,74 @@ namespace TourDataManagerConsoleApplication {
const
string
defaultLogin
=
"demo@biganto.ru"
;
const
string
defaultLogin
=
"demo@biganto.ru"
;
const
string
defaultPassword
=
"demo"
;
const
string
defaultPassword
=
"demo"
;
public
static
TourDataManager
.
TourDataManager
tourDataManager
;
public
static
void
Main
(
string
[]
args
){
public
static
void
Main
(
string
[]
args
){
var
tourDataManager
=
new
TourDataManager
.
TourDataManager
(
PersistentPath
);
tourDataManager
=
new
TourDataManager
.
TourDataManager
(
PersistentPath
);
MainWindow
();
//tourDataManager.Login(defaultLogin, defaultPassword);
//tourDataManager.Login(defaultLogin, defaultPassword);
AsyncMethod
(
tourDataManager
);
//
AsyncMethod(tourDataManager);
Console
.
Read
();
Console
.
Read
();
}
}
public
static
void
MainWindow
(){
Debug
.
Log
(
"Commands : \n0 - Auth\n1 - Show estates list\n2 - exit"
);
var
ch
=
Debug
.
ReadKey
();
switch
(
ch
){
case
'0'
:
Debug
.
Log
(
"Login : "
);
var
login
=
Console
.
ReadLine
();
Debug
.
Log
(
"Password : "
);
var
pass
=
Console
.
ReadLine
();
var
result
=
tourDataManager
.
Login
(
login
,
pass
);
Debug
.
Log
(
$"Auth result :
{
result
.
Item1
}
{
result
.
Item2
}
"
);
MainWindow
();
break
;
case
'1'
:
var
estates
=
tourDataManager
.
FetchEstatesAsync
().
Result
;
foreach
(
var
estate
in
estates
){
Debug
.
Log
(
estate
);
}
EstateWindow
();
break
;
case
'2'
:
Environment
.
Exit
(
0
);
break
;
}
}
public
static
void
EstateWindow
(){
Debug
.
Log
(
"Commands : \n0 - Fetch tours of estate\n1 - back\n2 - exit"
);
var
ch
=
Debug
.
ReadKey
();
switch
(
ch
){
case
'0'
:
Debug
.
Log
(
"Estate id : "
);
var
id
=
Console
.
ReadLine
();
var
tours
=
tourDataManager
.
FetchTourPreviewsAsync
(
Int32
.
Parse
(
id
)).
Result
;
foreach
(
var
tour
in
tours
){
Debug
.
Log
(
tour
);
}
EstateWindow
();
break
;
case
'1'
:
MainWindow
();
break
;
case
'2'
:
Environment
.
Exit
(
0
);
break
;
}
}
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
.
FetchEstatesAsync
();
Tour
[]
tours
=
null
;
Tour
[]
tours
=
null
;
foreach
(
var
estate
in
estates
){
foreach
(
var
estate
in
estates
){
Debug
.
Log
(
estate
);
Debug
.
Log
(
estate
);
tours
=
await
plugin
.
DownloadTourPreviews
(
estate
.
Id
);
tours
=
await
plugin
.
FetchTourPreviewsAsync
(
estate
.
Id
);
foreach
(
var
tour
in
tours
){
foreach
(
var
tour
in
tours
){
Debug
.
Log
(
tour
);
Debug
.
Log
(
tour
);
}
}
...
...
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