Added: ServerPage

This commit is contained in:
TheJoKlLa 2021-01-29 22:54:35 +01:00
parent bf9b2f19b7
commit 8812b2bfd1
13 changed files with 217 additions and 60 deletions

View File

@ -6,6 +6,7 @@ using Borepin.Dialog;
using Borepin.DialogModel;
using Borepin.Service.Connections;
using Borepin.Service.BFFH;
using Borepin.Service.Credentials;
namespace Borepin
{
@ -49,7 +50,10 @@ namespace Borepin
// Register Service
IConnectionService connectionService = new ConnectionService();
containerRegistry.RegisterInstance<IConnectionService>(connectionService);
containerRegistry.RegisterInstance<IBFFHService>(new BFFHService(connectionService));
ICredentialService credentialService = new CredentialService();
containerRegistry.RegisterInstance<ICredentialService>(credentialService);
containerRegistry.RegisterInstance<IBFFHService>(new BFFHService(connectionService, credentialService));
containerRegistry.RegisterInstance<IConnectionService>(new ConnectionService());
}
}

View File

@ -0,0 +1,19 @@
using System;
using System.Globalization;
using Xamarin.Forms;
namespace Borepin.Converter
{
public class InvertBoolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return !(bool)value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return !(bool)value;
}
}
}

View File

@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using Borepin.Model;
using Xamarin.Forms;
namespace Borepin.Converter
@ -11,7 +8,7 @@ namespace Borepin.Converter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value != null ? true : false;
return value != null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)

View File

@ -8,6 +8,7 @@ namespace Borepin.DialogModel
{
public class ConfirmDialogModel : BindableBase, IDialogAware
{
private object _Instance;
public ConfirmDialogModel()
{
ConfirmCommand = new DelegateCommand(ConfirmCommandExecute);
@ -40,7 +41,14 @@ namespace Borepin.DialogModel
}
private void ConfirmCommandExecute()
{
RequestClose(new DialogParameters { { "confirm", true } });
IDialogParameters parameters = new DialogParameters()
{
{ "result", "confirm" },
{ "instance", _Instance }
};
RequestClose(parameters);
}
private ICommand _AbortCommand;
@ -71,6 +79,7 @@ namespace Borepin.DialogModel
{
Title = parameters.GetValue<string>("title");
Message = parameters.GetValue<string>("message");
_Instance = parameters.GetValue<object>("instance");
}
}
}

View File

@ -8,6 +8,17 @@
</NavigationPage.TitleView>
<ContentPage.Content>
<StackLayout>
<Label Text="Active Connection" IsVisible="{Binding HasActiveConnection}"/>
<ListView ItemsSource="{Binding ActiveConnection}" IsVisible="{Binding HasActiveConnection}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<views:ServerListItemView />
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Label Text="Last Connections"/>
<ListView ItemsSource="{Binding ServerListItemViewModel_List}">
<ListView.ItemTemplate>
<DataTemplate>

View File

@ -1,12 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Borepin.Page.ServerPage">
x:Class="Borepin.Page.ServerPage"
xmlns:converter="clr-namespace:Borepin.Converter">
<ContentPage.Resources>
<ResourceDictionary>
<converter:InvertBoolConverter x:Key="invertBool" />
</ResourceDictionary>
</ContentPage.Resources>
<ContentPage.Content>
<StackLayout>
<Label Text="Server Page"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
<Label Text="{Binding Connection_Item.Address}"/>
<Button IsVisible="{Binding IsConnected, Converter={StaticResource invertBool}}" Text="Connect" Command="{Binding ConnectCommand}"/>
<Button IsVisible="{Binding IsConnected}" Text="Disconnect" Command="{Binding ConnectCommand}"/>
<Button Text="Delete" Command="{Binding DeleteCommand}"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>

View File

@ -11,11 +11,9 @@ namespace Borepin.PageModel
{
public class LoginPasswordPageModel : BindableBase
{
private INavigationService _NavigationService;
private IBFFHService _BFFHService;
private IConnectionService _ConnectionService;
private string _KnownUsername;
private readonly INavigationService _NavigationService;
private readonly IBFFHService _BFFHService;
private readonly IConnectionService _ConnectionService;
public LoginPasswordPageModel(INavigationService navigationService, IBFFHService bffhService, IConnectionService connectionService)
{
@ -30,13 +28,7 @@ namespace Borepin.PageModel
private void LoadData()
{
_KnownUsername = _BFFHService.ActiveConnection.Username;
if (_KnownUsername != null)
{
Username = _KnownUsername;
Password = "********";
}
}
private string _Username;
@ -62,21 +54,13 @@ namespace Borepin.PageModel
private async void AuthenticateCommandExecuted()
{
if(_KnownUsername == Username)
{
await _BFFHService.Authenticate();
await _ConnectionService.LogConnect(_BFFHService.ActiveConnection);
}
else
{
Connection connection_update = _BFFHService.ActiveConnection;
Connection connection_update = _BFFHService.ActiveConnection;
connection_update.Username = Username;
await _BFFHService.Authenticate(connection_update, Password);
connection_update.Username = Username;
await _BFFHService.Authenticate(connection_update, Password);
await _ConnectionService.AddConnection(_BFFHService.ActiveConnection);
await _ConnectionService.LogConnect(_BFFHService.ActiveConnection);
}
await _ConnectionService.AddConnection(_BFFHService.ActiveConnection);
await _ConnectionService.LogConnect(_BFFHService.ActiveConnection);
var result = await _NavigationService.NavigateAsync("/MainPage/NavigationPage/MachinesPage");

View File

@ -9,8 +9,8 @@ namespace Borepin.PageModel
{
public class MachinePageModel : BindableBase, INavigationAware
{
private INavigationService _NavigationService;
private IBFFHService _BFFHService;
private readonly INavigationService _NavigationService;
private readonly IBFFHService _BFFHService;
public MachinePageModel(INavigationService navigationService, IBFFHService bffhService)
{

View File

@ -9,7 +9,7 @@ namespace Borepin.PageModel
{
public class MachinesPageModel : BindableBase
{
private INavigationService _NavigationService;
private readonly INavigationService _NavigationService;
public MachinesPageModel(INavigationService navigationService)
{
@ -28,8 +28,10 @@ namespace Borepin.PageModel
{
Machine machine = obj as Machine;
NavigationParameters navigationParams = new NavigationParameters();
navigationParams.Add("machineID", machine.ID);
NavigationParameters navigationParams = new NavigationParameters
{
{ "machineID", machine.ID }
};
INavigationResult result = await _NavigationService.NavigateAsync($"MachinePage", navigationParams);
if (!result.Success)

View File

@ -14,9 +14,9 @@ namespace Borepin.PageModel
{
public class ServerListPageModel : BindableBase, INavigationAware
{
private INavigationService _NavigationService;
private IConnectionService _ConnectionService;
private IBFFHService _BFFHService;
private readonly INavigationService _NavigationService;
private readonly IConnectionService _ConnectionService;
private readonly IBFFHService _BFFHService;
public ServerListPageModel(INavigationService navigationService, IConnectionService connectionService, IBFFHService bffhService)
{
@ -26,19 +26,30 @@ namespace Borepin.PageModel
AddInstancesCommand = new DelegateCommand(AddInstancesCommandExecuted);
SelectInstanceCommand = new DelegateCommand<object>(SelectInstanceCommandExecuted);
Task.Run(LoadData);
}
private async Task<bool> LoadData()
{
List<Connection> list = await _ConnectionService.GetConnectionList();
ServerListItemViewModel_List = list.Select(x => new ServerListItemViewModel(x)).ToList();
if(_BFFHService.ActiveConnection != null)
if (_BFFHService.ActiveConnection != null)
{
ActiveConnection = new ServerListItemViewModel(_BFFHService.ActiveConnection);
ActiveConnection = new List<ServerListItemViewModel>
{
new ServerListItemViewModel(_BFFHService.ActiveConnection)
};
list.Remove(_BFFHService.ActiveConnection);
HasActiveConnection = true;
}
else
{
HasActiveConnection = false;
}
//list = (List<Connection>)list.OrderBy(x => x.LastTime);
ServerListItemViewModel_List = list.Select(x => new ServerListItemViewModel(x)).ToList();
return await Task.FromResult(true);
}
@ -51,12 +62,19 @@ namespace Borepin.PageModel
set => SetProperty(ref _ServerListItemViewModel_List, value);
}
private ServerListItemViewModel _ActiveConnection;
public ServerListItemViewModel ActiveConnection
private List<ServerListItemViewModel> _ActiveConnection;
public List<ServerListItemViewModel> ActiveConnection
{
get => _ActiveConnection;
set => SetProperty(ref _ActiveConnection, value);
}
private bool _HasActiveConnection = false;
public bool HasActiveConnection
{
get => _HasActiveConnection;
set => SetProperty(ref _HasActiveConnection, value);
}
#endregion
#region Commands
@ -70,10 +88,12 @@ namespace Borepin.PageModel
{
ServerListItemViewModel viewmodel = obj as ServerListItemViewModel;
NavigationParameters navigationParams = new NavigationParameters();
navigationParams.Add("instance", viewmodel.Instance);
NavigationParameters parameters = new NavigationParameters
{
{ "instance", viewmodel.Instance }
};
INavigationResult result = await _NavigationService.NavigateAsync($"ServerPage", navigationParams);
INavigationResult result = await _NavigationService.NavigateAsync($"ServerPage", parameters);
if (!result.Success)
{
System.Diagnostics.Debugger.Break();

View File

@ -1,19 +1,34 @@
using Borepin.Model;
using Borepin.Service.BFFH;
using Borepin.Service.Connections;
using Borepin.Service.Credentials;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Navigation;
using Prism.Services.Dialogs;
using System.Windows.Input;
namespace Borepin.PageModel
{
public class ServerPageModel : BindableBase, INavigationAware
{
private INavigationService _NavigationService;
private IConnectionService _ConnectionService;
private readonly INavigationService _NavigationService;
private readonly IDialogService _DialogService;
private readonly IConnectionService _ConnectionService;
private readonly IBFFHService _BFFHService;
private readonly ICredentialService _CredentialService;
public ServerPageModel(INavigationService navigationService, IConnectionService connectionService)
public ServerPageModel(INavigationService navigationService, IDialogService dialogService, IConnectionService connectionService, IBFFHService bffhService, ICredentialService credentialService)
{
_NavigationService = navigationService;
_DialogService = dialogService;
_ConnectionService = connectionService;
_BFFHService = bffhService;
_CredentialService = credentialService;
ConnectCommand = new DelegateCommand(ConnectCommandExecuted);
DeleteCommand = new DelegateCommand(DeleteCommandExecuted);
}
#region Properties
@ -23,6 +38,86 @@ namespace Borepin.PageModel
get => _Connection_Item;
set => SetProperty(ref _Connection_Item, value);
}
private bool _IsConnected;
public bool IsConnected
{
get => _IsConnected;
set => SetProperty(ref _IsConnected, value);
}
#endregion
#region Commands
private ICommand _ConnectCommand;
public ICommand ConnectCommand
{
get => _ConnectCommand;
set => SetProperty(ref _ConnectCommand, value);
}
private async void ConnectCommandExecuted()
{
if(IsConnected)
{
await _BFFHService.Disconnect();
IsConnected = false;
}
else
{
await _BFFHService.Connect(Connection_Item);
await _BFFHService.Authenticate();
IsConnected = true;
}
}
private ICommand _DeleteCommand;
public ICommand DeleteCommand
{
get => _DeleteCommand;
set => SetProperty(ref _DeleteCommand, value);
}
private void DeleteCommandExecuted()
{
DialogParameters parameters = new DialogParameters
{
{ "title", "Delete Server" },
{ "message", "Do you really want to delete this Server?" },
{ "instance", Connection_Item }
};
_DialogService.ShowDialog("ConfirmDialog", parameters, DeleteCommandExecuted_Dialog);
}
private async void DeleteCommandExecuted_Dialog(IDialogResult result)
{
if(result.Parameters.GetValue<string>("result") == "confirm")
{
Connection connection = (Connection)result.Parameters.GetValue<object>("instance");
if(_BFFHService.ActiveConnection != null && connection == _BFFHService.ActiveConnection)
{
await _BFFHService.Disconnect();
}
await _ConnectionService.RemoveConnection(connection);
await _CredentialService.RemoveCredentialsAsync(connection);
await _NavigationService.NavigateAsync("/MainPage/NavigationPage/ServerListPage");
}
else
{
INavigationParameters parameters = new NavigationParameters()
{
{ "instance" , result.Parameters.GetValue<object>("instance")}
};
OnNavigatedTo(parameters);
}
}
#endregion
#region INavigationAware
@ -34,6 +129,15 @@ namespace Borepin.PageModel
public void OnNavigatedTo(INavigationParameters parameters)
{
Connection_Item = parameters["instance"] as Connection;
if(_BFFHService.ActiveConnection != null && Connection_Item != null)
{
IsConnected = Connection_Item.Equals(_BFFHService.ActiveConnection);
}
else
{
IsConnected = false;
}
}
#endregion
}

View File

@ -14,10 +14,10 @@ namespace Borepin.Service.BFFH
private FabAccessAPI.Connection _Connection;
public BFFHService(IConnectionService connectionService)
public BFFHService(IConnectionService connectionService, ICredentialService credentialService)
{
_ConnectionService = connectionService;
_CredentialService = new CredentialService();
_CredentialService = credentialService;
}
public Model.Connection ActiveConnection { get; private set; }

View File

@ -61,7 +61,7 @@ namespace FabAccessAPI_Test {
Assert.NotNull(testmachine);
var minfo = await testmachine.GetMInfo();
Assert.NotNull(minfo);
_Log.Info($"Name: {minfo.Name}, Description: {minfo.Description}, State: {minfo.State.ToString()}");
_Log.Info($"Name: {minfo.Name}, Description: {minfo.Description}, State: {minfo.State}");
}
}
}