Skip to content

Commit

Permalink
order models and fix requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali-YousefiTelori committed Dec 4, 2018
1 parent 2cdcc86 commit 42588cf
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cross-Platform/SignalGoTest.Desktop/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<Application.Resources>
<cmd:CommandsViewModel x:Key="CommandsViewModel"/>
</Application.Resources>

<Application.Styles>

<StyleInclude Source="resm:Avalonia.Themes.Default.DefaultTheme.xaml?assembly=Avalonia.Themes.Default"/>
<StyleInclude Source="resm:Avalonia.Themes.Default.Accents.BaseLight.xaml?assembly=Avalonia.Themes.Default"/>
<Style Selector="Button">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

</TextBox>
<TreeView x:Name="TreeViewServices" BorderThickness="1" Background="White" Margin="0,5,0,0" Items="{Binding CurrentConnectionInfo.ItemsSource}" SelectedItem="{Binding SelectedTreeItem}" Grid.Row="1">

<TreeView.DataTemplates>
<TreeDataTemplate DataType="{x:Type self:ServiceDetailsInterface}" ItemsSource="{Binding Methods}">
<StackPanel Orientation="Horizontal">
Expand Down Expand Up @@ -142,8 +143,8 @@
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<TextBox x:Name="newRequestName" Text=""/>
<Button x:Name="btnAddRequest" Content="Add" Grid.Column="1"/>
<TextBox x:Name="newRequestName" Text="{Binding RequestName}"/>
<Button x:Name="btnAddRequest" Command="{Binding AddNewRequestCommand}" Content="Add" Grid.Column="1"/>
</Grid>
<ListBox x:Name="lstRequests" Grid.Row="1" Items="{Binding SelectedItem.Requests,ElementName=TreeViewServices}" SelectedItem="{Binding ServiceDetailsRequestInfo,Mode=OneWayToSource}" SelectedIndex="0">
<ListBox.ItemTemplate>
Expand Down
1 change: 1 addition & 0 deletions Cross-Platform/SignalGoTest.Models/ConnectionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public List<object> ItemsSource
items.AddRange(Items.Services);
items.AddRange(Items.Callbacks);
items.Add(Items.WebApiDetailsInfo);
Items.ProjectDomainDetailsInfo.Models = Items.ProjectDomainDetailsInfo.Models.OrderBy(x => x.ObjectType == SignalGo.Shared.Helpers.SerializeObjectType.Enum).ThenBy(x => x.Name).ToList();
items.Add(Items.ProjectDomainDetailsInfo);
return items;
}
Expand Down
62 changes: 62 additions & 0 deletions Cross-Platform/SignalGoTest.ViewModels/ConnectionInfoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using SignalGoTest.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Net;
Expand Down Expand Up @@ -52,11 +53,16 @@ public ConnectionInfoViewModel()
});
SendCommand = new Command(Send);
HttpUpdateCommand = new Command(HttpUpdate);
AddNewRequestCommand = new Command(AddNewRequest, () =>
{
return SelectedTreeItem is ServiceDetailsMethod;
});
}


private bool _IsAlert;
private string _SearchText = "";
private string _RequestName;
private object _SelectedTreeItem;
public Command ConnectCommand { get; set; }
public Command DisconnectCommand { get; set; }
Expand All @@ -65,6 +71,7 @@ public ConnectionInfoViewModel()
public Command<ServiceDetailsParameterInfo> LoadFullTemplateCommand { get; set; }
public Command SendCommand { get; set; }
public Command HttpUpdateCommand { get; set; }
public Command AddNewRequestCommand { get; set; }

public override bool IsBusy
{
Expand Down Expand Up @@ -161,9 +168,23 @@ public object SelectedTreeItem
{
_SelectedTreeItem = value;
OnPropertyChanged(nameof(SelectedTreeItem));
AddNewRequestCommand.ValidateCanExecute();
}
}

public string RequestName
{
get
{
return _RequestName;
}

set
{
_RequestName = value;
OnPropertyChanged(nameof(RequestName));
}
}

private void Disconnect()
{
Expand Down Expand Up @@ -236,6 +257,7 @@ public async void Connect()

BusyContent = "Receiving data...";
ProviderDetailsInfo result = await provider.GetListOfServicesWithDetials(CurrentConnectionInfo.ServerAddress);
result.ProjectDomainDetailsInfo.Models = result.ProjectDomainDetailsInfo.Models.OrderBy(x => x.ObjectType == SerializeObjectType.Enum).ThenBy(x => x.Name).ToList();
ProviderDetailsInfo oldItems = currentView.Items;
currentView.Items = result;
currentView.OnPropertyChanged("ItemsSource");
Expand Down Expand Up @@ -472,6 +494,46 @@ public async void Send()
}
}

private async void AddNewRequest()
{
try
{
ServiceDetailsMethod selectedMethod = (ServiceDetailsMethod)SelectedTreeItem;
if (selectedMethod == null)
return;
ObservableCollection<ServiceDetailsRequestInfo> requests = selectedMethod.Requests;
string newName = RequestName.Trim();
if (requests.Any(x => x.Name == newName) || string.IsNullOrEmpty(newName))
{
BusyContent = "name is exist or empty!";
IsBusy = true;
await Task.Delay(3000);
return;
}
ServiceDetailsRequestInfo request = new ServiceDetailsRequestInfo() { Name = newName, Parameters = new List<ServiceDetailsParameterInfo>() };
foreach (ServiceDetailsParameterInfo item in selectedMethod.Requests.FirstOrDefault().Parameters)
{
ServiceDetailsParameterInfo clone = item.Clone();
clone.Value = null;
clone.TemplateValue = "";
request.Parameters.Add(clone);
}
requests.Add(request);
RequestName = "";
MainViewModel.This.Save();
}
catch (Exception ex)
{
BusyContent = ex.Message;
IsBusy = true;
await Task.Delay(3000);
}
finally
{
IsBusy = false;
}
}

private async void HttpUpdate()
{
try
Expand Down

0 comments on commit 42588cf

Please sign in to comment.