11using System ;
22using System . Collections . Generic ;
3- using ServQLClient ;
3+ using SQLiteCLIENT ;
44
55namespace ServQLTerminal
66{
@@ -9,14 +9,6 @@ class Program
99 public static Connection connection { get ; set ; }
1010 public static Client client { get ; set ; }
1111
12- public static void ClearLine ( )
13- {
14-
15- Console . CursorLeft = 0 ;
16- Console . Write ( new String ( ' ' , 50 ) ) ;
17- Console . CursorLeft = 0 ;
18-
19- }
2012 public static string getPassword ( )
2113 {
2214 string result = string . Empty ;
@@ -50,47 +42,20 @@ public static string getPassword()
5042 }
5143 static void Main ( string [ ] args )
5244 {
53- bool header = false ;
5445 Console . WriteLine ( "ServQL Client" ) ;
55- int cursor = 0 ;
56- if ( args . Length == 1 ) connection = new Connection ( args [ 0 ] ) ;
46+ if ( args . Length == 1 ) connection = new Connection ( args [ 1 ] ) ;
5747 else
5848 {
5949 Console . Write ( "IP: " ) ;
6050 connection = new Connection ( Console . ReadLine ( ) ) ;
61- cursor = Console . CursorTop ;
62- Console . WriteLine ( "Connecting..." ) ;
63- }
64- try
65- {
66- client = new Client ( connection ) ;
67-
68- } catch ( Exception E )
69- {
70- Console . CursorTop = cursor ;
71- ClearLine ( ) ;
72- Console . WriteLine ( $ "Error connecting to { connection . ip } ") ;
73- return ;
7451 }
52+ client = new Client ( connection ) ;
53+
7554 String username = string . Empty ;
7655 string password = string . Empty ;
7756 while ( ! client . isLoged )
7857 {
79- try
80- {
81- connection . Open ( ) ;
82- }
83- catch ( Exception e )
84- {
85- Console . CursorTop = cursor ;
86- ClearLine ( ) ;
87- Console . WriteLine ( $ "Error connecting to { connection . ip } ") ;
88- return ;
89- }
90-
91-
92- Console . CursorTop = cursor ;
93- ClearLine ( ) ;
58+ connection . Open ( ) ;
9459 Console . Write ( "Username: " ) ;
9560 username = Console . ReadLine ( ) ;
9661 Console . Write ( "Password: " ) ;
@@ -107,7 +72,7 @@ static void Main(string[] args)
10772 string command ;
10873 string cArgs ;
10974 string [ ] commandSplited ;
110- Package . Response response = null ;
75+ Client . Package . Response response ;
11176 string prefix = "" ;
11277 while ( true )
11378 {
@@ -117,7 +82,7 @@ static void Main(string[] args)
11782 {
11883 prefix = "exec" ;
11984 }
120- else if ( command == "exit" )
85+ else if ( command == "exit" )
12186 {
12287 if ( prefix == "" ) break ;
12388 else prefix = "" ;
@@ -126,66 +91,25 @@ static void Main(string[] args)
12691 {
12792 if ( prefix == "" )
12893 {
129- commandSplited = command . Split ( ) ;
130- command = commandSplited [ 0 ] ;
131- cArgs = string . Join ( ' ' , commandSplited ) ;
132- cArgs = cArgs . Remove ( 0 , command . Length ) . Trim ( ) ;
94+ commandSplited = command . Split ( ) ;
95+ command = commandSplited [ 0 ] ;
96+ cArgs = string . Join ( ' ' , commandSplited ) ;
97+ cArgs = cArgs . Remove ( 0 , command . Length ) . Trim ( ) ;
13398
13499 }
135100 else
136101 {
137102 cArgs = command ;
138103 command = prefix ;
139104 }
140- switch ( command )
141- {
142- case "open" :
143- response = client . OpenDb ( cArgs ) ;
144- break ;
145- case "close" :
146- response = client . CloseDb ( ) ;
147- break ;
148- case "list" :
149-
150- if ( cArgs == "" )
151- {
152- header = false ;
153- response = client . GetDBsI ( ) ;
154-
155- }
156- else
157- {
158- response = client . sendCommand ( command , cArgs ) ;
159-
160- }
161- break ;
162- default :
163- header = true ;
164- response = client . sendCommand ( command , cArgs ) ;
165- break ;
166-
167- }
168- }
169- if ( response != null )
170- {
171- if ( response ? . Result == "ERROR" ) Console . WriteLine ( "ERROR" ) ;
105+ response = client . sendCommand ( command , cArgs ) ;
106+ if ( response ? . Result == "ERROR" || response == null ) Console . WriteLine ( "ERROR" ) ;
172107 else
173108 {
174- foreach ( string [ ] data in response . Data )
175- {
176- Console . WriteLine ( String . Join ( " , " , data ) ) ;
177- if ( header )
178- {
179- Console . WriteLine ( new string ( '-' , data . Length + 2 ) ) ;
180- header = false ;
181- }
182-
183- }
109+ foreach ( string data in response . Data ) Console . WriteLine ( data ) ;
184110 }
185- response = null ;
186- }
187111
188-
112+ }
189113 }
190114
191115
0 commit comments