132 lines
5.9 KiB
C#
132 lines
5.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Security;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Input;
|
|
using JD.Localization.Core.Model;
|
|
using JD.LocalizationExport.Service.API;
|
|
using JD.LocalizationExport.Service.Model.Options;
|
|
using JD.Oasis.Module.Actions;
|
|
using JD.Oasis.Module.View;
|
|
using JD.Oasis.Module.ViewModel;
|
|
using JD.Oasis.Service.API;
|
|
using JD.Oasis.Service.Implementation;
|
|
using Plume.Core.Logging;
|
|
using Plume.Icons;
|
|
using Plume.Interfaces.Modules;
|
|
using Plume.Interfaces.WPF.Actions;
|
|
using Plume.Interfaces.WPF.Dialogs;
|
|
using Plume.Interfaces.WPF.Modules;
|
|
using Plume.Interfaces.WPF.Notifications;
|
|
using Plume.Interfaces.WPF.StatusBar;
|
|
using Plume.Interfaces.WPF.ToolBar;
|
|
using Plume.Interfaces.WPF.Window;
|
|
using Plume.Perforce.Service.Api;
|
|
using Ubisoft.BasicControls;
|
|
|
|
namespace JD.Oasis.Module
|
|
{
|
|
public class OasisModule : IWpfModule
|
|
{
|
|
private OasisViewModel _oasisViewModel;
|
|
private string _perforceData;
|
|
private string _perforceCode;
|
|
|
|
public void Dispose()
|
|
{
|
|
// Nothing to dispose
|
|
}
|
|
|
|
public void Setup(IModuleSetup setup)
|
|
{
|
|
if (!(setup is OasisModuleSetup oasisSetup))
|
|
{
|
|
throw new ArgumentException($"Expecting an {nameof(OasisModuleSetup)} not a {setup.GetType()}", nameof(setup));
|
|
}
|
|
|
|
_perforceData = oasisSetup.PerforceDataHost;
|
|
if (string.IsNullOrEmpty(_perforceData))
|
|
{
|
|
throw new ArgumentNullException("You must specify a valid Data Perforce server!");
|
|
}
|
|
|
|
_perforceCode = oasisSetup.PerforceCodeHost;
|
|
if (string.IsNullOrEmpty(_perforceCode))
|
|
{
|
|
throw new ArgumentNullException("You must specify a valid Code Perforce server!");
|
|
}
|
|
}
|
|
|
|
public void Initialize(IWpfModuleContext context)
|
|
{
|
|
IWindowManager windowService = context.WindowManager ??
|
|
throw new ArgumentNullException(nameof(context.WindowManager));
|
|
IActionManager actionService = context.ActionManager ??
|
|
throw new ArgumentNullException(nameof(context.ActionManager));
|
|
IToolBarManager toolbarService = context.ToolBarManager ??
|
|
throw new ArgumentNullException(nameof(context.ToolBarManager));
|
|
IStatusBarManager statusBarService = context.StatusBarManager ??
|
|
throw new ArgumentNullException(nameof(context.StatusBarManager));
|
|
|
|
INotificationManager notificationService = context.NotificationManager ??
|
|
throw new ArgumentNullException(nameof(context.NotificationManager));
|
|
|
|
ILogger logger = context.Logger ??
|
|
throw new ArgumentNullException(nameof(context.Logger));
|
|
|
|
IOasisService oasisService = context.GetService<IOasisService>() ??
|
|
throw new ArgumentNullException(nameof(IOasisService));
|
|
|
|
ILocalizationExportService exportService = context.GetService<ILocalizationExportService>() ??
|
|
throw new ArgumentNullException(nameof(ILocalizationExportService));
|
|
|
|
IPerforceService perforceService = context.GetService<IPerforceService>() ??
|
|
throw new ArgumentNullException(nameof(IPerforceService));
|
|
|
|
// Set up a credential manager for Rosetta since the tool can be used in a context outside Ubisoft Active Directory
|
|
oasisService.SetCredentialsManager(new CredentialsManager(() => AskLoginCredentials(context.DialogManager)));
|
|
|
|
// Works but... Meh
|
|
var oasisViewModelTask = OasisViewModel.CreateAsync(oasisService, exportService, perforceService, _perforceData, _perforceCode, statusBarService, notificationService, logger).ConfigureAwait(false);
|
|
oasisViewModelTask.GetAwaiter().OnCompleted(async () =>
|
|
await Application.Current.Dispatcher.InvokeAsync(async () =>
|
|
{
|
|
_oasisViewModel = await oasisViewModelTask;
|
|
|
|
OasisToolWindow oasisToolWindow = new OasisToolWindow
|
|
{
|
|
DataContext = _oasisViewModel
|
|
};
|
|
windowService.AddToolWindow("OasisWindow",
|
|
"Oasis",
|
|
StandardIcon.TreeView,
|
|
oasisToolWindow,
|
|
DockingSide.Right,
|
|
new KeyGesture(Key.O, ModifierKeys.Control | ModifierKeys.Alt));
|
|
|
|
RefreshOasisDataAction refreshAction = new RefreshOasisDataAction(await oasisViewModelTask);
|
|
actionService.Register(() => refreshAction);
|
|
toolbarService.AddTextButton("Rosetta", refreshAction);
|
|
}));
|
|
}
|
|
|
|
private Tuple<string, string> AskLoginCredentials(Plume.Interfaces.WPF.Dialog.IDialogManager dialogManager)
|
|
{
|
|
DialogButton result = dialogManager.ShowLoginBox(
|
|
"Login to Oasis Web Service",
|
|
"Please use your Ubisoft credentials to login into Oasis Web Service",
|
|
out string userName, out string password);
|
|
|
|
return result?.StandardButton == StandardButton.Ok ? Tuple.Create(userName, password) : null;
|
|
}
|
|
|
|
public async Task OnLocalizationExportLaunched(IDictionary<ExportType, ExportOptionsModel> exportTypesAndOptionsToExecute, IEnumerable<UafLanguage> languagesToExport)
|
|
{
|
|
if (_oasisViewModel != null)
|
|
{
|
|
await _oasisViewModel.OnLocalizationExportLaunched(exportTypesAndOptionsToExecute, languagesToExport);
|
|
}
|
|
}
|
|
}
|
|
}
|