Added: Open Wiki

This commit is contained in:
TheJoKlLa 2022-07-18 18:54:23 +02:00
parent 79505ead2c
commit e20e585426
19 changed files with 381 additions and 23 deletions

View File

@ -81,6 +81,7 @@
<Compile Include="Services\APIService.cs" />
<Compile Include="Services\APIService_New.cs" />
<Compile Include="Services\APIServiceConnection.cs" />
<Compile Include="Services\BrowserService.cs" />
<Compile Include="Services\PreferenceStorageService.cs" />
<Compile Include="Services\SecretStorage.cs" />
<Compile Include="Services\VersioningService.cs" />

View File

@ -1,5 +1,6 @@
using Borepin.Droid.Services;
using Borepin.Service;
using Borepin.Service.Browser;
using Borepin.Service.Storage;
using Borepin.Service.Versioning;
using Prism;
@ -14,6 +15,7 @@ namespace Borepin.Droid
containerRegistry.Register<IPreferenceStorageService, PreferenceStorageService>();
containerRegistry.Register<ISecretStorageService, SecretStorage>();
containerRegistry.Register<IVersioningService, VersioningService>();
containerRegistry.Register<IBrowserService, BrowserService>();
containerRegistry.RegisterSingleton<IAPIService, APIService>();
}

View File

@ -0,0 +1,51 @@
using Borepin.Service.Browser;
using System;
using System.Threading.Tasks;
using Xamarin.Essentials;
namespace Borepin.Droid.Services
{
public class BrowserService : IBrowserService
{
private Xamarin.Essentials.BrowserLaunchOptions ConvertBrowserLaunchOptions(Service.Browser.BrowserLaunchOptions browserLaunchOptions)
{
return new Xamarin.Essentials.BrowserLaunchOptions()
{
Flags = (Xamarin.Essentials.BrowserLaunchFlags)browserLaunchOptions.Flags,
LaunchMode = (Xamarin.Essentials.BrowserLaunchMode)browserLaunchOptions.LaunchMode,
PreferredControlColor = browserLaunchOptions.PreferredControlColor,
PreferredToolbarColor = browserLaunchOptions.PreferredToolbarColor,
TitleMode = (Xamarin.Essentials.BrowserTitleMode)browserLaunchOptions.TitleMode
};
}
public async Task OpenAsync(string uri)
{
await Browser.OpenAsync(uri).ConfigureAwait(false);
}
public async Task OpenAsync(string uri, Service.Browser.BrowserLaunchMode browserLaunchMode)
{
await Browser.OpenAsync(uri, (Xamarin.Essentials.BrowserLaunchMode)browserLaunchMode).ConfigureAwait(false);
}
public async Task OpenAsync(string uri, Service.Browser.BrowserLaunchOptions browserLaunchOptions)
{
await Browser.OpenAsync(uri, ConvertBrowserLaunchOptions(browserLaunchOptions));
}
public async Task OpenAsync(Uri uri)
{
await Browser.OpenAsync(uri).ConfigureAwait(false);
}
public async Task OpenAsync(Uri uri, Service.Browser.BrowserLaunchMode browserLaunchMode)
{
await Browser.OpenAsync(uri, (Xamarin.Essentials.BrowserLaunchMode)browserLaunchMode).ConfigureAwait(false);
}
public async Task OpenAsync(Uri uri, Service.Browser.BrowserLaunchOptions browserLaunchOptions)
{
await Browser.OpenAsync(uri, ConvertBrowserLaunchOptions(browserLaunchOptions));
}
}
}

View File

@ -99,6 +99,7 @@
<Compile Include="PlatformInitializer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\APIService.cs" />
<Compile Include="Services\BrowserService.cs" />
<Compile Include="Services\PreferenceStorageService.cs" />
<Compile Include="Services\SecretStorageService.cs" />
<Compile Include="Services\VersioningService.cs" />

View File

@ -4,6 +4,7 @@ using Prism.Ioc;
using Borepin.Service.Storage;
using Borepin.Service.Versioning;
using Borepin.Service;
using Borepin.Service.Browser;
namespace Borepin.UWP
{
@ -14,6 +15,7 @@ namespace Borepin.UWP
containerRegistry.Register<IPreferenceStorageService, PreferenceStorageService>();
containerRegistry.Register<ISecretStorageService, SecretStorageService>();
containerRegistry.Register<IVersioningService, VersioningService>();
containerRegistry.Register<IBrowserService, BrowserService>();
containerRegistry.RegisterSingleton<IAPIService, APIService>();
}

View File

@ -0,0 +1,51 @@
using Borepin.Service.Browser;
using System;
using System.Threading.Tasks;
using Xamarin.Essentials;
namespace Borepin.UWP.Services
{
public class BrowserService : IBrowserService
{
private Xamarin.Essentials.BrowserLaunchOptions ConvertBrowserLaunchOptions(Service.Browser.BrowserLaunchOptions browserLaunchOptions)
{
return new Xamarin.Essentials.BrowserLaunchOptions()
{
Flags = (Xamarin.Essentials.BrowserLaunchFlags)browserLaunchOptions.Flags,
LaunchMode = (Xamarin.Essentials.BrowserLaunchMode)browserLaunchOptions.LaunchMode,
PreferredControlColor = browserLaunchOptions.PreferredControlColor,
PreferredToolbarColor = browserLaunchOptions.PreferredToolbarColor,
TitleMode = (Xamarin.Essentials.BrowserTitleMode)browserLaunchOptions.TitleMode
};
}
public async Task OpenAsync(string uri)
{
await Browser.OpenAsync(uri).ConfigureAwait(false);
}
public async Task OpenAsync(string uri, Service.Browser.BrowserLaunchMode browserLaunchMode)
{
await Browser.OpenAsync(uri, (Xamarin.Essentials.BrowserLaunchMode)browserLaunchMode).ConfigureAwait(false);
}
public async Task OpenAsync(string uri, Service.Browser.BrowserLaunchOptions browserLaunchOptions)
{
await Browser.OpenAsync(uri, ConvertBrowserLaunchOptions(browserLaunchOptions));
}
public async Task OpenAsync(Uri uri)
{
await Browser.OpenAsync(uri).ConfigureAwait(false);
}
public async Task OpenAsync(Uri uri, Service.Browser.BrowserLaunchMode browserLaunchMode)
{
await Browser.OpenAsync(uri, (Xamarin.Essentials.BrowserLaunchMode)browserLaunchMode).ConfigureAwait(false);
}
public async Task OpenAsync(Uri uri, Service.Browser.BrowserLaunchOptions browserLaunchOptions)
{
await Browser.OpenAsync(uri, ConvertBrowserLaunchOptions(browserLaunchOptions));
}
}
}

View File

@ -82,6 +82,7 @@
<Compile Include="Main.cs" />
<Compile Include="AppDelegate.cs" />
<Compile Include="Services\APIService.cs" />
<Compile Include="Services\BrowserService.cs" />
<Compile Include="Services\PreferenceStorageService.cs" />
<Compile Include="Services\SecretStorageService.cs" />
<Compile Include="Services\VersioningService.cs" />

View File

@ -1,5 +1,6 @@
using Borepin.iOS.Services;
using Borepin.Service;
using Borepin.Service.Browser;
using Borepin.Service.Storage;
using Borepin.Service.Versioning;
using Prism;
@ -14,6 +15,7 @@ namespace Borepin.iOS
containerRegistry.Register<IPreferenceStorageService, PreferenceStorageService>();
containerRegistry.Register<ISecretStorageService, SecretStorageService>();
containerRegistry.Register<IVersioningService, VersioningService>();
containerRegistry.Register<IBrowserService, BrowserService>();
containerRegistry.RegisterSingleton<IAPIService, APIService>();
}

View File

@ -0,0 +1,51 @@
using Borepin.Service.Browser;
using System;
using System.Threading.Tasks;
using Xamarin.Essentials;
namespace Borepin.iOS.Services
{
public class BrowserService : IBrowserService
{
private Xamarin.Essentials.BrowserLaunchOptions ConvertBrowserLaunchOptions(Service.Browser.BrowserLaunchOptions browserLaunchOptions)
{
return new Xamarin.Essentials.BrowserLaunchOptions()
{
Flags = (Xamarin.Essentials.BrowserLaunchFlags)browserLaunchOptions.Flags,
LaunchMode = (Xamarin.Essentials.BrowserLaunchMode)browserLaunchOptions.LaunchMode,
PreferredControlColor = browserLaunchOptions.PreferredControlColor,
PreferredToolbarColor = browserLaunchOptions.PreferredToolbarColor,
TitleMode = (Xamarin.Essentials.BrowserTitleMode)browserLaunchOptions.TitleMode
};
}
public async Task OpenAsync(string uri)
{
await Browser.OpenAsync(uri).ConfigureAwait(false);
}
public async Task OpenAsync(string uri, Service.Browser.BrowserLaunchMode browserLaunchMode)
{
await Browser.OpenAsync(uri, (Xamarin.Essentials.BrowserLaunchMode)browserLaunchMode).ConfigureAwait(false);
}
public async Task OpenAsync(string uri, Service.Browser.BrowserLaunchOptions browserLaunchOptions)
{
await Browser.OpenAsync(uri, ConvertBrowserLaunchOptions(browserLaunchOptions));
}
public async Task OpenAsync(Uri uri)
{
await Browser.OpenAsync(uri).ConfigureAwait(false);
}
public async Task OpenAsync(Uri uri, Service.Browser.BrowserLaunchMode browserLaunchMode)
{
await Browser.OpenAsync(uri, (Xamarin.Essentials.BrowserLaunchMode)browserLaunchMode).ConfigureAwait(false);
}
public async Task OpenAsync(Uri uri, Service.Browser.BrowserLaunchOptions browserLaunchOptions)
{
await Browser.OpenAsync(uri, ConvertBrowserLaunchOptions(browserLaunchOptions));
}
}
}

View File

@ -26,6 +26,7 @@ namespace Borepin.Model
//Space = new SpaceVisualize(_Machine.Space);
Name = _Machine.Name;
Description = _Machine.Description;
Wiki = _Machine.Wiki;
State = _Machine.State;
if(_Machine.Manager.Just != null)
@ -106,6 +107,13 @@ namespace Borepin.Model
set => SetProperty(ref _Description, value);
}
private string _Wiki;
public string Wiki
{
get => _Wiki;
set => SetProperty(ref _Wiki, value);
}
private MachineState _State;
public MachineState State
{

View File

@ -22,31 +22,38 @@
<ActivityIndicator IsRunning="{Binding IsBusy}"></ActivityIndicator>
</StackLayout>
<StackLayout IsVisible="{Binding IsBusy, Converter={StaticResource InvertBoolConverter}}">
<StackLayout IsVisible="{Binding IsConnected}">
<Label Text="{Binding MachineItem.Name}" Style="{StaticResource LabelStyle_Title}"/>
<Label Text="{Binding MachineItem.Description}" Style="{StaticResource Style_Label_Text_Center}"/>
<StackLayout IsVisible="{Binding MachineItem.CanUse}">
<Button Text="{x:Static resource_text:TextResource.MachinePage_Use}" Command="{Binding UseMachineCommand}" Style="{StaticResource Style_Button_Primary}"/>
<Grid IsVisible="{Binding IsConnected}">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackLayout Grid.Row="0">
<Label Text="{Binding MachineItem.Name}" Style="{StaticResource LabelStyle_Title}"/>
<Label Text="{Binding MachineItem.Description}" Style="{StaticResource Style_Label_Text_Center}"/>
<StackLayout Orientation="Horizontal" IsVisible="{Binding MachineItem.CurrentUser, Converter={StaticResource IsNotNullBoolConverter}}">
<Label Text="{x:Static resource_text:TextResource.MachinePage_CurrentUser}" Style="{StaticResource Style_Label_Property_Title}"/>
<Label Text="{Binding MachineItem.CurrentUser.Username}" Style="{StaticResource Style_Label_Property_Text}"/>
</StackLayout>
<Button Text="{x:Static resource_text:TextResource.MachinePage_Use}" IsVisible="{Binding MachineItem.CanUse}" Command="{Binding UseMachineCommand}" Style="{StaticResource Style_Button_Primary}"/>
<Label Text="{x:Static resource_text:TextResource.MachinePage_CanNotUseByPermission}" IsVisible="{Binding MachineItem.CanNotUseByPermission}" Style="{StaticResource Style_Label_Text_Center}"/>
<Button Text="{x:Static resource_text:TextResource.MachinePage_GiveBack}" IsVisible="{Binding MachineItem.CanInUse}" Command="{Binding GiveBackMachineCommand}" Style="{StaticResource Style_Button_Primary}"/>
</StackLayout>
<StackLayout IsVisible="{Binding MachineItem.CanNotUseByPermission}">
<Label Text="{x:Static resource_text:TextResource.MachinePage_CanNotUseByPermission}" Style="{StaticResource Style_Label_Text_Center}"/>
<StackLayout Grid.Row="1" VerticalOptions="End">
<Button VerticalOptions="End" Text="{x:Static resource_text:TextResource.MachinePage_OpenWiki}" IsVisible="{Binding MachineItem.Wiki, Converter={StaticResource IsNotNullBoolConverter}}" Command="{Binding OpenWikiCommand}" Style="{StaticResource Style_Button_Primary}"/>
</StackLayout>
<StackLayout IsVisible="{Binding MachineItem.CanInUse}">
<Button Text="{x:Static resource_text:TextResource.MachinePage_GiveBack}" Command="{Binding GiveBackMachineCommand}" Style="{StaticResource Style_Button_Primary}"/>
</StackLayout>
<StackLayout IsVisible="{Binding MachineItem.CurrentUser, Converter={StaticResource IsNotNullBoolConverter}}">
<Label Text="{x:Static resource_text:TextResource.MachinePage_CurrentUser}" Style="{StaticResource Style_Label_Property_Title}"/>
<Label Text="{Binding MachineItem.CurrentUser.Username}" Style="{StaticResource Style_Label_Property_Text}"/>
</StackLayout>
<StackLayout IsVisible="{Binding MachineItem.LastUser, Converter={StaticResource IsNotNullBoolConverter}}">
<Label Text="{x:Static resource_text:TextResource.MachinePage_LastUser}" Style="{StaticResource Style_Label_Property_Title}"/>
<Label Text="{Binding MachineItem.LastUser.Username}" Style="{StaticResource Style_Label_Property_Text}"/>
</StackLayout>
<StackLayout IsVisible="{Binding MachineItem.CanManage}">
<StackLayout Grid.Row="2" VerticalOptions="End" IsVisible="{Binding MachineItem.CanManage}">
<Label Text="{x:Static resource_text:TextResource.MachinePage_ManageMachine}" Style="{StaticResource Style_Label_Property_Title}"/>
<StackLayout Margin="10, 0, 0, 20" Orientation="Horizontal" IsVisible="{Binding MachineItem.LastUser, Converter={StaticResource IsNotNullBoolConverter}}">
<Label Text="{x:Static resource_text:TextResource.MachinePage_LastUser}" Style="{StaticResource Style_Label_Property_Title}"/>
<Label Text="{Binding MachineItem.LastUser.Username}" Style="{StaticResource Style_Label_Property_Text}" Margin="10, 0, 0, 0"/>
</StackLayout>
<Button Text="{x:Static resource_text:TextResource.MachinePage_ForceFree}" Command="{Binding ForceFreeMachineCommand}" Style="{StaticResource Style_Button_Primary}"/>
<Button Text="{x:Static resource_text:TextResource.MachinePage_ForceBlock}" Command="{Binding ForceBlockMachineCommand}" Style="{StaticResource Style_Button_Admin}"/>
<Button Text="{x:Static resource_text:TextResource.MachinePage_ForceDisable}" Command="{Binding ForceDisableMachineCommand}" Style="{StaticResource Style_Button_Admin}"/>
</StackLayout>
</StackLayout>
</Grid>
<Label Text="{x:Static resource_text:TextResource.PLEASECONNECTTOSERVER}" IsVisible="{Binding IsConnected, Converter={StaticResource InvertBoolConverter}}"></Label>
</StackLayout>
</StackLayout>

View File

@ -10,6 +10,7 @@ using Borepin.Service;
using Borepin.Base.Exceptions;
using Capnp.Rpc;
using System;
using Borepin.Service.Browser;
namespace Borepin.PageModel
{
@ -18,14 +19,20 @@ namespace Borepin.PageModel
#region Private Fields
private string _ID;
private Machine _Machine;
private IBrowserService _BrowserService;
#endregion
#region Contructors
public MachinePageModel(INavigationService navigationService, IPageDialogService pageDialogService, IAPIService apiService) : base(navigationService, pageDialogService, apiService)
public MachinePageModel(INavigationService navigationService, IPageDialogService pageDialogService, IAPIService apiService, IBrowserService browserService) : base(navigationService, pageDialogService, apiService)
{
_BrowserService = browserService;
UseMachineCommand = new DelegateCommand(UseMachineCommandExecute);
GiveBackMachineCommand = new DelegateCommand(GiveBackMachineCommandExecute);
ForceFreeMachineCommand = new DelegateCommand(ForceFreeMachineCommandExecute);
ForceBlockMachineCommand = new DelegateCommand(ForceBlockMachineCommandExecute);
ForceDisableMachineCommand = new DelegateCommand(ForceDisableMachineCommandExecute);
OpenWikiCommand = new DelegateCommand(OpenWikiCommandExecute);
}
#endregion
@ -149,6 +156,86 @@ namespace Borepin.PageModel
IsBusy = false;
}
private ICommand _ForceBlockMachineCommand;
public ICommand ForceBlockMachineCommand
{
get => _ForceBlockMachineCommand;
set => SetProperty(ref _ForceBlockMachineCommand, value);
}
public async void ForceBlockMachineCommandExecute()
{
IsBusy = true;
if (_API.IsConnected)
{
try
{
Machine.IManageInterface manageInterface = _Machine.Manage;
await manageInterface.Block().ConfigureAwait(false);
await LoadAPIData().ConfigureAwait(false);
}
catch (RpcException exception) when (string.Equals(exception.Message, "RPC connection is broken. Task would never return.", StringComparison.Ordinal))
{
Log.Debug("RPC Connection Loss");
}
}
IsBusy = false;
}
private ICommand _ForceDisableMachineCommand;
public ICommand ForceDisableMachineCommand
{
get => _ForceDisableMachineCommand;
set => SetProperty(ref _ForceDisableMachineCommand, value);
}
public async void ForceDisableMachineCommandExecute()
{
IsBusy = true;
if (_API.IsConnected)
{
try
{
Machine.IManageInterface manageInterface = _Machine.Manage;
await manageInterface.Disabled().ConfigureAwait(false);
await LoadAPIData().ConfigureAwait(false);
}
catch (RpcException exception) when (string.Equals(exception.Message, "RPC connection is broken. Task would never return.", StringComparison.Ordinal))
{
Log.Debug("RPC Connection Loss");
}
}
IsBusy = false;
}
private ICommand _OpenWikiCommand;
public ICommand OpenWikiCommand
{
get => _OpenWikiCommand;
set => SetProperty(ref _OpenWikiCommand, value);
}
public async void OpenWikiCommandExecute()
{
if(_Machine != null && _Machine.Wiki != null)
{
try
{
await _BrowserService.OpenAsync(_Machine.Wiki).ConfigureAwait(false);
}
catch
{
//TODO: Do something
}
}
}
#endregion
}
}

View File

@ -370,7 +370,25 @@ namespace Borepin.Resources.Text {
}
/// <summary>
/// Looks up a localized string similar to Force Free.
/// Looks up a localized string similar to Block Machine.
/// </summary>
internal static string MachinePage_ForceBlock {
get {
return ResourceManager.GetString("MachinePage_ForceBlock", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Disable Machine.
/// </summary>
internal static string MachinePage_ForceDisable {
get {
return ResourceManager.GetString("MachinePage_ForceDisable", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Free Machine.
/// </summary>
internal static string MachinePage_ForceFree {
get {
@ -405,6 +423,15 @@ namespace Borepin.Resources.Text {
}
}
/// <summary>
/// Looks up a localized string similar to Open Wiki.
/// </summary>
internal static string MachinePage_OpenWiki {
get {
return ResourceManager.GetString("MachinePage_OpenWiki", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Use.
/// </summary>

View File

@ -222,8 +222,14 @@ Ask in your Space if you can be trained on the machine to be unlocked for the ma
<data name="MachinePage_CurrentUser" xml:space="preserve">
<value>Current User:</value>
</data>
<data name="MachinePage_ForceBlock" xml:space="preserve">
<value>Block Machine</value>
</data>
<data name="MachinePage_ForceDisable" xml:space="preserve">
<value>Disable Machine</value>
</data>
<data name="MachinePage_ForceFree" xml:space="preserve">
<value>Force Free</value>
<value>Free Machine</value>
</data>
<data name="MachinePage_GiveBack" xml:space="preserve">
<value>GiveBack</value>
@ -234,6 +240,9 @@ Ask in your Space if you can be trained on the machine to be unlocked for the ma
<data name="MachinePage_ManageMachine" xml:space="preserve">
<value>Manage Machine:</value>
</data>
<data name="MachinePage_OpenWiki" xml:space="preserve">
<value>Open Wiki</value>
</data>
<data name="MachinePage_Use" xml:space="preserve">
<value>Use</value>
</data>

View File

@ -0,0 +1,10 @@
namespace Borepin.Service.Browser
{
public enum BrowserLaunchFlags
{
None = 0,
LaunchAdjacent = 1,
PresentAsPageSheet = 2,
PresentAsFormSheet = 4,
}
}

View File

@ -0,0 +1,8 @@
namespace Borepin.Service.Browser
{
public enum BrowserLaunchMode
{
SystemPreferred = 0,
External = 1
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Drawing;
namespace Borepin.Service.Browser
{
public class BrowserLaunchOptions
{
public BrowserLaunchFlags Flags;
public BrowserLaunchMode LaunchMode;
public Nullable<Color> PreferredControlColor;
public Nullable<Color> PreferredToolbarColor;
public BrowserTitleMode TitleMode;
}
}

View File

@ -0,0 +1,9 @@
namespace Borepin.Service.Browser
{
public enum BrowserTitleMode
{
Default = 0,
Show = 1,
Hide = 2
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Threading.Tasks;
namespace Borepin.Service.Browser
{
public interface IBrowserService
{
Task OpenAsync(string uri);
Task OpenAsync(string uri, BrowserLaunchMode browserLaunchMode);
Task OpenAsync(string uri, BrowserLaunchOptions browserLaunchOptions);
Task OpenAsync(Uri uri);
Task OpenAsync(Uri uri, BrowserLaunchMode browserLaunchMode);
Task OpenAsync(Uri uri, BrowserLaunchOptions browserLaunchOptions);
}
}