1111using SignalGoTest . Models ;
1212using System ;
1313using System . Collections . Generic ;
14+ using System . Collections . ObjectModel ;
1415using System . IO ;
1516using System . Linq ;
1617using System . Net ;
@@ -52,11 +53,16 @@ public ConnectionInfoViewModel()
5253 } ) ;
5354 SendCommand = new Command ( Send ) ;
5455 HttpUpdateCommand = new Command ( HttpUpdate ) ;
56+ AddNewRequestCommand = new Command ( AddNewRequest , ( ) =>
57+ {
58+ return SelectedTreeItem is ServiceDetailsMethod ;
59+ } ) ;
5560 }
5661
5762
5863 private bool _IsAlert ;
5964 private string _SearchText = "" ;
65+ private string _RequestName ;
6066 private object _SelectedTreeItem ;
6167 public Command ConnectCommand { get ; set ; }
6268 public Command DisconnectCommand { get ; set ; }
@@ -65,6 +71,7 @@ public ConnectionInfoViewModel()
6571 public Command < ServiceDetailsParameterInfo > LoadFullTemplateCommand { get ; set ; }
6672 public Command SendCommand { get ; set ; }
6773 public Command HttpUpdateCommand { get ; set ; }
74+ public Command AddNewRequestCommand { get ; set ; }
6875
6976 public override bool IsBusy
7077 {
@@ -161,9 +168,23 @@ public object SelectedTreeItem
161168 {
162169 _SelectedTreeItem = value ;
163170 OnPropertyChanged ( nameof ( SelectedTreeItem ) ) ;
171+ AddNewRequestCommand . ValidateCanExecute ( ) ;
164172 }
165173 }
166174
175+ public string RequestName
176+ {
177+ get
178+ {
179+ return _RequestName ;
180+ }
181+
182+ set
183+ {
184+ _RequestName = value ;
185+ OnPropertyChanged ( nameof ( RequestName ) ) ;
186+ }
187+ }
167188
168189 private void Disconnect ( )
169190 {
@@ -236,6 +257,7 @@ public async void Connect()
236257
237258 BusyContent = "Receiving data..." ;
238259 ProviderDetailsInfo result = await provider . GetListOfServicesWithDetials ( CurrentConnectionInfo . ServerAddress ) ;
260+ result . ProjectDomainDetailsInfo . Models = result . ProjectDomainDetailsInfo . Models . OrderBy ( x => x . ObjectType == SerializeObjectType . Enum ) . ThenBy ( x => x . Name ) . ToList ( ) ;
239261 ProviderDetailsInfo oldItems = currentView . Items ;
240262 currentView . Items = result ;
241263 currentView . OnPropertyChanged ( "ItemsSource" ) ;
@@ -472,6 +494,46 @@ public async void Send()
472494 }
473495 }
474496
497+ private async void AddNewRequest ( )
498+ {
499+ try
500+ {
501+ ServiceDetailsMethod selectedMethod = ( ServiceDetailsMethod ) SelectedTreeItem ;
502+ if ( selectedMethod == null )
503+ return ;
504+ ObservableCollection < ServiceDetailsRequestInfo > requests = selectedMethod . Requests ;
505+ string newName = RequestName . Trim ( ) ;
506+ if ( requests . Any ( x => x . Name == newName ) || string . IsNullOrEmpty ( newName ) )
507+ {
508+ BusyContent = "name is exist or empty!" ;
509+ IsBusy = true ;
510+ await Task . Delay ( 3000 ) ;
511+ return ;
512+ }
513+ ServiceDetailsRequestInfo request = new ServiceDetailsRequestInfo ( ) { Name = newName , Parameters = new List < ServiceDetailsParameterInfo > ( ) } ;
514+ foreach ( ServiceDetailsParameterInfo item in selectedMethod . Requests . FirstOrDefault ( ) . Parameters )
515+ {
516+ ServiceDetailsParameterInfo clone = item . Clone ( ) ;
517+ clone . Value = null ;
518+ clone . TemplateValue = "" ;
519+ request . Parameters . Add ( clone ) ;
520+ }
521+ requests . Add ( request ) ;
522+ RequestName = "" ;
523+ MainViewModel . This . Save ( ) ;
524+ }
525+ catch ( Exception ex )
526+ {
527+ BusyContent = ex . Message ;
528+ IsBusy = true ;
529+ await Task . Delay ( 3000 ) ;
530+ }
531+ finally
532+ {
533+ IsBusy = false ;
534+ }
535+ }
536+
475537 private async void HttpUpdate ( )
476538 {
477539 try
0 commit comments