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
Hide 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.Collections.Generic
;
using
System.Net.Http
;
using
System.Threading.Tasks
;
using
Ninject
;
namespace
TourDataManager
{
...
...
@@ -9,19 +10,22 @@ namespace TourDataManager {
[
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
,
new
FormUrlEncodedContent
(
new
[]{
new
KeyValuePair
<
string
,
string
>(
"email"
,
email
),
new
KeyValuePair
<
string
,
string
>(
"password"
,
password
)
}));
var
content
=
await
x
.
Content
.
ReadAsStringAsync
();
continuation
?.
Invoke
(
x
.
IsSuccessStatusCode
,
content
);
return
(
x
.
IsSuccessStatusCode
,
content
);
}
public
void
Logout
(){
throw
new
NotImplementedException
();
}
}
}
\ No newline at end of file
TourDataManager/Debug.cs
View file @
419ec5b0
...
...
@@ -12,5 +12,11 @@ namespace TourDataManager {
Console
.
WriteLine
(
msg
);
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.Threading.Tasks
;
namespace
TourDataManager
{
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
();
}
}
\ No newline at end of file
TourDataManager/TourDataManager.cs
View file @
419ec5b0
...
...
@@ -13,7 +13,7 @@ namespace TourDataManager {
/// <summary>
/// Фасад для всего плагина
/// </summary>
public
class
TourDataManager
{
public
class
TourDataManager
:
IAuthenticator
{
public
static
volatile
string
PersistentPath
;
...
...
@@ -21,9 +21,9 @@ namespace TourDataManager {
return
Path
.
Combine
(
PersistentPath
,
relative
);
}
p
ublic
FetchEstatesUseCase
estatesfetch
{
get
;
set
;
}
p
ublic
FetchTourPreviewsUseCase
tourpreviewsfetch
{
get
;
set
;
}
p
ublic
Db
database
{
get
;
set
;
}
p
rivate
FetchEstatesUseCase
estatesfetch
{
get
;
set
;
}
p
rivate
FetchTourPreviewsUseCase
tourpreviewsfetch
{
get
;
set
;
}
p
rivate
Db
database
{
get
;
set
;
}
private
IKernel
Container
;
...
...
@@ -38,22 +38,27 @@ namespace TourDataManager {
database
=
Container
.
Get
<
Db
>();
}
public
void
Login
(
string
email
,
string
password
){
Container
.
Get
<
IAuthenticator
>().
Login
(
email
,
password
,
(
b
,
s
)
=>
{
var
cookiestor
=
Container
.
Get
<
CookieStorage
>();
Debug
.
Log
(
$"Authorization :
{
s
}
"
);
Debug
.
Log
(
$"Cookie count in storage :
{
cookiestor
.
Get
().
Count
}
"
);
cookiestor
.
Save
();
});
public
async
Task
<(
bool
,
string
)>
LoginAsync
(
string
email
,
string
password
){
var
result
=
await
Container
.
Get
<
IAuthenticator
>().
LoginAsync
(
email
,
password
);
if
(
result
.
Item1
)
SaveCookie
();
return
result
;
}
public
async
Task
<
Estate
[
]>
DownloadEstates
(){
private
void
SaveCookie
(){
var
cookiestor
=
Container
.
Get
<
CookieStorage
>();
Debug
.
Log
(
$"Cookie saved. Current count :
{
cookiestor
.
Get
().
Count
}
"
);
cookiestor
.
Save
();
}
public
void
Logout
(){
throw
new
NotImplementedException
();
}
public
async
Task
<
Estate
[
]>
FetchEstatesAsync
(){
var
estates
=
await
estatesfetch
.
FetchEstatesFromServerAsync
();
database
.
InsertEstates
(
estates
);
return
estates
;
}
public
async
Task
<
Tour
[
]>
DownloadTourPreviews
(
long
estateId
){
public
async
Task
<
Tour
[
]>
FetchTourPreviewsAsync
(
long
estateId
){
var
tours
=
await
tourpreviewsfetch
.
FetchTourFromServerAsync
(
estateId
);
database
.
InsertTours
(
tours
);
return
tours
;
...
...
@@ -62,6 +67,13 @@ namespace TourDataManager {
public
ContentLoadingTask
DownloadTourContent
(
long
tourId
){
return
Container
.
Get
<
FetchTourContentUseCase
>().
FetchTourContentFromServerAsync
(
tourId
);
}
public
(
bool
,
string
)
Login
(
string
email
,
string
password
){
return
LoginAsync
(
email
,
password
).
Result
;
}
}
public
class
MyModule
:
NinjectModule
{
...
...
TourDataManagerConsoleApplication/Program.cs
View file @
419ec5b0
...
...
@@ -2,6 +2,7 @@
using
System.IO
;
using
System.Net
;
using
System.Threading.Tasks
;
using
Ninject.Activation.Strategies
;
using
TourDataManager
;
using
TourDataManager.Entities
;
...
...
@@ -12,23 +13,75 @@ namespace TourDataManagerConsoleApplication {
const
string
defaultLogin
=
"demo@biganto.ru"
;
const
string
defaultPassword
=
"demo"
;
public
static
TourDataManager
.
TourDataManager
tourDataManager
;
public
static
void
Main
(
string
[]
args
){
tourDataManager
=
new
TourDataManager
.
TourDataManager
(
PersistentPath
);
var
tourDataManager
=
new
TourDataManager
.
TourDataManager
(
PersistentPath
);
MainWindow
();
//tourDataManager.Login(defaultLogin, defaultPassword);
AsyncMethod
(
tourDataManager
);
//
AsyncMethod(tourDataManager);
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
){
try
{
var
estates
=
await
plugin
.
DownloadEstates
();
var
estates
=
await
plugin
.
FetchEstatesAsync
();
Tour
[]
tours
=
null
;
foreach
(
var
estate
in
estates
){
Debug
.
Log
(
estate
);
tours
=
await
plugin
.
DownloadTourPreviews
(
estate
.
Id
);
tours
=
await
plugin
.
FetchTourPreviewsAsync
(
estate
.
Id
);
foreach
(
var
tour
in
tours
){
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